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