|
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 the License "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 * Control Panel QT UI for WPA/WPA2 configuration |
|
16 * |
|
17 */ |
|
18 |
|
19 /* |
|
20 * %version: tr1cfwln#21.1.1 % |
|
21 */ |
|
22 //User Includes |
|
23 #include "cpwpaui.h" |
|
24 #include "cpwpacmnui.h" |
|
25 #include "wpakeyvalidator.h" |
|
26 |
|
27 // System includes |
|
28 #include <QStringList> |
|
29 #include <HbDeviceNotificationDialog> |
|
30 #include <QLocale> |
|
31 #include <qtranslator.h> |
|
32 #include <QCoreApplication> |
|
33 #include <cmconnectionmethod_shim.h> |
|
34 #include <cmmanagerdefines_shim.h> |
|
35 #include <eapqtconfiginterface.h> |
|
36 |
|
37 #include "OstTraceDefinitions.h" |
|
38 #ifdef OST_TRACE_COMPILER_IN_USE |
|
39 #include "cpwpauiTraces.h" |
|
40 #endif |
|
41 |
|
42 //Constants |
|
43 //The order in which WPA/WPA2 only mode appears in the list of available |
|
44 //security modes |
|
45 const int UI_ORDER_WPA_WPA2 = 40; |
|
46 /*! |
|
47 \class CpWpaUi |
|
48 \brief CpWpaUi implements the common Ui for WPA/WPA2 |
|
49 Security Settings Control Panel Plugins, |
|
50 which will allow viewing/editing of WPA/WPA2 Security Settings. |
|
51 */ |
|
52 //Contructs WPA/WPA2 object |
|
53 CpWpaUi::CpWpaUi() : |
|
54 mUi(NULL), mCmCM(NULL), mEapQtConfigInterface(NULL) |
|
55 { |
|
56 mTranslator = new QTranslator(this); |
|
57 mTranslator->load(":/loc/wlan_en_GB.qm"); |
|
58 |
|
59 qApp->installTranslator(mTranslator); |
|
60 |
|
61 } |
|
62 |
|
63 //Deletes all objects WPA/WPA2 owns |
|
64 CpWpaUi::~CpWpaUi() |
|
65 { |
|
66 OstTraceFunctionEntry1(CPWPAUI_CPWPAUI_ENTRY,this); |
|
67 //delete mEapQtConfigInterface; |
|
68 OstTraceFunctionExit1(CPWPAUI_CPWPAUI_EXIT,this); |
|
69 } |
|
70 |
|
71 // ======== MEMBER FUNCTIONS ======== |
|
72 |
|
73 /*! |
|
74 Getter for security mode. |
|
75 |
|
76 \return Security mode identifier |
|
77 */ |
|
78 CMManagerShim::WlanSecMode CpWpaUi::securityMode() const |
|
79 { |
|
80 OstTraceFunctionEntry1(CPWPAUI_MODE_ENTRY,this); |
|
81 OstTraceFunctionExit1(CPWPAUI_MODE_EXIT,this); |
|
82 //return security mode |
|
83 return CMManagerShim::WlanSecModeWpa; |
|
84 } |
|
85 |
|
86 /*! |
|
87 Getter for localization text identifier for the security mode, |
|
88 f.ex. "txt_occ_setlabel_wlan_security_mode_val_wpawpa2". This localized |
|
89 text will be shown in the UI. |
|
90 |
|
91 \return Localization text ID |
|
92 */ |
|
93 QString CpWpaUi::securityModeTextId() const |
|
94 { |
|
95 OstTraceFunctionEntry1(CPWPAUI_LOCALIZATIONID_ENTRY,this); |
|
96 OstTraceFunctionExit1(CPWPAUI_LOCALIZATIONID_EXIT,this); |
|
97 return "txt_occ_setlabel_wlan_security_mode_val_wpawpa2"; |
|
98 } |
|
99 |
|
100 /*! |
|
101 Sets the database reference (WLAN Service Table ID). |
|
102 |
|
103 \param id Database reference |
|
104 */ |
|
105 void CpWpaUi::setReference(CmConnectionMethodShim *cmCm, uint id) |
|
106 { |
|
107 OstTraceFunctionEntry1(CPWPAUI_SETREFERENCE_ENTRY,this); |
|
108 // Assuming that id is the connection method Id/IAP Id. |
|
109 mCmId = id; |
|
110 |
|
111 /*if (!mEapQtConfigInterface) { |
|
112 mEapQtConfigInterface = new EapQtConfigInterface( |
|
113 EapQtConfigInterface::EapBearerTypeWlan, mCmId); |
|
114 // fix, hangs |
|
115 }*/ |
|
116 |
|
117 //mCmCM is not deleted assuming mCmManager owns it. |
|
118 mCmCM = cmCm; |
|
119 OstTraceFunctionExit1(CPWPAUI_SETREFERENCE_EXIT,this); |
|
120 } |
|
121 |
|
122 /*! |
|
123 Getter for order number. This order number is used by the client of |
|
124 this interface to put the security modes in correct order in the list. |
|
125 |
|
126 \return An order number |
|
127 */ |
|
128 int CpWpaUi::orderNumber() const |
|
129 { |
|
130 OstTraceFunctionEntry1(CPWPAUI_ORDERNUMBER_ENTRY,this); |
|
131 OstTraceFunctionExit1(CPWPAUI_ORDERNUMBER_EXIT,this); |
|
132 return UI_ORDER_WPA_WPA2; |
|
133 } |
|
134 |
|
135 /*! |
|
136 Creates an UI instance. Caller owns the object. |
|
137 |
|
138 \param dataHelper Item data helper |
|
139 \return Pointer to an UI object |
|
140 */ |
|
141 CpSettingFormItemData* CpWpaUi::uiInstance(CpItemDataHelper &dataHelper) |
|
142 { |
|
143 OstTraceFunctionEntry1(CPWPAUI_UIINSTANCE_ENTRY,this); |
|
144 |
|
145 //reset the Common Ui Ptr |
|
146 mWpaUi.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa, dataHelper)); |
|
147 |
|
148 mUi = mWpaUi->createUi(mEapQtConfigInterface, mCmCM); |
|
149 |
|
150 connect(mWpaUi.data(), SIGNAL(keyChanged(QString&)), this, SLOT(pskKeyChanged(QString&))); |
|
151 |
|
152 connect(mWpaUi.data(), SIGNAL(pskEapModeToggled(int)), this, SLOT(wpaTypeChanged(int))); |
|
153 |
|
154 connect(mWpaUi.data(), SIGNAL(eapPluginChanged(int)), this, SLOT(currentEapPlugin(int))); |
|
155 //} |
|
156 OstTraceFunctionExit1(CPWPAUI_UIINSTANCE_EXIT,this); |
|
157 return mUi; |
|
158 } |
|
159 |
|
160 |
|
161 // ======== LOCAL FUNCTIONS ======== |
|
162 |
|
163 /*! |
|
164 Slot to handle change in wpa mode :- PSK /EAP |
|
165 |
|
166 \param pskEnable the current mode chosen |
|
167 */ |
|
168 /*void CpWpaUi::wpaTypeChanged(int pskEnable) |
|
169 { |
|
170 int err; |
|
171 OstTraceFunctionEntry1(CPWPAUI_WPATYPECHANGED_ENTRY,this); |
|
172 |
|
173 bool PskEnable = pskEnable ? ETrue : EFalse; |
|
174 |
|
175 QT_TRYCATCH_ERROR(err,mCmCM->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk, PskEnable)); |
|
176 |
|
177 if(err !=KErrNone) { |
|
178 OstTrace1( TRACE_ERROR, CPWPAUI_WPATYPECHANGED, "ERROR WPA/WPA2 wpatypereturned returned %d", err ); |
|
179 } |
|
180 tryUpdate(); |
|
181 OstTraceFunctionExit1(CPWPAUI_WPATYPECHANGED_EXIT,this); |
|
182 }*/ |
|
183 |
|
184 /*! |
|
185 Slot to handle change in pre-shared key string |
|
186 |
|
187 \param key changed string for PSK |
|
188 */ |
|
189 void CpWpaUi::pskKeyChanged(QString &key) |
|
190 { |
|
191 int err; |
|
192 OstTraceFunctionEntry1(CPWPAUI_PSKKEYCHANGED_ENTRY,this); |
|
193 //Store to native s60 type for validation |
|
194 TPtrC ptrName(reinterpret_cast<const TText*> (key.constData())); |
|
195 |
|
196 //Check for Validity of Pre-shared Key |
|
197 WpaKeyValidator::KeyStatus keystatus = WpaKeyValidator::validateWpaKey(key); |
|
198 |
|
199 if (keystatus == WpaKeyValidator::KeyStatusOk) { |
|
200 |
|
201 QT_TRYCATCH_ERROR(err,mCmCM->setString8Attribute(CMManagerShim::WlanWpaPreSharedKey, key)); |
|
202 if(err !=KErrNone) { |
|
203 OstTrace1( TRACE_ERROR,CPWPAUI_PSKKEYCHANGED, "ERROR WPA/WPA2: pskKeyChanged returned %d", err ); |
|
204 } |
|
205 tryUpdate(); |
|
206 } |
|
207 else { |
|
208 showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId( |
|
209 "txt_occ_info_invalid_input")); |
|
210 } |
|
211 OstTraceFunctionExit1(CPWPAUI_PSKKEYCHANGED_EXIT,this); |
|
212 } |
|
213 |
|
214 /*! |
|
215 Slot to handle change in eap method in use |
|
216 \param currentplugin plugin number to indicate the |
|
217 eap method in use |
|
218 */ |
|
219 /*void CpWpaUi::currentEapPlugin(int plugin ) |
|
220 { |
|
221 OstTraceFunctionEntry1(CPWPAUI_CURRENTEAPPLUGIN_ENTRY,this); |
|
222 |
|
223 //define enum to store the current EAP type |
|
224 //mCmCM->setIntAttribute( use appropriate enum to get the eap plugin index ); |
|
225 OstTraceFunctionExit1(CPWPAUI_CURRENTEAPPLUGIN_EXIT,this); |
|
226 }*/ |
|
227 |
|
228 bool CpWpaUi::tryUpdate() |
|
229 { |
|
230 OstTraceFunctionEntry1(CPWPAUI_TRYUPDATE_ENTRY,this); |
|
231 |
|
232 // Try update |
|
233 try { |
|
234 mCmCM->update(); |
|
235 } catch (const std::exception&) { |
|
236 // Handle error |
|
237 handleUpdateError(); |
|
238 |
|
239 OstTraceFunctionExit1(CPWPAUI_TRYUPDATE_EXIT,this); |
|
240 return false; |
|
241 } |
|
242 |
|
243 OstTraceFunctionExit1(DUP1_CPWPAUI_TRYUPDATE_EXIT,this); |
|
244 return true; |
|
245 } |
|
246 |
|
247 /*! |
|
248 Handles failed CommsDat update. |
|
249 */ |
|
250 void CpWpaUi::handleUpdateError() |
|
251 { |
|
252 OstTraceFunctionEntry1(CPWPAUI_HANDLEUPDATEERROR_ENTRY,this); |
|
253 |
|
254 // Show error note to user |
|
255 showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId("txt_occ_info_unable_to_save_setting")); |
|
256 // Reload settings from CommsDat and update UI |
|
257 try { |
|
258 mCmCM->refresh(); |
|
259 } catch (const std::exception&) { |
|
260 // Ignore error from refresh. Most likely this will not happen, but |
|
261 // if it does, there isn't very much we can do. |
|
262 OstTrace0( |
|
263 TRACE_ERROR, |
|
264 CPWPAUI_HANDLEUPDATEERROR, |
|
265 "Refresh failed"); |
|
266 }; |
|
267 updateWpaSettings(); |
|
268 |
|
269 OstTraceFunctionExit1(CPWPAUI_HANDLEUPDATEERROR_EXIT,this); |
|
270 } |
|
271 |
|
272 /*! |
|
273 Shows message box with "OK" button using given text. |
|
274 */ |
|
275 void CpWpaUi::showMessageBox(HbMessageBox::MessageBoxType type, const QString &text) |
|
276 { |
|
277 OstTraceFunctionEntry1(CPWPAUI_SHOWMESSAGEBOX_ENTRY,this); |
|
278 |
|
279 // Create a message box |
|
280 mMessageBox = QSharedPointer<HbMessageBox> (new HbMessageBox(type)); |
|
281 mMessageBox->setText(text); |
|
282 mMessageBox->open(); |
|
283 |
|
284 OstTraceFunctionExit1(CPWPAUI_SHOWMESSAGEBOX_EXIT,this); |
|
285 } |
|
286 |
|
287 void CpWpaUi::updateWpaSettings() |
|
288 { |
|
289 OstTraceFunctionEntry1(CPWPAUI_UPDATEWPASETTINGS_ENTRY,this); |
|
290 mWpaUi->reset(); |
|
291 OstTraceFunctionExit1(CPWPAUI_UPDATEWPASETTINGS_EXIT,this); |
|
292 } |
|
293 |
|
294 Q_EXPORT_PLUGIN2(CpWpaUi, CpWpaUi) |
|
295 ; |