wlanutilities/wlanwizard/src/wlanwizardpagesecuritymode.cpp
changeset 39 7b3e49e4608a
parent 31 e8f4211554fb
child 43 72ebcbb64834
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
    26 
    26 
    27 // User includes
    27 // User includes
    28 #include "wlanwizard_p.h"
    28 #include "wlanwizard_p.h"
    29 #include "wlanwizard.h"
    29 #include "wlanwizard.h"
    30 #include "wlanwizardpagesecuritymode.h"
    30 #include "wlanwizardpagesecuritymode.h"
       
    31 #include "wlanwizardscanlist.h"
    31 #include "OstTraceDefinitions.h"
    32 #include "OstTraceDefinitions.h"
    32 #ifdef OST_TRACE_COMPILER_IN_USE
    33 #ifdef OST_TRACE_COMPILER_IN_USE
    33 #include "wlanwizardpagesecuritymodeTraces.h"
    34 #include "wlanwizardpagesecuritymodeTraces.h"
    34 #endif
    35 #endif
    35 
    36 
    36 /*!
    37 /*!
    37  * Constructor. Member initialization.
    38  * Constructor method for the Sequrity mode query view object.
       
    39  * @param [in] parent pointer to parent object.
    38  */
    40  */
    39 WlanWizardPageSecurityMode::WlanWizardPageSecurityMode(
    41 WlanWizardPageSecurityMode::WlanWizardPageSecurityMode(
    40     WlanWizardPrivate* parent) :
    42     WlanWizardPrivate* parent) :
    41     WlanWizardPageInternal(parent), 
    43     WlanWizardPageInternal(parent), 
    42     mWidget(NULL),
    44     mWidget(NULL),
    55 {
    57 {
    56     delete mLoader;
    58     delete mLoader;
    57 }
    59 }
    58 
    60 
    59 /*!
    61 /*!
    60  * Page initialization. If view is already loaded, does nothing.
    62  * Page initialization. If view widget is already loaded, does nothing.
       
    63  * @return pointer to widget "occ_add_wlan_02".
    61  */
    64  */
    62 HbWidget* WlanWizardPageSecurityMode::initializePage()
    65 HbWidget* WlanWizardPageSecurityMode::initializePage()
    63 {
    66 {
    64     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESECURITYMODE_INITIALIZEPAGE,
    67     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESECURITYMODE_INITIALIZEPAGE,
    65         "WlanWizardPageSecurityMode::initializePage" );
    68         "WlanWizardPageSecurityMode::initializePage" );
    69         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    72         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    70         
    73         
    71         bool ok;
    74         bool ok;
    72 
    75 
    73         mLoader->load( ":/docml/occ_add_wlan_02_03.docml", &ok );
    76         mLoader->load( ":/docml/occ_add_wlan_02_03.docml", &ok );
    74         Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "Invalid docml file");
    77         Q_ASSERT(ok);
    75               
    78               
    76         // Initialize orientation
    79         // Initialize orientation
    77         loadDocml( mWizard->mainWindow()->orientation() );
    80         loadDocmlSection( mWizard->mainWindow()->orientation() );
    78 
    81 
    79         // Load widgets
    82         // Load widgets
    80         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_add_wlan_02"));
    83         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_add_wlan_02"));
    81         Q_ASSERT_X(mWidget != NULL, "WlanWizardPageSecurityMode", "View not found");
    84         Q_ASSERT(mWidget != NULL);
    82 
    85 
    83         mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list"));
    86         mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list"));
    84         Q_ASSERT_X(mList != NULL, "WlanWizardPageSecurityMode", "List not found");
    87         Q_ASSERT(mList != NULL);
    85 
    88 
    86         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6"));
    89         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6"));
    87         Q_ASSERT_X(mLabel != NULL, "WlanWizardPageSecurityMode", "Label not found");
    90         Q_ASSERT(mLabel != NULL);
    88         
    91         
    89         mLabel->setPlainText(hbTrId("txt_occ_dialog_select_network_security_mode"));
    92         mLabel->setPlainText(hbTrId("txt_occ_dialog_select_network_security_mode"));
    90 
       
    91         // Create contents to the security mode radio button list.
       
    92         populateSecModeList();
       
    93 
    93 
    94         // Connect orientation signal from the main window to orientation
    94         // Connect orientation signal from the main window to orientation
    95         // loader.
    95         // loader.
    96         ok &= connect( mWizard->mainWindow(),
    96         ok &= connect( mWizard->mainWindow(),
    97                  SIGNAL(orientationChanged(Qt::Orientation)),
    97                  SIGNAL(orientationChanged(Qt::Orientation)),
    98                  this, SLOT(loadDocml(Qt::Orientation)));
    98                  this, SLOT(loadDocmlSection(Qt::Orientation)));
       
    99         Q_ASSERT(ok);
    99  
   100  
   100         // Connect signal from the radio button list indicating that an item
   101         // Connect signal from the radio button list indicating that an item
   101         // has been selected to validation handler.
   102         // has been selected to validation handler.
   102         ok &= connect( mList, SIGNAL(itemSelected(int)),
   103         ok &= connect( mList, SIGNAL(itemSelected(int)),
   103                  this, SLOT(itemSelected(int)));
   104                  this, SLOT(itemSelected())); 
   104         
   105         Q_ASSERT(ok);
   105         Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "slot connection failed");
   106     }
   106         
   107     
   107         
   108     // Create contents to the security mode radio button list.
   108 
   109     populateSecModeList();
   109     }
   110 
   110     return mWidget;
   111     return mWidget;
   111 }
   112 }
   112 
   113 
   113 /*!
   114 /*!
   114  * Indicates the validity of the security mode page.
   115  * Validates the Sequrity more selection and sets the configuration in
   115  * @see WlanWizardPage
   116  * the wlanwizard.
   116  */
   117  * @param [out] removeFromStack returns false.
   117 bool WlanWizardPageSecurityMode::showPage()
   118  * @return depending on the sequrity mode, returns the appropriate view
   118 {
   119  * identifier.
   119     return mValid;
       
   120 }
       
   121 
       
   122 /*!
       
   123  * Sets the page as valid, if any mode is selected.
       
   124  * (Initially none is selected.) 
       
   125  */
       
   126 void WlanWizardPageSecurityMode::itemSelected(int /* index */)
       
   127 {
       
   128     OstTrace0( TRACE_BORDER, WLANWIZARDPAGESECURITYMODE_ITEMSELECTED,
       
   129         "WlanWizardPageSecurityMode::itemSelected" );
       
   130     
       
   131     mValid = true;
       
   132     mWizard->enableNextButton(mValid);
       
   133 }
       
   134 
       
   135 /*!
       
   136  * Evaluates and returns the next page id.
       
   137  * @see initializePage()
       
   138  */
   120  */
   139 int WlanWizardPageSecurityMode::nextId(bool &removeFromStack) const
   121 int WlanWizardPageSecurityMode::nextId(bool &removeFromStack) const
   140 {
   122 {
   141     removeFromStack = false;
   123     removeFromStack = false;
   142     
   124     
   152 
   134 
   153     return mPageIds.at( mList->selected() );
   135     return mPageIds.at( mList->selected() );
   154 }
   136 }
   155 
   137 
   156 /*!
   138 /*!
   157  * Loads the document with given orientation.
   139  * This method is overrides the default implementation from WlanWizardPage.
   158  */
   140  * It indicates whether the Next-button should be enabled or not.
   159 void WlanWizardPageSecurityMode::loadDocml(Qt::Orientation orientation)
   141  * @return true, if a mode has been selected.
       
   142  */
       
   143 bool WlanWizardPageSecurityMode::showPage()
       
   144 {
       
   145     return mValid;
       
   146 }
       
   147 
       
   148 /*!
       
   149  * Is invoked when user selects a mode from the radio button list.
       
   150  * (HbRadioButtonList's itemSelected-signal)
       
   151  */
       
   152 void WlanWizardPageSecurityMode::itemSelected()
       
   153 {
       
   154     OstTrace0( TRACE_BORDER, WLANWIZARDPAGESECURITYMODE_ITEMSELECTED,
       
   155         "WlanWizardPageSecurityMode::itemSelected" );
       
   156     
       
   157     mValid = true;
       
   158     mWizard->enableNextButton(mValid);
       
   159 }
       
   160 
       
   161 /*!
       
   162  * Loads the document orientation information from occ_add_wlan_02_03.docml
       
   163  * This is called each time phone orientation changes.
       
   164  * @param [in] orientation indicates whether the phone is in portrait or
       
   165  * landscape mode.
       
   166  */
       
   167 void WlanWizardPageSecurityMode::loadDocmlSection(Qt::Orientation orientation)
   160 {
   168 {
   161     OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESECURITYMODE_LOADDOCML,
   169     OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESECURITYMODE_LOADDOCML,
   162         "WlanWizardPageSecurityMode::loadDocml - orientation;orientation=%x",
   170         "WlanWizardPageSecurityMode::loadDocml - orientation;orientation=%x",
   163         ( TUint )( orientation ) );
   171         ( TUint )( orientation ) );
   164     
   172     
   165     bool ok;
   173     WlanWizardPageInternal::loadDocmlSection(
   166     if( orientation == Qt::Horizontal ) {
   174         mLoader,
   167         mLoader->load(":/docml/occ_add_wlan_02_03.docml", "landscape_section", &ok);
   175         orientation,
   168         Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "Landscape section not found");
   176         ":/docml/occ_add_wlan_02_03.docml", 
   169     }
   177         "portrait_section",
   170     else {
   178         "landscape_section");
   171         mLoader->load(":/docml/occ_add_wlan_02_03.docml", "portrait_section", &ok);
       
   172         Q_ASSERT_X(ok, "WlanWizardPageSecurityMode", "Portrait section not found");
       
   173     }
       
   174 }
   179 }
   175 
   180 
   176 /*!
   181 /*!
   177  * Support function that creates the contents of the security mode list. 
   182  * Support function that creates the contents of the security mode list. 
   178  */
   183  */
   180 {
   185 {
   181     QStringList items;
   186     QStringList items;
   182 
   187 
   183     mSecModes.clear();
   188     mSecModes.clear();
   184     mPageIds.clear();
   189     mPageIds.clear();
       
   190     mUsePsk.clear();
       
   191     
       
   192     // A list is created. Since there is no practical way of knowing whether
       
   193     // the new contents are different from the previous contents (if there
       
   194     // even were any in the first place) the validity is always reset.
       
   195     mValid = false;
   185 
   196 
   186     // Create the radio button list to correspond to correct security mode
   197     // Create the radio button list to correspond to correct security mode
   187     // identifiers and page identifiers.
   198     // identifiers and page identifiers.
   188     // Populate the list according to network mode selection.
   199     // Populate the list according to network mode selection.
   189     addToList(items, hbTrId("txt_occ_list_open"), 
   200     addToList(items, hbTrId("txt_occ_list_open"), 
   195         CMManagerShim::WlanSecModeWep,
   206         CMManagerShim::WlanSecModeWep,
   196         WlanWizardPageInternal::PageKeyQuery,
   207         WlanWizardPageInternal::PageKeyQuery,
   197         true);
   208         true);
   198 
   209 
   199     // In case of Ad-hoc network, exclude wpa, eap and 802.1X modes.
   210     // In case of Ad-hoc network, exclude wpa, eap and 802.1X modes.
   200     if(mWizard->configuration(WlanWizardPrivate::ConfNetworkMode).toInt()
   211     if (mWizard->configuration(WlanWizardPrivate::ConfNetworkMode).toInt()
   201         != CMManagerShim::Adhoc) {
   212         != CMManagerShim::Adhoc) {
   202 
   213 
   203         addToList(items, hbTrId("txt_occ_list_wpa_with_password"),
   214         addToList(items, hbTrId("txt_occ_list_wpa_with_password"),
   204             CMManagerShim::WlanSecModeWpa,
   215             CMManagerShim::WlanSecModeWpa,
   205             WlanWizardPageInternal::PageKeyQuery,
   216             WlanWizardPageInternal::PageKeyQuery,
   206             true);
   217             true);
   207 
   218 
   208         // TODO: Fix these codes
       
   209         addToList(items, hbTrId("txt_occ_list_wpa_with_eap"),
   219         addToList(items, hbTrId("txt_occ_list_wpa_with_eap"),
   210             CMManagerShim::WlanSecModeWpa,
   220             CMManagerShim::WlanSecModeWpa,
   211             WlanWizardPage::PageEapStart,
   221             WlanWizardPage::PageEapStart,
   212             false);
   222             false);
   213 
   223 
   219 
   229 
   220     mList->setItems(items);
   230     mList->setItems(items);
   221 }
   231 }
   222 
   232 
   223 /*!
   233 /*!
   224  * Creates lists for security modes and page id:s so that they can be referred
   234  * A support function to map the radio button list to a generic network
   225  * with radio button widget index.
   235  * mode list. This enables the changing of button order without it
       
   236  * affecting the entire class.
       
   237  * @param [out] list is a reference to a local list that will be placed as an
       
   238  * argument to the radio button list.
       
   239  * @param [in] item is a reference to the text value that is appended to the
       
   240  * list
       
   241  * @param [in] mode is the security mode associated with the item
       
   242  * @param [in] page is the id of the next wizard page when this item is selected.
       
   243  * @param [in] psk indicates whether password needs to be queried. 
   226  */
   244  */
   227 void WlanWizardPageSecurityMode::addToList(QStringList &list,
   245 void WlanWizardPageSecurityMode::addToList(QStringList &list,
   228     const QString &item, int mode, int page, bool psk)
   246     const QString &item, int mode, int page, bool psk)
   229 {
   247 {
   230     list << item;
   248     if (mWizard->configurationExists(WlanWizardHelper::ConfAvailableNetworkOptions)) {
   231     mSecModes.append(mode);
   249         WlanNetworkSetting netMode;
   232     mPageIds.append(page);
   250         netMode.mode = mWizard->configuration(WlanWizardPrivate::ConfNetworkMode).toInt();
   233     mUsePsk.append(psk);
   251         netMode.hidden = mWizard->configuration(WlanWizardPrivate::ConfHiddenWlan).toBool();
   234 }
   252 
   235 
   253         // wps always set to false at this point of the wizard.
   236 
   254         netMode.wpsSupported = false;
       
   255 
       
   256         WlanWizardScanList networkOptions = mWizard->configuration(
       
   257             WlanWizardHelper::ConfAvailableNetworkOptions).value<WlanWizardScanList>();
       
   258 
       
   259         for (int i = 0; i < networkOptions.secModes(netMode); i++) {
       
   260             WlanSecuritySetting secMode = networkOptions.getSecMode(netMode, i);
       
   261 
       
   262             if (secMode.mode == mode && secMode.usePsk == psk) {
       
   263                 list << item;
       
   264                 mSecModes.append(mode);
       
   265                 mPageIds.append(page);
       
   266                 mUsePsk.append(psk);
       
   267             }
       
   268         }
       
   269     }
       
   270     else {
       
   271         list << item;
       
   272         mSecModes.append(mode);
       
   273         mPageIds.append(page);
       
   274         mUsePsk.append(psk);
       
   275     }
       
   276 }