|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Data item for representing "Add Destination" button in UI. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <HbInputDialog> |
|
20 #include <HbAction> |
|
21 #include <HbMessageBox> |
|
22 #include <HbPopup> |
|
23 #include <cpitemdatahelper.h> |
|
24 #include <cmdestination_shim.h> |
|
25 #include <cmmanager_shim.h> |
|
26 |
|
27 // User includes |
|
28 #include "cpadddestinationentryitemdata.h" |
|
29 #include "cpdestinationgroup.h" |
|
30 #include "OstTraceDefinitions.h" |
|
31 #ifdef OST_TRACE_COMPILER_IN_USE |
|
32 #include "cpadddestinationentryitemdataTraces.h" |
|
33 #endif |
|
34 /*! |
|
35 \class CpAddDestinationEntryItemData |
|
36 \brief This class is a dummy destination. It does not contain |
|
37 access points but clicking it starts new destination |
|
38 creation process. |
|
39 */ |
|
40 |
|
41 // External function prototypes |
|
42 |
|
43 // Local constants |
|
44 |
|
45 // ======== LOCAL FUNCTIONS ======== |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 |
|
50 /*! |
|
51 |
|
52 Constructor. |
|
53 |
|
54 @param[in] itemDataHelper Helper from Control Panel for making connections. |
|
55 @param[in] parent Parent object. |
|
56 */ |
|
57 CpAddDestinationEntryItemData::CpAddDestinationEntryItemData(CpItemDataHelper &itemDataHelper, |
|
58 CpDestinationGroup *parent) |
|
59 : CpSettingFormEntryItemData(itemDataHelper), |
|
60 mParent(parent), |
|
61 mDialog(0) |
|
62 { |
|
63 OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_ENTRY); |
|
64 // Fix connections |
|
65 itemDataHelper.removeConnection(this,SIGNAL(pressed()),this,SLOT(onLaunchView())); |
|
66 itemDataHelper.addConnection(this,SIGNAL(clicked()),this,SLOT(onLaunchView())); |
|
67 OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_EXIT); |
|
68 } |
|
69 |
|
70 /*! |
|
71 Destructor. |
|
72 */ |
|
73 CpAddDestinationEntryItemData::~CpAddDestinationEntryItemData() |
|
74 { |
|
75 OstTraceFunctionEntry0(DUP1_CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_ENTRY); |
|
76 OstTraceFunctionExit0(DUP1_CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_EXIT); |
|
77 } |
|
78 |
|
79 /*! |
|
80 Inherited member from CpSettingFormEntryItemData. When this item is clicked |
|
81 new dialog is started for creating new destination. |
|
82 */ |
|
83 void CpAddDestinationEntryItemData::onLaunchView() |
|
84 { |
|
85 OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_ONLAUNCHVIEW_ENTRY); |
|
86 mDialog = new HbInputDialog(); |
|
87 mDialog->setAttribute(Qt::WA_DeleteOnClose); |
|
88 mDialog->lineEdit()->setMaxLength(DestinationNameMaxLength); |
|
89 mDialog->clearActions(); |
|
90 mDialog->setPromptText(hbTrId("txt_occ_dialog_destination_name")); |
|
91 mDialog->setInputMode(HbInputDialog::TextInput); |
|
92 mOkAction = new HbAction(hbTrId("txt_common_button_ok")); |
|
93 bool connected = connect(mOkAction, |
|
94 SIGNAL(triggered()), |
|
95 this, |
|
96 SLOT(setNewDestinationName())); |
|
97 Q_ASSERT(connected); |
|
98 HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel")); |
|
99 mDialog->addAction(mOkAction); |
|
100 mDialog->addAction(cancelAction); |
|
101 mDialog->show(); |
|
102 OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_ONLAUNCHVIEW_EXIT); |
|
103 } |
|
104 |
|
105 /*! |
|
106 This function is called when user selects OK from destination |
|
107 name query popup. The given name is valited and if the name is |
|
108 valid, new destination is created in commsdat with given name. |
|
109 If validation fails user is promted again for destination name. |
|
110 */ |
|
111 void CpAddDestinationEntryItemData::setNewDestinationName() |
|
112 { |
|
113 OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME_ENTRY); |
|
114 QString destinationName = mDialog->value().toString(); |
|
115 bool destinationNameInvalid = true; |
|
116 CmManagerShim *cmm = NULL; |
|
117 CmDestinationShim *destination = NULL; |
|
118 |
|
119 try { |
|
120 cmm = new CmManagerShim(); |
|
121 if (isDestinationNameValid(destinationName, cmm)) { |
|
122 // Destination name OK. Create new destination. |
|
123 destination = cmm->createDestination(destinationName); |
|
124 destinationNameInvalid = false; |
|
125 } |
|
126 } catch (const std::exception&) { |
|
127 OstTrace0( TRACE_NORMAL, DUP2_CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME, "CpAddDestinationEntryItemData::setNewDestinationName: exception caught" ); |
|
128 return; |
|
129 } |
|
130 |
|
131 if (!destinationNameInvalid) { |
|
132 // Update view |
|
133 if (mParent != 0) { |
|
134 mParent->addDestination(destinationName, destination->id()); |
|
135 } |
|
136 } else { |
|
137 showErrorNote(); |
|
138 } |
|
139 delete destination; |
|
140 delete cmm; |
|
141 OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME_EXIT); |
|
142 } |
|
143 |
|
144 /*! |
|
145 Inherited member from CpSettingFormEntryItemData. This item does not |
|
146 create new view because it does not need one. |
|
147 |
|
148 \return NULL |
|
149 */ |
|
150 CpBaseSettingView *CpAddDestinationEntryItemData::createSettingView() const |
|
151 { |
|
152 OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_CREATESETTINGVIEW_ENTRY); |
|
153 OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_CREATESETTINGVIEW_EXIT); |
|
154 return NULL; |
|
155 } |
|
156 |
|
157 /*! |
|
158 Function for checking if the given destination name is valid. Duplicate and |
|
159 and empty names are rejected. |
|
160 |
|
161 @param[in] dest Name which user has entered to be the name of the new destination. |
|
162 @param[in] cmm Pointer to CmManagerShim for accessing data in commsdat. |
|
163 \return true if name is valid. |
|
164 */ |
|
165 bool CpAddDestinationEntryItemData::isDestinationNameValid(const QString dest, CmManagerShim *cmm) const |
|
166 { |
|
167 OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_ENTRY); |
|
168 bool retVal = true; |
|
169 |
|
170 if (dest.length() > 0) { |
|
171 QList<uint> destinationList; |
|
172 cmm->allDestinations(destinationList); |
|
173 |
|
174 for (int i = 0; i < destinationList.count(); i ++) { |
|
175 CmDestinationShim *destination = cmm->destination(destinationList[i]); |
|
176 if (0 == dest.compare(destination->name())) { |
|
177 retVal = false; |
|
178 break; |
|
179 } |
|
180 delete destination; |
|
181 } |
|
182 } else { |
|
183 retVal = false; |
|
184 } |
|
185 OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_EXIT); |
|
186 return retVal; |
|
187 } |
|
188 |
|
189 /*! |
|
190 * Helper function for showing error note when user inputs |
|
191 * invalid destination name. |
|
192 */ |
|
193 void CpAddDestinationEntryItemData::showErrorNote() |
|
194 { |
|
195 OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_ENTRY); |
|
196 // Destination name NOK. Inform user and ask again. |
|
197 HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation); |
|
198 note->clearActions(); |
|
199 note->setAttribute(Qt::WA_DeleteOnClose); |
|
200 QString info = hbTrId("txt_occ_info_invalid_name"); |
|
201 note->setText(info); |
|
202 note->setTimeout(HbPopup::NoTimeout); |
|
203 HbAction *errorOk = new HbAction(hbTrId("txt_common_button_ok")); |
|
204 bool connected = connect( |
|
205 errorOk, |
|
206 SIGNAL(triggered()), |
|
207 this, |
|
208 SLOT(onLaunchView())); |
|
209 Q_ASSERT(connected); |
|
210 note->addAction(errorOk); |
|
211 note->show(); |
|
212 OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_EXIT); |
|
213 } |