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 * Dialog implementation for the CM Manager Application Settings UI. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 |
|
21 #include <HbDialog> |
|
22 #include <HbLabel> |
|
23 #include <HbRadioButtonList> |
|
24 #include <HbAction> |
|
25 #include <HbDocumentLoader> |
|
26 |
|
27 // User includes |
|
28 |
|
29 #include "cmradiodialog.h" |
|
30 |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "cmradiodialogTraces.h" |
|
34 #endif |
|
35 |
|
36 |
|
37 /*! |
|
38 \class CmRadioDialog |
|
39 \brief Radio dutton dialog class for Application Settings UI. |
|
40 */ |
|
41 |
|
42 // External function prototypes |
|
43 |
|
44 // Local constants |
|
45 |
|
46 // ======== LOCAL FUNCTIONS ======== |
|
47 |
|
48 // ======== MEMBER FUNCTIONS ======== |
|
49 |
|
50 /*! |
|
51 Constructor. |
|
52 |
|
53 @param parent Parent object. |
|
54 */ |
|
55 CmRadioDialog::CmRadioDialog(QObject *parent) : |
|
56 QObject(parent), |
|
57 mType(CmRadioDialogTypeDestination), |
|
58 mLoader(), |
|
59 mListItems(), |
|
60 mDialog(), |
|
61 mHeading(0), |
|
62 mList(0), |
|
63 mOkAction(0) |
|
64 { |
|
65 OstTraceFunctionEntry0(CMRADIODIALOG_CMRADIODIALOG_ENTRY); |
|
66 |
|
67 mLoader = QSharedPointer<HbDocumentLoader>(new HbDocumentLoader()); |
|
68 loadDocml(); |
|
69 |
|
70 OstTraceFunctionExit0(CMRADIODIALOG_CMRADIODIALOG_EXIT); |
|
71 } |
|
72 |
|
73 /*! |
|
74 Destructor. |
|
75 */ |
|
76 CmRadioDialog::~CmRadioDialog() |
|
77 { |
|
78 OstTraceFunctionEntry0(DUP1_CMRADIODIALOG_CMRADIODIALOG_ENTRY); |
|
79 OstTraceFunctionExit0(DUP1_CMRADIODIALOG_CMRADIODIALOG_EXIT); |
|
80 } |
|
81 |
|
82 /*! |
|
83 Heading setter. |
|
84 |
|
85 @param type Dialog type. |
|
86 */ |
|
87 void CmRadioDialog::setType(CmRadioDialogType type) |
|
88 { |
|
89 OstTraceFunctionEntry0(CMRADIODIALOG_SETTYPE_ENTRY); |
|
90 |
|
91 mType = type; |
|
92 |
|
93 OstTraceFunctionExit0(CMRADIODIALOG_SETTYPE_EXIT); |
|
94 } |
|
95 |
|
96 /*! |
|
97 Options setter. |
|
98 |
|
99 @param options Dialog options. |
|
100 */ |
|
101 void CmRadioDialog::setOptions(const QSet<CmRadioDialogOpt> &options) |
|
102 { |
|
103 OstTraceFunctionEntry0(CMRADIODIALOG_SETOPTIONS_ENTRY); |
|
104 |
|
105 mOptions = options; |
|
106 |
|
107 OstTraceFunctionExit0(CMRADIODIALOG_SETOPTIONS_EXIT); |
|
108 } |
|
109 |
|
110 /*! |
|
111 Radio button list items setter. |
|
112 |
|
113 @param list List of radio button item strings. |
|
114 */ |
|
115 void CmRadioDialog::setItems(const QStringList &list) |
|
116 { |
|
117 OstTraceFunctionEntry0(CMRADIODIALOG_SETITEMS_ENTRY); |
|
118 |
|
119 // Store the new items |
|
120 mListItems = list; |
|
121 |
|
122 // Append "Dedicated access point" |
|
123 if (mOptions.contains(CmRadioDialogOptDedicatedAP)) { |
|
124 mListItems.append(hbTrId("txt_occ_list_dedicated_access_point")); |
|
125 } |
|
126 |
|
127 // Set the items to the radio list |
|
128 mList->setItems(mListItems); |
|
129 |
|
130 OstTraceFunctionExit0(CMRADIODIALOG_SETITEMS_EXIT); |
|
131 } |
|
132 |
|
133 /*! |
|
134 Setter for current selection. |
|
135 |
|
136 @param index Radio list item current selection setter. Indexing from zero. |
|
137 */ |
|
138 void CmRadioDialog::setSelected(int index) |
|
139 { |
|
140 OstTraceFunctionEntry0(CMRADIODIALOG_SETSELECTED_ENTRY); |
|
141 |
|
142 OstTrace1( |
|
143 TRACE_NORMAL, |
|
144 CMRADIODIALOG_SETSELECTED, |
|
145 "CmRadioDialog::setSelected;index=%d", |
|
146 index); |
|
147 |
|
148 // The index must be valid |
|
149 Q_ASSERT(index < mList->items().count()); |
|
150 |
|
151 // Set the current selection |
|
152 mList->setSelected(index); |
|
153 |
|
154 OstTraceFunctionExit0(CMRADIODIALOG_SETSELECTED_EXIT); |
|
155 } |
|
156 |
|
157 /*! |
|
158 Getter for current selection. |
|
159 |
|
160 @return Current selection index. Indexing from zero. |
|
161 */ |
|
162 int CmRadioDialog::selected() const |
|
163 { |
|
164 OstTraceFunctionEntry0(CMRADIODIALOG_SELECTED_ENTRY); |
|
165 |
|
166 int selection = mList->selected(); |
|
167 |
|
168 OstTrace1( |
|
169 TRACE_NORMAL, |
|
170 CMRADIODIALOG_SELECTED, |
|
171 "CmRadioDialog::selected;index=%d", |
|
172 index); |
|
173 |
|
174 OstTraceFunctionExit0(CMRADIODIALOG_SELECTED_EXIT); |
|
175 return selection; |
|
176 } |
|
177 |
|
178 /*! |
|
179 Run the dialog asynchronously. When the dialog has finished, the signal |
|
180 finished(bool) is sent. |
|
181 */ |
|
182 void CmRadioDialog::open() |
|
183 { |
|
184 OstTraceFunctionEntry0(CMRADIODIALOG_EXEC_ENTRY); |
|
185 |
|
186 setHeading(); |
|
187 mDialog->open(this, SLOT(dialogClosed(HbAction*))); |
|
188 |
|
189 OstTraceFunctionExit0(CMRADIODIALOG_EXEC_EXIT); |
|
190 } |
|
191 |
|
192 /*! |
|
193 Dialog result handling slot. |
|
194 |
|
195 @param action Selected action. |
|
196 */ |
|
197 void CmRadioDialog::dialogClosed(HbAction *action) |
|
198 { |
|
199 OstTraceFunctionEntry0(CMRADIODIALOG_DIALOGCLOSED_ENTRY); |
|
200 |
|
201 // Extract the selection status |
|
202 bool success; |
|
203 if (action == mOkAction) { |
|
204 success = true; |
|
205 } else { |
|
206 success = false; |
|
207 } |
|
208 emit finished(success); |
|
209 |
|
210 OstTraceExt1( |
|
211 TRACE_NORMAL, |
|
212 CMRADIODIALOG_EXEC_RESULT, |
|
213 "CmRadioDialog::exec;success=%hhu", |
|
214 success); |
|
215 |
|
216 OstTraceFunctionExit0(CMRADIODIALOG_DIALOGCLOSED_EXIT); |
|
217 } |
|
218 |
|
219 /*! |
|
220 Dialog heading setter. |
|
221 */ |
|
222 void CmRadioDialog::setHeading() |
|
223 { |
|
224 OstTraceFunctionEntry0(CMRADIODIALOG_SETHEADING_ENTRY); |
|
225 |
|
226 QString heading; |
|
227 |
|
228 // Select correct header based on dialog type |
|
229 switch (mType) { |
|
230 case CmRadioDialogTypeDestination: |
|
231 heading = hbTrId("txt_occ_title_network_connection"); |
|
232 break; |
|
233 |
|
234 case CmRadioDialogTypeAccessPoint: |
|
235 heading = hbTrId("txt_occ_title_access_point"); |
|
236 break; |
|
237 |
|
238 #ifndef QT_NO_DEBUG |
|
239 default: |
|
240 // Unsupported dialog type detected |
|
241 Q_ASSERT(0); |
|
242 break; |
|
243 #endif |
|
244 } |
|
245 |
|
246 mHeading->setPlainText(heading); |
|
247 |
|
248 OstTraceFunctionExit0(CMRADIODIALOG_SETHEADING_EXIT); |
|
249 } |
|
250 |
|
251 /*! |
|
252 Docml loading for the dialog. |
|
253 */ |
|
254 void CmRadioDialog::loadDocml() |
|
255 { |
|
256 OstTraceFunctionEntry0(CMRADIODIALOG_LOADDOCML_ENTRY); |
|
257 bool ok = false; |
|
258 |
|
259 // Load the common section |
|
260 mLoader->load(":/docml/cmradiodialog.docml", &ok); |
|
261 Q_ASSERT(ok); |
|
262 |
|
263 mDialog = QSharedPointer<HbDialog>(qobject_cast<HbDialog *>(mLoader->findWidget("dialog"))); |
|
264 Q_ASSERT(mDialog); |
|
265 |
|
266 mHeading = qobject_cast<HbLabel *>(mLoader->findWidget("heading")); |
|
267 Q_ASSERT(mHeading); |
|
268 |
|
269 mList = qobject_cast<HbRadioButtonList *>(mLoader->findWidget("radioButtonList")); |
|
270 Q_ASSERT(mList); |
|
271 |
|
272 mOkAction = qobject_cast<HbAction *>(mLoader->findObject("okAction")); |
|
273 Q_ASSERT(mOkAction); |
|
274 |
|
275 OstTraceFunctionExit0(CMRADIODIALOG_LOADDOCML_EXIT); |
|
276 } |
|