cmmanager/cpwlanapplugin/src/cpwlanapview.cpp
changeset 27 489cf6208544
parent 23 7ec726f93df1
child 44 a0c4ceac30d0
equal deleted inserted replaced
23:7ec726f93df1 27:489cf6208544
    30 #include <HbEditorInterface>
    30 #include <HbEditorInterface>
    31 #include <HbUrlFilter>
    31 #include <HbUrlFilter>
    32 #include <HbPopup>
    32 #include <HbPopup>
    33 #include <HbMessageBox>
    33 #include <HbMessageBox>
    34 #include <HbAction>
    34 #include <HbAction>
       
    35 #include <HbStringUtil>
    35 #include <wlanmgmtcommon.h>
    36 #include <wlanmgmtcommon.h>
    36 #include <cpitemdatahelper.h>
    37 #include <cpitemdatahelper.h>
    37 #include <cpsettingformitemdata.h>
    38 #include <cpsettingformitemdata.h>
    38 #include <cppluginutility.h>
    39 #include <cppluginutility.h>
    39 #include <cmconnectionmethod_shim.h>
    40 #include <cmconnectionmethod_shim.h>
    77         mApSettingsGroupItem(0),
    78         mApSettingsGroupItem(0),
    78         mConnectionNameItem(0),
    79         mConnectionNameItem(0),
    79         mWlanNetworkNameItem(0),
    80         mWlanNetworkNameItem(0),
    80         mNetworkStatusItem(0),
    81         mNetworkStatusItem(0),
    81         mNetworkModeItem(0),
    82         mNetworkModeItem(0),
       
    83         mAdHocChannelItem(0),
    82         mSecurityModeItem(0),
    84         mSecurityModeItem(0),
    83         mHomepageItem(0),
    85         mHomepageItem(0),
    84         mSecuritySettingsGroupItem(0),
    86         mSecuritySettingsGroupItem(0),
    85         mAdvancedSettingsAction(0),
    87         mAdvancedSettingsAction(0),
    86         mCmConnectionMethod(cmConnectionMethod),
    88         mCmConnectionMethod(cmConnectionMethod),
   219         SIGNAL(currentIndexChanged(int)),
   221         SIGNAL(currentIndexChanged(int)),
   220         this,
   222         this,
   221         SLOT(networkModeChanged(int)));
   223         SLOT(networkModeChanged(int)));
   222     mApSettingsGroupItem->appendChild(mNetworkModeItem);
   224     mApSettingsGroupItem->appendChild(mNetworkModeItem);
   223     
   225     
       
   226     // Ad-hoc channel
       
   227     // Added dynamically according to set network mode
       
   228     
   224     // Security mode
   229     // Security mode
   225     mSecurityModeItem = new CpSettingFormItemData(
   230     mSecurityModeItem = new CpSettingFormItemData(
   226         HbDataFormModelItem::ComboBoxItem,
   231         HbDataFormModelItem::ComboBoxItem,
   227         hbTrId("txt_occ_setlabel_wlan_security_mode"));
   232         hbTrId("txt_occ_setlabel_wlan_security_mode"));
   228     // Load WLAN security plugins and construct map
   233     // Security modes added dynamically according to set network mode
   229     mSecurityModeMap.insert(0, NULL); // open mode
   234 
   230     // Load all security plugins and construct map
       
   231     loadSecurityPlugins();
       
   232     // Add items to combobox
       
   233     QStringList securityModeItems;
       
   234     foreach (CpWlanSecurityPluginInterface *plugin, mSecurityModeMap) {
       
   235         if (plugin) {
       
   236             // Add security mode from plugin
       
   237             securityModeItems
       
   238                 << hbTrId(plugin->securityModeTextId().toLatin1());
       
   239         } else {
       
   240             // Add open mode
       
   241             securityModeItems
       
   242                 << hbTrId("txt_occ_setlabel_wlan_security_mode_val_open");
       
   243         }
       
   244     }
       
   245     mSecurityModeItem->setContentWidgetData("items", securityModeItems);
       
   246     // Connect signal and add item to group
   235     // Connect signal and add item to group
   247     mForm->addConnection(
   236     mForm->addConnection(
   248         mSecurityModeItem,
   237         mSecurityModeItem,
   249         SIGNAL(currentIndexChanged(int)),
   238         SIGNAL(currentIndexChanged(int)),
   250         this,
   239         this,
   294     mNetworkStatusItem->setContentWidgetData(
   283     mNetworkStatusItem->setContentWidgetData(
   295         "currentIndex",
   284         "currentIndex",
   296         mNetworkStatusMap.key(scanSsid));
   285         mNetworkStatusMap.key(scanSsid));
   297     
   286     
   298     // Network mode
   287     // Network mode
   299     int networkMode =  mCmConnectionMethod->getIntAttribute(
   288     CMManagerShim::WlanConnMode networkMode =
   300         CMManagerShim::WlanConnectionMode);
   289 		static_cast<CMManagerShim::WlanConnMode>
       
   290       	(mCmConnectionMethod->getIntAttribute(
       
   291             CMManagerShim::WlanConnectionMode));
   301     mNetworkModeItem->setContentWidgetData(
   292     mNetworkModeItem->setContentWidgetData(
   302         "currentIndex",
   293         "currentIndex",
   303         mNetworkModeMap.key(networkMode));
   294         mNetworkModeMap.key(networkMode));
   304     
   295     
       
   296     // Ad-hoc channel
       
   297     updateAdHocChannelItem(networkMode);
       
   298     
   305     // Security mode
   299     // Security mode
   306     QVariant securityMode = mCmConnectionMethod->getIntAttribute(
   300     updateSecurityModeItem(networkMode);
   307         CMManagerShim::WlanSecurityMode);
       
   308     // Iterate through the map to find correct security plugin and set
       
   309     // mode index
       
   310     int securityModeIndex = 0;
       
   311     QMapIterator<int, CpWlanSecurityPluginInterface *> i(mSecurityModeMap);
       
   312     while (i.hasNext()) {
       
   313         i.next();
       
   314         if (i.value()
       
   315             && i.value()->securityMode() == securityMode.toInt()) {
       
   316             securityModeIndex = i.key();
       
   317         }
       
   318     }
       
   319     mSecurityModeItem->setContentWidgetData("currentIndex",
       
   320         securityModeIndex);
       
   321     
   301     
   322     // Homepage
   302     // Homepage
   323     QString homepage = mCmConnectionMethod->getStringAttribute(
   303     QString homepage = mCmConnectionMethod->getStringAttribute(
   324         CMManagerShim::CmStartPage);
   304         CMManagerShim::CmStartPage);
   325     mHomepageItem->setContentWidgetData("text", homepage);
   305     mHomepageItem->setContentWidgetData("text", homepage);
   328 }
   308 }
   329 
   309 
   330 /*!
   310 /*!
   331     Loads all WLAN security plugins.
   311     Loads all WLAN security plugins.
   332 */
   312 */
   333 void CpWlanApView::loadSecurityPlugins()
   313 void CpWlanApView::loadSecurityPlugins(
       
   314     CMManagerShim::WlanConnMode networkMode)
   334 {
   315 {
   335     OstTraceFunctionEntry0(CPWLANAPVIEW_LOADSECURITYPLUGINS_ENTRY);
   316     OstTraceFunctionEntry0(CPWLANAPVIEW_LOADSECURITYPLUGINS_ENTRY);
   336     
   317     
   337     // Load security plugins
   318     // Load security plugins
   338     QList<CpWlanSecurityPluginInterface *> plugins;
   319     QList<CpWlanSecurityPluginInterface *> plugins;
   355                 plugins.append(plugin);
   336                 plugins.append(plugin);
   356             }
   337             }
   357         }
   338         }
   358     }
   339     }
   359     
   340     
   360     // Add security plugins to map
   341     // Add security plugins to map. If network mode is ad-hoc, only WEP
       
   342     // is allowed.
   361     int i;
   343     int i;
   362     i = mSecurityModeMap.size();
   344     i = mSecurityModeMap.size();
   363     foreach (CpWlanSecurityPluginInterface *plugin, plugins) {
   345     foreach (CpWlanSecurityPluginInterface *plugin, plugins) {
   364         mSecurityModeMap.insert(i, plugin);
   346         if (networkMode != CMManagerShim::Adhoc
   365         i++;
   347             || plugin->securityMode() == CMManagerShim::WlanSecModeWep) {
       
   348             mSecurityModeMap.insert(i, plugin);
       
   349             i++;
       
   350         }
   366     }
   351     }
   367     
   352     
   368     OstTraceFunctionExit0(CPWLANAPVIEW_LOADSECURITYPLUGINS_EXIT);
   353     OstTraceFunctionExit0(CPWLANAPVIEW_LOADSECURITYPLUGINS_EXIT);
   369 }
   354 }
   370 
   355 
   471     
   456     
   472     OstTraceFunctionExit0(CPWLANAPVIEW_HANDLEUPDATEERROR_EXIT);
   457     OstTraceFunctionExit0(CPWLANAPVIEW_HANDLEUPDATEERROR_EXIT);
   473 }
   458 }
   474 
   459 
   475 /*!
   460 /*!
       
   461     Updates Ad-hoc channel item. Setting item is shown if network mode is
       
   462     ad-hoc, otherwise it is not shown.
       
   463  */
       
   464 void CpWlanApView::updateAdHocChannelItem(
       
   465     CMManagerShim::WlanConnMode networkMode)
       
   466 {
       
   467     if (networkMode == CMManagerShim::Infra) {
       
   468         // Infrastructure
       
   469         if (mAdHocChannelItem) {
       
   470             mApSettingsGroupItem->removeChild(
       
   471                 mApSettingsGroupItem->indexOf(mAdHocChannelItem));
       
   472             mAdHocChannelItem = NULL;
       
   473         }
       
   474     } else {
       
   475         // Ad-hoc
       
   476         if (!mAdHocChannelItem) {
       
   477             // Ad-hoc channel item not shown, add it
       
   478             mAdHocChannelItem = new CpSettingFormItemData(
       
   479                 HbDataFormModelItem::ComboBoxItem,
       
   480                 hbTrId("txt_occ_setlabel_adhoc_channel"));
       
   481             // Add items to combobox
       
   482             QStringList adHocChannelItems;
       
   483             adHocChannelItems
       
   484                 << hbTrId("txt_occ_setlabel_adhoc_channel_val_automatic");
       
   485             for (int i = WlanAdHocChannelMinValue;
       
   486                 i <= WlanAdHocChannelMaxValue;
       
   487                 i++) {
       
   488                 QString channel;
       
   489                 channel.setNum(i);
       
   490                 adHocChannelItems << HbStringUtil::convertDigits(channel);
       
   491             }
       
   492             mAdHocChannelItem->setContentWidgetData(
       
   493                 "items",
       
   494                 adHocChannelItems);
       
   495             // Connect signal and add item to group
       
   496             mForm->addConnection(
       
   497                 mAdHocChannelItem,
       
   498                 SIGNAL(currentIndexChanged(int)),
       
   499                 this,
       
   500                 SLOT(adHocChannelChanged(int)));
       
   501             // Add item after the network mode item
       
   502             mApSettingsGroupItem->insertChild(
       
   503                 mApSettingsGroupItem->indexOf(mNetworkModeItem) + 1,
       
   504                 mAdHocChannelItem);
       
   505         }
       
   506         // Update ad-hoc item
       
   507         int adHocChannelId = mCmConnectionMethod->getIntAttribute(
       
   508             CMManagerShim::WlanChannelID);
       
   509         mAdHocChannelItem->setContentWidgetData(
       
   510             "currentIndex",
       
   511             adHocChannelId);
       
   512     }
       
   513 }
       
   514 
       
   515 /*!
       
   516     Updates security mode item.
       
   517  */
       
   518 void CpWlanApView::updateSecurityModeItem(
       
   519     CMManagerShim::WlanConnMode networkMode)
       
   520 {
       
   521     // Load WLAN security plugins and construct map
       
   522     mSecurityModeMap.clear();
       
   523     mSecurityModeMap.insert(0, NULL); // open mode
       
   524     loadSecurityPlugins(networkMode);
       
   525     
       
   526     // Add items to combobox
       
   527     QStringList securityModeItems;
       
   528     foreach (CpWlanSecurityPluginInterface *plugin, mSecurityModeMap) {
       
   529         if (plugin) {
       
   530             // Add security mode from plugin
       
   531             securityModeItems
       
   532                 << hbTrId(plugin->securityModeTextId().toLatin1());
       
   533         } else {
       
   534             // Add open mode
       
   535             securityModeItems
       
   536                 << hbTrId("txt_occ_setlabel_wlan_security_mode_val_open");
       
   537         }
       
   538     }
       
   539     // Remove connection before setting new content, because combobox
       
   540     // will emit currentIndexChanged signal and we don't want that.
       
   541     mForm->removeConnection(
       
   542         mSecurityModeItem,
       
   543         SIGNAL(currentIndexChanged(int)),
       
   544         this,
       
   545         SLOT(securityModeChanged(int)));
       
   546     mSecurityModeItem->setContentWidgetData("items", securityModeItems);
       
   547     mForm->addConnection(
       
   548         mSecurityModeItem,
       
   549         SIGNAL(currentIndexChanged(int)),
       
   550         this,
       
   551         SLOT(securityModeChanged(int)));
       
   552     
       
   553     uint securityMode = mCmConnectionMethod->getIntAttribute(
       
   554         CMManagerShim::WlanSecurityMode);
       
   555     // Iterate through the map to find correct security plugin and set
       
   556     // mode index
       
   557     int securityModeIndex = 0;
       
   558     QMapIterator<int, CpWlanSecurityPluginInterface *> i(mSecurityModeMap);
       
   559     while (i.hasNext()) {
       
   560         i.next();
       
   561         if (i.value()
       
   562             && i.value()->securityMode() == securityMode) {
       
   563             securityModeIndex = i.key();
       
   564         }
       
   565     }
       
   566     mSecurityModeItem->setContentWidgetData("currentIndex",
       
   567         securityModeIndex);
       
   568     
       
   569     if (securityMode != CMManagerShim::WlanSecModeOpen
       
   570         && securityModeIndex == 0) {
       
   571         // Security plugin implementing the selected security mode not found,
       
   572         // set security mode to open also in CommsDat  
       
   573         mCmConnectionMethod->setIntAttribute(
       
   574             CMManagerShim::WlanSecurityMode,
       
   575             CMManagerShim::WlanSecModeOpen);
       
   576         // Try update
       
   577         try {
       
   578             mCmConnectionMethod->update();
       
   579         }
       
   580         catch (const std::exception&) {
       
   581             // Error in update, but can't show error notes at this point
       
   582         }
       
   583     }
       
   584 }
       
   585 
       
   586 /*!
   476     Stores connection name.
   587     Stores connection name.
   477 */
   588 */
   478 void CpWlanApView::connectionNameChanged()
   589 void CpWlanApView::connectionNameChanged()
   479 {
   590 {
   480     OstTraceFunctionEntry0(CPWLANAPVIEW_CONNECTIONNAMECHANGED_ENTRY);
   591     OstTraceFunctionEntry0(CPWLANAPVIEW_CONNECTIONNAMECHANGED_ENTRY);
   545 void CpWlanApView::networkStatusChanged(int index)
   656 void CpWlanApView::networkStatusChanged(int index)
   546 {
   657 {
   547     OstTraceFunctionEntry0(CPWLANAPVIEW_NETWORKSTATUSCHANGED_ENTRY);
   658     OstTraceFunctionEntry0(CPWLANAPVIEW_NETWORKSTATUSCHANGED_ENTRY);
   548     
   659     
   549     // Update to CommsDat
   660     // Update to CommsDat
   550     mCmConnectionMethod->setBoolAttribute(CMManagerShim::WlanScanSSID,
   661     mCmConnectionMethod->setBoolAttribute(
       
   662         CMManagerShim::WlanScanSSID,
   551         mNetworkStatusMap.value(index));
   663         mNetworkStatusMap.value(index));
   552     (void)tryUpdate();
   664     (void)tryUpdate();
   553     
   665     
   554     OstTraceFunctionExit0(CPWLANAPVIEW_NETWORKSTATUSCHANGED_EXIT);
   666     OstTraceFunctionExit0(CPWLANAPVIEW_NETWORKSTATUSCHANGED_EXIT);
   555 }
   667 }
   560 void CpWlanApView::networkModeChanged(int index)
   672 void CpWlanApView::networkModeChanged(int index)
   561 {
   673 {
   562     OstTraceFunctionEntry0(CPWLANAPVIEW_NETWORKMODECHANGED_ENTRY);
   674     OstTraceFunctionEntry0(CPWLANAPVIEW_NETWORKMODECHANGED_ENTRY);
   563     
   675     
   564     // Update to CommsDat
   676     // Update to CommsDat
   565     mCmConnectionMethod->setIntAttribute(CMManagerShim::WlanConnectionMode,
   677     mCmConnectionMethod->setIntAttribute(
       
   678         CMManagerShim::WlanConnectionMode,
   566         mNetworkModeMap.value(index));
   679         mNetworkModeMap.value(index));
       
   680     if (tryUpdate()) {
       
   681         // If mode is ad-hoc, ad-hoc channel item must be shown
       
   682         CMManagerShim::WlanConnMode networkMode =
       
   683             static_cast<CMManagerShim::WlanConnMode>
       
   684                 (mNetworkModeMap.value(index));
       
   685         updateAdHocChannelItem(networkMode);
       
   686 		// Also security mode list may need updating
       
   687         updateSecurityModeItem(networkMode);
       
   688     }
       
   689     
       
   690     OstTraceFunctionExit0(CPWLANAPVIEW_NETWORKMODECHANGED_EXIT);
       
   691 }
       
   692 
       
   693 /*!
       
   694     Stores ad-hoc channel ID.
       
   695 */
       
   696 void CpWlanApView::adHocChannelChanged(int index)
       
   697 {
       
   698     OstTraceFunctionEntry0(CPWLANAPVIEW_ADHOCCHANNELCHANGED_ENTRY);
       
   699     
       
   700     // Update to CommsDat
       
   701     mCmConnectionMethod->setIntAttribute(
       
   702         CMManagerShim::WlanChannelID,
       
   703         index);
   567     (void)tryUpdate();
   704     (void)tryUpdate();
   568     
   705     
   569     OstTraceFunctionExit0(CPWLANAPVIEW_NETWORKMODECHANGED_EXIT);
   706     OstTraceFunctionExit0(CPWLANAPVIEW_ADHOCCHANNELCHANGED_EXIT);
   570 }
   707 }
   571 
   708 
   572 /*!
   709 /*!
   573     Stores WLAN security mode.
   710     Stores WLAN security mode.
   574 */
   711 */
   578     
   715     
   579     // Get security plugin
   716     // Get security plugin
   580     CpWlanSecurityPluginInterface *plugin = mSecurityModeMap.value(index);
   717     CpWlanSecurityPluginInterface *plugin = mSecurityModeMap.value(index);
   581     // Update to CommsDat
   718     // Update to CommsDat
   582     if (plugin) {
   719     if (plugin) {
   583         mCmConnectionMethod->setIntAttribute(CMManagerShim::WlanSecurityMode,
   720         mCmConnectionMethod->setIntAttribute(
       
   721             CMManagerShim::WlanSecurityMode,
   584             plugin->securityMode());
   722             plugin->securityMode());
   585     } else {
   723     } else {
   586         mCmConnectionMethod->setIntAttribute(CMManagerShim::WlanSecurityMode,
   724         mCmConnectionMethod->setIntAttribute(
       
   725             CMManagerShim::WlanSecurityMode,
   587             CMManagerShim::WlanSecModeOpen);
   726             CMManagerShim::WlanSecModeOpen);
   588     }
   727     }
   589     (void)tryUpdate();
   728     (void)tryUpdate();
   590     
   729     
   591     // Update UI
   730     // Update UI