wlanutilities/wlanwizard/src/wlanwizardpagessid.cpp
changeset 39 7b3e49e4608a
parent 31 e8f4211554fb
child 43 72ebcbb64834
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
     1 /*
     1 /*
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3 * All rights reserved.
     4  * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8  *
     8 *
     9  * Initial Contributors:
     9 * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11  *
    11 *
    12  * Contributors:
    12 * Contributors:
    13  *
    13 *
    14  * Description: 
    14 * Description: 
    15  *   WLAN Wizard Page: SSID Selection.
    15 * WLAN Wizard Page: SSID Selection.
    16  *
    16 */
    17  */
       
    18 
    17 
    19 // System includes
    18 // System includes
    20 #include <HbDocumentLoader>
    19 #include <HbDocumentLoader>
    21 #include <HbMainWindow>
    20 #include <HbMainWindow>
    22 #include <HbWidget>
    21 #include <HbWidget>
    33 #ifdef OST_TRACE_COMPILER_IN_USE
    32 #ifdef OST_TRACE_COMPILER_IN_USE
    34 #include "wlanwizardpagessidTraces.h"
    33 #include "wlanwizardpagessidTraces.h"
    35 #endif
    34 #endif
    36 
    35 
    37 /*!
    36 /*!
    38  * Constructor. Member initialization.
    37  * Constructor method for the SSID query view object.
       
    38  * @param [in] parent pointer to parent object.
    39  */
    39  */
    40 WlanWizardPageSsid::WlanWizardPageSsid(WlanWizardPrivate* parent) :
    40 WlanWizardPageSsid::WlanWizardPageSsid(WlanWizardPrivate* parent) :
    41     WlanWizardPageInternal(parent),
    41     WlanWizardPageInternal(parent),
    42     mWidget(NULL),
    42     mWidget(NULL),
    43     mLabel(NULL),
    43     mLabel(NULL),
    44     mSsid(NULL),
    44     mSsid(NULL),
    45     mLabelError(NULL),
       
    46     mLoader(NULL)
    45     mLoader(NULL)
    47 {
    46 {
    48 
    47 
    49 }
    48 }
    50 
    49 
    57     delete mLoader;
    56     delete mLoader;
    58 }
    57 }
    59 
    58 
    60 /*!
    59 /*!
    61  * Page initialization. If view is already loaded, does nothing.
    60  * Page initialization. If view is already loaded, does nothing.
       
    61  * @return pointer to widget "occ_add_wlan_01".
    62  */
    62  */
    63 HbWidget* WlanWizardPageSsid::initializePage()
    63 HbWidget* WlanWizardPageSsid::initializePage()
    64 {
    64 {
    65     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESSID_INITIALIZEPAGE,
    65     OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESSID_INITIALIZEPAGE,
    66         "WlanWizardPageSsid::initializePage" );
    66         "WlanWizardPageSsid::initializePage" );
    67 
    67 
    68     if (mWidget == NULL) {
    68     // It is not possible for this method to be called more than once during
    69         bool ok;
    69     // wizard lifetime.
       
    70     Q_ASSERT(mWidget == NULL);
    70 
    71 
    71         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    72     bool ok;
    72 
    73 
    73         mLoader->load(":/docml/occ_add_wlan_01_04.docml", &ok);
    74     mLoader = new HbDocumentLoader(mWizard->mainWindow());
    74         Q_ASSERT_X(ok, "WlanWizardPageSsid", "Invalid docml file");
       
    75 
    75 
    76         // Load orientation
    76     mLoader->load(":/docml/occ_add_wlan_01_04.docml", &ok);
    77         loadDocml(mWizard->mainWindow()->orientation());
    77     Q_ASSERT(ok);
    78 
    78 
    79         // Load widgets
    79     // Load orientation
    80         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget(
    80     loadDocmlSection(mWizard->mainWindow()->orientation());
    81             "occ_add_wlan_01"));
       
    82         Q_ASSERT_X(mWidget != NULL, "WlanWizardPageSsid", "View not found");
       
    83 
    81 
    84         mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog"));
    82     // Load widgets
    85         Q_ASSERT_X(mLabel != NULL, "WlanWizardPageSsid", "dialog not found");
    83     mWidget = qobject_cast<HbWidget*> (mLoader->findWidget(
       
    84         "occ_add_wlan_01"));
       
    85     Q_ASSERT(mWidget != NULL);
    86 
    86 
    87         mSsid = qobject_cast<HbLineEdit*> (mLoader->findWidget("lineEditKey"));
    87     mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog"));
    88         Q_ASSERT_X(mSsid != NULL, "WlanWizardPageSsid", "lineEditKey not found");
    88     Q_ASSERT(mLabel != NULL);
    89 
    89 
    90         mLabelError = qobject_cast<HbLabel*> (mLoader->findWidget(
    90     mSsid = qobject_cast<HbLineEdit*> (mLoader->findWidget("lineEditKey"));
    91             "labelErrorNote"));
    91     Q_ASSERT(mSsid != NULL);
    92         Q_ASSERT_X(mLabelError != NULL, "WlanWizardPageSsid",
       
    93             "labelErrorNote not found");
       
    94 
    92 
    95         mLabel->setPlainText(hbTrId(
    93     mLabel->setPlainText(hbTrId(
    96             "txt_occ_dialog_insert_the_name_of_the_new_wlan_net"));
    94         "txt_occ_dialog_insert_the_name_of_the_new_wlan_net"));
    97 
    95 
    98         // Connect orientation signal from the main window to orientation
    96     // Connect orientation signal from the main window to orientation
    99         // loader.
    97     // loader.
   100         ok &= connect(mWizard->mainWindow(),
    98     ok = connect(mWizard->mainWindow(),
   101             SIGNAL(orientationChanged(Qt::Orientation)), this,
    99         SIGNAL(orientationChanged(Qt::Orientation)), this,
   102             SLOT(loadDocml(Qt::Orientation)));
   100         SLOT(loadDocmlSection(Qt::Orientation)));
       
   101     Q_ASSERT(ok);
   103 
   102 
   104         // Connect text change-signal from input dialog to handler function
   103     // Connect text change-signal from input dialog to handler function
   105         ok &= connect(mSsid, SIGNAL(textChanged(const QString &)), this,
   104     ok = connect(mSsid, SIGNAL(textChanged(const QString &)), this,
   106             SLOT(textChanged(const QString &)));
   105         SLOT(textChanged(const QString &)));
       
   106     Q_ASSERT(ok);
   107 
   107 
   108         Q_ASSERT(ok);
   108     HbEditorInterface editInterface(mSsid);
       
   109     
       
   110     // TODO: remove (HbEditorConstraints) type cast when 
       
   111     // Q_DECLARE_OPERATORS_FOR_FLAGS(HbEditorConstraints) is defined (SDK xxx)
       
   112     editInterface.setInputConstraints(
       
   113         (HbEditorConstraints)(HbEditorConstraintAutoCompletingField |
       
   114             HbEditorConstraintLatinAlphabetOnly));
       
   115     
       
   116     editInterface.setSmileyTheme(HbSmileyTheme());
       
   117     editInterface.setEditorClass(HbInputEditorClassNetworkName);
       
   118     mSsid->setInputMethodHints(
       
   119         Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase);
       
   120     mSsid->setMaxLength(WlanWizardUtils::SsidMaxLength);
   109 
   121 
   110         HbEditorInterface editInterface(mSsid);
   122 	return mWidget;
   111         editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly);
       
   112 
       
   113 
       
   114         editInterface.setSmileyTheme(HbSmileyTheme());
       
   115         //editInterface.setEditorClass(HbInputEditorClassNetworkName);
       
   116         mSsid->setInputMethodHints(
       
   117             Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase);
       
   118         mSsid->setMaxLength(WlanWizardUtils::SsidMaxLength);
       
   119         mSsid->installEventFilter(this);
       
   120     }
       
   121 	
       
   122 	// Open virtual keyboard by setting focus to line edit
       
   123 	mSsid->setFocus();
       
   124 
       
   125     return mWidget;
       
   126 }
   123 }
   127 
   124 
   128 /*!
   125 /*!
   129  * Selection of the next page.
   126  * This method is overrides the default implementation from WlanWizardPage.
       
   127  * It indicates whether the Next-button should be enabled or not.
       
   128  * @return true, if mSsid edit field is not empty.
       
   129  */
       
   130 bool WlanWizardPageSsid::showPage()
       
   131 {
       
   132     // Initiate the scanning of public APs here.
       
   133     mWizard->wlanQtUtils()->scanWlanAps();
       
   134     
       
   135     // Open virtual keyboard by setting focus to line edit
       
   136     mSsid->setFocus();
       
   137 
       
   138     return !(mSsid->text().isEmpty());
       
   139 }
       
   140 
       
   141 /*!
       
   142  * Stores the SSID selection in the configuration.
       
   143  * @param [out] removeFromStack returns false.
       
   144  * @return WlanWizardPageScanning page id.
   130  */
   145  */
   131 int WlanWizardPageSsid::nextId(bool &removeFromStack) const
   146 int WlanWizardPageSsid::nextId(bool &removeFromStack) const
   132 {
   147 {
   133     int pageId = WlanWizardPage::PageNone;
       
   134     removeFromStack = false;
   148     removeFromStack = false;
   135 
   149 
   136     WlanWizardUtils::SsidStatus status = WlanWizardUtils::validateSsid(
   150     // SSID is stored into configuration
   137         mSsid->text());
   151     mWizard->setConfiguration(WlanWizardPrivate::ConfSsid, mSsid->text());
   138 
   152     
   139     if (status != WlanWizardUtils::SsidStatusOk) {
   153     return WlanWizardPageInternal::PageScanning;
   140         mLabelError->setPlainText(SsidStatusToErrorString(status));
       
   141     }
       
   142     else {
       
   143         // SSID is stored into configuration
       
   144         mWizard->setConfiguration(WlanWizardPrivate::ConfSsid, mSsid->text());
       
   145         pageId = WlanWizardPageInternal::PageScanning;
       
   146     }
       
   147 
       
   148     return pageId;
       
   149 }
   154 }
   150 
   155 
   151 /*!
   156 /*!
   152  * Load the document with given screen orientation.
   157  * Loads the document orientation information from occ_add_wlan_01_04.docml
       
   158  * This is called each time phone orientation changes.
       
   159  * @param [in] orientation indicates whether the phone is in portrait or
       
   160  * landscape mode.
   153  */
   161  */
   154 void WlanWizardPageSsid::loadDocml(Qt::Orientation orientation)
   162 void WlanWizardPageSsid::loadDocmlSection(Qt::Orientation orientation)
   155 {
   163 {
   156     OstTrace1( TRACE_FLOW, WLANWIZARDPAGESSID_LOADDOCML,
   164     OstTrace1( TRACE_FLOW, WLANWIZARDPAGESSID_LOADDOCML,
   157         "WlanWizardPageSsid::loadDocml - orientation ;orientation=%x",
   165         "WlanWizardPageSsid::loadDocml - orientation ;orientation=%x",
   158         ( TUint )( orientation ) );
   166         ( TUint )( orientation ) );
   159 
   167 
   160     bool ok;
   168     WlanWizardPageInternal::loadDocmlSection(
   161     // Then load the orientation specific section
   169         mLoader,
   162     if (orientation == Qt::Horizontal) {
   170         orientation,
   163         qDebug("Loading landscape section for wlan_01_04");
   171         ":/docml/occ_add_wlan_01_04.docml", 
   164         mLoader->load(":/docml/occ_add_wlan_01_04.docml", "landscape_section",
   172         "portrait_section",
   165             &ok);
   173         "landscape_section");
   166         Q_ASSERT(ok);
       
   167     }
       
   168     else {
       
   169         Q_ASSERT(orientation == Qt::Vertical);
       
   170         qDebug("Loading portrait section for wlan_01_04");
       
   171         mLoader->load(":/docml/occ_add_wlan_01_04.docml", "portrait_section",
       
   172             &ok);
       
   173         Q_ASSERT(ok);
       
   174     }
       
   175 }
   174 }
   176 
   175 
   177 /*!
   176 /*!
   178  * Actions, when user makes changes to the text editor widget.
   177  * Executed when changes have been made to the mSsid field (and the field is
       
   178  * not empty).
       
   179  * @param [in] text is not used at this point.
   179  */
   180  */
   180 void WlanWizardPageSsid::textChanged(const QString & /* text */)
   181 void WlanWizardPageSsid::textChanged(const QString &text)
   181 {
   182 {
       
   183     Q_UNUSED(text);
   182     OstTrace0( TRACE_FLOW, WLANWIZARDPAGESSID_TEXTCHANGED,
   184     OstTrace0( TRACE_FLOW, WLANWIZARDPAGESSID_TEXTCHANGED,
   183         "WlanWizardPageSsid::textChanged in text edit widget" );
   185         "WlanWizardPageSsid::textChanged in text edit widget" );
   184 
   186 
   185     mWizard->enableNextButton(showPage());
   187     mWizard->enableNextButton(!(mSsid->text().isEmpty()));
   186 }
   188 }
   187 
       
   188 /*!
       
   189  * Returns true, if the text editor widget contains any characters.
       
   190  */
       
   191 bool WlanWizardPageSsid::showPage()
       
   192 {
       
   193     // Initiate the scanning of public APs here.
       
   194     mWizard->wlanQtUtils()->scanWlanAps();
       
   195 
       
   196    return !(mSsid->text().isEmpty());
       
   197 }
       
   198 
       
   199 /*!
       
   200  * Filter to catch focus event to the text editor widget.
       
   201  */
       
   202 bool WlanWizardPageSsid::eventFilter(QObject *obj, QEvent *event)
       
   203 {
       
   204     if (obj == mSsid && event->type() == QEvent::FocusIn) {
       
   205         OstTrace0( TRACE_BORDER, WLANWIZARDPAGESSID_EVENTFILTER,
       
   206             "WlanWizardPageSsid::eventFilter text edit widget received focus" );
       
   207 
       
   208         mLabelError->setPlainText("");
       
   209     }
       
   210     return false;
       
   211 }
       
   212 
       
   213 /*!
       
   214  * Conversion function from SsidStatus to plain text.
       
   215  */
       
   216 QString WlanWizardPageSsid::SsidStatusToErrorString(
       
   217     WlanWizardUtils::SsidStatus status) const
       
   218 {
       
   219     QString errorString;
       
   220     switch (status) {
       
   221     case WlanWizardUtils::SsidStatusIllegalCharacters:
       
   222         errorString = hbTrId(
       
   223             "txt_occ_dialog_illegal_characters_in_key_please_c");
       
   224         break;
       
   225     case WlanWizardUtils::SsidStatusInvalidLength:
       
   226         errorString
       
   227             = hbTrId("txt_occ_dialog_key_is_of_incorrect_length_please");
       
   228         break;
       
   229     case WlanWizardUtils::SsidStatusOk:
       
   230     default:
       
   231         Q_ASSERT(WlanWizardUtils::SsidStatusOk == status);
       
   232         break;
       
   233     }
       
   234     return errorString;
       
   235 }
       
   236