wlanutilities/wlanwizard/src/wlanwizardpagenetworkmode.cpp
changeset 38 2dc6da6fb431
child 39 7b3e49e4608a
equal deleted inserted replaced
29:dbe86d96ce5b 38:2dc6da6fb431
       
     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 Page: Network mode Selection.
       
    16  *
       
    17  */
       
    18 
       
    19 // System includes
       
    20 #include <HbDocumentLoader>
       
    21 #include <HbWidget>
       
    22 #include <HbRadioButtonList>
       
    23 #include <HbMainWindow>
       
    24 #include <HbLabel>
       
    25 #include <cmmanagerdefines_shim.h>
       
    26 
       
    27 // User includes
       
    28 #include "wlanwizard_p.h"
       
    29 #include "wlanwizard.h"
       
    30 #include "wlanwizardpagenetworkmode.h"
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "wlanwizardpagenetworkmodeTraces.h"
       
    34 #endif
       
    35 
       
    36 /*!
       
    37  * Contructor. Member initialization.
       
    38  */
       
    39 WlanWizardPageNetworkMode::WlanWizardPageNetworkMode(
       
    40     WlanWizardPrivate* parent) :
       
    41     WlanWizardPageInternal(parent),
       
    42     mWidget(NULL),
       
    43     mList(NULL),
       
    44     mLabel(NULL),
       
    45     mLoader(NULL),
       
    46     mValid(false)
       
    47 {
       
    48 }
       
    49 
       
    50 /*!
       
    51  * Destructor. Loader widget is deleted.
       
    52  * All document widgets are deleted by wlanwizard_p destructor. 
       
    53  */
       
    54 WlanWizardPageNetworkMode::~WlanWizardPageNetworkMode()
       
    55 {
       
    56     delete mLoader;
       
    57 }
       
    58 
       
    59 /*!
       
    60  * Page initialization. If view is already loaded, does nothing.
       
    61  */
       
    62 HbWidget* WlanWizardPageNetworkMode::initializePage()
       
    63 {
       
    64     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_INITIALIZEPAGE,
       
    65         "WlanWizardPageNetworkMode::initializePage" );
       
    66 
       
    67     if (mWidget == NULL) {
       
    68         mLoader = new HbDocumentLoader(mWizard->mainWindow());
       
    69 
       
    70         bool ok;
       
    71 
       
    72         mLoader->load(":/docml/occ_add_wlan_02_03.docml", &ok);
       
    73         Q_ASSERT_X(ok, "WLAN Wizard", "Invalid docml file");
       
    74 
       
    75         loadDocml(mWizard->mainWindow()->orientation());
       
    76 
       
    77         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget(
       
    78             "occ_add_wlan_02"));
       
    79         Q_ASSERT_X(mWidget != NULL, "WlanWizardPageNetworkMode", "View not found");
       
    80 
       
    81         mList = qobject_cast<HbRadioButtonList*> (mLoader->findWidget("list"));
       
    82         Q_ASSERT_X(mList != NULL, "WlanWizardPageNetworkMode", "List not found");
       
    83 
       
    84         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog_6"));
       
    85         Q_ASSERT_X(mLabel != NULL, "WlanWizardPageNetworkMode", "Label not found");
       
    86 
       
    87         // Connect document loading to main window orientation changes.
       
    88         ok &= connect(mWizard->mainWindow(),
       
    89             SIGNAL(orientationChanged(Qt::Orientation)), this,
       
    90             SLOT(loadDocml(Qt::Orientation)));
       
    91 
       
    92         // Connect a function to a radio button selection.
       
    93         ok &= connect(mList, SIGNAL(itemSelected(int)), this,
       
    94             SLOT(itemSelected(int)));
       
    95 
       
    96         Q_ASSERT_X(ok, "WLAN Wizard", "orientationChanged slot connection failed");
       
    97 
       
    98         mLabel->setPlainText(hbTrId(
       
    99             "txt_occ_dialog_select_network_mode_and_status"));
       
   100 
       
   101         QStringList items;
       
   102 
       
   103         addToList(items, hbTrId("txt_occ_dblist_val_infrastructure_public"),
       
   104             CMManagerShim::Infra, false);
       
   105 
       
   106         addToList(items, hbTrId("txt_occ_list_infrastructure_hidden"),
       
   107             CMManagerShim::Infra, true);
       
   108 
       
   109         addToList(items, hbTrId("txt_occ_list_adhoc_1"), CMManagerShim::Adhoc,
       
   110             false);
       
   111 
       
   112         mList->setItems(items);
       
   113 
       
   114     }
       
   115     return mWidget;
       
   116 }
       
   117 
       
   118 /*!
       
   119  * When moving to next page, write user selections to the wizard and return
       
   120  * Security mode query page id.
       
   121  */
       
   122 int WlanWizardPageNetworkMode::nextId(bool &removeFromStack) const
       
   123 {
       
   124     removeFromStack = false;
       
   125     // TODO: wk18: proper code
       
   126     mWizard->setConfiguration(WlanWizardPrivate::ConfNetworkMode,
       
   127         mNetworkModes.at(mList->selected()));
       
   128     
       
   129     mWizard->setConfiguration(WlanWizardPrivate::ConfHiddenWlan,
       
   130         mIsHidden.at(mList->selected()));
       
   131 
       
   132     return WlanWizardPageInternal::PageNetworkSecurity;
       
   133 }
       
   134 
       
   135 /*!
       
   136  * Indicates the validity of the network mode page.
       
   137  * @see WlanWizardPage
       
   138  */
       
   139 bool WlanWizardPageNetworkMode::showPage()
       
   140 {
       
   141     return mValid;
       
   142 }
       
   143 
       
   144 /*!
       
   145  * Sets the page as valid, if any mode is selected.
       
   146  * (Initially none is selected.) 
       
   147  */
       
   148 void WlanWizardPageNetworkMode::itemSelected(int /* index */)
       
   149 {
       
   150     OstTrace0( TRACE_BORDER, WLANWIZARDPAGENETWORKMODE_ITEMSELECTED,
       
   151         "WlanWizardPageNetworkMode::itemSelected" );
       
   152 
       
   153     mValid = true;
       
   154     mWizard->enableNextButton(mValid);
       
   155 }
       
   156 
       
   157 /*!
       
   158  * Loads the ui layout file with current orientation.
       
   159  */
       
   160 void WlanWizardPageNetworkMode::loadDocml(Qt::Orientation orientation)
       
   161 {
       
   162     OstTrace1( TRACE_NORMAL, WLANWIZARDPAGENETWORKMODE_LOADDOCML,
       
   163         "WlanWizardPageNetworkMode::loadDocml - Orientation;orientation=%x",
       
   164         ( TUint )( orientation ) );
       
   165 
       
   166     bool ok;
       
   167     if (orientation == Qt::Horizontal) {
       
   168         mLoader->load(":/docml/occ_add_wlan_02_03.docml", "landscape_section",
       
   169             &ok);
       
   170         Q_ASSERT_X(ok, "WLAN Wizard", "Landscape section not found");
       
   171     }
       
   172     else {
       
   173         mLoader->load(":/docml/occ_add_wlan_02_03.docml", "portrait_section",
       
   174             &ok);
       
   175         Q_ASSERT_X(ok, "WLAN Wizard", "Portrait section not found");
       
   176     }
       
   177 }
       
   178 
       
   179 /*!
       
   180  * Mode and visibility lists are populated to the same order as the radio
       
   181  * button list.
       
   182  */
       
   183 void WlanWizardPageNetworkMode::addToList(QStringList &list,
       
   184     const QString &item, int mode, bool isHidden)
       
   185 {
       
   186     list << item;
       
   187     mNetworkModes.append(mode);
       
   188     mIsHidden.append(isHidden);
       
   189 }
       
   190