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 * Control Panel WLAN AP settings view implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <QString> |
|
21 #include <QVariant> |
|
22 #include <QDir> |
|
23 #include <QPluginLoader> |
|
24 #include <HbMainWindow> |
|
25 #include <HbMenu> |
|
26 #include <HbDataForm> |
|
27 #include <HbDataFormModel> |
|
28 #include <HbDataFormViewItem> |
|
29 #include <HbLineEdit> |
|
30 #include <HbEditorInterface> |
|
31 #include <HbUrlFilter> |
|
32 #include <HbPopup> |
|
33 #include <HbMessageBox> |
|
34 #include <HbAction> |
|
35 #include <HbStringUtil> |
|
36 #include <wlanmgmtcommon.h> |
|
37 #include <cpitemdatahelper.h> |
|
38 #include <cpsettingformitemdata.h> |
|
39 #include <cppluginutility.h> |
|
40 #include <cmconnectionmethod_shim.h> |
|
41 #include <cpwlansecurityplugininterface.h> |
|
42 |
|
43 // User includes |
|
44 #include "cpwlanapplugin.h" |
|
45 #include "cpwlanapview.h" |
|
46 #include "cpwlanapadvancedview.h" |
|
47 #include "OstTraceDefinitions.h" |
|
48 #ifdef OST_TRACE_COMPILER_IN_USE |
|
49 #include "cpwlanapviewTraces.h" |
|
50 #endif |
|
51 |
|
52 /*! |
|
53 \class CpWlanApView |
|
54 \brief This class implements the WLAN AP Control Panel settings view. |
|
55 */ |
|
56 |
|
57 // External function prototypes |
|
58 |
|
59 // Local constants |
|
60 |
|
61 static const QString wlanSecurityPluginsDir = |
|
62 "\\resource\\qt\\plugins\\controlpanel\\wlansecurity"; |
|
63 |
|
64 // ======== LOCAL FUNCTIONS ======== |
|
65 |
|
66 // ======== MEMBER FUNCTIONS ======== |
|
67 |
|
68 /*! |
|
69 Constructor. |
|
70 */ |
|
71 CpWlanApView::CpWlanApView( |
|
72 CmConnectionMethodShim *cmConnectionMethod, |
|
73 QGraphicsItem *parent) : |
|
74 CpBaseSettingView(0, parent), |
|
75 mForm(0), |
|
76 mModel(0), |
|
77 mItemDataHelper(0), |
|
78 mApSettingsGroupItem(0), |
|
79 mConnectionNameItem(0), |
|
80 mWlanNetworkNameItem(0), |
|
81 mNetworkStatusItem(0), |
|
82 mNetworkModeItem(0), |
|
83 mAdHocChannelItem(0), |
|
84 mSecurityModeItem(0), |
|
85 mHomepageItem(0), |
|
86 mSecuritySettingsGroupItem(0), |
|
87 mAdvancedSettingsAction(0), |
|
88 mCmConnectionMethod(cmConnectionMethod), |
|
89 mMessageBox(0) |
|
90 { |
|
91 OstTraceFunctionEntry0(CPWLANAPVIEW_CPWLANAPVIEW_ENTRY); |
|
92 |
|
93 // Add "Advanced settings" menu item |
|
94 HbMenu *menu = this->menu(); |
|
95 mAdvancedSettingsAction = menu->addAction( |
|
96 hbTrId("txt_occ_opt_advanced_settings")); |
|
97 bool status = connect( |
|
98 menu, |
|
99 SIGNAL(triggered(HbAction*)), |
|
100 this, |
|
101 SLOT(menuActionTriggered(HbAction*))); |
|
102 Q_ASSERT(status); |
|
103 |
|
104 // Construct WLAN AP settings UI |
|
105 mForm = new HbDataForm(); |
|
106 this->setWidget(mForm); |
|
107 CpPluginUtility::addCpItemPrototype(mForm); |
|
108 mModel = new HbDataFormModel(mForm); |
|
109 |
|
110 // The parameter given as 0 is a HbDataForm pointer, not parent |
|
111 mItemDataHelper = new CpItemDataHelper(0); |
|
112 mItemDataHelper->setParent(this); |
|
113 |
|
114 // Add access point settings group |
|
115 createAccessPointSettingsGroup(); |
|
116 |
|
117 mItemDataHelper->bindToForm(mForm); |
|
118 mForm->setModel(mModel); |
|
119 |
|
120 status = connect( |
|
121 mForm, |
|
122 SIGNAL(itemShown(const QModelIndex)), |
|
123 this, |
|
124 SLOT(setEditorPreferences(const QModelIndex))); |
|
125 Q_ASSERT(status); |
|
126 |
|
127 // Expand access point settings group |
|
128 mForm->setExpanded(mModel->indexFromItem(mApSettingsGroupItem), TRUE); |
|
129 |
|
130 // Add security settings group if necessary |
|
131 updateSecurityGroup( |
|
132 mSecurityModeItem->contentWidgetData("currentIndex").toInt()); |
|
133 |
|
134 OstTraceFunctionExit0(CPWLANAPVIEW_CPWLANAPVIEW_EXIT); |
|
135 } |
|
136 |
|
137 /*! |
|
138 Destructor. |
|
139 */ |
|
140 CpWlanApView::~CpWlanApView() |
|
141 { |
|
142 OstTraceFunctionEntry0(DUP1_CPWLANAPVIEW_CPWLANAPVIEW_ENTRY); |
|
143 |
|
144 OstTraceFunctionExit0(DUP1_CPWLANAPVIEW_CPWLANAPVIEW_EXIT); |
|
145 } |
|
146 |
|
147 /*! |
|
148 Creates the WLAN "Access point settings" group. |
|
149 */ |
|
150 void CpWlanApView::createAccessPointSettingsGroup() |
|
151 { |
|
152 OstTraceFunctionEntry0(CPWLANAPVIEW_CREATEACCESSPOINTSETTINGSGROUP_ENTRY); |
|
153 |
|
154 // Access point settings group |
|
155 mApSettingsGroupItem = new HbDataFormModelItem( |
|
156 HbDataFormModelItem::GroupItem, |
|
157 hbTrId("txt_occ_subhead_access_point_settings")); |
|
158 mModel->appendDataFormItem(mApSettingsGroupItem); |
|
159 |
|
160 // Connection name |
|
161 mConnectionNameItem = new CpSettingFormItemData( |
|
162 HbDataFormModelItem::TextItem, |
|
163 hbTrId("txt_occ_setlabel_connection_name")); |
|
164 // Connect signal and add item to group |
|
165 mForm->addConnection( |
|
166 mConnectionNameItem, |
|
167 SIGNAL(editingFinished()), |
|
168 this, |
|
169 SLOT(connectionNameChanged())); |
|
170 mConnectionNameItem->setContentWidgetData("objectName", "connectionNameEdit"); |
|
171 mApSettingsGroupItem->appendChild(mConnectionNameItem); |
|
172 |
|
173 // WLAN network name |
|
174 mWlanNetworkNameItem = new CpSettingFormItemData( |
|
175 HbDataFormModelItem::TextItem, |
|
176 hbTrId("txt_occ_setlabel_wlan_network_name")); |
|
177 // Connect signal and add item to group |
|
178 mForm->addConnection( |
|
179 mWlanNetworkNameItem, |
|
180 SIGNAL(editingFinished()), |
|
181 this, |
|
182 SLOT(wlanNetworkNameChanged())); |
|
183 mWlanNetworkNameItem->setContentWidgetData("objectName", "wlanNetworkNameEdit"); |
|
184 mApSettingsGroupItem->appendChild(mWlanNetworkNameItem); |
|
185 |
|
186 // Network status |
|
187 mNetworkStatusItem = new CpSettingFormItemData( |
|
188 HbDataFormModelItem::ComboBoxItem, |
|
189 hbTrId("txt_occ_setlabel_network_status")); |
|
190 // Add items to combobox |
|
191 QStringList networkStatusItems; |
|
192 networkStatusItems |
|
193 << hbTrId("txt_occ_setlabel_network_status_val_public") |
|
194 << hbTrId("txt_occ_setlabel_network_status_val_hidden"); |
|
195 mNetworkStatusItem->setContentWidgetData("items", networkStatusItems); |
|
196 // Construct map to link item indexes to setting values |
|
197 mNetworkStatusMap.insert(0, false); // public |
|
198 mNetworkStatusMap.insert(1, true); // hidden |
|
199 // Connect signal and add item to group |
|
200 mForm->addConnection( |
|
201 mNetworkStatusItem, |
|
202 SIGNAL(currentIndexChanged(int)), |
|
203 this, |
|
204 SLOT(networkStatusChanged(int))); |
|
205 mNetworkStatusItem->setContentWidgetData("objectName", "networkStatusCB"); |
|
206 mApSettingsGroupItem->appendChild(mNetworkStatusItem); |
|
207 |
|
208 // Network mode |
|
209 mNetworkModeItem = new CpSettingFormItemData( |
|
210 HbDataFormModelItem::ComboBoxItem, |
|
211 hbTrId("txt_occ_setlabel_wlan_network_mode")); |
|
212 // Add items to combobox |
|
213 QStringList networkModeItems; |
|
214 networkModeItems |
|
215 << hbTrId("txt_occ_setlabel_wlan_network_mode_val_infrastruct") |
|
216 << hbTrId("txt_occ_setlabel_wlan_network_mode_val_adhoc"); |
|
217 mNetworkModeItem->setContentWidgetData("items", networkModeItems); |
|
218 // Construct map to link item indexes to setting values |
|
219 mNetworkModeMap.insert(0, CMManagerShim::Infra); // infrastructure |
|
220 mNetworkModeMap.insert(1, CMManagerShim::Adhoc); // adhoc |
|
221 // Connect signal and add item to group |
|
222 mForm->addConnection( |
|
223 mNetworkModeItem, |
|
224 SIGNAL(currentIndexChanged(int)), |
|
225 this, |
|
226 SLOT(networkModeChanged(int))); |
|
227 mNetworkModeItem->setContentWidgetData("objectName", "networkModeCB"); |
|
228 mApSettingsGroupItem->appendChild(mNetworkModeItem); |
|
229 |
|
230 // Ad-hoc channel |
|
231 // Added dynamically according to set network mode |
|
232 |
|
233 // Security mode |
|
234 mSecurityModeItem = new CpSettingFormItemData( |
|
235 HbDataFormModelItem::ComboBoxItem, |
|
236 hbTrId("txt_occ_setlabel_wlan_security_mode")); |
|
237 // Security modes added dynamically according to set network mode |
|
238 |
|
239 // Connect signal and add item to group |
|
240 mForm->addConnection( |
|
241 mSecurityModeItem, |
|
242 SIGNAL(currentIndexChanged(int)), |
|
243 this, |
|
244 SLOT(securityModeChanged(int))); |
|
245 mSecurityModeItem->setContentWidgetData("objectName", "securityModeCB"); |
|
246 mApSettingsGroupItem->appendChild(mSecurityModeItem); |
|
247 |
|
248 // Homepage |
|
249 mHomepageItem = new CpSettingFormItemData( |
|
250 HbDataFormModelItem::TextItem, |
|
251 hbTrId("txt_occ_setlabel_homepage")); |
|
252 // Connect signal and add item to group |
|
253 mForm->addConnection( |
|
254 mHomepageItem, |
|
255 SIGNAL(editingFinished()), |
|
256 this, |
|
257 SLOT(homepageChanged())); |
|
258 mHomepageItem->setContentWidgetData("objectName", "homepageEdit"); |
|
259 mApSettingsGroupItem->appendChild(mHomepageItem); |
|
260 |
|
261 // Read settings from CommsDat and update widgets |
|
262 updateAccessPointSettingsGroup(); |
|
263 |
|
264 OstTraceFunctionExit0(CPWLANAPVIEW_CREATEACCESSPOINTSETTINGSGROUP_EXIT); |
|
265 } |
|
266 |
|
267 /*! |
|
268 Reads attribute values and updates "Access point settings" group settings. |
|
269 */ |
|
270 void CpWlanApView::updateAccessPointSettingsGroup() |
|
271 { |
|
272 OstTraceFunctionEntry0(CPWLANAPVIEW_UPDATEACCESSPOINTSETTINGSGROUP_ENTRY); |
|
273 |
|
274 // Get attributes from CommsDat and set values to UI widgets |
|
275 |
|
276 // Connection name |
|
277 QString connectionName = mCmConnectionMethod->getStringAttribute( |
|
278 CMManagerShim::CmName); |
|
279 mConnectionNameItem->setContentWidgetData("text", connectionName); |
|
280 |
|
281 // WLAN network name |
|
282 QString networkName = mCmConnectionMethod->getStringAttribute( |
|
283 CMManagerShim::WlanSSID); |
|
284 mWlanNetworkNameItem->setContentWidgetData("text", networkName); |
|
285 |
|
286 // Network status |
|
287 bool scanSsid = mCmConnectionMethod->getBoolAttribute( |
|
288 CMManagerShim::WlanScanSSID); |
|
289 mNetworkStatusItem->setContentWidgetData( |
|
290 "currentIndex", |
|
291 mNetworkStatusMap.key(scanSsid)); |
|
292 |
|
293 // Network mode |
|
294 CMManagerShim::WlanConnMode networkMode = |
|
295 static_cast<CMManagerShim::WlanConnMode> |
|
296 (mCmConnectionMethod->getIntAttribute( |
|
297 CMManagerShim::WlanConnectionMode)); |
|
298 mNetworkModeItem->setContentWidgetData( |
|
299 "currentIndex", |
|
300 mNetworkModeMap.key(networkMode)); |
|
301 |
|
302 // Ad-hoc channel |
|
303 updateAdHocChannelItem(networkMode); |
|
304 |
|
305 // Security mode |
|
306 updateSecurityModeItem(networkMode); |
|
307 |
|
308 // Homepage |
|
309 QString homepage = mCmConnectionMethod->getStringAttribute( |
|
310 CMManagerShim::CmStartPage); |
|
311 mHomepageItem->setContentWidgetData("text", homepage); |
|
312 |
|
313 OstTraceFunctionExit0(CPWLANAPVIEW_UPDATEACCESSPOINTSETTINGSGROUP_EXIT); |
|
314 } |
|
315 |
|
316 /*! |
|
317 Loads all WLAN security plugins. |
|
318 */ |
|
319 void CpWlanApView::loadSecurityPlugins( |
|
320 CMManagerShim::WlanConnMode networkMode) |
|
321 { |
|
322 OstTraceFunctionEntry0(CPWLANAPVIEW_LOADSECURITYPLUGINS_ENTRY); |
|
323 |
|
324 // Load security plugins |
|
325 QList<CpWlanSecurityPluginInterface *> plugins; |
|
326 QDir pluginsDir(wlanSecurityPluginsDir); |
|
327 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { |
|
328 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); |
|
329 CpWlanSecurityPluginInterface *plugin = |
|
330 qobject_cast<CpWlanSecurityPluginInterface *>(loader.instance()); |
|
331 if (plugin) { |
|
332 // Sort items based on the orderNumber() |
|
333 QList<CpWlanSecurityPluginInterface *>::iterator i; |
|
334 for (i = plugins.begin(); i != plugins.end(); ++i) { |
|
335 if ((*i)->orderNumber() > plugin->orderNumber()) { |
|
336 plugins.insert(i, plugin); |
|
337 plugin = NULL; |
|
338 break; |
|
339 } |
|
340 } |
|
341 if (plugin) { |
|
342 plugins.append(plugin); |
|
343 } |
|
344 } |
|
345 } |
|
346 |
|
347 // Add security plugins to map. If network mode is ad-hoc, only WEP |
|
348 // is allowed. |
|
349 int i; |
|
350 i = mSecurityModeMap.size(); |
|
351 foreach (CpWlanSecurityPluginInterface *plugin, plugins) { |
|
352 if (networkMode != CMManagerShim::Adhoc |
|
353 || plugin->securityMode() == CMManagerShim::WlanSecModeWep) { |
|
354 mSecurityModeMap.insert(i, plugin); |
|
355 i++; |
|
356 } |
|
357 } |
|
358 |
|
359 OstTraceFunctionExit0(CPWLANAPVIEW_LOADSECURITYPLUGINS_EXIT); |
|
360 } |
|
361 |
|
362 /*! |
|
363 Updates the "Security settings" group. |
|
364 */ |
|
365 void CpWlanApView::updateSecurityGroup(int index) |
|
366 { |
|
367 OstTraceFunctionEntry0(CPWLANAPVIEW_UPDATESECURITYGROUP_ENTRY); |
|
368 |
|
369 // Remove old security settings group |
|
370 if (mSecuritySettingsGroupItem) { |
|
371 mModel->removeItem(mSecuritySettingsGroupItem); |
|
372 mSecuritySettingsGroupItem = NULL; |
|
373 } |
|
374 |
|
375 // Add new security settings group |
|
376 if (index > 0) { |
|
377 // Get correct security plugin |
|
378 CpWlanSecurityPluginInterface *plugin = mSecurityModeMap.value(index); |
|
379 if (plugin) { |
|
380 // Ask plugin to create the security group |
|
381 plugin->setReference( |
|
382 mCmConnectionMethod, |
|
383 mCmConnectionMethod->getIntAttribute(CMManagerShim::CmId)); |
|
384 mSecuritySettingsGroupItem = plugin->uiInstance(*mItemDataHelper); |
|
385 if (mSecuritySettingsGroupItem) { |
|
386 // And add it to dataform |
|
387 mModel->appendDataFormItem(mSecuritySettingsGroupItem); |
|
388 } |
|
389 } |
|
390 } |
|
391 |
|
392 OstTraceFunctionExit0(CPWLANAPVIEW_UPDATESECURITYGROUP_EXIT); |
|
393 } |
|
394 |
|
395 /*! |
|
396 Shows message box with "OK" button using given text. |
|
397 */ |
|
398 void CpWlanApView::showMessageBox( |
|
399 HbMessageBox::MessageBoxType type, |
|
400 const QString &text) |
|
401 { |
|
402 OstTraceFunctionEntry0(CPWLANAPVIEW_SHOWMESSAGEBOX_ENTRY); |
|
403 |
|
404 // Create a message box |
|
405 mMessageBox = QSharedPointer<HbMessageBox>(new HbMessageBox(type)); |
|
406 mMessageBox->setText(text); |
|
407 mMessageBox->setModal(true); |
|
408 mMessageBox->setTimeout(HbPopup::NoTimeout); |
|
409 mMessageBox->open(); |
|
410 |
|
411 OstTraceFunctionExit0(CPWLANAPVIEW_SHOWMESSAGEBOX_EXIT); |
|
412 } |
|
413 |
|
414 /*! |
|
415 Tries to update connection method changes to CommsDat. |
|
416 Returns "true" if success, "false" if some error happened. |
|
417 */ |
|
418 bool CpWlanApView::tryUpdate() |
|
419 { |
|
420 OstTraceFunctionEntry0(CPWLANAPVIEW_TRYUPDATE_ENTRY); |
|
421 |
|
422 // Try update |
|
423 try { |
|
424 mCmConnectionMethod->update(); |
|
425 } |
|
426 catch (const std::exception&) { |
|
427 // Handle error |
|
428 handleUpdateError(); |
|
429 |
|
430 OstTraceFunctionExit0(CPWLANAPVIEW_TRYUPDATE_EXIT); |
|
431 return false; |
|
432 } |
|
433 |
|
434 OstTraceFunctionExit0(DUP1_CPWLANAPVIEW_TRYUPDATE_EXIT); |
|
435 return true; |
|
436 } |
|
437 |
|
438 /*! |
|
439 Handles failed CommsDat update. |
|
440 */ |
|
441 void CpWlanApView::handleUpdateError() |
|
442 { |
|
443 OstTraceFunctionEntry0(CPWLANAPVIEW_HANDLEUPDATEERROR_ENTRY); |
|
444 |
|
445 // Show error note to user |
|
446 showMessageBox( |
|
447 HbMessageBox::MessageTypeWarning, |
|
448 hbTrId("txt_occ_info_unable_to_save_setting")); |
|
449 // Reload settings from CommsDat and update UI |
|
450 try { |
|
451 mCmConnectionMethod->refresh(); |
|
452 } |
|
453 catch (const std::exception&) { |
|
454 // Ignore error from refresh. Most likely this will not happen, but |
|
455 // if it does, there isn't very much we can do. |
|
456 OstTrace0( |
|
457 TRACE_ERROR, |
|
458 CPWLANAPPLUGIN_HANDLEUPDATEERROR, |
|
459 "Refresh failed"); |
|
460 }; |
|
461 updateAccessPointSettingsGroup(); |
|
462 |
|
463 OstTraceFunctionExit0(CPWLANAPVIEW_HANDLEUPDATEERROR_EXIT); |
|
464 } |
|
465 |
|
466 /*! |
|
467 Updates Ad-hoc channel item. Setting item is shown if network mode is |
|
468 ad-hoc, otherwise it is not shown. |
|
469 */ |
|
470 void CpWlanApView::updateAdHocChannelItem( |
|
471 CMManagerShim::WlanConnMode networkMode) |
|
472 { |
|
473 if (networkMode == CMManagerShim::Infra) { |
|
474 // Infrastructure |
|
475 if (mAdHocChannelItem) { |
|
476 mApSettingsGroupItem->removeChild( |
|
477 mApSettingsGroupItem->indexOf(mAdHocChannelItem)); |
|
478 mAdHocChannelItem = NULL; |
|
479 } |
|
480 } else { |
|
481 // Ad-hoc |
|
482 if (!mAdHocChannelItem) { |
|
483 // Ad-hoc channel item not shown, add it |
|
484 mAdHocChannelItem = new CpSettingFormItemData( |
|
485 HbDataFormModelItem::ComboBoxItem, |
|
486 hbTrId("txt_occ_setlabel_adhoc_channel")); |
|
487 // Add items to combobox |
|
488 QStringList adHocChannelItems; |
|
489 adHocChannelItems |
|
490 << hbTrId("txt_occ_setlabel_adhoc_channel_val_automatic"); |
|
491 for (int i = WlanAdHocChannelMinValue; |
|
492 i <= WlanAdHocChannelMaxValue; |
|
493 i++) { |
|
494 QString channel; |
|
495 channel.setNum(i); |
|
496 adHocChannelItems << HbStringUtil::convertDigits(channel); |
|
497 } |
|
498 mAdHocChannelItem->setContentWidgetData( |
|
499 "items", |
|
500 adHocChannelItems); |
|
501 // Connect signal and add item to group |
|
502 mForm->addConnection( |
|
503 mAdHocChannelItem, |
|
504 SIGNAL(currentIndexChanged(int)), |
|
505 this, |
|
506 SLOT(adHocChannelChanged(int))); |
|
507 // Add item after the network mode item |
|
508 mApSettingsGroupItem->insertChild( |
|
509 mApSettingsGroupItem->indexOf(mNetworkModeItem) + 1, |
|
510 mAdHocChannelItem); |
|
511 } |
|
512 // Update ad-hoc item |
|
513 int adHocChannelId = mCmConnectionMethod->getIntAttribute( |
|
514 CMManagerShim::WlanChannelID); |
|
515 mAdHocChannelItem->setContentWidgetData( |
|
516 "currentIndex", |
|
517 adHocChannelId); |
|
518 } |
|
519 } |
|
520 |
|
521 /*! |
|
522 Updates security mode item. |
|
523 */ |
|
524 void CpWlanApView::updateSecurityModeItem( |
|
525 CMManagerShim::WlanConnMode networkMode) |
|
526 { |
|
527 // Load WLAN security plugins and construct map |
|
528 mSecurityModeMap.clear(); |
|
529 mSecurityModeMap.insert(0, NULL); // open mode |
|
530 loadSecurityPlugins(networkMode); |
|
531 |
|
532 // Add items to combobox |
|
533 QStringList securityModeItems; |
|
534 foreach (CpWlanSecurityPluginInterface *plugin, mSecurityModeMap) { |
|
535 if (plugin) { |
|
536 // Add security mode from plugin |
|
537 securityModeItems |
|
538 << hbTrId(plugin->securityModeTextId().toLatin1()); |
|
539 } else { |
|
540 // Add open mode |
|
541 securityModeItems |
|
542 << hbTrId("txt_occ_setlabel_wlan_security_mode_val_open"); |
|
543 } |
|
544 } |
|
545 // Remove connection before setting new content, because combobox |
|
546 // will emit currentIndexChanged signal and we don't want that. |
|
547 mForm->removeConnection( |
|
548 mSecurityModeItem, |
|
549 SIGNAL(currentIndexChanged(int)), |
|
550 this, |
|
551 SLOT(securityModeChanged(int))); |
|
552 mSecurityModeItem->setContentWidgetData("items", securityModeItems); |
|
553 mForm->addConnection( |
|
554 mSecurityModeItem, |
|
555 SIGNAL(currentIndexChanged(int)), |
|
556 this, |
|
557 SLOT(securityModeChanged(int))); |
|
558 |
|
559 uint securityMode = mCmConnectionMethod->getIntAttribute( |
|
560 CMManagerShim::WlanSecurityMode); |
|
561 // Iterate through the map to find correct security plugin and set |
|
562 // mode index |
|
563 int securityModeIndex = 0; |
|
564 QMapIterator<int, CpWlanSecurityPluginInterface *> i(mSecurityModeMap); |
|
565 while (i.hasNext()) { |
|
566 i.next(); |
|
567 if (i.value() |
|
568 && i.value()->securityMode() == securityMode) { |
|
569 securityModeIndex = i.key(); |
|
570 } |
|
571 } |
|
572 mSecurityModeItem->setContentWidgetData("currentIndex", |
|
573 securityModeIndex); |
|
574 |
|
575 if (securityMode != CMManagerShim::WlanSecModeOpen |
|
576 && securityModeIndex == 0) { |
|
577 // Security plugin implementing the selected security mode not found, |
|
578 // set security mode to open also in CommsDat |
|
579 mCmConnectionMethod->setIntAttribute( |
|
580 CMManagerShim::WlanSecurityMode, |
|
581 CMManagerShim::WlanSecModeOpen); |
|
582 // Try update |
|
583 try { |
|
584 mCmConnectionMethod->update(); |
|
585 } |
|
586 catch (const std::exception&) { |
|
587 // Error in update, but can't show error notes at this point |
|
588 } |
|
589 } |
|
590 } |
|
591 |
|
592 /*! |
|
593 Stores connection name. |
|
594 */ |
|
595 void CpWlanApView::connectionNameChanged() |
|
596 { |
|
597 OstTraceFunctionEntry0(CPWLANAPVIEW_CONNECTIONNAMECHANGED_ENTRY); |
|
598 |
|
599 QString connectionName = |
|
600 mConnectionNameItem->contentWidgetData("text").toString(); |
|
601 if (!connectionName.isEmpty()) { |
|
602 // Update to CommsDat |
|
603 mCmConnectionMethod->setStringAttribute( |
|
604 CMManagerShim::CmName, |
|
605 connectionName); |
|
606 if (tryUpdate()) { |
|
607 // Update successful |
|
608 // Read name because in case the name already exists it will |
|
609 // be made unique by CMManager |
|
610 connectionName = mCmConnectionMethod->getStringAttribute( |
|
611 CMManagerShim::CmName); |
|
612 mConnectionNameItem->setContentWidgetData("text", connectionName); |
|
613 } |
|
614 } else { |
|
615 // Inform user of invalid name |
|
616 showMessageBox( |
|
617 HbMessageBox::MessageTypeInformation, |
|
618 hbTrId("txt_occ_info_invalid_name")); |
|
619 |
|
620 // Empty name not allowed, revert back to old value |
|
621 connectionName = mCmConnectionMethod->getStringAttribute( |
|
622 CMManagerShim::CmName); |
|
623 mConnectionNameItem->setContentWidgetData("text", connectionName); |
|
624 } |
|
625 |
|
626 OstTraceFunctionExit0(CPWLANAPVIEW_CONNECTIONNAMECHANGED_EXIT); |
|
627 } |
|
628 |
|
629 /*! |
|
630 Stores WLAN network name. |
|
631 */ |
|
632 void CpWlanApView::wlanNetworkNameChanged() |
|
633 { |
|
634 OstTraceFunctionEntry0(CPWLANAPVIEW_WLANNETWORKNAMECHANGED_ENTRY); |
|
635 |
|
636 // Update to CommsDat |
|
637 QString wlanNetworkName = |
|
638 mWlanNetworkNameItem->contentWidgetData("text").toString(); |
|
639 if (!wlanNetworkName.isEmpty()) { |
|
640 mCmConnectionMethod->setStringAttribute( |
|
641 CMManagerShim::WlanSSID, |
|
642 wlanNetworkName); |
|
643 (void)tryUpdate(); |
|
644 } else { |
|
645 // Inform user of invalid name |
|
646 showMessageBox( |
|
647 HbMessageBox::MessageTypeInformation, |
|
648 hbTrId("txt_occ_info_invalid_name")); |
|
649 |
|
650 // Empty name not allowed, revert back to old value |
|
651 wlanNetworkName = mCmConnectionMethod->getStringAttribute( |
|
652 CMManagerShim::WlanSSID); |
|
653 mWlanNetworkNameItem->setContentWidgetData("text", wlanNetworkName); |
|
654 } |
|
655 |
|
656 OstTraceFunctionExit0(CPWLANAPVIEW_WLANNETWORKNAMECHANGED_EXIT); |
|
657 } |
|
658 |
|
659 /*! |
|
660 Stores WLAN network status. |
|
661 */ |
|
662 void CpWlanApView::networkStatusChanged(int index) |
|
663 { |
|
664 OstTraceFunctionEntry0(CPWLANAPVIEW_NETWORKSTATUSCHANGED_ENTRY); |
|
665 |
|
666 // Update to CommsDat |
|
667 mCmConnectionMethod->setBoolAttribute( |
|
668 CMManagerShim::WlanScanSSID, |
|
669 mNetworkStatusMap.value(index)); |
|
670 (void)tryUpdate(); |
|
671 |
|
672 OstTraceFunctionExit0(CPWLANAPVIEW_NETWORKSTATUSCHANGED_EXIT); |
|
673 } |
|
674 |
|
675 /*! |
|
676 Stores WLAN network mode. |
|
677 */ |
|
678 void CpWlanApView::networkModeChanged(int index) |
|
679 { |
|
680 OstTraceFunctionEntry0(CPWLANAPVIEW_NETWORKMODECHANGED_ENTRY); |
|
681 |
|
682 // Update to CommsDat |
|
683 mCmConnectionMethod->setIntAttribute( |
|
684 CMManagerShim::WlanConnectionMode, |
|
685 mNetworkModeMap.value(index)); |
|
686 if (tryUpdate()) { |
|
687 // If mode is ad-hoc, ad-hoc channel item must be shown |
|
688 CMManagerShim::WlanConnMode networkMode = |
|
689 static_cast<CMManagerShim::WlanConnMode> |
|
690 (mNetworkModeMap.value(index)); |
|
691 updateAdHocChannelItem(networkMode); |
|
692 // Also security mode list may need updating |
|
693 updateSecurityModeItem(networkMode); |
|
694 } |
|
695 |
|
696 OstTraceFunctionExit0(CPWLANAPVIEW_NETWORKMODECHANGED_EXIT); |
|
697 } |
|
698 |
|
699 /*! |
|
700 Stores ad-hoc channel ID. |
|
701 */ |
|
702 void CpWlanApView::adHocChannelChanged(int index) |
|
703 { |
|
704 OstTraceFunctionEntry0(CPWLANAPVIEW_ADHOCCHANNELCHANGED_ENTRY); |
|
705 |
|
706 // Update to CommsDat |
|
707 mCmConnectionMethod->setIntAttribute( |
|
708 CMManagerShim::WlanChannelID, |
|
709 index); |
|
710 (void)tryUpdate(); |
|
711 |
|
712 OstTraceFunctionExit0(CPWLANAPVIEW_ADHOCCHANNELCHANGED_EXIT); |
|
713 } |
|
714 |
|
715 /*! |
|
716 Stores WLAN security mode. |
|
717 */ |
|
718 void CpWlanApView::securityModeChanged(int index) |
|
719 { |
|
720 OstTraceFunctionEntry0(CPWLANAPVIEW_SECURITYMODECHANGED_ENTRY); |
|
721 |
|
722 // Get security plugin |
|
723 CpWlanSecurityPluginInterface *plugin = mSecurityModeMap.value(index); |
|
724 // Update to CommsDat |
|
725 if (plugin) { |
|
726 mCmConnectionMethod->setIntAttribute( |
|
727 CMManagerShim::WlanSecurityMode, |
|
728 plugin->securityMode()); |
|
729 } else { |
|
730 mCmConnectionMethod->setIntAttribute( |
|
731 CMManagerShim::WlanSecurityMode, |
|
732 CMManagerShim::WlanSecModeOpen); |
|
733 } |
|
734 (void)tryUpdate(); |
|
735 |
|
736 // Update UI |
|
737 updateSecurityGroup( |
|
738 mSecurityModeItem->contentWidgetData("currentIndex").toInt()); |
|
739 |
|
740 OstTraceFunctionExit0(CPWLANAPVIEW_SECURITYMODECHANGED_EXIT); |
|
741 } |
|
742 |
|
743 /*! |
|
744 Stores homepage. |
|
745 */ |
|
746 void CpWlanApView::homepageChanged() |
|
747 { |
|
748 OstTraceFunctionEntry0(CPWLANAPVIEW_HOMEPAGECHANGED_ENTRY); |
|
749 |
|
750 // Update to CommsDat |
|
751 QString homepage = mHomepageItem->contentWidgetData("text").toString(); |
|
752 mCmConnectionMethod->setStringAttribute( |
|
753 CMManagerShim::CmStartPage, |
|
754 homepage); |
|
755 (void)tryUpdate(); |
|
756 |
|
757 OstTraceFunctionExit0(CPWLANAPVIEW_HOMEPAGECHANGED_EXIT); |
|
758 } |
|
759 |
|
760 /*! |
|
761 Handles view menu actions. |
|
762 */ |
|
763 void CpWlanApView::menuActionTriggered(HbAction *action) |
|
764 { |
|
765 OstTraceFunctionEntry0(CPWLANAPVIEW_MENUACTIONTRIGGERED_ENTRY); |
|
766 |
|
767 if (action == mAdvancedSettingsAction) { |
|
768 HbMainWindow *mainWindow = this->mainWindow(); |
|
769 |
|
770 // Create the advanced settings view |
|
771 HbView *newView = new CpWlanApAdvancedView(mCmConnectionMethod); |
|
772 // Connect signal to return back to the previous view |
|
773 bool status = QObject::connect( |
|
774 newView, |
|
775 SIGNAL(aboutToClose()), |
|
776 this, |
|
777 SLOT(restoreCurrentView())); |
|
778 Q_ASSERT(status); |
|
779 |
|
780 mainWindow->addView(newView); |
|
781 mainWindow->setCurrentView(newView); |
|
782 } |
|
783 |
|
784 OstTraceFunctionExit0(CPWLANAPVIEW_MENUACTIONTRIGGERED_EXIT); |
|
785 } |
|
786 |
|
787 /*! |
|
788 Removes current view from main window and sets this view as the |
|
789 current view. Used when "back" button is pressed in "Advanced settings" |
|
790 view. |
|
791 */ |
|
792 void CpWlanApView::restoreCurrentView() |
|
793 { |
|
794 OstTraceFunctionEntry0(CPWLANAPVIEW_RESTORECURRENTVIEW_ENTRY); |
|
795 |
|
796 HbMainWindow *mainWindow = this->mainWindow(); |
|
797 |
|
798 // Remove the previous view and delete it |
|
799 HbView *prevView = mainWindow->currentView(); |
|
800 mainWindow->removeView(prevView); |
|
801 prevView->deleteLater(); |
|
802 |
|
803 // Set this view on top |
|
804 mainWindow->setCurrentView(this); |
|
805 |
|
806 OstTraceFunctionExit0(CPWLANAPVIEW_RESTORECURRENTVIEW_EXIT); |
|
807 } |
|
808 |
|
809 /*! |
|
810 Sets editor preferences for all HbLineEdit items. |
|
811 */ |
|
812 void CpWlanApView::setEditorPreferences(const QModelIndex modelIndex) |
|
813 { |
|
814 OstTraceFunctionEntry0(CPWLANAPVIEW_SETEDITORPREFERENCES_ENTRY); |
|
815 |
|
816 HbDataFormViewItem *viewItem = qobject_cast<HbDataFormViewItem *> |
|
817 (mForm->itemByIndex(modelIndex)); |
|
818 HbDataFormModelItem *modelItem = mModel->itemFromIndex(modelIndex); |
|
819 |
|
820 if (modelItem == mConnectionNameItem |
|
821 || modelItem == mWlanNetworkNameItem |
|
822 || modelItem == mHomepageItem ) { |
|
823 // HbLineEdit items, get editor and editor interface |
|
824 HbLineEdit *edit = qobject_cast<HbLineEdit *> |
|
825 (viewItem->dataItemContentWidget()); |
|
826 HbEditorInterface editInterface(edit); |
|
827 |
|
828 if (modelItem == mConnectionNameItem) { |
|
829 // Setup editor for connection name |
|
830 editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly); |
|
831 edit->setInputMethodHints(Qt::ImhNoPredictiveText); |
|
832 edit->setMaxLength(CMManagerShim::CmNameLength); |
|
833 } else if (modelItem == mWlanNetworkNameItem) { |
|
834 // Setup editor for WLAN SSID |
|
835 editInterface.setMode(HbInputModeNone); |
|
836 editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly); |
|
837 editInterface.setEditorClass(HbInputEditorClassNetworkName); |
|
838 editInterface.setDigitType(HbDigitTypeNone); |
|
839 edit->setInputMethodHints( |
|
840 Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase); |
|
841 edit->setMaxLength(CMManagerShim::WlanSSIDLength); |
|
842 } else { /* mHomepageItem */ |
|
843 // Setup editor for URL |
|
844 editInterface.setMode(HbInputModeNone); |
|
845 editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly); |
|
846 editInterface.setFilter(HbUrlFilter::instance()); |
|
847 editInterface.setEditorClass(HbInputEditorClassUrl); |
|
848 editInterface.setDigitType(HbDigitTypeNone); |
|
849 edit->setInputMethodHints( |
|
850 Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase); |
|
851 edit->setMaxLength(CMManagerShim::CmStartPageLength); |
|
852 } |
|
853 } |
|
854 |
|
855 OstTraceFunctionExit0(CPWLANAPVIEW_SETEDITORPREFERENCES_EXIT); |
|
856 } |
|