wlanutilities/wlanwizard/src/wlanwizardscanlist.cpp
branchRCL_3
changeset 24 63be7eb3fc78
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
       
     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  *   Wlan Wizard Scan List: Hierarchical list of scan results that can be
       
    16  *   utilized to limit available selection options in manual wlan wizard.
       
    17  *
       
    18  */
       
    19 
       
    20 // System includes
       
    21 #include <HbGlobal>
       
    22 #include <QString>
       
    23 #include <cmmanagerdefines_shim.h>
       
    24 #include <wlanqtutilsap.h>
       
    25 
       
    26 // User includes
       
    27 #include "wlanwizardscanlist.h"
       
    28 #include "wlanwizardpageinternal.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "wlanwizardscanlistTraces.h"
       
    32 #endif
       
    33 
       
    34 
       
    35 /*!
       
    36  * Constructor for WlanWizardScanList object.
       
    37  */
       
    38 WlanWizardScanList::WlanWizardScanList(): mWpsSelected(false)
       
    39 {
       
    40     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_ENTRY );
       
    41 
       
    42     OstTraceFunctionExit0( WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_EXIT );
       
    43 }
       
    44 
       
    45 /*!
       
    46  * Copy Constructor for WlanWizardScanList object.
       
    47  * @param [in] scanList is the object to be copied.
       
    48  */
       
    49 WlanWizardScanList::WlanWizardScanList(const WlanWizardScanList &scanList):
       
    50 mOpenOptions(scanList.mOpenOptions), mWpsSelected(false)
       
    51 {
       
    52     OstTraceFunctionEntry0( DUP1_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_ENTRY );
       
    53 
       
    54     OstTraceFunctionExit0( DUP1_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_EXIT );
       
    55 }
       
    56 
       
    57 /*!
       
    58  * Destructor for WlanWizardScanList object.
       
    59  */
       
    60 WlanWizardScanList::~WlanWizardScanList()
       
    61 {
       
    62     OstTraceFunctionEntry0( DUP2_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_ENTRY );
       
    63 
       
    64     OstTraceFunctionExit0( DUP2_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_EXIT );
       
    65 }
       
    66 
       
    67 /*!
       
    68  * This function builds a hash list of scan results. Key value in a hash item
       
    69  * is the network mode and the associated value is a list of security modes.
       
    70  * In other words, it is a list of network modes where each network mode points
       
    71  * to one or more security modes.
       
    72  * @param [in] results contains a list of scan results.
       
    73  */
       
    74 void WlanWizardScanList::build(const QList<WlanScanResult> &results)
       
    75 {
       
    76     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_BUILD_ENTRY );
       
    77     
       
    78     mWpsSelected = true;
       
    79     
       
    80     for (int i = 0; i < results.size(); i++) {
       
    81         WlanNetworkSetting netMode;
       
    82         WlanSecuritySetting secMode;
       
    83         WlanScanResult item = results.at(i);
       
    84 
       
    85         netMode.wpsSupported = item.scanResult->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool();
       
    86         netMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
       
    87         netMode.hidden = (netMode.mode == CMManagerShim::Adhoc) ? false : item.networkHidden;
       
    88 
       
    89         secMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
       
    90         secMode.usePsk = (secMode.mode == CMManagerShim::WlanSecModeWep) ? true
       
    91             : item.scanResult->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool();
       
    92 
       
    93         switch (secMode.mode) {
       
    94         case CMManagerShim::WlanSecMode802_1x:
       
    95             secMode.nextPageId = WlanWizardPage::PageEapStart;
       
    96             break;
       
    97 
       
    98         case CMManagerShim::WlanSecModeWep:
       
    99             secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
       
   100             break;
       
   101 
       
   102         case CMManagerShim::WlanSecModeWpa:
       
   103         case CMManagerShim::WlanSecModeWpa2:
       
   104             if (secMode.usePsk) {
       
   105                 secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
       
   106             }
       
   107             else {
       
   108                 secMode.nextPageId = WlanWizardPage::PageEapStart;
       
   109             }
       
   110             break;
       
   111 
       
   112         default:
       
   113             Q_ASSERT(CMManagerShim::WlanSecModeOpen == secMode.mode ||
       
   114                 CMManagerShim::WlanSecModeWapi == secMode.mode);
       
   115             secMode.nextPageId = WlanWizardPage::PageProcessSettings;
       
   116             break;
       
   117 
       
   118         }
       
   119 
       
   120         // prevent duplicate settings.
       
   121         if (!mOpenOptions.contains(netMode)) {
       
   122             mWpsSelected = (mWpsSelected && netMode.wpsSupported);
       
   123             QList<WlanSecuritySetting> secList;
       
   124             secList.append(secMode);
       
   125             mOpenOptions.insert(netMode, secList);
       
   126         }
       
   127         else if (!(mOpenOptions.find(netMode)->contains(secMode))) {
       
   128             mOpenOptions.find(netMode)->append(secMode);  
       
   129         }
       
   130         // else an identical key-value pair is already in the list -> not added.
       
   131     }
       
   132     OstTraceFunctionExit0( WLANWIZARDSCANLIST_BUILD_EXIT );
       
   133 }
       
   134 
       
   135 /*!
       
   136  * This function returns a security mode setting at the requested location.
       
   137  * This function does not do any validity checks for the lists, so the user
       
   138  * needs to use netModes and secModes functions to prevent over-indexing.
       
   139  * @param [in] netMode key value for the hash list.
       
   140  * @param [in] index list index pointing to the security mode item.
       
   141  * @return security setting item reference.
       
   142  */
       
   143 const WlanSecuritySetting &WlanWizardScanList::getSecMode(
       
   144     WlanNetworkSetting netMode,
       
   145     int index) const
       
   146 {
       
   147     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_GETSECMODE_ENTRY );
       
   148     return mOpenOptions.value(netMode).at(index);
       
   149 }
       
   150 
       
   151 /*!
       
   152  * The number of key values available in the hash list.
       
   153  * @return the number of keys.
       
   154  */
       
   155 int WlanWizardScanList::netModes() const
       
   156 {
       
   157     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_NETMODES_ENTRY );
       
   158     return mOpenOptions.size();
       
   159 }
       
   160 
       
   161 /*!
       
   162  * The size of the security mode list associated to a network mode.
       
   163  * @param [in] netMode key value for the hash list.
       
   164  * @return the size of the list associated with the key.
       
   165  */
       
   166 int WlanWizardScanList::secModes(WlanNetworkSetting netMode) const
       
   167 {
       
   168     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_SECMODES_ENTRY );
       
   169     Q_ASSERT(mOpenOptions.contains(netMode));
       
   170     return mOpenOptions.find(netMode)->size();
       
   171 }
       
   172 
       
   173 /*!
       
   174  * This function returns the list of keys in the hash.
       
   175  * @return a list of keys.
       
   176  */
       
   177 QList<WlanNetworkSetting> WlanWizardScanList::getNetModes() const
       
   178 {
       
   179     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_GETNETMODES_ENTRY );
       
   180     return mOpenOptions.keys();
       
   181 }
       
   182 
       
   183 /*!
       
   184  * This function indicates whether the list of scan results supports
       
   185  * Wi-Fi Protected Setup.
       
   186  * @return true, if all result network modes support wps, false if even
       
   187  * a single result does not.
       
   188  */
       
   189 bool WlanWizardScanList::wpsSelected() const
       
   190 {
       
   191     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_WPSSELECTED_ENTRY );
       
   192     return mWpsSelected;
       
   193 }