wlanutilities/wpswizard/src/wpswizardstepfour.cpp
branchRCL_3
changeset 24 63be7eb3fc78
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
       
     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  *   WPS Wizard Page: Step 4 progress bar display
       
    16  *
       
    17  */
       
    18 
       
    19 // System includes
       
    20 #include <HbDocumentLoader>
       
    21 #include <HbWidget>
       
    22 #include <HbRadioButtonList>
       
    23 #include <HbLineEdit>
       
    24 #include <HbLabel>
       
    25 #include <HbProgressBar>
       
    26 #include <HbMessageBox>
       
    27 #include <HbMainWindow>
       
    28 #include <platform\wlanerrorcodes.h>
       
    29 
       
    30 // User includes
       
    31 #include "wpswizardstepfour.h"
       
    32 #include "wpswizardstepfour_p.h"
       
    33 #include "wpswizard_p.h"
       
    34 
       
    35 // Trace includes
       
    36 
       
    37 
       
    38 #include "OstTraceDefinitions.h"
       
    39 #ifdef OST_TRACE_COMPILER_IN_USE
       
    40 #include "wpswizardstepfourTraces.h"
       
    41 #endif
       
    42 
       
    43 // External function prototypes
       
    44 
       
    45 // Local constants
       
    46 
       
    47 
       
    48 /*!
       
    49    \class WpsPageStepFour
       
    50    \brief Implementation of wps wizard page for step four.
       
    51  */
       
    52 
       
    53 // ======== LOCAL FUNCTIONS ========
       
    54 
       
    55 // ======== MEMBER FUNCTIONS ========
       
    56 
       
    57 
       
    58 /*!
       
    59    Constructor for WPS page four
       
    60    
       
    61    @param [in] parent Pointer to the WPS wizard private implementation 
       
    62  */
       
    63 WpsPageStepFour::WpsPageStepFour(WpsWizardPrivate* parent) :
       
    64     WpsWizardPage(parent), 
       
    65     mWidget(NULL), 
       
    66     mWpsErrorCode(0), 
       
    67     mCountCredentials(0), 
       
    68     mLoader(NULL),
       
    69     d_ptr(NULL)
       
    70 {
       
    71     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_ENTRY, this);
       
    72     d_ptr.reset(new WpsPageStepFourPrivate(this));
       
    73     OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_EXIT, this);
       
    74 }
       
    75 
       
    76 /*!
       
    77    Destructor
       
    78  */
       
    79 WpsPageStepFour::~WpsPageStepFour()
       
    80 {
       
    81     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_DESTRUCTOR_ENTRY, this);   
       
    82     delete mLoader;
       
    83     OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_DESTRUCTOR_EXIT, this);
       
    84 }
       
    85 
       
    86 /*!
       
    87    Loads the page with all the widgets
       
    88    
       
    89    @return HbWidget* Returns the view widget
       
    90  */
       
    91 HbWidget* WpsPageStepFour::initializePage()
       
    92 {
       
    93     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_INITIALIZEPAGE_ENTRY, this);
       
    94 
       
    95     if (!mWidget) {    
       
    96         bool ok;
       
    97 
       
    98         mLoader = new HbDocumentLoader(mWizard->mainWindow());
       
    99         
       
   100         mLoader->load(":/docml/occ_wps_P4.docml", &ok);
       
   101         Q_ASSERT(ok);
       
   102         
       
   103         // Initialize orientation
       
   104         loadDocmlSection(mWizard->mainWindow()->orientation());
       
   105 
       
   106         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_wps_P4"));
       
   107         Q_ASSERT(mWidget);
       
   108 
       
   109         bool connectOk = connect(
       
   110             mWizard->mainWindow(), 
       
   111             SIGNAL(orientationChanged(Qt::Orientation)),
       
   112             this, 
       
   113             SLOT(loadDocmlSection(Qt::Orientation)));
       
   114         Q_ASSERT(connectOk);
       
   115     }
       
   116 
       
   117     OstTraceFunctionExit1(WPSPAGESTEPFOUR_INITIALIZEPAGE_EXIT, this);
       
   118 
       
   119     return mWidget;
       
   120 }
       
   121 
       
   122 /*!
       
   123    In case the wizard page needs timer protection to the page use this
       
   124    method to start control operation of the page. This method will be called
       
   125    after requiresStartOperation() if true is returned with different call
       
   126    stack.
       
   127    
       
   128    See requiresStartOperation(), WlanWizardHelper::nextPage().
       
   129  */
       
   130 
       
   131 void WpsPageStepFour::startOperation()
       
   132 {
       
   133     startWpsRunner();
       
   134 }
       
   135 
       
   136 /*!
       
   137    Funtion to determine the next page to be displayed in the wizard process
       
   138    
       
   139    @param [out] removeFromStack bool variable indicating whether the current 
       
   140    page should be removed from the stack
       
   141    
       
   142    @return int Page Id of the next page to be displayed.
       
   143  */
       
   144 int WpsPageStepFour::nextId(bool &removeFromStack) const
       
   145 {
       
   146     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_NEXTID_ENTRY, this);
       
   147 
       
   148     int id = WpsWizardPage::PageNone;
       
   149     removeFromStack = false;
       
   150     
       
   151     // Error has occured go to error page
       
   152     if(mWpsErrorCode != 0) {
       
   153         return WlanWizardPage::PageGenericError;
       
   154     }
       
   155     
       
   156     if(mCountCredentials == 0) {
       
   157         id = WlanWizardPage::PageProcessSettings;
       
   158     } else if (mCountCredentials >= 2) {
       
   159         id = WpsWizardPage::PageWpsWizardStep5;
       
   160     } else {
       
   161         // only one response received. So go to the summary page
       
   162         mWizard->storeSettings(0);
       
   163         id = WlanWizardPage::PageProcessSettings;
       
   164     } 
       
   165     
       
   166     OstTraceFunctionExit1(WPSPAGESTEPFOUR_NEXTID_EXIT, this);
       
   167     return id;
       
   168 }
       
   169 
       
   170 /*!
       
   171    If the wizard page requires timer protection and asyncronous time
       
   172    lasting operation, protect parameters should return true. This is used
       
   173    in pages e.g. where progressbar is shown. The whole point is to 
       
   174    initialize the UI before starting the operation, so that the progress bar
       
   175    is painted before the operation takes place.
       
   176    
       
   177    In practise this means that if true is returned in protect.
       
   178    - WlanWizardPage::startOperation() is called to start the page operation.
       
   179    - 1.5sec timer is used to protect the page
       
   180    - wizardPage MUST call WlanWizardHelper::nextPage() to trigger entry to
       
   181      next wizard page.
       
   182    
       
   183    @return true if protection is need. see description of the method.
       
   184  */
       
   185 
       
   186 bool WpsPageStepFour::requiresStartOperation()
       
   187 {
       
   188     return true;
       
   189 }
       
   190 
       
   191 /*!
       
   192    Determines the Number of steps to move backwards when 'Prev' Button
       
   193    is clicked
       
   194    
       
   195    @return int Number of pages to move backwards
       
   196  */
       
   197 int WpsPageStepFour::previousTriggered()
       
   198 {
       
   199     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_PREVIOUSTRIGGERED_ENTRY, this);
       
   200     d_ptr->Cancel();
       
   201     OstTraceFunctionExit1(WPSPAGESTEPFOUR_PREVIOUSTRIGGERED_EXIT, this);
       
   202     return (PageWpsWizardStep4 - PageWpsWizardStep2) - 1;
       
   203 }
       
   204 
       
   205 /*!
       
   206    Determines whether the Next action button should be enabled or not
       
   207    
       
   208    @return bool Indicating whether next button is enabled or not.
       
   209  */
       
   210 bool WpsPageStepFour::showPage()
       
   211 {
       
   212     mWpsErrorCode = 0;
       
   213     
       
   214     return false;
       
   215 }
       
   216 
       
   217 /*!
       
   218    Handles the error case. Based on the error code decides
       
   219    whether to retry or stop the wizard
       
   220    
       
   221    @param [in] aErrorCode integer variable indicating the error codes
       
   222  */
       
   223 void WpsPageStepFour::handleError(int aErrorCode)
       
   224 {
       
   225     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_HANDLEERROR_ENTRY, this);
       
   226     QString str;
       
   227     OstTrace1( TRACE_ERROR, WPSPAGESTEPFOUR_HANDLEERROR, "WpsPageStepFour::handleError;aErrorCode=%d", aErrorCode );
       
   228     mWpsErrorCode = aErrorCode;
       
   229     switch (aErrorCode) {
       
   230         case KErrWlanProtectedSetupOOBInterfaceReadError:
       
   231         case KErrWlanProtectedSetupDecryptionCRCFailure:
       
   232         case KErrWlanProtectedSetup2_4ChannelNotSupported:
       
   233         case KErrWlanProtectedSetup5_0ChannelNotSupported:
       
   234         case KErrWlanProtectedSetupNetworkAuthFailure:
       
   235         case KErrWlanProtectedSetupNoDHCPResponse:
       
   236         case KErrWlanProtectedSetupFailedDHCPConfig:
       
   237         case KErrWlanProtectedSetupIPAddressConflict:
       
   238         case KErrWlanProtectedSetupCouldNotConnectToRegistrar:
       
   239         case KErrWlanProtectedSetupMultiplePBCSessionsDetected:
       
   240         case KErrWlanProtectedSetupRogueActivitySuspected:
       
   241         case KErrWlanProtectedSetupDeviceBusy:
       
   242         case KErrWlanProtectedSetupSetupLocked:
       
   243         case KErrWlanProtectedSetupMessageTimeout:
       
   244         case KErrWlanProtectedSetupRegistrationSessionTimeout:
       
   245             str = QString(hbTrId("txt_occ_dialog_configuration_failed_please_try_ag"));
       
   246             break;
       
   247 
       
   248         case KErrWlanProtectedSetupDevicePasswordAuthFailure:
       
   249         case KErrWlanProtectedSetupPINMethodNotSupported:
       
   250         case KErrWlanProtectedSetupPBMethodNotSupported:
       
   251         default:
       
   252             str = QString(hbTrId("txt_occ_dialog_configuration_failed_authenticatio"));
       
   253             break;
       
   254 
       
   255         } 
       
   256     
       
   257     mValid = false;
       
   258     mWizard->setConfiguration(WlanWizardHelper::ConfGenericErrorString, str);
       
   259     mWizard->setConfiguration(
       
   260             WlanWizardHelper::ConfGenericErrorPageStepsBackwards,
       
   261             (PageWpsWizardStep4 - PageWpsWizardStep2));
       
   262     mWizard->nextPage();
       
   263   
       
   264     OstTraceFunctionExit1(WPSPAGESTEPFOUR_HANDLEERROR_EXIT, this) ;
       
   265 }
       
   266 
       
   267 /*!
       
   268    Provides the functionality to initiate the WPS functionality
       
   269  */
       
   270 void WpsPageStepFour::startWpsRunner()
       
   271 {
       
   272     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_STARTWPSRUNNER_ENTRY, this);
       
   273     mValid  = false;
       
   274     d_ptr->StartSetup(mWizard->getSsid(), mWizard->getPin());
       
   275     OstTraceFunctionExit1(WPSPAGESTEPFOUR_STARTWPSRUNNER_EXIT, this);
       
   276 }
       
   277 
       
   278 /*!
       
   279    Stores the credentials set by the user, through the WPs Wizard
       
   280    
       
   281    @param [in] credentials List of Credentials entered by user.
       
   282    
       
   283    @param credentialscount Number Of Credentials in the list 
       
   284  */
       
   285 void WpsPageStepFour::setCredentials(
       
   286     QList<TWlanProtectedSetupCredentialAttribute>& credentials,
       
   287     int credentialscount)
       
   288 {
       
   289     OstTraceFunctionEntry1( WPSPAGESTEPFOUR_SETCREDENTIALS_ENTRY, this );
       
   290 
       
   291     mCountCredentials = credentialscount;
       
   292     mWizard->storeSettingsArray(credentials);
       
   293     mWizard->nextPage();
       
   294     // enable the next button
       
   295 
       
   296     OstTraceFunctionExit1( WPSPAGESTEPFOUR_SETCREDENTIALS_EXIT, this );
       
   297 }
       
   298 
       
   299 /*!
       
   300    CallBack when the cancel button is clicked
       
   301  */
       
   302 void WpsPageStepFour::cancelTriggered()
       
   303 {
       
   304     OstTraceFunctionEntry1( WPSPAGESTEPFOUR_CANCELTRIGGERED_ENTRY, this );
       
   305     d_ptr->Cancel();
       
   306     OstTraceFunctionExit1( WPSPAGESTEPFOUR_CANCELTRIGGERED_EXIT, this );
       
   307 }
       
   308 
       
   309 /*!
       
   310    Loads docml at initialization phase and when HbMainWindow sends 
       
   311    orientation() signal.
       
   312    
       
   313    @param orientation[in] orientation to be loaded.
       
   314  */
       
   315 void WpsPageStepFour::loadDocmlSection(Qt::Orientation orientation)
       
   316 {
       
   317     bool ok = false;
       
   318     
       
   319     // Load the orientation specific section
       
   320     if (orientation == Qt::Horizontal) {
       
   321     mLoader->load(":/docml/occ_wps_P4.docml", "landscape", &ok);
       
   322         Q_ASSERT(ok);
       
   323     } 
       
   324     else {
       
   325         Q_ASSERT(orientation == Qt::Vertical);
       
   326         mLoader->load(":/docml/occ_wps_P4.docml", "portrait", &ok);
       
   327         Q_ASSERT(ok);
       
   328     }
       
   329 }
       
   330