wlanutilities/wlanwizard/src/wlanwizardpagenetworkmode.cpp
changeset 46 2fbd1d709fe7
parent 38 2dc6da6fb431
child 43 72ebcbb64834
equal deleted inserted replaced
45:d9ec2b8c6bad 46:2fbd1d709fe7
    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 "wlanwizardpagenetworkmode.h"
    30 #include "wlanwizardpagenetworkmode.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 "wlanwizardpagenetworkmodeTraces.h"
    34 #include "wlanwizardpagenetworkmodeTraces.h"
    34 #endif
    35 #endif
    35 
    36 
    36 /*!
    37 // Local constants
    37  * Contructor. Member initialization.
    38 
       
    39 /*!
       
    40  * Constructor method for the network mode view object
       
    41  * @param parent [in] pointer to parent object.
    38  */
    42  */
    39 WlanWizardPageNetworkMode::WlanWizardPageNetworkMode(
    43 WlanWizardPageNetworkMode::WlanWizardPageNetworkMode(
    40     WlanWizardPrivate* parent) :
    44     WlanWizardPrivate* parent) :
    41     WlanWizardPageInternal(parent),
    45     WlanWizardPageInternal(parent),
    42     mWidget(NULL),
    46     mWidget(NULL),
    56     delete mLoader;
    60     delete mLoader;
    57 }
    61 }
    58 
    62 
    59 /*!
    63 /*!
    60  * Page initialization. If view is already loaded, does nothing.
    64  * Page initialization. If view is already loaded, does nothing.
       
    65  * Inherited from WlanWizardPage.
    61  */
    66  */
    62 HbWidget* WlanWizardPageNetworkMode::initializePage()
    67 HbWidget* WlanWizardPageNetworkMode::initializePage()
    63 {
    68 {
    64     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_INITIALIZEPAGE,
    69     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_INITIALIZEPAGE,
    65         "WlanWizardPageNetworkMode::initializePage" );
    70         "WlanWizardPageNetworkMode::initializePage" );
    68         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    73         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    69 
    74 
    70         bool ok;
    75         bool ok;
    71 
    76 
    72         mLoader->load(":/docml/occ_add_wlan_02_03.docml", &ok);
    77         mLoader->load(":/docml/occ_add_wlan_02_03.docml", &ok);
    73         Q_ASSERT_X(ok, "WLAN Wizard", "Invalid docml file");
    78         Q_ASSERT(ok);
    74 
    79 
    75         loadDocml(mWizard->mainWindow()->orientation());
    80         loadDocmlSection(mWizard->mainWindow()->orientation());
    76 
    81 
    77         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget(
    82         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget(
    78             "occ_add_wlan_02"));
    83             "occ_add_wlan_02"));
    79         Q_ASSERT_X(mWidget != NULL, "WlanWizardPageNetworkMode", "View not found");
    84         Q_ASSERT(mWidget != NULL);
    80 
    85 
    81         mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list"));
    86         mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list"));
    82         Q_ASSERT_X(mList != NULL, "WlanWizardPageNetworkMode", "List not found");
    87         Q_ASSERT(mList != NULL);
    83 
    88 
    84         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6"));
    89         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6"));
    85         Q_ASSERT_X(mLabel != NULL, "WlanWizardPageNetworkMode", "Label not found");
    90         Q_ASSERT(mLabel != NULL);
    86 
    91 
    87         // Connect document loading to main window orientation changes.
    92         // Connect document loading to main window orientation changes.
    88         ok &= connect(mWizard->mainWindow(),
    93         ok = connect(mWizard->mainWindow(),
    89             SIGNAL(orientationChanged(Qt::Orientation)), this,
    94             SIGNAL(orientationChanged(Qt::Orientation)), this,
    90             SLOT(loadDocml(Qt::Orientation)));
    95             SLOT(loadDocmlSection(Qt::Orientation)));
    91 
    96         Q_ASSERT(ok);
       
    97         
    92         // Connect a function to a radio button selection.
    98         // Connect a function to a radio button selection.
    93         ok &= connect(mList, SIGNAL(itemSelected(int)), this,
    99         ok = connect(mList, SIGNAL(itemSelected(int)), this,
    94             SLOT(itemSelected(int)));
   100             SLOT(itemSelected()));
    95 
   101         Q_ASSERT(ok);
    96         Q_ASSERT_X(ok, "WLAN Wizard", "orientationChanged slot connection failed");
       
    97 
   102 
    98         mLabel->setPlainText(hbTrId(
   103         mLabel->setPlainText(hbTrId(
    99             "txt_occ_dialog_select_network_mode_and_status"));
   104             "txt_occ_dialog_select_network_mode_and_status"));
   100 
   105     }
   101         QStringList items;
   106     
   102 
   107     QStringList items;
   103         addToList(items, hbTrId("txt_occ_dblist_val_infrastructure_public"),
   108     
   104             CMManagerShim::Infra, false);
   109     populateRadioButtonList(items);
   105 
   110     
   106         addToList(items, hbTrId("txt_occ_list_infrastructure_hidden"),
   111     mList->setItems(items);
   107             CMManagerShim::Infra, true);
   112     
   108 
       
   109         addToList(items, hbTrId("txt_occ_list_adhoc_1"), CMManagerShim::Adhoc,
       
   110             false);
       
   111 
       
   112         mList->setItems(items);
       
   113 
       
   114     }
       
   115     return mWidget;
   113     return mWidget;
   116 }
   114 }
   117 
   115 
   118 /*!
   116 /*!
   119  * When moving to next page, write user selections to the wizard and return
   117  * Evaluates the network mode selection and sets the configuration in
   120  * Security mode query page id.
   118  * the wlanwizard.
       
   119  * @param [out] removeFromStack always returns false.
       
   120  * @return WlanWizardPageSecurityMode page id.
   121  */
   121  */
   122 int WlanWizardPageNetworkMode::nextId(bool &removeFromStack) const
   122 int WlanWizardPageNetworkMode::nextId(bool &removeFromStack) const
   123 {
   123 {
   124     removeFromStack = false;
   124     removeFromStack = false;
   125     // TODO: wk18: proper code
   125     WlanNetworkSetting setting;
       
   126     setting.mode = mNetworkModes.at(mList->selected());
       
   127     setting.hidden = mIsHidden.at(mList->selected());
       
   128     
       
   129     // TODO: Still no wps handling.
       
   130     setting.wpsSupported = false;
       
   131     
   126     mWizard->setConfiguration(WlanWizardPrivate::ConfNetworkMode,
   132     mWizard->setConfiguration(WlanWizardPrivate::ConfNetworkMode,
   127         mNetworkModes.at(mList->selected()));
   133         setting.mode);
   128     
   134     
   129     mWizard->setConfiguration(WlanWizardPrivate::ConfHiddenWlan,
   135     mWizard->setConfiguration(WlanWizardPrivate::ConfHiddenWlan,
   130         mIsHidden.at(mList->selected()));
   136         setting.hidden);
   131 
   137 
       
   138     if (mWizard->configurationExists(WlanWizardPrivate::ConfAvailableNetworkOptions)) {
       
   139         return selectNextPage(setting);
       
   140     }
       
   141     
   132     return WlanWizardPageInternal::PageNetworkSecurity;
   142     return WlanWizardPageInternal::PageNetworkSecurity;
   133 }
   143 }
   134 
   144 
   135 /*!
   145 /*!
   136  * Indicates the validity of the network mode page.
   146  * This method is overrides the default implementation from WlanWizardPage.
   137  * @see WlanWizardPage
   147  * It indicates whether the Next-button should be enabled or not.
       
   148  * @return mValid, which is true if a radio button has been selected.
   138  */
   149  */
   139 bool WlanWizardPageNetworkMode::showPage()
   150 bool WlanWizardPageNetworkMode::showPage()
   140 {
   151 {
   141     return mValid;
   152     return mValid;
   142 }
   153 }
   143 
   154 
   144 /*!
   155 /*!
   145  * Sets the page as valid, if any mode is selected.
   156  * This function is invoked when user selects a mode from the radio button list.
   146  * (Initially none is selected.) 
   157  * (HbRadioButtonList's itemSelected-signal)
   147  */
   158  */
   148 void WlanWizardPageNetworkMode::itemSelected(int /* index */)
   159 void WlanWizardPageNetworkMode::itemSelected()
   149 {
   160 {
   150     OstTrace0( TRACE_BORDER, WLANWIZARDPAGENETWORKMODE_ITEMSELECTED,
   161     OstTrace0( TRACE_BORDER, WLANWIZARDPAGENETWORKMODE_ITEMSELECTED,
   151         "WlanWizardPageNetworkMode::itemSelected" );
   162         "WlanWizardPageNetworkMode::itemSelected" );
   152 
   163 
   153     mValid = true;
   164     mValid = true;
   154     mWizard->enableNextButton(mValid);
   165     mWizard->enableNextButton(mValid);
   155 }
   166 }
   156 
   167 
   157 /*!
   168 /*!
   158  * Loads the ui layout file with current orientation.
   169  * Loads the document orientation information from occ_add_wlan_02_03.docml.
   159  */
   170  * This is called each time phone orientation changes.
   160 void WlanWizardPageNetworkMode::loadDocml(Qt::Orientation orientation)
   171  * @param [in] orientation indicates whether the phone is in portrait or
       
   172  * landscape mode.
       
   173  */
       
   174 void WlanWizardPageNetworkMode::loadDocmlSection(Qt::Orientation orientation)
   161 {
   175 {
   162     OstTrace1( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_LOADDOCML,
   176     OstTrace1( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_LOADDOCML,
   163         "WlanWizardPageNetworkMode::loadDocml - Orientation;orientation=%x",
   177         "WlanWizardPageNetworkMode::loadDocml - Orientation;orientation=%x",
   164         ( TUint )( orientation ) );
   178         ( TUint )( orientation ) );
   165 
   179 
   166     bool ok;
   180     WlanWizardPageInternal::loadDocmlSection(
   167     if (orientation == Qt::Horizontal) {
   181         mLoader,
   168         mLoader->load(":/docml/occ_add_wlan_02_03.docml", "landscape_section",
   182         orientation,
   169             &ok);
   183         ":/docml/occ_add_wlan_02_03.docml", 
   170         Q_ASSERT_X(ok, "WLAN Wizard", "Landscape section not found");
   184         "portrait_section",
   171     }
   185         "landscape_section");
   172     else {
   186 }
   173         mLoader->load(":/docml/occ_add_wlan_02_03.docml", "portrait_section",
   187 
   174             &ok);
   188 /*!
   175         Q_ASSERT_X(ok, "WLAN Wizard", "Portrait section not found");
   189  * A support function to map the radio button list to a generic network
   176     }
   190  * mode list. This enables the changing of button order without it
   177 }
   191  * affecting the entire class.
   178 
   192  * In case previous scan has revealed multiple results with the same ssid, only
   179 /*!
   193  * available network mode options are shown in the radio button list.
   180  * Mode and visibility lists are populated to the same order as the radio
   194  * @param [out] list is the list of captions used for the radio buttons.
   181  * button list.
   195  * @param [in] item is the caption to be added.
       
   196  * @param [in] mode is the network mode to be added.
       
   197  * @param [in] isHidden is the visibility status of the network.
   182  */
   198  */
   183 void WlanWizardPageNetworkMode::addToList(QStringList &list,
   199 void WlanWizardPageNetworkMode::addToList(QStringList &list,
   184     const QString &item, int mode, bool isHidden)
   200     const QString &item, int mode, bool isHidden)
   185 {
   201 {
   186     list << item;
   202         
   187     mNetworkModes.append(mode);
   203     if (mWizard->configurationExists(WlanWizardHelper::ConfAvailableNetworkOptions)) {
   188     mIsHidden.append(isHidden);
   204         WlanWizardScanList networkOptions = mWizard->configuration(
   189 }
   205             WlanWizardHelper::ConfAvailableNetworkOptions).value<WlanWizardScanList> ();
   190 
   206 
       
   207         QList<WlanNetworkSetting> modes = networkOptions.getNetModes();
       
   208 
       
   209         for (int i = 0; i < modes.size(); i++) {
       
   210             if (modes[i].mode == mode && modes[i].hidden == isHidden) {
       
   211                 list << item;
       
   212                 mNetworkModes.append(mode);
       
   213                 mIsHidden.append(isHidden);
       
   214             }
       
   215         }
       
   216     }
       
   217     else {  
       
   218         list << item;
       
   219         mNetworkModes.append(mode);
       
   220         mIsHidden.append(isHidden);
       
   221     }
       
   222 }
       
   223 
       
   224 /*!
       
   225  * This function checks the sets up the radio button list for user input.
       
   226  * @param [out] list is the list of captions used for the radio buttons.
       
   227  */
       
   228 void WlanWizardPageNetworkMode::populateRadioButtonList(QStringList &list)
       
   229 {
       
   230     list.clear();
       
   231     mNetworkModes.clear();
       
   232     mIsHidden.clear();
       
   233 
       
   234     // A list is created. Since there is no practical way of knowing whether
       
   235     // the new contents are different from the previous contents (if there
       
   236     // even were any in the first place) the validity is always reset.
       
   237     mValid = false;
       
   238         
       
   239     addToList(list, hbTrId("txt_occ_dblist_val_infrastructure_public"),
       
   240         CMManagerShim::Infra, false);
       
   241 
       
   242     addToList(list, hbTrId("txt_occ_list_infrastructure_hidden"),
       
   243         CMManagerShim::Infra, true);
       
   244 
       
   245     addToList(list, hbTrId("txt_occ_list_adhoc_1"), CMManagerShim::Adhoc,
       
   246         false);
       
   247 }
       
   248 
       
   249 /*!
       
   250  * This function selects the next page. Security mode may be skipped in case
       
   251  * scan results exist and only single option remains.
       
   252  * @param [in] setting indicates the selected network mode.
       
   253  * @return Security mode query page identifier unless it can be skipped.
       
   254  */
       
   255 int WlanWizardPageNetworkMode::selectNextPage(const WlanNetworkSetting &setting) const
       
   256 {
       
   257     WlanWizardScanList networkOptions = mWizard->configuration(
       
   258         WlanWizardHelper::ConfAvailableNetworkOptions).value<WlanWizardScanList>();
       
   259     
       
   260     if (networkOptions.secModes(setting) == SingleResult) {
       
   261         WlanSecuritySetting secMode = networkOptions.getSecMode(setting);
       
   262         
       
   263         mWizard->setConfiguration(WlanWizardHelper::ConfSecurityMode, secMode.mode);
       
   264         mWizard->setConfiguration(WlanWizardHelper::ConfUsePsk, secMode.usePsk);
       
   265         return secMode.nextPageId;
       
   266     }
       
   267     
       
   268     return WlanWizardPageInternal::PageNetworkSecurity;
       
   269 }
       
   270