|
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: Dialog implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <eapqtvalidator.h> |
|
19 #include <eapqtexpandedeaptype.h> |
|
20 #include <eapqtconfiginterface.h> |
|
21 #include <eapqtconfig.h> |
|
22 #include "eapusernamepwddialog.h" |
|
23 #include "OstTraceDefinitions.h" |
|
24 #ifdef OST_TRACE_COMPILER_IN_USE |
|
25 |
|
26 #endif |
|
27 |
|
28 /** |
|
29 * The constructor |
|
30 */ |
|
31 EapUsernamePwdDialog::EapUsernamePwdDialog(const QVariantMap ¶meters) |
|
32 :mEdit1(NULL), |
|
33 mEdit2(NULL), |
|
34 mUnameValidator(NULL), |
|
35 mPwdValidator(NULL), |
|
36 mTranslator(new HbTranslator("eapprompts")) |
|
37 { |
|
38 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_EAPUSERNAMEPWDDIALOG_ENTRY ); |
|
39 qDebug("EapUsernamePwdDialog::EapUsernamePwdDialog ENTER"); |
|
40 |
|
41 createDialog(parameters); |
|
42 |
|
43 mClose = false; |
|
44 mOkActionPressed = false; |
|
45 |
|
46 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_EAPUSERNAMEPWDDIALOG_EXIT ); |
|
47 qDebug("EapUsernamePwdDialog::EapUsernamePwdDialog EXIT"); |
|
48 } |
|
49 |
|
50 /** |
|
51 * The construction of the dialog |
|
52 */ |
|
53 void EapUsernamePwdDialog::createDialog(const QVariantMap ¶meters ) |
|
54 { |
|
55 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CREATEDIALOG_ENTRY ); |
|
56 qDebug("EapUsernamePwdDialog::createDialog ENTER"); |
|
57 |
|
58 QString keyauthmethod = QString("authmethod"); |
|
59 QString keyuname = QString("username"); |
|
60 QString keyeaptype = QString("eaptype"); |
|
61 |
|
62 QString unamestr = QString(""); |
|
63 QString authMethodstr = QString("FOO"); |
|
64 |
|
65 if ( parameters.empty() == false ) { |
|
66 if ( parameters.contains(keyuname) ) { |
|
67 QVariant variant = parameters.value(keyuname); |
|
68 unamestr = variant.toString(); |
|
69 } |
|
70 if ( parameters.contains(keyauthmethod) ) { |
|
71 QVariant variant = parameters.value(keyauthmethod); |
|
72 authMethodstr = variant.toString(); |
|
73 } |
|
74 } |
|
75 |
|
76 QString labelText1 = QString(hbTrId("txt_occ_dialog_1_user_name").arg(authMethodstr)); |
|
77 QString labelText2 = QString(hbTrId("txt_occ_dialog_password")); |
|
78 |
|
79 //Set the dialog to be on the screen until user reacts |
|
80 //by pressing any of the Action buttons |
|
81 this->setModal(true); |
|
82 this->setTimeout(HbPopup::NoTimeout); |
|
83 this->setDismissPolicy(HbPopup::NoDismiss); |
|
84 this->setAdditionalRowVisible(true); |
|
85 |
|
86 this->setPromptText(labelText1, 0); |
|
87 mEdit1 = this->lineEdit(0); |
|
88 mEdit1->setText(unamestr); |
|
89 |
|
90 this->setPromptText(labelText2, 1); |
|
91 mEdit2 = this->lineEdit(1); |
|
92 |
|
93 QByteArray ba; |
|
94 |
|
95 if ( parameters.contains(keyeaptype) ) { |
|
96 QVariant variant = parameters.value(keyeaptype); |
|
97 ba = variant.toByteArray(); |
|
98 } |
|
99 Q_ASSERT( ba.isEmpty() == false ); |
|
100 |
|
101 EapQtExpandedEapType e_type(ba); |
|
102 EapQtConfigInterface eap_config_if; |
|
103 |
|
104 mUnameValidator = eap_config_if.validatorEap(e_type, |
|
105 EapQtConfig::Username); |
|
106 mUnameValidator->updateEditor(mEdit1); |
|
107 |
|
108 mPwdValidator = eap_config_if.validatorEap(e_type, |
|
109 EapQtConfig::Password); |
|
110 mPwdValidator->updateEditor(mEdit2); |
|
111 |
|
112 QList<QAction*> action_list = this->actions(); |
|
113 |
|
114 for ( int i = 0; i < action_list.count(); i++ ) { |
|
115 this->removeAction(action_list.at(i)); |
|
116 } |
|
117 |
|
118 HbAction* actionOk = new HbAction(hbTrId("txt_common_button_ok"),this); |
|
119 this->addAction(actionOk); |
|
120 HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this); |
|
121 this->addAction( actionCancel ); |
|
122 |
|
123 disconnect(actionOk, SIGNAL(triggered()),this, SLOT(close())); |
|
124 bool connected = connect(actionOk, SIGNAL(triggered()), this, SLOT(okPressed())); |
|
125 Q_ASSERT(connected == true); |
|
126 |
|
127 disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close())); |
|
128 connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed())); |
|
129 Q_ASSERT(connected == true); |
|
130 |
|
131 // Connect the about to close and hide signals, so that we are able to inform |
|
132 // the caller that the dialog was closed |
|
133 connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog())); |
|
134 Q_ASSERT(connected == true); |
|
135 connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog())); |
|
136 Q_ASSERT(connected == true); |
|
137 |
|
138 OstTraceFunctionExit0( DUP1_EAPUSERNAMEPWDDIALOG_CREATEDIALOG_EXIT ); |
|
139 qDebug("EapUsernamePwdDialog::createDialog EXIT"); |
|
140 } |
|
141 |
|
142 /** |
|
143 * Destructor |
|
144 */ |
|
145 EapUsernamePwdDialog::~EapUsernamePwdDialog() |
|
146 { |
|
147 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_DEAPUSERNAMEPWDDIALOG_ENTRY ); |
|
148 qDebug("EapUsernamePwdDialog::~EapUsernamePwdDialog"); |
|
149 |
|
150 //The dialog widgets are deleted as the dialog is deleted |
|
151 delete mPwdValidator; |
|
152 delete mUnameValidator; |
|
153 |
|
154 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_DEAPUSERNAMEPWDDIALOG_EXIT ); |
|
155 } |
|
156 |
|
157 /** |
|
158 * Line edit validator |
|
159 */ |
|
160 bool EapUsernamePwdDialog::validate() const |
|
161 { |
|
162 qDebug("EapUsernamePwdDialog::validate ENTER"); |
|
163 |
|
164 bool valid = false; |
|
165 |
|
166 if ( mUnameValidator->validate(mEdit1->text())== EapQtValidator::StatusOk && |
|
167 mPwdValidator->validate(mEdit2->text()) == EapQtValidator::StatusOk ) { |
|
168 |
|
169 qDebug("EapUsernamePwdDialog::validate(): returns TRUE"); |
|
170 valid = true; |
|
171 } |
|
172 |
|
173 qDebug("EapUsernamePwdDialog::validate EXIT"); |
|
174 return valid; |
|
175 } |
|
176 |
|
177 /** |
|
178 * Function is called when the Ok Action button is pressed |
|
179 */ |
|
180 void EapUsernamePwdDialog::okPressed() |
|
181 { |
|
182 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_OKPRESSED_ENTRY ); |
|
183 qDebug("EapUsernamePwdDialog::okPressed ENTER"); |
|
184 |
|
185 if ( validate() == true && mOkActionPressed == false ) { |
|
186 |
|
187 mOkActionPressed = true; |
|
188 |
|
189 QVariantMap data; |
|
190 |
|
191 QString editStr1 = mEdit1->text(); |
|
192 |
|
193 QString editStr2 = mEdit2->text(); |
|
194 |
|
195 QVariant variant1(editStr1); |
|
196 |
|
197 QVariant variant2(editStr2); |
|
198 |
|
199 data["username"] = variant1; |
|
200 data["password"] = variant2; |
|
201 |
|
202 qDebug("EapUsernamePwdDialog::okPressed: emit deviceDialogData"); |
|
203 |
|
204 emit deviceDialogData(data); |
|
205 closeDeviceDialog(true); |
|
206 } |
|
207 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_OKPRESSED_EXIT ); |
|
208 qDebug("EapUsernamePwdDialog::okPressed EXIT"); |
|
209 } |
|
210 |
|
211 /** |
|
212 * Function is called when the Cancel Action button is pressed |
|
213 */ |
|
214 void EapUsernamePwdDialog::cancelPressed() |
|
215 { |
|
216 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CANCELPRESSED_ENTRY ); |
|
217 qDebug("EapUsernamePwdDialog::cancelPressed ENTER"); |
|
218 |
|
219 if (!mClose) { |
|
220 mClose = true; |
|
221 closeDeviceDialog(true); |
|
222 } |
|
223 qDebug("EapUsernamePwdDialog::cancelPressed EXIT"); |
|
224 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_CANCELPRESSED_EXIT ); |
|
225 } |
|
226 |
|
227 /** |
|
228 * Function is called when the dialog is about to close |
|
229 * |
|
230 */ |
|
231 void EapUsernamePwdDialog::closingDialog() |
|
232 { |
|
233 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CLOSINGDIALOG_ENTRY ); |
|
234 qDebug("EapUsernamePwdDialog::closingDialog ENTER"); |
|
235 |
|
236 closeDeviceDialog(false); |
|
237 |
|
238 qDebug("EapUsernamePwdDialog::closingDialog EXIT"); |
|
239 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_CLOSINGDIALOG_EXIT ); |
|
240 } |
|
241 |
|
242 /** |
|
243 * Updating the dialog during its showing is not allowed. |
|
244 */ |
|
245 bool EapUsernamePwdDialog::setDeviceDialogParameters |
|
246 (const QVariantMap ¶meters) |
|
247 { |
|
248 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY ); |
|
249 |
|
250 Q_UNUSED(parameters) |
|
251 // changing the dialog after presenting it is not supported. |
|
252 |
|
253 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT ); |
|
254 return true; |
|
255 } |
|
256 |
|
257 /** |
|
258 * Not supported, 0 always returned |
|
259 */ |
|
260 int EapUsernamePwdDialog::deviceDialogError() const |
|
261 { |
|
262 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGERROR_ENTRY ); |
|
263 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGERROR_EXIT); |
|
264 return 0; |
|
265 } |
|
266 |
|
267 /** |
|
268 * Dialog is closed and the signal about closing is emitted |
|
269 */ |
|
270 void EapUsernamePwdDialog::closeDeviceDialog(bool byClient) |
|
271 { |
|
272 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CLOSEDEVICEDIALOG_ENTRY ); |
|
273 qDebug("EapUsernamePwdDialog::closeDeviceDialog ENTER"); |
|
274 |
|
275 //If the user closes the dialog, then the deviceDialogClosed is emitted |
|
276 if ( byClient == true ) |
|
277 { |
|
278 qDebug("EapUsernamePwdDialog::closeDeviceDialog: emit deviceDialogClosed"); |
|
279 emit deviceDialogClosed(); |
|
280 } |
|
281 |
|
282 qDebug("EapUsernamePwdDialog::closeDeviceDialog EXIT"); |
|
283 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_CLOSEDEVICEDIALOG_EXIT ); |
|
284 } |
|
285 |
|
286 /** |
|
287 * This dialog widget is returned to the caller |
|
288 */ |
|
289 HbPopup *EapUsernamePwdDialog::deviceDialogWidget() const |
|
290 { |
|
291 OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGWIDGET_ENTRY ); |
|
292 OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGWIDGET_EXIT ); |
|
293 |
|
294 return const_cast<EapUsernamePwdDialog*>(this); |
|
295 } |
|
296 |