|
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 * CM Manager Application Settings UI private implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 |
|
21 #include <QTranslator> |
|
22 #include <HbApplication> |
|
23 #include <HbLabel> |
|
24 #include <HbListDialog> |
|
25 #include <cmmanager_shim.h> |
|
26 |
|
27 // User includes |
|
28 |
|
29 #include "cmradiodialog.h" |
|
30 #include "cmapplsettingsui_p.h" |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "cmapplsettingsui_pTraces.h" |
|
34 #endif |
|
35 |
|
36 |
|
37 /*! |
|
38 \class CmApplSettingsUiPrivate |
|
39 \brief Private implementation class for Application Settings UI. |
|
40 |
|
41 Displays a radio button list dialog for an application that can be used |
|
42 to select a destination or connection method. |
|
43 |
|
44 */ |
|
45 |
|
46 // External function prototypes |
|
47 |
|
48 // Local constants |
|
49 |
|
50 // ======== LOCAL FUNCTIONS ======== |
|
51 |
|
52 // ======== MEMBER FUNCTIONS ======== |
|
53 |
|
54 /*! |
|
55 Constructor. |
|
56 |
|
57 @param q_pointer Parent object. |
|
58 */ |
|
59 CmApplSettingsUiPrivate::CmApplSettingsUiPrivate(CmApplSettingsUi *q_pointer) : |
|
60 QObject(q_pointer), |
|
61 q_ptr(q_pointer), |
|
62 mAppTranslator(new QTranslator(this)), |
|
63 mCommonTranslator(new QTranslator(this)), |
|
64 mListItems( |
|
65 CmApplSettingsUi::ShowDestinations | |
|
66 CmApplSettingsUi::ShowConnectionMethods), |
|
67 mSettingData(), |
|
68 mDestinationDialog(0), |
|
69 mConnMethodDialog(0), |
|
70 mSelection(), |
|
71 mDestinations(), |
|
72 mConnMethods() |
|
73 { |
|
74 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_CMAPPLSETTINGSUIPRIVATE_ENTRY); |
|
75 |
|
76 // Initialize to default selection |
|
77 mSelection.result = CmApplSettingsUi::SelectionTypeDestination; |
|
78 mSelection.id = 0; |
|
79 |
|
80 // Install common localization |
|
81 QString lang = QLocale::system().name(); |
|
82 QString path = "Z:/resource/qt/translations/"; |
|
83 bool loadStatus = mCommonTranslator->load("common_" + lang, path); |
|
84 qApp->installTranslator(mCommonTranslator); |
|
85 |
|
86 // Install this library's localization |
|
87 loadStatus = mAppTranslator->load("cmapplsettingsui_" + lang, path); |
|
88 qApp->installTranslator(mAppTranslator); |
|
89 |
|
90 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_CMAPPLSETTINGSUIPRIVATE_EXIT); |
|
91 } |
|
92 |
|
93 /*! |
|
94 Destructor. |
|
95 */ |
|
96 CmApplSettingsUiPrivate::~CmApplSettingsUiPrivate() |
|
97 { |
|
98 OstTraceFunctionEntry0(DUP1_CMAPPLSETTINGSUIPRIVATE_CMAPPLSETTINGSUIPRIVATE_ENTRY); |
|
99 OstTraceFunctionExit0(DUP1_CMAPPLSETTINGSUIPRIVATE_CMAPPLSETTINGSUIPRIVATE_EXIT); |
|
100 } |
|
101 |
|
102 /*! |
|
103 Options setter. |
|
104 |
|
105 @param[in] listItems Dialog list items configuration. |
|
106 @param[in] bearerFilter Dialog Connection Method bearer filter. |
|
107 */ |
|
108 void CmApplSettingsUiPrivate::setOptions( |
|
109 const QFlags<CmApplSettingsUi::SelectionDialogItems> &listItems, |
|
110 const QSet<CmApplSettingsUi::BearerTypeFilter> &bearerFilter) |
|
111 { |
|
112 // Store the options |
|
113 mListItems = listItems; |
|
114 mSettingData.setBearerFilter(bearerFilter); |
|
115 } |
|
116 |
|
117 /*! |
|
118 Dialog selection setter. |
|
119 |
|
120 @param[in] selection Dialog selection to set. |
|
121 */ |
|
122 void CmApplSettingsUiPrivate::setSelection( |
|
123 const CmApplSettingsUi::SettingSelection &selection) |
|
124 { |
|
125 // Set the selection. |
|
126 // If the selection is invalid, it is ignored later on, |
|
127 // and default is used instead. |
|
128 mSelection = selection; |
|
129 } |
|
130 |
|
131 /*! |
|
132 Dialog selection getter. Returns the current selection. |
|
133 |
|
134 @return Current dialog selection. |
|
135 */ |
|
136 CmApplSettingsUi::SettingSelection CmApplSettingsUiPrivate::selection() const |
|
137 { |
|
138 return mSelection; |
|
139 } |
|
140 |
|
141 /*! |
|
142 This function runs the dialog asynchronously. Use the setters to |
|
143 configure the dialog before running. After the dialog has been closed |
|
144 (accepted or cancelled), the signal finished() is emitted. |
|
145 */ |
|
146 void CmApplSettingsUiPrivate::open() |
|
147 { |
|
148 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_OPEN_ENTRY); |
|
149 |
|
150 // Fetch filtered Destinations and Connection Methods |
|
151 bool settingsRead = true; |
|
152 if (mListItems.testFlag(CmApplSettingsUi::ShowDestinations)) { |
|
153 settingsRead = mSettingData.fetchDestinations(mDestinations); |
|
154 } |
|
155 if (mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods)) { |
|
156 settingsRead &= mSettingData.fetchConnMethods(mConnMethods); |
|
157 } |
|
158 |
|
159 if (!settingsRead) { |
|
160 // Settings reading failed |
|
161 emitFinished(CmApplSettingsUi::ApplSettingsErrorSettingsRead); |
|
162 } else if (mListItems.testFlag(CmApplSettingsUi::ShowDestinations)) { |
|
163 // Start with destination view |
|
164 runDestinationDialog(); |
|
165 } else if (mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods)) { |
|
166 // Start directly with connection method view |
|
167 runConnectionMethodDialog(); |
|
168 } else { |
|
169 // Nothing to show, so finish |
|
170 emitFinished(CmApplSettingsUi::ApplSettingsErrorNoContent); |
|
171 } |
|
172 |
|
173 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_OPEN_EXIT); |
|
174 } |
|
175 |
|
176 /*! |
|
177 Destination selection dialog execution. |
|
178 */ |
|
179 void CmApplSettingsUiPrivate::runDestinationDialog() |
|
180 { |
|
181 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_RUNDESTINATIONDIALOG_ENTRY); |
|
182 |
|
183 // Check that there is some content to show: |
|
184 // -At least one Destination |
|
185 // -Or at least one Connection Method under "Dedicated access point" |
|
186 if (mDestinations.isEmpty() |
|
187 && (!mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods) |
|
188 || mConnMethods.isEmpty())) { |
|
189 // Nothing to show, so finish |
|
190 emitFinished(CmApplSettingsUi::ApplSettingsErrorNoContent); |
|
191 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_RUNDESTINATIONDIALOG_EXIT); |
|
192 return; |
|
193 } |
|
194 |
|
195 // Create a new Destination dialog |
|
196 delete mDestinationDialog; |
|
197 mDestinationDialog = new CmRadioDialog(this); |
|
198 mDestinationDialog->setType(CmRadioDialogTypeDestination); |
|
199 |
|
200 // Add Dedicated access point option if requested & supported |
|
201 if (mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods) |
|
202 && !mConnMethods.isEmpty()) { |
|
203 QSet<CmRadioDialogOpt> options; |
|
204 options.insert(CmRadioDialogOptDedicatedAP); |
|
205 mDestinationDialog->setOptions(options); |
|
206 } |
|
207 |
|
208 // Add destinations to the dialog |
|
209 QStringList destinations; |
|
210 for (int i = 0; i < mDestinations.count(); i++) { |
|
211 destinations << mDestinations[i]->name; |
|
212 } |
|
213 mDestinationDialog->setItems(destinations); |
|
214 |
|
215 // Set selection |
|
216 int index = 0; // Default index is the first |
|
217 if (mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods) |
|
218 && mSelection.result == CmApplSettingsUi::SelectionTypeConnectionMethod |
|
219 && !mConnMethods.isEmpty()) { |
|
220 // Dedicated access point |
|
221 index = destinations.count(); |
|
222 } else { |
|
223 int destinationIndex = findDestination(mSelection.id); |
|
224 if (destinationIndex != ItemNotFound) { |
|
225 index = destinationIndex; |
|
226 } |
|
227 } |
|
228 mDestinationDialog->setSelected(index); |
|
229 |
|
230 // Execute the dialog |
|
231 bool connected = connect( |
|
232 mDestinationDialog, |
|
233 SIGNAL(finished(bool)), |
|
234 this, |
|
235 SLOT(destinationDialogResult(bool))); |
|
236 Q_ASSERT(connected); |
|
237 mDestinationDialog->open(); |
|
238 |
|
239 OstTraceFunctionExit0(DUP1_CMAPPLSETTINGSUIPRIVATE_RUNDESTINATIONDIALOG_EXIT); |
|
240 } |
|
241 |
|
242 /*! |
|
243 Connection method selection dialog execution. |
|
244 */ |
|
245 void CmApplSettingsUiPrivate::runConnectionMethodDialog() |
|
246 { |
|
247 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_RUNCONNECTIONMETHODDIALOG_ENTRY); |
|
248 |
|
249 // Check that there is at least one Connection Method to show |
|
250 if (mConnMethods.count() == 0) { |
|
251 // Nothing to show, so finish |
|
252 emitFinished(CmApplSettingsUi::ApplSettingsErrorNoContent); |
|
253 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_RUNCONNECTIONMETHODDIALOG_EXIT); |
|
254 return; |
|
255 } |
|
256 |
|
257 // Create a dialog & configure it |
|
258 delete mConnMethodDialog; |
|
259 mConnMethodDialog = new CmRadioDialog(this); |
|
260 mConnMethodDialog->setType(CmRadioDialogTypeAccessPoint); |
|
261 |
|
262 // Add connection methods to the dialog |
|
263 QStringList connectionMethods; |
|
264 for (int i = 0; i < mConnMethods.count(); i++) { |
|
265 connectionMethods << mConnMethods[i]->name; |
|
266 } |
|
267 mConnMethodDialog->setItems(connectionMethods); |
|
268 |
|
269 // Set selection |
|
270 int index = findConnectionMethod(mSelection.id); |
|
271 if (index == ItemNotFound) { |
|
272 // Connection Method not found |
|
273 index = 0; |
|
274 } |
|
275 mConnMethodDialog->setSelected(index); |
|
276 |
|
277 // Execute the dialog |
|
278 bool connected = connect( |
|
279 mConnMethodDialog, |
|
280 SIGNAL(finished(bool)), |
|
281 this, |
|
282 SLOT(connMethodDialogResult(bool))); |
|
283 Q_ASSERT(connected); |
|
284 mConnMethodDialog->open(); |
|
285 |
|
286 OstTraceFunctionExit0(DUP1_CMAPPLSETTINGSUIPRIVATE_RUNCONNECTIONMETHODDIALOG_EXIT); |
|
287 } |
|
288 |
|
289 /*! |
|
290 Destination search function. |
|
291 |
|
292 @param destinationId Destination ID. |
|
293 |
|
294 @return Returns index if found, and ItemNotFound if not. |
|
295 */ |
|
296 int CmApplSettingsUiPrivate::findDestination(uint destinationId) const |
|
297 { |
|
298 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_FINDDESTINATION_ENTRY); |
|
299 |
|
300 int result = ItemNotFound; |
|
301 |
|
302 for (int i = 0; i < mDestinations.count(); i++) { |
|
303 if (mDestinations[i]->id == destinationId) { |
|
304 result = i; |
|
305 break; |
|
306 } |
|
307 } |
|
308 |
|
309 OstTraceExt2( |
|
310 TRACE_NORMAL, |
|
311 CMAPPLSETTINGSUIPRIVATE_FINDDESTINATION, |
|
312 "CmApplSettingsUiPrivate::findDestination;destinationId=%u;result=%d", |
|
313 destinationId, |
|
314 result); |
|
315 |
|
316 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_FINDDESTINATION_EXIT); |
|
317 return result; |
|
318 } |
|
319 |
|
320 /*! |
|
321 Connection Method search function. |
|
322 |
|
323 @param connMethodId Connection Method ID. |
|
324 |
|
325 @return Returns index if found, and ItemNotFound if not. |
|
326 */ |
|
327 int CmApplSettingsUiPrivate::findConnectionMethod(uint connMethodId) const |
|
328 { |
|
329 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_FINDCONNECTIONMETHOD_ENTRY); |
|
330 |
|
331 int result = ItemNotFound; |
|
332 |
|
333 for (int i = 0; i < mConnMethods.count(); i++) { |
|
334 if (mConnMethods[i]->id == connMethodId) { |
|
335 result = i; |
|
336 break; |
|
337 } |
|
338 } |
|
339 |
|
340 OstTraceExt2( |
|
341 TRACE_NORMAL, |
|
342 CMAPPLSETTINGSUIPRIVATE_FINDCONNECTIONMETHOD, |
|
343 "CmApplSettingsUiPrivate::findConnectionMethod;connMethodId=%u;result=%d", |
|
344 connMethodId, |
|
345 result); |
|
346 |
|
347 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_FINDCONNECTIONMETHOD_EXIT); |
|
348 return result; |
|
349 } |
|
350 |
|
351 /*! |
|
352 Emits the completion signal "finished(uint)". |
|
353 |
|
354 @param status Finishing status code. |
|
355 */ |
|
356 void CmApplSettingsUiPrivate::emitFinished(uint status) const |
|
357 { |
|
358 OstTrace1( |
|
359 TRACE_NORMAL, |
|
360 CMAPPLSETTINGSUIPRIVATE_EMITFINISHED, |
|
361 "CmApplSettingsUiPrivate::emitFinished;status=%u", |
|
362 status); |
|
363 emit q_ptr->finished(status); |
|
364 } |
|
365 |
|
366 /*! |
|
367 Destination dialog result handling slot. |
|
368 |
|
369 @param success Destination dialog result - TRUE if accepted. |
|
370 */ |
|
371 void CmApplSettingsUiPrivate::destinationDialogResult(bool success) |
|
372 { |
|
373 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_DESTINATIONDIALOGRESULT_ENTRY); |
|
374 |
|
375 if (success) { |
|
376 // Dialog was accepted - user clicked "OK" |
|
377 int index = mDestinationDialog->selected(); |
|
378 if (mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods) |
|
379 && index == mDestinations.count()) { |
|
380 // Dedicated access point was selected |
|
381 runConnectionMethodDialog(); |
|
382 } else { |
|
383 // Destination was selected |
|
384 mSelection.result = CmApplSettingsUi::SelectionTypeDestination; |
|
385 mSelection.id = mDestinations[index]->id; |
|
386 emitFinished(CmApplSettingsUi::ApplSettingsErrorNone); |
|
387 } |
|
388 } else { |
|
389 // Dialog was cancelled - user clicked "Cancel" |
|
390 emitFinished(CmApplSettingsUi::ApplSettingsErrorCancel); |
|
391 } |
|
392 |
|
393 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_DESTINATIONDIALOGRESULT_EXIT); |
|
394 } |
|
395 |
|
396 /*! |
|
397 Connection method dialog result handling slot. |
|
398 |
|
399 @param success Connection method dialog result - TRUE if accepted. |
|
400 */ |
|
401 void CmApplSettingsUiPrivate::connMethodDialogResult(bool success) |
|
402 { |
|
403 OstTraceFunctionEntry0(CMAPPLSETTINGSUIPRIVATE_CONNMETHODDIALOGRESULT_ENTRY); |
|
404 |
|
405 if (success) { |
|
406 // Dialog was accepted - user clicked "OK" |
|
407 int index = mConnMethodDialog->selected(); |
|
408 mSelection.result = CmApplSettingsUi::SelectionTypeConnectionMethod; |
|
409 mSelection.id = mConnMethods[index]->id; |
|
410 emitFinished(CmApplSettingsUi::ApplSettingsErrorNone); |
|
411 } else { |
|
412 // Dialog was cancelled - user clicked "Cancel" |
|
413 emitFinished(CmApplSettingsUi::ApplSettingsErrorCancel); |
|
414 } |
|
415 |
|
416 OstTraceFunctionExit0(CMAPPLSETTINGSUIPRIVATE_CONNMETHODDIALOGRESULT_EXIT); |
|
417 } |