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: Prompt Dialog implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <HbTranslator> |
|
19 #include <QLocale> |
|
20 #include <QList> |
|
21 #include <HbLabel> |
|
22 #include <HbDialog> |
|
23 #include <HbDocumentLoader> |
|
24 #include <HbPushButton> |
|
25 #include <HbView> |
|
26 #include <HbApplication> |
|
27 #include "cellularpromptdialog.h" |
|
28 #include "OstTraceDefinitions.h" |
|
29 #ifdef OST_TRACE_COMPILER_IN_USE |
|
30 #include "cellularpromptdialogTraces.h" |
|
31 #endif |
|
32 |
|
33 |
|
34 |
|
35 // The index numbers of the buttons of the dialog |
|
36 const int firstButtonIndex = 1; |
|
37 const int middleButtonIndex = 2; |
|
38 const int cancelButtonIndex = 3; |
|
39 |
|
40 /** |
|
41 * The constructor |
|
42 */ |
|
43 CellularPromptDialog::CellularPromptDialog(const QVariantMap ¶meters) |
|
44 { |
|
45 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CELLULARPROMPTDIALOG_ENTRY ); |
|
46 |
|
47 // Install localization |
|
48 mTranslator = QSharedPointer<HbTranslator>(new HbTranslator("cellularpromptdialog")); |
|
49 |
|
50 createDialog(parameters); |
|
51 mClose = false; |
|
52 |
|
53 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CELLULARPROMPTDIALOG_EXIT ); |
|
54 } |
|
55 |
|
56 |
|
57 /** |
|
58 * The construction of the dialog |
|
59 */ |
|
60 void CellularPromptDialog::createDialog(const QVariantMap ¶meters) |
|
61 { |
|
62 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CREATEDIALOG_ENTRY ); |
|
63 |
|
64 // Set the button and label texts according to the network (home or abroad) |
|
65 QString labelText; |
|
66 QString button1Text; |
|
67 QString button2Text; |
|
68 QString button3Text(hbTrId("txt_occ_button_cellular_cancel")); |
|
69 |
|
70 // There is only one value in the QVariantMap that we are interested in, |
|
71 // whether we are in home network or not |
|
72 QList<QVariant> list = parameters.values(); |
|
73 bool homeNetwork = true; |
|
74 |
|
75 if (list.count() > 0) { |
|
76 homeNetwork = list[0].toBool(); |
|
77 } |
|
78 |
|
79 if (homeNetwork) { |
|
80 labelText = QString(hbTrId("txt_occ_title_connect_to_internet_using_cellular_d")); |
|
81 button1Text = QString(hbTrId("txt_occ_button_connect_automatically")); |
|
82 button2Text = QString(hbTrId("txt_occ_button_connect_this_time")); |
|
83 } else { |
|
84 labelText = QString(hbTrId("txt_occ_title_connect_to_internet_in_this_country")); |
|
85 button1Text = QString(hbTrId("txt_occ_button_connect_this_time")); |
|
86 } |
|
87 |
|
88 HbDocumentLoader loader; |
|
89 bool ok = true; |
|
90 |
|
91 if (homeNetwork) { |
|
92 loader.load(":/xml/prompt_home.docml", &ok); |
|
93 } else { |
|
94 loader.load(":/xml/prompt_abroad.docml", &ok); |
|
95 } |
|
96 |
|
97 if ( !ok ) { |
|
98 // send information about cancelling to the observer, the xml loading failed |
|
99 cancelPressed(); |
|
100 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CREATEDIALOG_EXIT ); |
|
101 return; |
|
102 } |
|
103 |
|
104 // store the pointer to the dialog in order to be able to delete |
|
105 // it in the destructor |
|
106 mDialog = qobject_cast<HbDialog*>( loader.findWidget ("dialog")); |
|
107 Q_ASSERT(mDialog != NULL); |
|
108 |
|
109 // fetch the needed widgets, update their texts and connect the |
|
110 // clicked signals of the buttons to correct slots. |
|
111 HbWidget *container = qobject_cast<HbWidget*>( loader.findWidget ("container")); |
|
112 this->setContentWidget(container); |
|
113 |
|
114 // Set the dialog to be on the screen for 30 seconds, unless |
|
115 // the user reacts earlier |
|
116 this->setModal(true); |
|
117 this->setTimeout(30000); |
|
118 this->setDismissPolicy(HbPopup::NoDismiss); |
|
119 |
|
120 HbLabel* label = qobject_cast<HbLabel*>( loader.findWidget("label") ); |
|
121 Q_ASSERT(label != NULL); |
|
122 label->setPlainText(labelText); |
|
123 label->setTextWrapping(Hb::TextWordWrap); |
|
124 |
|
125 HbPushButton* firstButton = qobject_cast<HbPushButton*>( loader.findWidget("topButton") ); |
|
126 Q_ASSERT(firstButton != NULL); |
|
127 firstButton->setText(button1Text); |
|
128 |
|
129 HbPushButton* middleButton = NULL; |
|
130 if ( homeNetwork ) { |
|
131 middleButton = qobject_cast<HbPushButton*>( loader.findWidget("middleButton") ); |
|
132 Q_ASSERT(middleButton != NULL); |
|
133 middleButton->setText(button2Text); |
|
134 } |
|
135 |
|
136 HbPushButton* cancelButton = qobject_cast<HbPushButton*>( loader.findWidget("cancelButton") ); |
|
137 Q_ASSERT(cancelButton != NULL); |
|
138 cancelButton->setText(button3Text); |
|
139 |
|
140 // Connect the button clicks to slots, assert if connecting fails |
|
141 bool connected = connect( firstButton, SIGNAL(clicked()), this, SLOT( firstButtonPressed() )); |
|
142 Q_ASSERT(connected == true); |
|
143 |
|
144 if ( homeNetwork ) { |
|
145 connected = connect( middleButton, SIGNAL(clicked()), this, SLOT( middleButtonPressed() )); |
|
146 Q_ASSERT(connected == true); |
|
147 } |
|
148 |
|
149 connected = connect( cancelButton, SIGNAL(clicked()), this, SLOT( cancelPressed() )); |
|
150 Q_ASSERT(connected == true); |
|
151 // Connect the about to close and hide signals, so that we are able to inform |
|
152 // the caller that the dialog was closed, for example due to timeout |
|
153 connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog())); |
|
154 Q_ASSERT(connected == true); |
|
155 connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog())); |
|
156 Q_ASSERT(connected == true); |
|
157 |
|
158 OstTraceFunctionExit0( DUP1_CELLULARPROMPTDIALOG_CREATEDIALOG_EXIT ); |
|
159 } |
|
160 |
|
161 /** |
|
162 * Destructor |
|
163 */ |
|
164 CellularPromptDialog::~CellularPromptDialog() |
|
165 { |
|
166 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_DCELLULARPROMPTDIALOG_ENTRY ); |
|
167 |
|
168 // The dialog widgets are deleted as the dialog is deleted |
|
169 if (mDialog != NULL) { |
|
170 delete mDialog; |
|
171 } |
|
172 mDialog = NULL; |
|
173 |
|
174 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_DCELLULARPROMPTDIALOG_EXIT ); |
|
175 } |
|
176 |
|
177 /** |
|
178 * Function is called when the first button is pressed and the |
|
179 * index of the button is emitted |
|
180 */ |
|
181 void CellularPromptDialog::firstButtonPressed() |
|
182 { |
|
183 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_FIRSTBUTTONPRESSED_ENTRY ); |
|
184 |
|
185 QVariantMap data; |
|
186 QVariant variant(firstButtonIndex); |
|
187 data.insert("button", variant); |
|
188 // emit the data of the selected button and close the dialog |
|
189 emit deviceDialogData(data); |
|
190 close(); |
|
191 |
|
192 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_FIRSTBUTTONPRESSED_EXIT ); |
|
193 } |
|
194 |
|
195 /** |
|
196 * Function is called when the second button is pressed and the |
|
197 * index of the button is emitted |
|
198 */ |
|
199 void CellularPromptDialog::middleButtonPressed() |
|
200 { |
|
201 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_MIDDLEBUTTONPRESSED_ENTRY ); |
|
202 |
|
203 QVariantMap data; |
|
204 QVariant variant(middleButtonIndex); |
|
205 data.insert("button", variant); |
|
206 // emit the data of the selected button and close the dialog |
|
207 emit deviceDialogData(data); |
|
208 close(); |
|
209 |
|
210 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_MIDDLEBUTTONPRESSED_EXIT ); |
|
211 } |
|
212 |
|
213 /** |
|
214 * Function is called when the third button is pressed and the |
|
215 * index of the button is emitted |
|
216 */ |
|
217 void CellularPromptDialog::cancelPressed() |
|
218 { |
|
219 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CANCELPRESSED_ENTRY ); |
|
220 |
|
221 QVariantMap data; |
|
222 QVariant variant(cancelButtonIndex); |
|
223 data.insert("button", variant); |
|
224 // emit the data of the selected button and close the dialog |
|
225 emit deviceDialogData(data); |
|
226 close(); |
|
227 |
|
228 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CANCELPRESSED_EXIT ); |
|
229 } |
|
230 |
|
231 /** |
|
232 * Function is called when the dialog is about to close |
|
233 */ |
|
234 void CellularPromptDialog::closingDialog() |
|
235 { |
|
236 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CLOSINGDIALOG_ENTRY ); |
|
237 |
|
238 if (!mClose) { |
|
239 mClose = true; |
|
240 closeDeviceDialog(false); |
|
241 } |
|
242 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CLOSINGDIALOG_EXIT ); |
|
243 } |
|
244 |
|
245 |
|
246 /** |
|
247 * Updating the dialog during its showing is not allowed. |
|
248 */ |
|
249 bool CellularPromptDialog::setDeviceDialogParameters |
|
250 (const QVariantMap ¶meters) |
|
251 { |
|
252 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY ); |
|
253 |
|
254 Q_UNUSED(parameters) |
|
255 // changing the dialog after presenting it is not supported. |
|
256 |
|
257 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT ); |
|
258 return true; |
|
259 } |
|
260 |
|
261 /** |
|
262 * Not supported, 0 always returned |
|
263 */ |
|
264 int CellularPromptDialog::deviceDialogError() const |
|
265 { |
|
266 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_DEVICEDIALOGERROR_ENTRY ); |
|
267 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_DEVICEDIALOGERROR_EXIT); |
|
268 return 0; |
|
269 } |
|
270 |
|
271 /** |
|
272 * Dialog is closed and the signal about closing is emitted |
|
273 */ |
|
274 void CellularPromptDialog::closeDeviceDialog(bool byClient) |
|
275 { |
|
276 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CLOSEDEVICEDIALOG_ENTRY ); |
|
277 |
|
278 Q_UNUSED(byClient) |
|
279 close(); |
|
280 // If the user closes the dialog, then the deviceDialogClosed is emitted |
|
281 emit deviceDialogClosed(); |
|
282 |
|
283 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CLOSEDEVICEDIALOG_EXIT ); |
|
284 } |
|
285 |
|
286 /** |
|
287 * This dialog widget is returned to the caller |
|
288 */ |
|
289 HbPopup *CellularPromptDialog::deviceDialogWidget() const |
|
290 { |
|
291 OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_DEVICEDIALOGWIDGET_ENTRY ); |
|
292 OstTraceFunctionExit0( CELLULARPROMPTDIALOG_DEVICEDIALOGWIDGET_EXIT ); |
|
293 |
|
294 return const_cast<CellularPromptDialog*>(this); |
|
295 } |
|
296 |
|