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