wlanutilities/wlanwizard/src/wlanwizardscanlist.cpp
changeset 39 7b3e49e4608a
child 43 72ebcbb64834
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
       
     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 
       
    30 /*!
       
    31  * Constructor for WlanWizardScanList object.
       
    32  */
       
    33 WlanWizardScanList::WlanWizardScanList()
       
    34 {
       
    35 
       
    36 }
       
    37 
       
    38 /*!
       
    39  * Copy Constructor for WlanWizardScanList object.
       
    40  * @param [in] scanList is the object to be copied.
       
    41  */
       
    42 WlanWizardScanList::WlanWizardScanList(const WlanWizardScanList &scanList):
       
    43     mOpenOptions(scanList.mOpenOptions)
       
    44 {
       
    45 
       
    46 }
       
    47 
       
    48 /*!
       
    49  * Destructor for WlanWizardScanList object.
       
    50  */
       
    51 WlanWizardScanList::~WlanWizardScanList()
       
    52 {
       
    53 
       
    54 }
       
    55 
       
    56 /*!
       
    57  * This function builds a hash list of scan results. Key value in a hash item
       
    58  * is the network mode and the associated value is a list of security modes.
       
    59  * In other words, it is a list of network modes where each network mode points
       
    60  * to one or more security modes.
       
    61  * @param [in] results contains a list of scan results.
       
    62  */
       
    63 void WlanWizardScanList::build(const QList<WlanScanResult> &results)
       
    64 {
       
    65     for (int i = 0; i < results.size(); i++) {
       
    66         WlanNetworkSetting netMode;
       
    67         WlanSecuritySetting secMode;
       
    68         WlanScanResult item = results.at(i);
       
    69         
       
    70         netMode.wpsSupported = item.scanResult->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool();
       
    71         netMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
       
    72         netMode.hidden = (netMode.mode == CMManagerShim::Adhoc) ? false : item.networkHidden;
       
    73         
       
    74         secMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
       
    75         secMode.usePsk = (secMode.mode == CMManagerShim::WlanSecModeWep) ? true
       
    76             : item.scanResult->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool();
       
    77 
       
    78         switch (secMode.mode) {
       
    79         case CMManagerShim::WlanSecMode802_1x:
       
    80             secMode.nextPageId = WlanWizardPage::PageEapStart;
       
    81             break;
       
    82             
       
    83         case CMManagerShim::WlanSecModeWep:
       
    84             secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
       
    85             break;
       
    86             
       
    87         case CMManagerShim::WlanSecModeWpa:
       
    88         case CMManagerShim::WlanSecModeWpa2:
       
    89             if (secMode.usePsk) {
       
    90                 secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
       
    91             }
       
    92             else {
       
    93                 secMode.nextPageId = WlanWizardPage::PageEapStart;
       
    94             }
       
    95             break;
       
    96 
       
    97         default:
       
    98             Q_ASSERT(CMManagerShim::WlanSecModeOpen == secMode.mode ||
       
    99                 CMManagerShim::WlanSecModeWapi == secMode.mode);
       
   100             secMode.nextPageId = WlanWizardPage::PageProcessSettings;
       
   101             break;
       
   102             
       
   103         }
       
   104         
       
   105         // prevent duplicate settings.
       
   106         if (!mOpenOptions.contains(netMode)) {
       
   107             QList<WlanSecuritySetting> secList;
       
   108             secList.append(secMode);
       
   109             mOpenOptions.insert(netMode, secList);
       
   110         }
       
   111         else if (!(mOpenOptions.find(netMode)->contains(secMode))) {
       
   112             mOpenOptions.find(netMode)->append(secMode);  
       
   113         }
       
   114         // else an identical key-value pair is already in the list -> not added.
       
   115     }
       
   116 }
       
   117 
       
   118 /*!
       
   119  * This function returns a security mode setting at the requested location.
       
   120  * This function does not do any validity checks for the lists, so the user
       
   121  * needs to use netModes and secModes functions to prevent over-indexing.
       
   122  * @param [in] netMode key value for the hash list.
       
   123  * @param [in] index list index pointing to the security mode item.
       
   124  * @return security setting item reference.
       
   125  */
       
   126 const WlanSecuritySetting &WlanWizardScanList::getSecMode(
       
   127     WlanNetworkSetting netMode,
       
   128     int index) const
       
   129 {
       
   130     return mOpenOptions.value(netMode).at(index);
       
   131 }
       
   132 
       
   133 /*!
       
   134  * The number of key values available in the hash list.
       
   135  * @return the number of keys.
       
   136  */
       
   137 int WlanWizardScanList::netModes() const
       
   138 {
       
   139     return mOpenOptions.size();
       
   140 }
       
   141 
       
   142 /*!
       
   143  * The size of the security mode list associated to a network mode.
       
   144  * @param [in] netMode key value for the hash list.
       
   145  * @return the size of the list associated with the key.
       
   146  */
       
   147 int WlanWizardScanList::secModes(WlanNetworkSetting netMode) const
       
   148 {
       
   149     return mOpenOptions.find(netMode)->size();
       
   150 }
       
   151 
       
   152 /*!
       
   153  * This function returns the list of keys in the hash.
       
   154  * @return a list of keys.
       
   155  */
       
   156 QList<WlanNetworkSetting> WlanWizardScanList::getNetModes() const
       
   157 {
       
   158     return mOpenOptions.keys();
       
   159 }
       
   160