wlanutilities/wlanwizard/src/wlanwizardpageprocessingsettings.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: Processing settings, connection and running ict.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <HbMainWindow>
       
    20 #include <HbDocumentLoader>
       
    21 #include <HbWidget>
       
    22 #include <HbLabel>
       
    23 #include <HbProgressBar>
       
    24 #include <HbParameterLengthLimiter>
       
    25 #include <wlanerrorcodes.h>
       
    26 
       
    27 // User includes
       
    28 #include "wlanwizardplugin.h"
       
    29 #include "wlanqtutils.h"
       
    30 #include "wlanwizard_p.h"
       
    31 #include "wlanwizardpageprocessingsettings.h"
       
    32 #include "OstTraceDefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "wlanwizardpageprocessingsettingsTraces.h"
       
    35 #endif
       
    36 
       
    37 /*!
       
    38    \class WlanWizardPageProcessingSettings
       
    39    \brief Implements Processing settings wizard page.
       
    40    
       
    41    In this page 
       
    42    - possible wizard plugin settings are stored
       
    43    - connection to the wlan ap is established
       
    44    - ICT (Internet connectivity test) is run 
       
    45  */
       
    46 
       
    47 // External function prototypes
       
    48 
       
    49 // Local constants
       
    50 
       
    51 // ======== LOCAL FUNCTIONS ========
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 
       
    56 /*!
       
    57    Constructor.
       
    58    
       
    59    @param [in] parent pointer to private implementation of wizard.
       
    60  */
       
    61 WlanWizardPageProcessingSettings::WlanWizardPageProcessingSettings(
       
    62     WlanWizardPrivate* parent) :
       
    63     WlanWizardPageInternal(parent), 
       
    64     mDocLoader(NULL),
       
    65     mWidget(NULL), 
       
    66     mLabel(NULL), 
       
    67     mNextPageId(WlanWizardPageInternal::PageSummary)
       
    68 {
       
    69     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_WLANWIZARDPAGEPROCESSINGSETTINGS_ENTRY );
       
    70     WlanQtUtils* utils = mWizard->wlanQtUtils();
       
    71 
       
    72     bool ok;
       
    73     ok = connect(
       
    74         utils,
       
    75         SIGNAL(wlanNetworkOpened(int)), 
       
    76         this,
       
    77         SLOT(wlanNetworkOpened(int)));
       
    78     Q_ASSERT(ok);
       
    79     
       
    80     ok = connect(
       
    81         utils,
       
    82         SIGNAL(wlanNetworkClosed(int,int)), 
       
    83         this,
       
    84         SLOT(wlanNetworkClosed(int,int)));
       
    85     Q_ASSERT(ok);
       
    86     
       
    87     ok = connect(
       
    88         utils,
       
    89         SIGNAL(ictResult(int,int)), 
       
    90         this,
       
    91         SLOT(ictResult(int,int)));
       
    92     Q_ASSERT(ok);
       
    93 
       
    94     Q_UNUSED(ok);
       
    95     Q_ASSERT(ok);
       
    96     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_WLANWIZARDPAGEPROCESSINGSETTINGS_EXIT );
       
    97 }
       
    98 
       
    99 /*!
       
   100    Destructor.
       
   101  */
       
   102 WlanWizardPageProcessingSettings::~WlanWizardPageProcessingSettings()
       
   103 {
       
   104     OstTraceFunctionEntry0( DUP1_WLANWIZARDPAGEPROCESSINGSETTINGS_WLANWIZARDPAGEPROCESSINGSETTINGS_ENTRY );
       
   105     // signals are automatically disconnected
       
   106     delete mDocLoader;
       
   107     
       
   108     // Wizard framework deletes the visualization (owns mWidget).
       
   109     OstTraceFunctionExit0( DUP1_WLANWIZARDPAGEPROCESSINGSETTINGS_WLANWIZARDPAGEPROCESSINGSETTINGS_EXIT );
       
   110 }
       
   111 
       
   112 /*!
       
   113    See WlanWizardPage::initializePage()
       
   114  */
       
   115 HbWidget* WlanWizardPageProcessingSettings::initializePage()
       
   116 {
       
   117     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_INITIALIZEPAGE_ENTRY );
       
   118     if (!mWidget) {
       
   119         mDocLoader = new HbDocumentLoader(mWizard->mainWindow());
       
   120         
       
   121         bool ok;
       
   122         mDocLoader->load(":/docml/occ_add_wlan_06.docml", &ok);
       
   123         Q_ASSERT(ok);
       
   124         loadDocmlSection(mWizard->mainWindow()->orientation());
       
   125         
       
   126         mWidget = qobject_cast<HbWidget*> (mDocLoader->findWidget("occ_add_wlan_06"));
       
   127         Q_ASSERT(mWidget != NULL);
       
   128 
       
   129         mLabel = qobject_cast<HbLabel*> (mDocLoader->findWidget("dialog"));
       
   130         Q_ASSERT(mLabel != NULL);
       
   131 
       
   132         ok = connect(
       
   133             mWizard->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   134             this, SLOT(loadDocmlSection(Qt::Orientation)));
       
   135         Q_ASSERT(ok);
       
   136     }
       
   137     
       
   138     mLabel->setPlainText(
       
   139         HbParameterLengthLimiter(
       
   140             "txt_occ_dialog_checking_connection_to_1").arg(
       
   141                 mWizard->configuration(WlanWizardPrivate::ConfSsid).toString()));
       
   142 
       
   143     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_INITIALIZEPAGE_EXIT );
       
   144     return mWidget;
       
   145 }
       
   146 
       
   147 /*!
       
   148    See WlanWizardPage::nextId()
       
   149    
       
   150    @param [out] removeFromStack return value is always true
       
   151    
       
   152    @return WlanWizardPageInternal::PageSummary
       
   153  */
       
   154 int WlanWizardPageProcessingSettings::nextId(bool &removeFromStack) const
       
   155 {
       
   156     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_NEXTID_ENTRY );
       
   157     removeFromStack = true;
       
   158     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_NEXTID_EXIT );
       
   159     return mNextPageId;
       
   160 }
       
   161 
       
   162 
       
   163 /*!
       
   164    See WlanWizardPage::showPage()
       
   165    
       
   166    @return false. Next button is dimmed when the page is displayed.
       
   167  */
       
   168 bool WlanWizardPageProcessingSettings::showPage()
       
   169 {
       
   170     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_SHOWPAGE_ENTRY );
       
   171     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_SHOWPAGE_EXIT );
       
   172     return false;
       
   173 }
       
   174 
       
   175 /*!
       
   176    Loads docml at initialization phase and when HbMainWindow sends orientation()
       
   177    signal.
       
   178    
       
   179    @param [in] orientation to be loaded.
       
   180  */
       
   181 void WlanWizardPageProcessingSettings::loadDocmlSection(Qt::Orientation orientation)
       
   182 {
       
   183     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_LOADDOCMLSECTION_ENTRY );
       
   184     WlanWizardPageInternal::loadDocmlSection(
       
   185         mDocLoader,
       
   186         orientation,
       
   187         ":/docml/occ_add_wlan_06.docml", 
       
   188         "portrait_section",
       
   189         "landscape_section");
       
   190     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_LOADDOCMLSECTION_EXIT );
       
   191 }
       
   192 
       
   193 /*!
       
   194    This method is connected to WlanQtUtils::wlanNetworkClosed(int, int) signal.
       
   195    to get disconnected status events of currently established connection.
       
   196    
       
   197    In case of failure, movement to generic error page is triggered.
       
   198    
       
   199    @param [in] iapId IAP ID
       
   200    @param [in] reason Symbian Error code.
       
   201  */
       
   202 void WlanWizardPageProcessingSettings::wlanNetworkClosed(int iapId, int reason)
       
   203 {
       
   204     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKCLOSED_ENTRY );
       
   205     OstTraceExt2( TRACE_BORDER,
       
   206         WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKCLOSED, 
       
   207         "WlanWizardPageProcessingSettings::wlanNetworkClosed;iapId=%d;reason=%d",
       
   208         iapId, reason );
       
   209         
       
   210     if (iapId != mWizard->configuration(WlanWizardHelper::ConfIapId).toInt()) {
       
   211         OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKCLOSED_EXIT );
       
   212         return;
       
   213     }
       
   214 
       
   215     mWizard->setConfiguration(WlanWizardPrivate::ConfIctStatus, false);
       
   216     mWizard->setConfiguration(WlanWizardPrivate::ConfConnected, false);
       
   217     
       
   218     if (mWizard->isCurrentPage(mWidget)) {
       
   219         QString errorText;
       
   220         switch (reason) {
       
   221         case KErrWlanOpenAuthFailed:
       
   222         case KErrWlanSharedKeyAuthRequired:
       
   223         case KErrWlanWpaAuthRequired:
       
   224         case KErrWlanWpaAuthFailed:
       
   225         case KErrWlan802dot1xAuthFailed:
       
   226         case KErrWlanIllegalEncryptionKeys:
       
   227         case KErrWlanPskModeRequired:
       
   228         case KErrWlanEapModeRequired:
       
   229             errorText = hbTrId("txt_occ_dialog_authentication_unsuccessful");
       
   230             break;
       
   231             
       
   232         case KErrWlanIllegalWpaPskKey:
       
   233             errorText = hbTrId("txt_occ_dialog_incorrect_wpa_preshared_key_pleas");
       
   234             break;
       
   235             
       
   236         case KErrWlanSharedKeyAuthFailed:
       
   237             errorText = hbTrId("txt_occ_dialog_incorrect_wep_key_please_check_the");
       
   238             break;
       
   239 
       
   240         default:
       
   241             // Handles also KErrNone
       
   242             // Get plugin specific localized error text if any
       
   243             WlanWizardPlugin *plugin = mWizard->wlanWizardPlugin();
       
   244             
       
   245             if (plugin){
       
   246                 errorText = plugin->errorString(reason);
       
   247             }
       
   248             if (errorText.length() == 0) {
       
   249                 errorText = hbTrId("txt_occ_dialog_connection_failed");
       
   250             }
       
   251             break;
       
   252         }
       
   253         mNextPageId = WlanWizardPageInternal::PageGenericError;
       
   254         mWizard->setConfiguration(
       
   255             WlanWizardHelper::ConfGenericErrorString, errorText);
       
   256         
       
   257         mWizard->setConfiguration(
       
   258             WlanWizardHelper::ConfGenericErrorPageStepsBackwards, 
       
   259             WlanWizardPage::OneStepBackwards);
       
   260         
       
   261         mWizard->nextPage();
       
   262     }
       
   263     
       
   264     OstTrace0( 
       
   265         TRACE_BORDER, WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKCLOSED_DONE,
       
   266         "WlanWizardPageProcessingSettings::wlanNetworkClosed - Done" );
       
   267     OstTraceFunctionExit0( DUP1_WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKCLOSED_EXIT );
       
   268 }
       
   269 
       
   270 /*!
       
   271    Handles ictResult(int, bool) signal from WlanQtUtils and calls
       
   272    WlanWizardHelper::nextPage() to trigger movement to next page.
       
   273    
       
   274    @param [in] iapId IAP ID
       
   275    @param [in] reason ICT result, Symbian error code
       
   276  */
       
   277 void WlanWizardPageProcessingSettings::ictResult(int iapId, int reason)
       
   278 {
       
   279     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_ICTRESULT_ENTRY );
       
   280     OstTraceExt2( 
       
   281         TRACE_BORDER, 
       
   282         WLANWIZARDPAGEPROCESSINGSETTINGS_ICTRESULT, 
       
   283         "WlanWizardPageProcessingSettings::ictResult;iapId=%d;result=%d", 
       
   284         iapId, reason );
       
   285     
       
   286     if (iapId != mWizard->configuration(WlanWizardHelper::ConfIapId).toInt()) {
       
   287         OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_ICTRESULT_EXIT );
       
   288         return;
       
   289     }
       
   290     
       
   291     // Cast of result .
       
   292     WlanQtUtils::IctStatus status = 
       
   293         static_cast<WlanQtUtils::IctStatus>(reason);
       
   294 
       
   295     if(status == WlanQtUtils::IctCancelled) {
       
   296         
       
   297         mNextPageId = WlanWizardPageInternal::PageNone;
       
   298         mWizard->cancelTriggered();
       
   299     }
       
   300     else {
       
   301         mWizard->setConfiguration(WlanWizardPrivate::ConfConnected, true);
       
   302     }
       
   303     mWizard->setConfiguration(WlanWizardPrivate::ConfIctStatus, status);
       
   304         
       
   305     mWizard->nextPage();
       
   306     
       
   307     OstTrace0( TRACE_BORDER, WLANWIZARDPAGEPROCESSINGSETTINGS_ICTRESULT_DONE, 
       
   308         "WlanWizardPageProcessingSettings::ictResult - Done" );
       
   309     OstTraceFunctionExit0( DUP1_WLANWIZARDPAGEPROCESSINGSETTINGS_ICTRESULT_EXIT );
       
   310 }
       
   311 
       
   312 /*!
       
   313    Handles wlanNetworkOpened(int) signal from WlanQtUtils.
       
   314    
       
   315    @param [in] iapId IAP ID
       
   316  */
       
   317 void WlanWizardPageProcessingSettings::wlanNetworkOpened(int iapId)
       
   318 {
       
   319     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKOPENED_ENTRY );
       
   320     Q_UNUSED(iapId);
       
   321     OstTrace1(
       
   322         TRACE_BORDER, 
       
   323         WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKOPENED, 
       
   324         "WlanWizardPageProcessingSettings::wlanNetworkOpened;iapId=%d", 
       
   325         iapId);
       
   326     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_WLANNETWORKOPENED_EXIT );
       
   327 }
       
   328 
       
   329 /*!
       
   330    See WlanWizardPage::requiresStartOperation().
       
   331    
       
   332    Indicates to framework that startOperation() needs to called.
       
   333  */
       
   334 bool WlanWizardPageProcessingSettings::requiresStartOperation()
       
   335 {
       
   336     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_REQUIRESSTARTOPERATION_ENTRY );
       
   337     OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_REQUIRESSTARTOPERATION_EXIT );
       
   338     return true;
       
   339 }
       
   340 
       
   341 /*!
       
   342    See WlanWizardPage::startOperation().
       
   343    
       
   344    Starts the page operation.
       
   345  */
       
   346 void WlanWizardPageProcessingSettings::startOperation()
       
   347 {
       
   348     OstTraceFunctionEntry0( WLANWIZARDPAGEPROCESSINGSETTINGS_STARTOPERATION_ENTRY );
       
   349     if (mWizard->handleIap()) {
       
   350         mNextPageId = WlanWizardPageInternal::PageSummary;
       
   351         
       
   352         // in case wlan connection is already established disconnect it
       
   353         // note that connectIap() disconnects implicitly connection when 
       
   354         // same IAP is already connected.
       
   355         WlanQtUtils* utils = mWizard->wlanQtUtils();
       
   356         int connectedIapId = utils->activeIap();
       
   357         int iapId = mWizard->configuration(WlanWizardHelper::ConfIapId).toInt();
       
   358         if (connectedIapId != iapId){
       
   359             utils->disconnectIap(connectedIapId);
       
   360         }
       
   361         mWizard->wlanQtUtils()->connectIap( iapId, true);        
       
   362     } else {
       
   363         mNextPageId = WlanWizardPageInternal::PageGenericError;
       
   364         mWizard->setConfiguration(
       
   365             WlanWizardHelper::ConfGenericErrorString, 
       
   366             hbTrId("txt_occ_dialog_unable_to_save_settings_please_ret"));
       
   367         
       
   368         mWizard->setConfiguration(
       
   369             WlanWizardHelper::ConfGenericErrorPageStepsBackwards, 
       
   370             WlanWizardPage::OneStepBackwards);
       
   371         mWizard->nextPage();
       
   372     }
       
   373 	OstTraceFunctionExit0( WLANWIZARDPAGEPROCESSINGSETTINGS_STARTOPERATION_EXIT );
       
   374 }