wlanutilities/wpswizard/src/wpswizardstepthreenumber.cpp
branchGCC_SURGE
changeset 47 b3d8f88532b7
parent 19 10810c91db26
parent 46 2fbd1d709fe7
equal deleted inserted replaced
34:30a5f517c615 47:b3d8f88532b7
     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.
    15  *   WPS Wizard Page: Step 3 Number enter mode.
    15  *   WPS Wizard Page: Step 3 Number enter mode.
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 // System includes
    19 // System includes
    20 #include <hbdocumentloader.h>
    20 #include <HbDocumentLoader>
    21 #include <hbwidget.h>
    21 #include <HbWidget>
    22 #include <hbradiobuttonlist.h>
    22 #include <HbRadiobuttonList>
    23 #include <hblineedit.h>
    23 #include <HbLineEdit>
    24 #include <hblabel.h>
    24 #include <HbLabel>
    25 #include <QTextStream>
    25 #include <QTextStream>
    26 #include <QTime>
    26 #include <QTime>
       
    27 #include <HbMainWindow>
    27 
    28 
    28 // User includes
    29 // User includes
    29 #include "wpswizardstepthreenumber.h"
    30 #include "wpswizardstepthreenumber.h"
    30 #include "wpswizard_p.h"
    31 #include "wpswizard_p.h"
    31 
    32 
    32 // Trace includes
    33 // Trace includes
    33 #include "OstTraceDefinitions.h"
    34 #include "OstTraceDefinitions.h"
    34 #ifdef OST_TRACE_COMPILER_IN_USE
    35 #ifdef OST_TRACE_COMPILER_IN_USE
    35 #include "wpspagestepthreenumberTraces.h"
    36 #include "wpswizardstepthreenumberTraces.h"
    36 #endif
    37 #endif
    37 
    38 
       
    39 // External function prototypes
       
    40 
    38 // Local constants
    41 // Local constants
    39 #define KMaxPINLength 8
    42 const static int KMaxPINLength = 8;
    40 
    43 
    41 
    44 /*!
    42 /*!
    45    \class WpsPageStepThreeNumber
    43  * Constructor for WPS page three number entry mode
    46    \brief Implementation of wps wizard page for step three PIN Entry mode. 
    44  * 
    47  */
    45  * \param WpsWizardPrivate* Pointer to the WPS wizard private implementation 
    48 
       
    49 // ======== LOCAL FUNCTIONS ========
       
    50 
       
    51 // ======== MEMBER FUNCTIONS ========
       
    52 
       
    53 /*!
       
    54    Constructor for WPS page three number entry mode
       
    55    
       
    56    @param [in] parent Pointer to the WPS wizard private implementation 
    46  */
    57  */
    47 WpsPageStepThreeNumber::WpsPageStepThreeNumber(WpsWizardPrivate* parent) :
    58 WpsPageStepThreeNumber::WpsPageStepThreeNumber(WpsWizardPrivate* parent) :
    48     WpsWizardPage(parent), mWidget(NULL), mRadio(NULL), mValid(true)
    59     WpsWizardPage(parent), 
    49 {
    60     mWidget(NULL), 
    50 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this)
    61     mHeading(NULL),
    51 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this)
    62     mLoader(NULL)
    52 
    63 {
    53 }
    64     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this); 
    54 
    65     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this);
    55 
    66 
    56 /*!
    67 }
    57  * Destructor
    68 
       
    69 /*!
       
    70    Destructor
    58  */
    71  */
    59 WpsPageStepThreeNumber::~WpsPageStepThreeNumber()
    72 WpsPageStepThreeNumber::~WpsPageStepThreeNumber()
    60 {
    73 {
    61     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this)
    74     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_DESTRUCTOR_ENTRY, this);
    62 
    75     delete mLoader;
    63     delete mWidget;
    76     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_DESTRUCTOR_EXIT, this);
    64 
    77 }
    65 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this)
    78 
    66 
    79 /*!
    67 }
    80    Loads the page with all the widgets
    68 
    81    
    69 
    82    @return HbWidget* Returns the view widget
    70 /*!
       
    71   * Loads the page with all the widgets
       
    72   * 
       
    73   * \return HbWidget* Returns the view widget
       
    74  */
    83  */
    75 HbWidget* WpsPageStepThreeNumber::initializePage()
    84 HbWidget* WpsPageStepThreeNumber::initializePage()
    76 {
    85 {
    77     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_ENTRY, this)
    86     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_ENTRY, this);
    78 
    87 
    79     if (!mWidget) {
    88     if (!mWidget) {
    80         bool ok;
    89         bool ok;
    81         HbDocumentLoader loader;
    90         mLoader = new HbDocumentLoader(mWizard->mainWindow());
    82         loader.load(":/docml/occ_wps_P3.docml", &ok);
    91         
    83         Q_ASSERT_X(ok, "WPS Wizard", "Invalid docml file");
    92         mLoader->load(":/docml/occ_wps_02_03.docml", &ok);
    84 
    93         Q_ASSERT(ok);
    85         mWidget = qobject_cast<HbWidget*> (loader.findWidget("occ_wps_P3"));
    94         
    86         Q_ASSERT_X(mWidget != 0, "WPS Wizard", "View not found");
    95         // Initialize orientation
    87 
    96         loadDocmlSection(mWizard->mainWindow()->orientation());
    88         mHeading = qobject_cast<HbLabel*> (loader.findWidget("label_heading"));
    97 
    89         Q_ASSERT_X(mHeading != 0, "WPS wizard", "Header not found");
    98         mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_wps_P2"));
    90 
    99         Q_ASSERT(mWidget);
    91         int randomNumber = computeRandNumber();
   100 
    92         mHeading->setPlainText(hbTrId("txt_occ_dialog_enter_1_on_the_wireless_station_t").arg(
   101         mHeading= qobject_cast<HbLabel*> (mLoader->findWidget("label_heading"));
       
   102         Q_ASSERT(mHeading);
       
   103         
       
   104         bool connectOk = connect(
       
   105             mWizard->mainWindow(), 
       
   106             SIGNAL(orientationChanged(Qt::Orientation)),
       
   107             this, 
       
   108             SLOT(loadDocmlSection(Qt::Orientation)));
       
   109         Q_ASSERT(connectOk);
       
   110     } 
       
   111     
       
   112     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_EXIT, this);
       
   113 
       
   114     return mWidget;
       
   115 }
       
   116 
       
   117 /*!
       
   118    Funtion to determine the next page to be displayed in the wizard process
       
   119    
       
   120    @param [out] removeFromStack bool indicating whether the current page should be 
       
   121    removed from the stack
       
   122    
       
   123    @return int Page Id of the next page to be displayed.
       
   124  */
       
   125 int WpsPageStepThreeNumber::nextId(bool &removeFromStack) const
       
   126 {
       
   127     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_NEXTID_ENTRY, this);
       
   128     removeFromStack = false;
       
   129     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_NEXTID_EXIT, this);
       
   130 
       
   131     return WpsWizardPage::PageWpsWizardStep4;
       
   132 }
       
   133 
       
   134 /*!
       
   135    Determines the Number of steps to move backwards when 'Prev' Button
       
   136    is clicked
       
   137    
       
   138    @return int Number of pages to move backwards
       
   139  */
       
   140 int WpsPageStepThreeNumber::previousTriggered()
       
   141 {
       
   142     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_ENTRY, this);
       
   143     
       
   144     mWizard->setPin(0);
       
   145     
       
   146     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_EXIT, this);
       
   147     return (PageWpsWizardStep3_Number - PageWpsWizardStep2) - 1;
       
   148 }
       
   149 
       
   150 /*!
       
   151    CallBack when the cancel button is clicked
       
   152  */
       
   153 void WpsPageStepThreeNumber::cancelTriggered()
       
   154 {
       
   155     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_ENTRY, this);
       
   156     mWizard->setPin(0);    
       
   157     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_EXIT, this);
       
   158 }
       
   159 
       
   160 
       
   161 /*!
       
   162    Determines whether the Next action button should be enabled or not
       
   163    
       
   164    @return bool Indicating whether next button is enabled or not.
       
   165  */
       
   166 bool WpsPageStepThreeNumber::showPage()
       
   167 {
       
   168     int randomNumber = computeRandNumber();
       
   169     mHeading->setPlainText(hbTrId(
       
   170             "txt_occ_dialog_enter_1_on_the_wireless_station_t").arg(
    93             randomNumber));
   171             randomNumber));
    94         mWizard->setPin(randomNumber);
   172     mWizard->setPin(randomNumber);
    95         mWizard->enableNextButton(true);
   173     return true;
    96     }
   174 }
    97     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_EXIT, this)
   175 
    98 
   176 /*!
    99     return mWidget;
   177    Computes the Random number based on current system time
   100 }
   178    
   101 
   179    @return int Returns the generated random number
   102 
       
   103 /*!
       
   104   * Funtion to determine the next page to be displayed in the wizard process
       
   105   * 
       
   106   * \param bool& RemoveFromStack indicating whether the current page should be 
       
   107   * removed from the stack
       
   108   * 
       
   109   * \return int Page Id of the next page to be displayed.
       
   110  */
       
   111 int WpsPageStepThreeNumber::nextId(bool &removeFromStack) const
       
   112 {
       
   113     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_NEXTID_ENTRY, this)
       
   114 
       
   115     int id = WlanWizardPage::PageNone;
       
   116     removeFromStack = false;
       
   117     id = WpsWizardPage::PageWpsWizardStep4;
       
   118     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_NEXTID_EXIT, this)
       
   119 
       
   120     return id;
       
   121 }
       
   122 
       
   123 /*!
       
   124  * Determines the Number of steps to move backwards when 'Prev' Button
       
   125  * is clicked
       
   126  * 
       
   127  * \return int Number of pages to move backwards
       
   128 */
       
   129 int WpsPageStepThreeNumber::stepsBackwards()
       
   130 {
       
   131     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_STEPSBACKWARDS_ENTRY, this)
       
   132     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_STEPBACKWARDS_EXIT, this)
       
   133 
       
   134     return (PageWpsWizardStep3_Number - PageWpsWizardStep2) - 1;
       
   135 }
       
   136 
       
   137 /*!
       
   138   * Callback when the previous button is clicked
       
   139  */
       
   140 void WpsPageStepThreeNumber::previousTriggered()
       
   141 {
       
   142     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_ENTRY, this)
       
   143 
       
   144     mWizard->setPin(0);
       
   145 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_EXIT, this)
       
   146 
       
   147 }
       
   148 
       
   149 /*!
       
   150  * CallBack when the cancel button is clicked
       
   151 */
       
   152 void WpsPageStepThreeNumber::cancelTriggered()
       
   153 {
       
   154     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_ENTRY, this)
       
   155 
       
   156     mWizard->setPin(0);
       
   157 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_EXIT, this)
       
   158 
       
   159 }
       
   160 
       
   161 /*!
       
   162  * Validates the content of the pages
       
   163  * 
       
   164  * \return bool Indicating the result of the operation
       
   165 */
       
   166 bool WpsPageStepThreeNumber::validate() const
       
   167 {
       
   168 
       
   169     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_VALIDATE_ENTRY, this)
       
   170     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_VALIDATE_EXIT, this)
       
   171 
       
   172     return mValid;
       
   173 }
       
   174 
       
   175 /*!
       
   176  * Computes the Random number based on current system time
       
   177  * 
       
   178  * \return int Returns the generated random number
       
   179  */
   180  */
   180 int WpsPageStepThreeNumber::computeRandNumber()
   181 int WpsPageStepThreeNumber::computeRandNumber()
   181 {
   182 {
   182 
   183     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_ENTRY, this);
   183     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_ENTRY, this)
       
   184 
   184 
   185     int pin = 0;
   185     int pin = 0;
   186     QTime time(0, 0);
   186     QTime time(0, 0);
   187     int seed = time.secsTo(QTime::currentTime());
   187     int seed = time.secsTo(QTime::currentTime());
       
   188     
   188     do {
   189     do {
   189         qsrand(seed);
   190         qsrand(seed);
   190         pin = qrand();
   191         pin = qrand();
   191     } while (pin < (10 ^ (KMaxPINLength - 2)) || (((pin / 1000000) % 10)) == 0);
   192     } while (pin < (10 ^ (KMaxPINLength - 2)) || (((pin / 1000000) % 10)) == 0);
       
   193     
   192     //last digit is checksum, so we need 7 digits
   194     //last digit is checksum, so we need 7 digits
   193     //and the first shouldn't be 0
   195     //and the first shouldn't be 0
   194     pin = pin % 10000000;
   196     pin = pin % 10000000;
   195     TInt checkSum = computeCheckSum(pin);
   197     int checkSum = computeCheckSum(pin);
   196     pin *= 10;
   198     pin *= 10;
   197     pin += checkSum;
   199     pin += checkSum;
   198     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_EXIT, this)
   200     
       
   201     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_EXIT, this);
   199     return pin;
   202     return pin;
   200 }
   203 }
   201 
   204 
   202 /*!
   205 /*!
   203  * Computes the checksum for a given pin
   206    Computes the checksum for a given pin
   204  * 
   207    
   205  * \return Returns the generated checksum
   208    @return Returns the generated checksum
   206  */
   209  */
   207 int WpsPageStepThreeNumber::computeCheckSum(int aPin)
   210 int WpsPageStepThreeNumber::computeCheckSum(int aPin)
   208 {
   211 {
   209 
   212     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_ENTRY, this);
   210     OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_ENTRY, this)
       
   211 
   213 
   212     int accum = 0;
   214     int accum = 0;
   213     aPin *= 10;
   215     aPin *= 10;
   214     accum += 3 * ((aPin / 10000000) % 10);
   216     accum += 3 * ((aPin / 10000000) % 10);
   215     accum += 1 * ((aPin / 1000000) % 10);
   217     accum += 1 * ((aPin / 1000000) % 10);
   217     accum += 1 * ((aPin / 10000) % 10);
   219     accum += 1 * ((aPin / 10000) % 10);
   218     accum += 3 * ((aPin / 1000) % 10);
   220     accum += 3 * ((aPin / 1000) % 10);
   219     accum += 1 * ((aPin / 100) % 10);
   221     accum += 1 * ((aPin / 100) % 10);
   220     accum += 3 * ((aPin / 10) % 10);
   222     accum += 3 * ((aPin / 10) % 10);
   221     int digit = (accum % 10);
   223     int digit = (accum % 10);
   222     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_EXIT, this)
   224     OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_EXIT, this);
   223     return (10 - digit) % 10;
   225     return (10 - digit) % 10;
   224 }
   226 }
   225 
   227 
       
   228 /*!
       
   229    Loads docml at initialization phase and when HbMainWindow sends 
       
   230    orientation() signal.
       
   231    
       
   232    @param [in] orientation orientation to be loaded.
       
   233  */
       
   234 void WpsPageStepThreeNumber::loadDocmlSection(Qt::Orientation orientation)
       
   235 {
       
   236     bool ok = false;
       
   237 
       
   238     // Load the orientation specific section
       
   239     if (orientation == Qt::Horizontal) {
       
   240         mLoader->load(":/docml/occ_wps_02_03.docml", "landscape", &ok);
       
   241         Q_ASSERT(ok);
       
   242     } else {
       
   243         Q_ASSERT(orientation == Qt::Vertical);
       
   244         mLoader->load(":/docml/occ_wps_02_03.docml", "portrait", &ok);
       
   245         Q_ASSERT(ok);
       
   246     }
       
   247 }
       
   248