14 * Control Panel QT UI for WPA2 only configuration |
14 * Control Panel QT UI for WPA2 only configuration |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 /* |
18 /* |
19 * %version: 17 % |
19 * %version: 22 % |
20 */ |
20 */ |
21 |
21 |
22 // User includes |
22 // User includes |
23 #include "cpwpa2ui.h" |
23 #include "cpwpa2ui.h" |
24 #include "cpwpacmnui.h" |
24 #include "cpwpacmnui.h" |
25 #include "wpa2keyvalidator.h" |
|
26 |
25 |
27 // System includes |
26 // System includes |
28 #include <HbDeviceNotificationDialog> |
|
29 #include <cmmanagerdefines_shim.h> |
27 #include <cmmanagerdefines_shim.h> |
30 #include <cmconnectionmethod_shim.h> |
28 #include <cmconnectionmethod_shim.h> |
31 #include <eapqtconfiginterface.h> |
29 #include <eapqtconfiginterface.h> |
32 #include <QStringList> |
30 #include <QStringList> |
33 #include <QLocale> |
31 #include <HbTranslator> |
34 #include <QCoreApplication> |
|
35 |
32 |
|
33 //Trace Definition |
36 #include "OstTraceDefinitions.h" |
34 #include "OstTraceDefinitions.h" |
37 #ifdef OST_TRACE_COMPILER_IN_USE |
35 #ifdef OST_TRACE_COMPILER_IN_USE |
38 #include "cpwpa2uiTraces.h" |
36 #include "cpwpa2uiTraces.h" |
39 #endif |
37 #endif |
40 |
38 |
41 |
39 |
42 // Constants |
40 // Constants |
43 //The order in which WPA2 only mode appears in the list of available |
41 //The order in which WPA2 only mode appears in the list of available |
44 //security mode |
42 //security mode |
45 const int UI_ORDER_WPA2_ONLY = 50; |
43 const int UI_ORDER_WPA2_ONLY = 30; |
46 |
44 |
47 /*! |
45 /*! |
48 \class CpWpa2Ui |
46 \class CpWpa2Ui |
49 \brief CpWpa2Ui implements the Ui for WPA2 only |
47 \brief CpWpa2Ui implements the Ui for WPA2 only |
50 Security Settings Control Panel Plugin, |
48 Security Settings Control Panel Plugin, |
51 which will allow viewing/editing of WPA2 only Security Settings. |
49 which will allow viewing/editing of WPA2 only Security Settings. |
52 */ |
50 */ |
53 //Contructs WPA2 object |
51 /*! |
|
52 * Constructor |
|
53 * |
|
54 */ |
54 CpWpa2Ui::CpWpa2Ui() : |
55 CpWpa2Ui::CpWpa2Ui() : |
55 mUi(NULL), mCmCM(NULL), mEapQtConfigInterface(NULL), |
56 mUi(NULL), |
56 mWpa2Ui(NULL) |
57 mTranslator(new HbTranslator("cpwlansecsettingsplugin")), |
|
58 mCmCM(NULL), |
|
59 mEapQtConfigInterface(NULL), |
|
60 mWpa2Ui(NULL) |
57 { |
61 { |
58 mTranslator = new QTranslator(this); |
|
59 mTranslator->load(":/loc/wlan_en_GB.qm"); |
|
60 |
|
61 qApp->installTranslator(mTranslator); |
|
62 |
|
63 /*mTranslator = QSharedPointer<HbTranslator> ( |
|
64 new HbTranslator("wlan_en_GB"));*/ |
|
65 |
62 |
66 } |
63 } |
67 |
64 |
68 //Deletes all objects WPA2 owns |
65 //Destructor |
69 CpWpa2Ui::~CpWpa2Ui() |
66 CpWpa2Ui::~CpWpa2Ui() |
70 { |
67 { |
71 OstTraceFunctionEntry1(CPWPA2UI_CPWPA2UI_ENTRY,this); |
68 OstTraceFunctionEntry1(CPWPA2UI_CPWPA2UI_ENTRY,this); |
72 //delete mEapQtConfigInterface; |
69 delete mEapQtConfigInterface; |
|
70 delete mTranslator; |
73 OstTraceFunctionExit1(CPWPA2UI_CPWPA2UI_EXIT,this); |
71 OstTraceFunctionExit1(CPWPA2UI_CPWPA2UI_EXIT,this); |
74 } |
72 } |
75 |
73 |
76 // ======== MEMBER FUNCTIONS ======== |
74 // ======== MEMBER FUNCTIONS ======== |
77 |
75 |
95 |
93 |
96 \return Localization text ID |
94 \return Localization text ID |
97 */ |
95 */ |
98 QString CpWpa2Ui::securityModeTextId() const |
96 QString CpWpa2Ui::securityModeTextId() const |
99 { |
97 { |
100 OstTraceFunctionEntry1(CPWPA2UI_LOCALIZATIONID_ENTRY,this); |
98 OstTraceFunctionEntry1(CPWPA2UI_SECURITYMODETEXTID_ENTRY,this); |
101 OstTraceFunctionExit1(CPWPA2UI_LOCALIZATIONID_EXIT,this); |
99 OstTraceFunctionExit1(CPWPA2UI_SECURITYMODETEXTID_EXIT,this); |
102 return "txt_occ_setlabel_wlan_security_mode_val_wpa2_only"; |
100 return "txt_occ_setlabel_wlan_security_mode_val_wpa2_only"; |
103 } |
101 } |
104 |
102 |
105 /*! |
103 /*! |
106 Sets the database reference (WLAN Service Table ID). |
104 Sets the database reference IAP id. |
107 |
105 |
108 \param id Database reference |
106 \param id Database reference |
109 */ |
107 */ |
110 void CpWpa2Ui::setReference(CmConnectionMethodShim *cmCm, uint id) |
108 void CpWpa2Ui::setReference(CmConnectionMethodShim *cmCm, uint id) |
111 { |
109 { |
112 OstTraceFunctionEntry1(CPWPA2UI_SETREFERENCE_ENTRY,this); |
110 OstTraceFunctionEntry1(CPWPA2UI_SETREFERENCE_ENTRY,this); |
113 // Assuming that id is the connection method Id/IAP Id. |
111 if (!mEapQtConfigInterface) { |
114 |
|
115 mCmId = id; |
|
116 |
|
117 /*if (!mEapQtConfigInterface) { |
|
118 mEapQtConfigInterface = new EapQtConfigInterface( |
112 mEapQtConfigInterface = new EapQtConfigInterface( |
119 EapQtConfigInterface::EapBearerTypeWlan, mCmId); |
113 EapQtConfigInterface::EapBearerTypeWlan, id); |
120 //fix, hangs |
114 } else { |
121 }*/ |
115 mEapQtConfigInterface->setConfigurationReference(id); |
|
116 } |
122 |
117 |
123 //mCmCM is not deleted assuming mCmManager owns it. |
118 //mCmCM is not deleted assuming mCmManager owns it. |
124 mCmCM = cmCm; |
119 mCmCM = cmCm; |
125 OstTraceFunctionExit1(CPWPA2UI_SETREFERENCE_EXIT,this); |
120 OstTraceFunctionExit1(CPWPA2UI_SETREFERENCE_EXIT,this); |
126 } |
121 } |
146 */ |
141 */ |
147 CpSettingFormItemData* CpWpa2Ui::uiInstance(CpItemDataHelper &dataHelpper) |
142 CpSettingFormItemData* CpWpa2Ui::uiInstance(CpItemDataHelper &dataHelpper) |
148 { |
143 { |
149 OstTraceFunctionEntry1(CPWPA2UI_UIINSTANCE_ENTRY,this); |
144 OstTraceFunctionEntry1(CPWPA2UI_UIINSTANCE_ENTRY,this); |
150 |
145 |
151 //reset the Common Ui Ptr |
146 //reset the Common Ui Ptr |
152 mWpa2Ui.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa2, dataHelpper)); |
147 mWpa2Ui.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa2, dataHelpper)); |
153 |
148 |
154 mUi = mWpa2Ui->createUi(mEapQtConfigInterface, mCmCM); |
149 mUi = mWpa2Ui->createUi(mEapQtConfigInterface, mCmCM); |
155 |
150 |
156 connect(mWpa2Ui.data(), SIGNAL(keyChanged(QString&)), this, |
|
157 SLOT(pskKeyChanged(QString&))); |
|
158 |
|
159 connect(mWpa2Ui.data(), SIGNAL(pskEapModeToggled(int)), this, |
|
160 SLOT(wpaTypeChanged(int))); |
|
161 |
|
162 connect(mWpa2Ui.data(), SIGNAL(eapPluginChanged(int)), this, |
|
163 SLOT(currentEapPlugin(int))); |
|
164 |
|
165 OstTraceFunctionExit1(CPWPA2UI_UIINSTANCE_EXIT,this); |
151 OstTraceFunctionExit1(CPWPA2UI_UIINSTANCE_EXIT,this); |
166 return mUi; |
152 return mUi; |
167 } |
153 } |
168 |
154 |
169 // ======== LOCAL FUNCTIONS ======== |
|
170 /*! |
155 /*! |
171 Slot to handle change in wpa mode :- PSK /EAP |
156 Validates current security settings. This function is called whenever |
|
157 user tries to exit from the settings view. If the plugin determines |
|
158 that some settings need editing before considered valid, it shall |
|
159 return false. A dialog will be shown to the user indicating that |
|
160 settings are still incomplete and asking if he/she wishes to exit |
|
161 anyway. |
172 |
162 |
173 \param pskEnable the current mode chosen |
163 \return True if security settings for WPA2 only are valid, false if not. |
174 */ |
164 */ |
175 /*void CpWpa2Ui::wpaTypeChanged(int pskEnable) |
165 bool CpWpa2Ui::validateSettings() |
176 { |
166 { |
177 int err; |
167 return mWpa2Ui->validateSettings(); |
178 OstTraceFunctionEntry1(CPWPA2UI_WPATYPECHANGED_ENTRY,this); |
|
179 |
|
180 bool PskEnable = pskEnable ? ETrue : EFalse; |
|
181 |
|
182 QT_TRYCATCH_ERROR(err,mCmCM->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk, PskEnable)); |
|
183 |
|
184 if(err !=KErrNone) { |
|
185 OstTrace1( TRACE_ERROR, CPWPA2UI_WPATYPECHANGED, "ERROR WPA2 only:wpatypereturned returned %d", err ); |
|
186 } |
|
187 tryUpdate(); |
|
188 OstTraceFunctionExit1(CPWPA2UI_WPATYPECHANGED_EXIT,this); |
|
189 }*/ |
|
190 |
|
191 /*! |
|
192 Slot to handle change in pre-shared key string |
|
193 |
|
194 \param key changed string for PSK |
|
195 */ |
|
196 void CpWpa2Ui::pskKeyChanged(QString &key) |
|
197 { |
|
198 int err; |
|
199 OstTraceFunctionEntry1(CPWPA2UI_PSKKEYCHANGED_ENTRY,this); |
|
200 |
|
201 //Check for Validity of Pre-shared Key |
|
202 Wpa2KeyValidator::KeyStatus keystatus = Wpa2KeyValidator::validateWpa2Key(key); |
|
203 |
|
204 if (keystatus == Wpa2KeyValidator::KeyStatusOk) { |
|
205 QT_TRYCATCH_ERROR(err, mCmCM->setString8Attribute(CMManagerShim::WlanWpaPreSharedKey, key)); |
|
206 if(err !=KErrNone) { |
|
207 OstTrace1( TRACE_ERROR, CPWPA2UI_PSKKEYCHANGED, "ERROR WPA2 only: pskKeyChanged returned %d", err ); |
|
208 } |
|
209 tryUpdate(); |
|
210 } |
|
211 |
|
212 else { |
|
213 showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId( |
|
214 "txt_occ_info_invalid_input")); |
|
215 } |
|
216 OstTraceFunctionExit1(CPWPA2UI_PSKKEYCHANGED_EXIT,this); |
|
217 } |
|
218 |
|
219 /*! |
|
220 Slot to handle change in eap method in use |
|
221 \param currentplugin plugin number to indicate the |
|
222 eap method in use |
|
223 */ |
|
224 /*void CpWpa2Ui::currentEapPlugin(int currentPlugin ) |
|
225 { |
|
226 OstTraceFunctionEntry1(CPWPA2UI_CURRENTEAPPLUGIN_ENTRY,this); |
|
227 |
|
228 // define enum to store the current EAP type |
|
229 //mCmCM->setIntAttribute( use appropriate enum to get the eap plugin index ); |
|
230 OstTraceFunctionExit1(CPWPA2UI_CURRENTEAPPLUGIN_EXIT,this); |
|
231 }*/ |
|
232 |
|
233 bool CpWpa2Ui::tryUpdate() |
|
234 { |
|
235 OstTraceFunctionEntry1(CPWPA2UI_TRYUPDATE_ENTRY,this); |
|
236 |
|
237 // Try update |
|
238 try { |
|
239 mCmCM->update(); |
|
240 } |
|
241 catch (const std::exception&) { |
|
242 // Handle error |
|
243 handleUpdateError(); |
|
244 |
|
245 OstTraceFunctionExit1(CPWPA2UI_TRYUPDATE_EXIT,this); |
|
246 return false; |
|
247 } |
|
248 |
|
249 OstTraceFunctionExit1(DUP1_CPWPA2UI_TRYUPDATE_EXIT,this); |
|
250 return true; |
|
251 } |
|
252 |
|
253 /*! |
|
254 Handles failed CommsDat update. |
|
255 */ |
|
256 void CpWpa2Ui::handleUpdateError() |
|
257 { |
|
258 OstTraceFunctionEntry1(CPWPA2UI_HANDLEUPDATEERROR_ENTRY,this); |
|
259 |
|
260 // Show error note to user |
|
261 showMessageBox( |
|
262 HbMessageBox::MessageTypeWarning, |
|
263 hbTrId("txt_occ_info_unable_to_save_setting")); |
|
264 // Reload settings from CommsDat and update UI |
|
265 try { |
|
266 mCmCM->refresh(); |
|
267 } |
|
268 catch (const std::exception&) { |
|
269 // Ignore error from refresh. Most likely this will not happen, but |
|
270 // if it does, there isn't very much we can do. |
|
271 OstTrace0( |
|
272 TRACE_ERROR, |
|
273 CPWPA2UI_HANDLEUPDATEERROR, |
|
274 "Refresh failed"); |
|
275 }; |
|
276 updateWpaSettings(); |
|
277 |
|
278 OstTraceFunctionExit1(CPWPA2UI_HANDLEUPDATEERROR_EXIT,this); |
|
279 } |
|
280 |
|
281 /*! |
|
282 Shows message box with "OK" button using given text. |
|
283 */ |
|
284 void CpWpa2Ui::showMessageBox( |
|
285 HbMessageBox::MessageBoxType type, |
|
286 const QString &text) |
|
287 { |
|
288 OstTraceFunctionEntry1(CPWPA2UI_SHOWMESSAGEBOX_ENTRY,this); |
|
289 |
|
290 // Create a message box |
|
291 mMessageBox = QSharedPointer<HbMessageBox>(new HbMessageBox(type)); |
|
292 mMessageBox->setText(text); |
|
293 mMessageBox->open(); |
|
294 |
|
295 OstTraceFunctionExit1(CPWPA2UI_SHOWMESSAGEBOX_EXIT,this); |
|
296 } |
168 } |
297 |
169 |
298 |
170 |
299 void CpWpa2Ui::updateWpaSettings() |
|
300 { |
|
301 OstTraceFunctionEntry1(CPWPA2UI_UPDATEWPASETTINGS_ENTRY,this); |
|
302 mWpa2Ui->reset(); |
|
303 OstTraceFunctionExit1(CPWPA2UI_UPDATEWPASETTINGS_EXIT,this); |
|
304 } |
|
305 |
|
306 Q_EXPORT_PLUGIN2(CpWpa2Ui, CpWpa2Ui) |
171 Q_EXPORT_PLUGIN2(CpWpa2Ui, CpWpa2Ui) |
307 ; |
172 ; |