wlanutilities/wlanwizard/src/wlanwizardpagekeyquery.cpp
changeset 31 e8f4211554fb
child 39 7b3e49e4608a
equal deleted inserted replaced
30:ab513c8439db 31:e8f4211554fb
       
     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: Key query page for WEP and WPA (2).
       
    16  *
       
    17  */
       
    18 
       
    19 // System includes
       
    20 #include <HbDocumentLoader>
       
    21 #include <HbMainWindow>
       
    22 #include <HbWidget>
       
    23 #include <HbLabel>
       
    24 #include <HbLineEdit>
       
    25 #include <HbEditorInterface>
       
    26 
       
    27 // User includes
       
    28 #include "wlanwizard.h"
       
    29 #include "wlanwizard_p.h"
       
    30 #include "wlanwizardpagekeyquery.h"
       
    31 #include "wlanwizardutils.h"
       
    32 
       
    33 /*!
       
    34    \class WlanWizardPageKeyQuery
       
    35    \brief Implements Key Query page for WEP and WPA. 
       
    36  */
       
    37 
       
    38 // External function prototypes
       
    39 
       
    40 // Local constants
       
    41 
       
    42 // ======== LOCAL FUNCTIONS ========
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 
       
    47 /*!
       
    48    Constructor.
       
    49    
       
    50    @param [in] parent pointer to private implementation of wizard.
       
    51  */
       
    52 WlanWizardPageKeyQuery::WlanWizardPageKeyQuery(WlanWizardPrivate* parent) :
       
    53     WlanWizardPageInternal(parent), 
       
    54     mWidget(NULL), 
       
    55     mLabelTitle(NULL),
       
    56     mLineEdit(NULL), 
       
    57     mLabelError(NULL), 
       
    58     mDocLoader(NULL)
       
    59 {
       
    60 }
       
    61 
       
    62 /*!
       
    63    Destructor.
       
    64  */
       
    65 WlanWizardPageKeyQuery::~WlanWizardPageKeyQuery()
       
    66 {
       
    67     delete mDocLoader;
       
    68     
       
    69     // Wizard framework deletes the visualization (owns mWidget).
       
    70 }
       
    71 
       
    72 /*!
       
    73    See WlanWizardPage::initializePage()
       
    74    
       
    75    Initializes the key query page and initializes objects based on the security
       
    76    mode.
       
    77  */
       
    78 HbWidget* WlanWizardPageKeyQuery::initializePage()
       
    79 {
       
    80     if (!mWidget) {
       
    81         bool ok;
       
    82         
       
    83         mDocLoader = new HbDocumentLoader(mWizard->mainWindow());
       
    84         
       
    85         // Load document common part
       
    86         mDocLoader->load(":/docml/occ_add_wlan_01_04.docml", &ok);
       
    87         Q_ASSERT(ok);
       
    88               
       
    89         // Initialize orientation
       
    90         loadDocmlSection(mWizard->mainWindow()->orientation());
       
    91         
       
    92         // Load widgets
       
    93         mWidget = 
       
    94             qobject_cast<HbWidget*> (mDocLoader->findWidget("occ_add_wlan_01"));
       
    95         Q_ASSERT(mWidget != NULL);
       
    96 
       
    97         mLabelTitle = qobject_cast<HbLabel*> (mDocLoader->findWidget("dialog"));
       
    98         Q_ASSERT(mLabelTitle != NULL);
       
    99 
       
   100         mLineEdit = qobject_cast<HbLineEdit*> (mDocLoader->findWidget("lineEditKey"));
       
   101         Q_ASSERT(mLineEdit != NULL);
       
   102 
       
   103         mLabelError = 
       
   104             qobject_cast<HbLabel*> (mDocLoader->findWidget("labelErrorNote"));
       
   105         Q_ASSERT(mLabelError != NULL);
       
   106         
       
   107         ok = connect(
       
   108             mWizard->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   109             this, SLOT(loadDocmlSection(Qt::Orientation)));
       
   110         Q_ASSERT(ok);
       
   111         
       
   112         HbEditorInterface editInterface(mLineEdit);
       
   113         editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly);
       
   114         editInterface.setSmileyTheme(HbSmileyTheme());
       
   115         mLineEdit->setInputMethodHints(
       
   116             Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase);
       
   117         mLineEdit->installEventFilter(this);
       
   118     }
       
   119 
       
   120     if (mWizard->configuration(WlanWizardHelper::ConfSecurityMode) ==
       
   121         CMManagerShim::WlanSecModeWep) {
       
   122         mLineEdit->setMaxLength(WlanWizardUtils::WepHex128BitMaxLength);    
       
   123     } else {
       
   124         mLineEdit->setMaxLength(WlanWizardUtils::WpaMaxLength);
       
   125     }
       
   126     
       
   127     mLabelTitle->setPlainText(
       
   128         hbTrId("txt_occ_dialog_enter_key_for_1").arg(mWizard->configuration(
       
   129             WlanWizardPrivate::ConfSsid).toString()));
       
   130     
       
   131     return mWidget;
       
   132 }
       
   133 
       
   134 /*!
       
   135    Loads docml at initialization phase and when HbMainWindow sends orientation()
       
   136    signal.
       
   137    
       
   138    @param [in] orientation to be loaded.
       
   139  */
       
   140 void WlanWizardPageKeyQuery::loadDocmlSection(Qt::Orientation orientation)
       
   141 {
       
   142     bool ok = false;
       
   143     
       
   144     // Load the orientation specific section
       
   145     if (orientation == Qt::Horizontal) {
       
   146         mDocLoader->load(
       
   147             ":/docml/occ_add_wlan_01_04.docml", "landscape_section", &ok);
       
   148         Q_ASSERT(ok);
       
   149     } else {
       
   150         Q_ASSERT(orientation == Qt::Vertical);
       
   151         mDocLoader->load(
       
   152             ":/docml/occ_add_wlan_01_04.docml", "portrait_section", &ok);
       
   153         Q_ASSERT(ok);
       
   154     }
       
   155 }
       
   156 
       
   157 /*!
       
   158    See WlanWizardPage::nextId()
       
   159    
       
   160    @param [in,out] removeFromStack return value is always false
       
   161    
       
   162    @return In case user has entered incorrect key an appropriate error text is
       
   163    displayed and WlanWizardPage::PageNone is returned.
       
   164    
       
   165    In case user has entered a valid WEP or WPA key, the key is stored into
       
   166    internal configuration and WlanWizardPage::PageProcessSettings is returned.
       
   167    
       
   168  */
       
   169 int WlanWizardPageKeyQuery::nextId(bool &removeFromStack) const
       
   170 {
       
   171     WlanWizardUtils::KeyStatus status(WlanWizardUtils::KeyStatusOk);
       
   172     int pageId = WlanWizardPage::PageNone;
       
   173     int secMode = mWizard->configuration(
       
   174         WlanWizardPrivate::ConfSecurityMode).toInt();
       
   175     
       
   176     if (secMode == CMManagerShim::WlanSecModeWep) {
       
   177         status = WlanWizardUtils::validateWepKey(mLineEdit->text());   
       
   178     }
       
   179     else {
       
   180         Q_ASSERT(
       
   181             secMode == CMManagerShim::WlanSecModeWpa ||
       
   182             secMode == CMManagerShim::WlanSecModeWpa2);
       
   183         
       
   184         status = WlanWizardUtils::validateWpaKey(mLineEdit->text());
       
   185     }
       
   186     QString errorString = keyStatusToErrorString(status);
       
   187         
       
   188     if (errorString.length() == 0 ) {
       
   189         if (secMode == CMManagerShim::WlanSecModeWep) {
       
   190             mWizard->setConfiguration(WlanWizardPrivate::ConfKeyWep1, mLineEdit->text());
       
   191             mWizard->setConfiguration(WlanWizardPrivate::ConfKeyWep2, mLineEdit->text());
       
   192             mWizard->setConfiguration(WlanWizardPrivate::ConfKeyWep3, mLineEdit->text());
       
   193             mWizard->setConfiguration(WlanWizardPrivate::ConfKeyWep4, mLineEdit->text());
       
   194             mWizard->setConfiguration(WlanWizardPrivate::ConfKeyWepDefault, 
       
   195                 CMManagerShim::WepKeyIndex1);
       
   196         } else {
       
   197             mWizard->setConfiguration(WlanWizardPrivate::ConfKeyWpa, mLineEdit->text());   
       
   198         }
       
   199         pageId = WlanWizardPage::PageProcessSettings;
       
   200     }
       
   201     else {
       
   202         mLabelError->setPlainText(errorString);
       
   203     }
       
   204 
       
   205     removeFromStack = false;
       
   206     return pageId;
       
   207 }
       
   208 
       
   209 /*!
       
   210    See WlanWizardPage::showPage()
       
   211  */
       
   212 bool WlanWizardPageKeyQuery::showPage()
       
   213 {
       
   214     // Open virtual keyboard by setting focus to line edit
       
   215     mLineEdit->setFocus();
       
   216     
       
   217     return true;
       
   218 }
       
   219 
       
   220 /*!
       
   221    When focus moves into the Key editor and there is visible error text, it
       
   222    is cleared.
       
   223    
       
   224    @param [in] obj Pointer to the object the event was sent to
       
   225    @param [in] event Pointer to the sent event.
       
   226    
       
   227    @return false. do not eat the event.
       
   228  */
       
   229 bool WlanWizardPageKeyQuery::eventFilter(QObject *obj, QEvent *event)
       
   230 {
       
   231     if (obj == mLineEdit && event->type() == QEvent::FocusIn) {
       
   232         mLabelError->setPlainText("");
       
   233     }
       
   234     return false;
       
   235 }
       
   236 
       
   237 /*!
       
   238    Maps provided error code to error text.
       
   239    
       
   240    @param [in] status status of key validation
       
   241    
       
   242    @return An error text in case of error, empty string is returned on 
       
   243    successful case.
       
   244  */
       
   245 QString WlanWizardPageKeyQuery::keyStatusToErrorString(
       
   246     WlanWizardUtils::KeyStatus status) const
       
   247 {
       
   248     QString errorString;
       
   249     switch (status) {
       
   250     case WlanWizardUtils::KeyStatusIllegalCharacters:
       
   251         errorString = hbTrId("txt_occ_dialog_illegal_characters_in_key_please_c");
       
   252         break;
       
   253 
       
   254     case WlanWizardUtils::KeyStatusWpaTooShort:
       
   255     case WlanWizardUtils::KeyStatusWpaTooLong:
       
   256         errorString = hbTrId("txt_occ_dialog_preshared_key_too_short_at_least");
       
   257         break;
       
   258 
       
   259     case WlanWizardUtils::KeyStatusWepInvalidLength:
       
   260         errorString = hbTrId("txt_occ_dialog_key_is_of_incorrect_length_please");
       
   261         break;
       
   262 
       
   263     case WlanWizardUtils::KeyStatusOk:
       
   264     default:
       
   265         Q_ASSERT(WlanWizardUtils::KeyStatusOk == status);
       
   266         // nothing to do here.
       
   267         break;
       
   268     }
       
   269     return errorString;
       
   270 }