wlanutilities/wlanwizard/src/wlanwizardpagesecuritymode.cpp
changeset 39 7b3e49e4608a
parent 31 e8f4211554fb
child 43 72ebcbb64834
--- a/wlanutilities/wlanwizard/src/wlanwizardpagesecuritymode.cpp	Thu Jun 10 15:44:54 2010 +0300
+++ b/wlanutilities/wlanwizard/src/wlanwizardpagesecuritymode.cpp	Thu Jun 24 10:49:51 2010 +0300
@@ -28,13 +28,15 @@
 #include "wlanwizard_p.h"
 #include "wlanwizard.h"
 #include "wlanwizardpagesecuritymode.h"
+#include "wlanwizardscanlist.h"
 #include "OstTraceDefinitions.h"
 #ifdef OST_TRACE_COMPILER_IN_USE
 #include "wlanwizardpagesecuritymodeTraces.h"
 #endif
 
 /*!
- * Constructor. Member initialization.
+ * Constructor method for the Sequrity mode query view object.
+ * @param [in] parent pointer to parent object.
  */
 WlanWizardPageSecurityMode::WlanWizardPageSecurityMode(
     WlanWizardPrivate* parent) :
@@ -57,7 +59,8 @@
 }
 
 /*!
- * Page initialization. If view is already loaded, does nothing.
+ * Page initialization. If view widget is already loaded, does nothing.
+ * @return pointer to widget "occ_add_wlan_02".
  */
 HbWidget* WlanWizardPageSecurityMode::initializePage()
 {
@@ -71,70 +74,49 @@
         bool ok;
 
         mLoader->load( ":/docml/occ_add_wlan_02_03.docml", &ok );
-        Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "Invalid docml file");
+        Q_ASSERT(ok);
               
         // Initialize orientation
-        loadDocml( mWizard->mainWindow()->orientation() );
+        loadDocmlSection( mWizard->mainWindow()->orientation() );
 
         // Load widgets
         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_add_wlan_02"));
-        Q_ASSERT_X(mWidget != NULL, "WlanWizardPageSecurityMode", "View not found");
+        Q_ASSERT(mWidget != NULL);
 
         mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list"));
-        Q_ASSERT_X(mList != NULL, "WlanWizardPageSecurityMode", "List not found");
+        Q_ASSERT(mList != NULL);
 
         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6"));
-        Q_ASSERT_X(mLabel != NULL, "WlanWizardPageSecurityMode", "Label not found");
+        Q_ASSERT(mLabel != NULL);
         
         mLabel->setPlainText(hbTrId("txt_occ_dialog_select_network_security_mode"));
 
-        // Create contents to the security mode radio button list.
-        populateSecModeList();
-
         // Connect orientation signal from the main window to orientation
         // loader.
         ok &= connect( mWizard->mainWindow(),
                  SIGNAL(orientationChanged(Qt::Orientation)),
-                 this, SLOT(loadDocml(Qt::Orientation)));
+                 this, SLOT(loadDocmlSection(Qt::Orientation)));
+        Q_ASSERT(ok);
  
         // Connect signal from the radio button list indicating that an item
         // has been selected to validation handler.
         ok &= connect( mList, SIGNAL(itemSelected(int)),
-                 this, SLOT(itemSelected(int)));
-        
-        Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "slot connection failed");
-        
-        
+                 this, SLOT(itemSelected())); 
+        Q_ASSERT(ok);
+    }
+    
+    // Create contents to the security mode radio button list.
+    populateSecModeList();
 
-    }
     return mWidget;
 }
 
 /*!
- * Indicates the validity of the security mode page.
- * @see WlanWizardPage
- */
-bool WlanWizardPageSecurityMode::showPage()
-{
-    return mValid;
-}
-
-/*!
- * Sets the page as valid, if any mode is selected.
- * (Initially none is selected.) 
- */
-void WlanWizardPageSecurityMode::itemSelected(int /* index */)
-{
-    OstTrace0( TRACE_BORDER, WLANWIZARDPAGESECURITYMODE_ITEMSELECTED,
-        "WlanWizardPageSecurityMode::itemSelected" );
-    
-    mValid = true;
-    mWizard->enableNextButton(mValid);
-}
-
-/*!
- * Evaluates and returns the next page id.
- * @see initializePage()
+ * Validates the Sequrity more selection and sets the configuration in
+ * the wlanwizard.
+ * @param [out] removeFromStack returns false.
+ * @return depending on the sequrity mode, returns the appropriate view
+ * identifier.
  */
 int WlanWizardPageSecurityMode::nextId(bool &removeFromStack) const
 {
@@ -154,23 +136,46 @@
 }
 
 /*!
- * Loads the document with given orientation.
+ * This method is overrides the default implementation from WlanWizardPage.
+ * It indicates whether the Next-button should be enabled or not.
+ * @return true, if a mode has been selected.
+ */
+bool WlanWizardPageSecurityMode::showPage()
+{
+    return mValid;
+}
+
+/*!
+ * Is invoked when user selects a mode from the radio button list.
+ * (HbRadioButtonList's itemSelected-signal)
  */
-void WlanWizardPageSecurityMode::loadDocml(Qt::Orientation orientation)
+void WlanWizardPageSecurityMode::itemSelected()
+{
+    OstTrace0( TRACE_BORDER, WLANWIZARDPAGESECURITYMODE_ITEMSELECTED,
+        "WlanWizardPageSecurityMode::itemSelected" );
+    
+    mValid = true;
+    mWizard->enableNextButton(mValid);
+}
+
+/*!
+ * Loads the document orientation information from occ_add_wlan_02_03.docml
+ * This is called each time phone orientation changes.
+ * @param [in] orientation indicates whether the phone is in portrait or
+ * landscape mode.
+ */
+void WlanWizardPageSecurityMode::loadDocmlSection(Qt::Orientation orientation)
 {
     OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESECURITYMODE_LOADDOCML,
         "WlanWizardPageSecurityMode::loadDocml - orientation;orientation=%x",
         ( TUint )( orientation ) );
     
-    bool ok;
-    if( orientation == Qt::Horizontal ) {
-        mLoader->load(":/docml/occ_add_wlan_02_03.docml", "landscape_section", &ok);
-        Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "Landscape section not found");
-    }
-    else {
-        mLoader->load(":/docml/occ_add_wlan_02_03.docml", "portrait_section", &ok);
-        Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "Portrait section not found");
-    }
+    WlanWizardPageInternal::loadDocmlSection(
+        mLoader,
+        orientation,
+        ":/docml/occ_add_wlan_02_03.docml", 
+        "portrait_section",
+        "landscape_section");
 }
 
 /*!
@@ -182,6 +187,12 @@
 
     mSecModes.clear();
     mPageIds.clear();
+    mUsePsk.clear();
+    
+    // A list is created. Since there is no practical way of knowing whether
+    // the new contents are different from the previous contents (if there
+    // even were any in the first place) the validity is always reset.
+    mValid = false;
 
     // Create the radio button list to correspond to correct security mode
     // identifiers and page identifiers.
@@ -197,7 +208,7 @@
         true);
 
     // In case of Ad-hoc network, exclude wpa, eap and 802.1X modes.
-    if(mWizard->configuration(WlanWizardPrivate::ConfNetworkMode).toInt()
+    if (mWizard->configuration(WlanWizardPrivate::ConfNetworkMode).toInt()
         != CMManagerShim::Adhoc) {
 
         addToList(items, hbTrId("txt_occ_list_wpa_with_password"),
@@ -205,7 +216,6 @@
             WlanWizardPageInternal::PageKeyQuery,
             true);
 
-        // TODO: Fix these codes
         addToList(items, hbTrId("txt_occ_list_wpa_with_eap"),
             CMManagerShim::WlanSecModeWpa,
             WlanWizardPage::PageEapStart,
@@ -221,16 +231,46 @@
 }
 
 /*!
- * Creates lists for security modes and page id:s so that they can be referred
- * with radio button widget index.
+ * A support function to map the radio button list to a generic network
+ * mode list. This enables the changing of button order without it
+ * affecting the entire class.
+ * @param [out] list is a reference to a local list that will be placed as an
+ * argument to the radio button list.
+ * @param [in] item is a reference to the text value that is appended to the
+ * list
+ * @param [in] mode is the security mode associated with the item
+ * @param [in] page is the id of the next wizard page when this item is selected.
+ * @param [in] psk indicates whether password needs to be queried. 
  */
 void WlanWizardPageSecurityMode::addToList(QStringList &list,
     const QString &item, int mode, int page, bool psk)
 {
-    list << item;
-    mSecModes.append(mode);
-    mPageIds.append(page);
-    mUsePsk.append(psk);
+    if (mWizard->configurationExists(WlanWizardHelper::ConfAvailableNetworkOptions)) {
+        WlanNetworkSetting netMode;
+        netMode.mode = mWizard->configuration(WlanWizardPrivate::ConfNetworkMode).toInt();
+        netMode.hidden = mWizard->configuration(WlanWizardPrivate::ConfHiddenWlan).toBool();
+
+        // wps always set to false at this point of the wizard.
+        netMode.wpsSupported = false;
+
+        WlanWizardScanList networkOptions = mWizard->configuration(
+            WlanWizardHelper::ConfAvailableNetworkOptions).value<WlanWizardScanList>();
+
+        for (int i = 0; i < networkOptions.secModes(netMode); i++) {
+            WlanSecuritySetting secMode = networkOptions.getSecMode(netMode, i);
+
+            if (secMode.mode == mode && secMode.usePsk == psk) {
+                list << item;
+                mSecModes.append(mode);
+                mPageIds.append(page);
+                mUsePsk.append(psk);
+            }
+        }
+    }
+    else {
+        list << item;
+        mSecModes.append(mode);
+        mPageIds.append(page);
+        mUsePsk.append(psk);
+    }
 }
-
-