wlanutilities/wpswizard/src/wpswizardstepfour.cpp
changeset 39 7b3e49e4608a
parent 19 10810c91db26
child 60 822a45792fdd
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 the License "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.
    14  * Description: 
    14  * Description: 
    15  *   WPS Wizard Page: Step 4 progress bar display
    15  *   WPS Wizard Page: Step 4 progress bar display
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 /*
       
    20  * %version: 1 %
       
    21  */
       
    22 
       
    23 // System includes
    19 // System includes
    24 #include <hbdocumentloader.h>
    20 #include <HbDocumentLoader>
    25 #include <hbwidget.h>
    21 #include <HbWidget>
    26 #include <hbradiobuttonlist.h>
    22 #include <HbRadioButtonList>
    27 #include <hblineedit.h>
    23 #include <HbLineEdit>
    28 #include <hblabel.h>
    24 #include <HbLabel>
    29 #include <hbprogressbar.h>
    25 #include <HbProgressBar>
    30 #include <hbmessagebox.h>
    26 #include <HbMessageBox>
       
    27 #include <HbMainWindow>
       
    28 #include <platform\wlanerrorcodes.h>
    31 
    29 
    32 // User includes
    30 // User includes
    33 #include "wpswizardstepfour.h"
    31 #include "wpswizardstepfour.h"
       
    32 #include "wpswizardstepfour_p.h"
    34 #include "wpswizard_p.h"
    33 #include "wpswizard_p.h"
    35 
    34 
    36 // Trace includes
    35 // Trace includes
       
    36 
       
    37 
    37 #include "OstTraceDefinitions.h"
    38 #include "OstTraceDefinitions.h"
    38 #ifdef OST_TRACE_COMPILER_IN_USE
    39 #ifdef OST_TRACE_COMPILER_IN_USE
    39 #include "wpspagestepfourTraces.h"
    40 #include "wpswizardstepfourTraces.h"
    40 #endif
    41 #endif
    41 
    42 
    42 /*!
    43 // External function prototypes
    43  * Constructor for WPS page four
    44 
    44  * 
    45 // Local constants
    45  * \param WpsWizardPrivate* Pointer to the WPS wizard private implementation 
    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 
    46  */
    62  */
    47 WpsPageStepFour::WpsPageStepFour(WpsWizardPrivate* parent) :
    63 WpsPageStepFour::WpsPageStepFour(WpsWizardPrivate* parent) :
    48     WpsWizardPage(parent), mWidget(NULL), mRadio(NULL), mValid(false)
    64     WpsWizardPage(parent), 
    49 {
    65     mWidget(NULL), 
    50 OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_ENTRY, this)
    66     mWpsErrorCode(0), 
    51 OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_EXIT, this)
    67     mCountCredentials(0), 
    52 
    68     mLoader(NULL),
    53 }
    69     d_ptr(NULL)
    54 
    70 {
    55 /*!
    71     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_ENTRY, this);
    56  * Destructor
    72     d_ptr.reset(new WpsPageStepFourPrivate(this));
       
    73     OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_EXIT, this);
       
    74 }
       
    75 
       
    76 /*!
       
    77    Destructor
    57  */
    78  */
    58 WpsPageStepFour::~WpsPageStepFour()
    79 WpsPageStepFour::~WpsPageStepFour()
    59 {
    80 {
    60     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_ENTRY, this)
    81     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_DESTRUCTOR_ENTRY, this);   
    61 
    82     delete mLoader;
    62     delete mWidget;
    83     OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_DESTRUCTOR_EXIT, this);
    63     delete mWpsActiveRunner;
    84 }
    64 
    85 
    65 OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSPAGESTEPFOUR_EXIT, this)
    86 /*!
    66 }
    87    Loads the page with all the widgets
    67 
    88    
    68 /*!
    89    @return HbWidget* Returns the view widget
    69   * Loads the page with all the widgets
       
    70   * 
       
    71   * \return HbWidget* Returns the view widget
       
    72  */
    90  */
    73 HbWidget* WpsPageStepFour::initializePage()
    91 HbWidget* WpsPageStepFour::initializePage()
    74 {
    92 {
    75     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_INITIALIZEPAGE_ENTRY, this)
    93     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_INITIALIZEPAGE_ENTRY, this);
    76 
    94 
    77     if (!mWidget) {
    95     if (!mWidget) {    
    78         bool ok;
    96         bool ok;
    79         HbDocumentLoader loader;
    97 
    80         loader.load(":/docml/occ_wps_P4.docml", &ok);
    98         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    81         Q_ASSERT_X(ok, "WPS Wizard", "Invalid docml file");
    99         
    82 
   100         mLoader->load(":/docml/occ_wps_P4.docml", &ok);
    83         mWidget = qobject_cast<HbWidget*> (loader.findWidget("occ_wps_P4"));
   101         Q_ASSERT(ok);
    84         Q_ASSERT_X(mWidget != 0, "WPS Wizard", "View not found");
   102         
    85 
   103         // Initialize orientation
    86         //mTitle = qobject_cast<HbLabel*> (loader.findWidget("label_title"));
   104         loadDocmlSection(mWizard->mainWindow()->orientation());
    87         //Q_ASSERT_X(mTitle != 0, "WPS wizard", "title not found");
   105 
    88 
   106         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_wps_P4"));
    89         mHeading = qobject_cast<HbLabel*> (loader.findWidget("label_heading"));
   107         Q_ASSERT(mWidget);
    90         Q_ASSERT_X(mTitle != 0, "WPS wizard", "Header not found");
   108 
    91 
   109         bool connectOk = connect(
    92         mProgressBar = qobject_cast<HbProgressBar*> (loader.findWidget("horizontalProgressBar"));
   110             mWizard->mainWindow(), 
    93         Q_ASSERT_X(mRadio != 0, "WPS Wizard", "List not found");
   111             SIGNAL(orientationChanged(Qt::Orientation)),
    94 
   112             this, 
    95         // start the framework.
   113             SLOT(loadDocmlSection(Qt::Orientation)));
    96         mWpsActiveRunner = CWpsActiveRunner::NewL(*this);
   114         Q_ASSERT(connectOk);
    97         Q_ASSERT(error == NULL);
       
    98     }
   115     }
    99 
   116 
   100     mProgressBar->setRange(0, 0);
   117     OstTraceFunctionExit1(WPSPAGESTEPFOUR_INITIALIZEPAGE_EXIT, this);
   101 
       
   102     StartWpsRunner();
       
   103     OstTraceFunctionExit1(WPSPAGESTEPFOUR_INITIALIZEPAGE_EXIT, this)
       
   104 
   118 
   105     return mWidget;
   119     return mWidget;
   106 }
   120 }
   107 
   121 
   108 /*!
   122 /*!
   109   * Funtion to determine the next page to be displayed in the wizard process
   123    In case the wizard page needs timer protection to the page use this
   110   * 
   124    method to start control operation of the page. This method will be called
   111   * \param bool& RemoveFromStack indicating whether the current page should be 
   125    after requiresStartOperation() if true is returned with different call
   112   * removed from the stack
   126    stack.
   113   * 
   127    
   114   * \return int Page Id of the next page to be displayed.
   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.
   115  */
   143  */
   116 int WpsPageStepFour::nextId(bool &removeFromStack) const
   144 int WpsPageStepFour::nextId(bool &removeFromStack) const
   117 {
   145 {
   118     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_NEXTID_ENTRY, this)
   146     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_NEXTID_ENTRY, this);
   119 
   147 
   120     int id = WpsWizardPage::PageNone;
   148     int id = WpsWizardPage::PageNone;
   121     removeFromStack = false;
   149     removeFromStack = false;
   122     if (countCredentials >= 2) {
   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) {
   123         id = WpsWizardPage::PageWpsWizardStep5;
   159         id = WpsWizardPage::PageWpsWizardStep5;
   124     }
   160     } else {
   125     else {
       
   126         // only one response received. So go to the summary page
   161         // only one response received. So go to the summary page
   127         mWizard->storeSettings(0);
   162         mWizard->storeSettings(0);
   128         id = WlanWizardPage::PageProcessSettings;
   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);
   129     }
   328     }
   130     OstTraceFunctionExit1(WPSPAGESTEPFOUR_NEXTID_EXIT, this)
   329 }
   131 
   330 
   132     return id;
       
   133 }
       
   134 
       
   135 
       
   136 /*!
       
   137   * Determines the Number of steps to move backwards when 'Prev' Button
       
   138   * is clicked
       
   139   * 
       
   140   * \return int Number of pages to move backwards
       
   141  */
       
   142 int WpsPageStepFour::stepsBackwards()
       
   143 {
       
   144     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_STEPSBACKWARDS_ENTRY, this)
       
   145     OstTraceFunctionExit1(WPSPAGESTEPFOUR_STEPBACKWARDS_EXIT, this)
       
   146 
       
   147     return (PageWpsWizardStep4 - PageWpsWizardStep2) - 1;
       
   148 }
       
   149 
       
   150 /*!
       
   151   * Callback when the previous button is clicked
       
   152  */
       
   153 void WpsPageStepFour::previousTriggered()
       
   154 {
       
   155     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_PREVIOUSTRIGGERED_ENTRY, this)
       
   156 
       
   157     mWpsActiveRunner->DoCancel();
       
   158 OstTraceFunctionExit1(WPSPAGESTEPFOUR_PREVIOUSTRIGGERED_EXIT, this)
       
   159 
       
   160 }
       
   161 
       
   162 /*!
       
   163  * CallBack when the cancel button is clicked
       
   164 */
       
   165 void WpsPageStepFour::cancelTriggered()
       
   166 {
       
   167     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_CANCELTRIGGERED_ENTRY, this)
       
   168 
       
   169     mWpsActiveRunner->DoCancel();
       
   170 OstTraceFunctionExit1(WPSPAGESTEPFOUR_CANCELTRIGGERED_EXIT, this)
       
   171 
       
   172 }
       
   173 
       
   174 /*!
       
   175   * Validates the content of the pages
       
   176   * 
       
   177   * \return bool Indicating the result of the operation
       
   178  */
       
   179 bool WpsPageStepFour::validate() const
       
   180 {
       
   181     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_VALIDATE_ENTRY, this)
       
   182     OstTraceFunctionExit1(WPSPAGESTEPFOUR_VALIDATE_EXIT, this)
       
   183 
       
   184     return mValid;
       
   185 }
       
   186 
       
   187 
       
   188 /*!
       
   189  * CallBack function when the middleware WPS call returns back
       
   190  * 
       
   191  * \param QList An array of received settngs
       
   192  * \param int Error indicating the result of the operation
       
   193  * 
       
   194  */
       
   195 void WpsPageStepFour::WpsActiveRunnerStopped(
       
   196     QList<TWlanProtectedSetupCredentialAttribute>& aCredentials, TInt aError)
       
   197 {
       
   198     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_WPSACTIVERUNNERSTOPPED_ENTRY, this)
       
   199 
       
   200     mWpsErrorCode = aError;
       
   201     if (aError == KErrNone) {
       
   202         countCredentials = aCredentials.count();
       
   203         mWizard->storeSettingsArray(aCredentials);
       
   204         mWizard->nextPage();
       
   205     }
       
   206     else if (aError == KErrCancel) {
       
   207         // operation was cancelled 
       
   208 
       
   209     }
       
   210     else {
       
   211         QString str;
       
   212         str = QString("Error: %1").arg(aError);
       
   213         mProgressBar->setVisible(false);
       
   214         //mHeading->setPlainText("General Error");
       
   215         mHeading->setPlainText(str);
       
   216         mWizard->enableNextButton(false);
       
   217 
       
   218     }
       
   219 OstTraceFunctionExit1(WPSPAGESTEPFOUR_WPSACTIVERUNNERSTOPPED_EXIT, this)
       
   220 }
       
   221 
       
   222 
       
   223 /*!
       
   224  * Provides the functionality to initiate the WPS functionality
       
   225  */
       
   226 void WpsPageStepFour::StartWpsRunner()
       
   227 {
       
   228 
       
   229     OstTraceFunctionEntry1(WPSPAGESTEPFOUR_STARTWPSRUNNER_ENTRY, this)
       
   230 
       
   231     // convert QString to symbian RBuf8
       
   232 
       
   233     QString ssid = mWizard->getSsid();
       
   234 
       
   235     TPtrC ptrName(reinterpret_cast<const TText*> (ssid.constData()));
       
   236 
       
   237     RBuf8 ssidName;
       
   238     ssidName.Create(ptrName.Length());
       
   239     ssidName.Copy(ptrName);
       
   240 
       
   241     mWpsActiveRunner->StartSetup(ssidName, mWizard->getPin());
       
   242     ssidName.Close();
       
   243 OstTraceFunctionExit1(WPSPAGESTEPFOUR_STARTWPSRUNNER_EXIT, this)
       
   244 }