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