wlanutilities/wpswizard/src/wpswizardstepthreenumber.cpp
changeset 39 7b3e49e4608a
parent 19 10810c91db26
child 53 bdc64aa9b954
--- a/wlanutilities/wpswizard/src/wpswizardstepthreenumber.cpp	Thu Jun 10 15:44:54 2010 +0300
+++ b/wlanutilities/wpswizard/src/wpswizardstepthreenumber.cpp	Thu Jun 24 10:49:51 2010 +0300
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
  * All rights reserved.
  * This component and the accompanying materials are made available
- * under the terms of the License "Eclipse Public License v1.0"
+ * under the terms of "Eclipse Public License v1.0"
  * which accompanies this distribution, and is available
  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
  *
@@ -17,13 +17,14 @@
  */
 
 // System includes
-#include <hbdocumentloader.h>
-#include <hbwidget.h>
-#include <hbradiobuttonlist.h>
-#include <hblineedit.h>
-#include <hblabel.h>
+#include <HbDocumentLoader>
+#include <HbWidget>
+#include <HbRadiobuttonList>
+#include <HbLineEdit>
+#include <HbLabel>
 #include <QTextStream>
 #include <QTime>
+#include <HbMainWindow>
 
 // User includes
 #include "wpswizardstepthreenumber.h"
@@ -32,182 +33,183 @@
 // Trace includes
 #include "OstTraceDefinitions.h"
 #ifdef OST_TRACE_COMPILER_IN_USE
-#include "wpspagestepthreenumberTraces.h"
+#include "wpswizardstepthreenumberTraces.h"
 #endif
 
+// External function prototypes
+
 // Local constants
-#define KMaxPINLength 8
-
+const static int KMaxPINLength = 8;
 
 /*!
- * Constructor for WPS page three number entry mode
- * 
- * \param WpsWizardPrivate* Pointer to the WPS wizard private implementation 
+   \class WpsPageStepThreeNumber
+   \brief Implementation of wps wizard page for step three PIN Entry mode. 
+ */
+
+// ======== LOCAL FUNCTIONS ========
+
+// ======== MEMBER FUNCTIONS ========
+
+/*!
+   Constructor for WPS page three number entry mode
+   
+   @param [in] parent Pointer to the WPS wizard private implementation 
  */
 WpsPageStepThreeNumber::WpsPageStepThreeNumber(WpsWizardPrivate* parent) :
-    WpsWizardPage(parent), mWidget(NULL), mRadio(NULL), mValid(true)
+    WpsWizardPage(parent), 
+    mWidget(NULL), 
+    mHeading(NULL),
+    mLoader(NULL)
 {
-OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this)
-OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this)
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this); 
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this);
 
 }
 
-
 /*!
- * Destructor
+   Destructor
  */
 WpsPageStepThreeNumber::~WpsPageStepThreeNumber()
 {
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this)
-
-    delete mWidget;
-
-OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this)
-
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_DESTRUCTOR_ENTRY, this);
+    delete mLoader;
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_DESTRUCTOR_EXIT, this);
 }
 
-
 /*!
-  * Loads the page with all the widgets
-  * 
-  * \return HbWidget* Returns the view widget
+   Loads the page with all the widgets
+   
+   @return HbWidget* Returns the view widget
  */
 HbWidget* WpsPageStepThreeNumber::initializePage()
 {
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_ENTRY, this)
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_ENTRY, this);
 
     if (!mWidget) {
         bool ok;
-        HbDocumentLoader loader;
-        loader.load(":/docml/occ_wps_P3.docml", &ok);
-        Q_ASSERT_X(ok, "WPS Wizard", "Invalid docml file");
+        mLoader = new HbDocumentLoader(mWizard->mainWindow());
+        
+        mLoader->load(":/docml/occ_wps_02_03.docml", &ok);
+        Q_ASSERT(ok);
+        
+        // Initialize orientation
+        loadDocmlSection(mWizard->mainWindow()->orientation());
 
-        mWidget = qobject_cast<HbWidget*> (loader.findWidget("occ_wps_P3"));
-        Q_ASSERT_X(mWidget != 0, "WPS Wizard", "View not found");
+        mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_wps_P2"));
+        Q_ASSERT(mWidget);
 
-        mHeading = qobject_cast<HbLabel*> (loader.findWidget("label_heading"));
-        Q_ASSERT_X(mHeading != 0, "WPS wizard", "Header not found");
-
-        int randomNumber = computeRandNumber();
-        mHeading->setPlainText(hbTrId("txt_occ_dialog_enter_1_on_the_wireless_station_t").arg(
-            randomNumber));
-        mWizard->setPin(randomNumber);
-        mWizard->enableNextButton(true);
-    }
-    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_EXIT, this)
+        mHeading= qobject_cast<HbLabel*> (mLoader->findWidget("label_heading"));
+        Q_ASSERT(mHeading);
+        
+        bool connectOk = connect(
+            mWizard->mainWindow(), 
+            SIGNAL(orientationChanged(Qt::Orientation)),
+            this, 
+            SLOT(loadDocmlSection(Qt::Orientation)));
+        Q_ASSERT(connectOk);
+    } 
+    
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_EXIT, this);
 
     return mWidget;
 }
 
+/*!
+   Funtion to determine the next page to be displayed in the wizard process
+   
+   @param [out] removeFromStack bool indicating whether the current page should be 
+   removed from the stack
+   
+   @return int Page Id of the next page to be displayed.
+ */
+int WpsPageStepThreeNumber::nextId(bool &removeFromStack) const
+{
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_NEXTID_ENTRY, this);
+    removeFromStack = false;
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_NEXTID_EXIT, this);
+
+    return WpsWizardPage::PageWpsWizardStep4;
+}
+
+/*!
+   Determines the Number of steps to move backwards when 'Prev' Button
+   is clicked
+   
+   @return int Number of pages to move backwards
+ */
+int WpsPageStepThreeNumber::previousTriggered()
+{
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_ENTRY, this);
+    
+    mWizard->setPin(0);
+    
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_EXIT, this);
+    return (PageWpsWizardStep3_Number - PageWpsWizardStep2) - 1;
+}
+
+/*!
+   CallBack when the cancel button is clicked
+ */
+void WpsPageStepThreeNumber::cancelTriggered()
+{
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_ENTRY, this);
+    mWizard->setPin(0);    
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_EXIT, this);
+}
+
 
 /*!
-  * Funtion to determine the next page to be displayed in the wizard process
-  * 
-  * \param bool& RemoveFromStack indicating whether the current page should be 
-  * removed from the stack
-  * 
-  * \return int Page Id of the next page to be displayed.
+   Determines whether the Next action button should be enabled or not
+   
+   @return bool Indicating whether next button is enabled or not.
  */
-int WpsPageStepThreeNumber::nextId(bool &removeFromStack) const
+bool WpsPageStepThreeNumber::showPage()
 {
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_NEXTID_ENTRY, this)
-
-    int id = WlanWizardPage::PageNone;
-    removeFromStack = false;
-    id = WpsWizardPage::PageWpsWizardStep4;
-    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_NEXTID_EXIT, this)
-
-    return id;
-}
-
-/*!
- * Determines the Number of steps to move backwards when 'Prev' Button
- * is clicked
- * 
- * \return int Number of pages to move backwards
-*/
-int WpsPageStepThreeNumber::stepsBackwards()
-{
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_STEPSBACKWARDS_ENTRY, this)
-    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_STEPBACKWARDS_EXIT, this)
-
-    return (PageWpsWizardStep3_Number - PageWpsWizardStep2) - 1;
+    int randomNumber = computeRandNumber();
+    mHeading->setPlainText(hbTrId(
+            "txt_occ_dialog_enter_1_on_the_wireless_station_t").arg(
+            randomNumber));
+    mWizard->setPin(randomNumber);
+    return true;
 }
 
 /*!
-  * Callback when the previous button is clicked
- */
-void WpsPageStepThreeNumber::previousTriggered()
-{
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_ENTRY, this)
-
-    mWizard->setPin(0);
-OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_EXIT, this)
-
-}
-
-/*!
- * CallBack when the cancel button is clicked
-*/
-void WpsPageStepThreeNumber::cancelTriggered()
-{
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_ENTRY, this)
-
-    mWizard->setPin(0);
-OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_EXIT, this)
-
-}
-
-/*!
- * Validates the content of the pages
- * 
- * \return bool Indicating the result of the operation
-*/
-bool WpsPageStepThreeNumber::validate() const
-{
-
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_VALIDATE_ENTRY, this)
-    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_VALIDATE_EXIT, this)
-
-    return mValid;
-}
-
-/*!
- * Computes the Random number based on current system time
- * 
- * \return int Returns the generated random number
+   Computes the Random number based on current system time
+   
+   @return int Returns the generated random number
  */
 int WpsPageStepThreeNumber::computeRandNumber()
 {
-
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_ENTRY, this)
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_ENTRY, this);
 
     int pin = 0;
     QTime time(0, 0);
     int seed = time.secsTo(QTime::currentTime());
+    
     do {
         qsrand(seed);
         pin = qrand();
     } while (pin < (10 ^ (KMaxPINLength - 2)) || (((pin / 1000000) % 10)) == 0);
+    
     //last digit is checksum, so we need 7 digits
     //and the first shouldn't be 0
     pin = pin % 10000000;
-    TInt checkSum = computeCheckSum(pin);
+    int checkSum = computeCheckSum(pin);
     pin *= 10;
     pin += checkSum;
-    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_EXIT, this)
+    
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_EXIT, this);
     return pin;
 }
 
 /*!
- * Computes the checksum for a given pin
- * 
- * \return Returns the generated checksum
+   Computes the checksum for a given pin
+   
+   @return Returns the generated checksum
  */
 int WpsPageStepThreeNumber::computeCheckSum(int aPin)
 {
-
-    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_ENTRY, this)
+    OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_ENTRY, this);
 
     int accum = 0;
     aPin *= 10;
@@ -219,7 +221,28 @@
     accum += 1 * ((aPin / 100) % 10);
     accum += 3 * ((aPin / 10) % 10);
     int digit = (accum % 10);
-    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_EXIT, this)
+    OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_EXIT, this);
     return (10 - digit) % 10;
 }
 
+/*!
+   Loads docml at initialization phase and when HbMainWindow sends 
+   orientation() signal.
+   
+   @param [in] orientation orientation to be loaded.
+ */
+void WpsPageStepThreeNumber::loadDocmlSection(Qt::Orientation orientation)
+{
+    bool ok = false;
+
+    // Load the orientation specific section
+    if (orientation == Qt::Horizontal) {
+        mLoader->load(":/docml/occ_wps_02_03.docml", "landscape", &ok);
+        Q_ASSERT(ok);
+    } else {
+        Q_ASSERT(orientation == Qt::Vertical);
+        mLoader->load(":/docml/occ_wps_02_03.docml", "portrait", &ok);
+        Q_ASSERT(ok);
+    }
+}
+