wlanutilities/wlanwizard/src/wlanwizard_p.cpp
branchGCC_SURGE
changeset 47 b3d8f88532b7
parent 46 2fbd1d709fe7
child 43 72ebcbb64834
equal deleted inserted replaced
34:30a5f517c615 47:b3d8f88532b7
       
     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: Private implementation.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QLocale>
       
    20 #include <QApplication>
       
    21 #include <QGraphicsWidget>
       
    22 #include <QTimer>
       
    23 #include <QDebug>
       
    24 #include <HbTranslator>
       
    25 #include <HbDocumentLoader>
       
    26 #include <HbMainWindow>
       
    27 #include <HbDialog>
       
    28 #include <HbStackedWidget>
       
    29 #include <HbLabel>
       
    30 #include <HbAction>
       
    31 #include <HbStyleLoader>
       
    32 
       
    33 // User includes
       
    34 #include "eapwizard.h"
       
    35 #include "wpswizard.h"
       
    36 #include "wlanqtutils.h"
       
    37 #include "wlanqtutilsap.h"
       
    38 #include "wlanwizardplugin.h"
       
    39 #include "wlanwizard.h"
       
    40 #include "wlanwizard_p.h"
       
    41 #include "wlanwizardutils.h"
       
    42 #include "wlanwizardpagekeyquery.h"
       
    43 #include "wlanwizardpagesummary.h"
       
    44 #include "wlanwizardpageprocessingsettings.h"
       
    45 #include "wlanwizardpagegenericerror.h"
       
    46 #include "wlanwizardpagessid.h"
       
    47 #include "wlanwizardpagenetworkmode.h"
       
    48 #include "wlanwizardpagescanning.h"
       
    49 #include "wlanwizardpagesecuritymode.h"
       
    50 
       
    51 #include "OstTraceDefinitions.h"
       
    52 #ifdef OST_TRACE_COMPILER_IN_USE
       
    53 #include "wlanwizard_pTraces.h"
       
    54 #endif
       
    55 
       
    56 /*!
       
    57    \class WlanWizardPrivate
       
    58    \brief Private implementation of WlanWizard. Implements the interface
       
    59    WlanWizardHelper to the wizard plugins. 
       
    60  */
       
    61 
       
    62 // External function prototypes
       
    63 
       
    64 // Local constants
       
    65 
       
    66 /*!
       
    67    \var PageTimeout Timeout for timer protected pages. 1.5sec
       
    68  */
       
    69 
       
    70 // ======== LOCAL FUNCTIONS ========
       
    71 
       
    72 // ======== MEMBER FUNCTIONS ========
       
    73 
       
    74 /*!
       
    75    Constructor of private implementation.
       
    76    
       
    77    @param [in] wizard Pointer to the API class.
       
    78    @param [in] mainWindow pointer to mainwindow.
       
    79  */
       
    80 WlanWizardPrivate::WlanWizardPrivate(
       
    81     WlanWizard* wizard, 
       
    82     HbMainWindow *mainWindow) :
       
    83     QObject(wizard),
       
    84     q_ptr(wizard), 
       
    85     mMainWindow(mainWindow), 
       
    86     mPageTimer(new QTimer(this)),
       
    87     mTitle(NULL),
       
    88     mActionNext(NULL),
       
    89     mActionPrevious(NULL),
       
    90     mActionFinish(NULL),
       
    91     mActionCancel(NULL),
       
    92     mStackedWidget(NULL),
       
    93     mDialog(NULL),
       
    94     mTranslator(new HbTranslator("wlanwizard")),
       
    95     mWlanQtUtils(new WlanQtUtils()),
       
    96     mDocLoader(new HbDocumentLoader(mainWindow)),
       
    97     mEapWizard(NULL), 
       
    98     mWpsWizard(NULL), 
       
    99     mFirstPageId(WlanWizardPageInternal::PageNone),
       
   100     mPageFinished(false),
       
   101     mClosed(false)
       
   102 {
       
   103     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_WLANWIZARDPRIVATE,
       
   104         "WlanWizardPrivate::WlanWizardPrivate;this=%x", 
       
   105         this );
       
   106     
       
   107     // Set initial values for configurations
       
   108     setConfiguration(ConfIapId, WlanQtUtils::IapIdNone);
       
   109     setConfiguration(ConfConnected, false);
       
   110     setConfiguration(ConfHiddenWlan, false);
       
   111     setConfiguration(ConfProcessSettings, false);
       
   112     setConfiguration(ConfIctStatus, false);
       
   113 
       
   114     // Initialize timer for timer protected pages
       
   115     mPageTimer->setSingleShot(true);
       
   116 
       
   117     // Load the wizard frame (title, content, actions) from docml 
       
   118     loadDocml();
       
   119 
       
   120     // Creates the control object of the wlan wizard pages. 
       
   121     createPages();
       
   122 
       
   123     // EAP Wizard will add wizard pages at construction phase using
       
   124     // WlanWizardHelper::addPage()
       
   125     mEapWizard.reset(new EapWizard(this) );
       
   126 
       
   127     // WPS Wizard will add wizard pages at construction phase using
       
   128     // WlanWizardHelper::addPage()
       
   129     mWpsWizard.reset(new WpsWizard(this));
       
   130 
       
   131     // First page is SSID query, unless client sets configurations via
       
   132     // setParameters(), which decides the first page..
       
   133     mFirstPageId = WlanWizardPageInternal::PageSsid;
       
   134 
       
   135     OstTraceExt2( TRACE_BORDER, WLANWIZARDPRIVATE_WLANWIZARDPRIVATE_DONE,
       
   136         "WlanWizardPrivate::WlanWizardPrivate - done;"
       
   137         "this=%x;mFirstPageId=%{PageIds}",
       
   138         ( unsigned )this, mFirstPageId );
       
   139 }
       
   140 
       
   141 /*!
       
   142    Destructor.
       
   143  */
       
   144 WlanWizardPrivate::~WlanWizardPrivate()
       
   145 {
       
   146     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_DWLANWIZARDPRIVATE,
       
   147         "WlanWizardPrivate::~WlanWizardPrivate;this=%x",
       
   148         this );
       
   149     
       
   150     // Remove wizard pages from stackedwidgets, since stackedwidget owns the
       
   151     // objects and all pages are deleted below. 
       
   152     while (mStackedWidget->count()) {
       
   153         mStackedWidget->removeAt(0);
       
   154     }
       
   155 
       
   156     // Delete UI instances (HbWidget) of pages
       
   157     QHashIterator<HbWidget*, WlanWizardPage*> i(mPageMapper);
       
   158     while (i.hasNext()) {
       
   159         i.next();
       
   160         delete i.key();
       
   161     }
       
   162     mPageMapper.clear();
       
   163 
       
   164     // WlanWizardPage objects are automatically deleted since this is the
       
   165     // parent of the objects.
       
   166     mPages.clear();
       
   167     
       
   168     // timer is cancelled/deleted automatically when the parent (this) is deleted 
       
   169     
       
   170     // TODO: See TSW Error: MTAA-854DK8 and loadDocml()
       
   171     HbStyleLoader::unregisterFilePath(":/css/custom.css");
       
   172     
       
   173     mDialog->setAttribute( Qt::WA_DeleteOnClose, true );
       
   174     mDialog->close();
       
   175     // Remove the pointer from QScopedPointer to prevent double deallocation
       
   176     mDialog.take();
       
   177     
       
   178     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_DWLANWIZARDPRIVATE_DONE,
       
   179         "WlanWizardPrivate::~WlanWizardPrivate-Done;this=%x",
       
   180         this );
       
   181 }
       
   182 
       
   183 /*!
       
   184    See WlanWizard::setParameters().
       
   185  */
       
   186 void WlanWizardPrivate::setParameters(
       
   187     const QString &ssid, 
       
   188     int networkMode, 
       
   189     int securityMode, 
       
   190     bool usePsk,
       
   191     bool hidden, 
       
   192     bool wps)
       
   193 {
       
   194     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_SETPARAMETERS, 
       
   195         "WlanWizardPrivate::setParameters;this=%x", 
       
   196         this );
       
   197     
       
   198     mFirstPageId = getNextPageId(
       
   199         ssid, networkMode, securityMode, usePsk, hidden, wps);
       
   200     
       
   201     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_SETPARAMETERS_DONE, 
       
   202         "WlanWizardPrivate::setParameters - Done;this=%x", 
       
   203         this );
       
   204 }
       
   205 
       
   206 /*!
       
   207    See WlanWizard::show().
       
   208  */
       
   209 void WlanWizardPrivate::show()
       
   210 {
       
   211     OstTraceExt2( TRACE_BORDER, WLANWIZARDPRIVATE_SHOW,
       
   212         "WlanWizardPrivate::show;this=%x;mFirstPageId=%{PageIds}", 
       
   213         ( unsigned )this, mFirstPageId );
       
   214     
       
   215     Q_ASSERT(mClosed == false);
       
   216     showPage(mFirstPageId, false);
       
   217     mDialog->show();
       
   218     
       
   219     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_SHOW_DONE,
       
   220         "WlanWizardPrivate::show - Done;this=%x;",
       
   221         (unsigned)this );
       
   222 }
       
   223 
       
   224 /*!
       
   225    See WlanWizard::setParameters() for descriptions of parameters.
       
   226    
       
   227    Based on the provided parameters next page id is returned.
       
   228    
       
   229    @return next page id based on provided configurations.
       
   230  */
       
   231 int WlanWizardPrivate::getNextPageId(
       
   232     const QString &ssid, 
       
   233     int networkMode, 
       
   234     int securityMode, 
       
   235     bool usePsk,
       
   236     bool hidden, 
       
   237     bool wps)
       
   238 {
       
   239     setConfiguration(ConfProcessSettings, true);
       
   240     setConfiguration(ConfSsid, ssid);
       
   241     setConfiguration(ConfNetworkMode, networkMode);
       
   242     setConfiguration(ConfSecurityMode, securityMode);
       
   243     setConfiguration(ConfUsePsk, usePsk);
       
   244     setConfiguration(ConfHiddenWlan, hidden);
       
   245 
       
   246     OstTrace1( TRACE_NORMAL, WLANWIZARDPRIVATE_GETNEXTPAGEID, 
       
   247         "WlanWizardPrivate::getNextPageId;wps=%u", 
       
   248         wps );
       
   249 
       
   250     return nextPageId(wps);
       
   251 }
       
   252 
       
   253 /*!
       
   254    Utility method for WLAN Wizard pages to query the wlanqtutils class.
       
   255    
       
   256    @return a valid pointer to WlanQtUtils class.
       
   257  */
       
   258 WlanQtUtils* WlanWizardPrivate::wlanQtUtils() const
       
   259 {
       
   260     Q_ASSERT(mWlanQtUtils);
       
   261     return mWlanQtUtils.data();
       
   262 }
       
   263 
       
   264 /*!
       
   265    Utility method for WLAN Wizard pages to query active wizard plugin object
       
   266    
       
   267    @return NULL in case plugin is not active.
       
   268  */ 
       
   269 WlanWizardPlugin* WlanWizardPrivate::wlanWizardPlugin() const
       
   270 {
       
   271     WlanWizardPlugin* plugin = NULL;
       
   272 
       
   273     if (isEapEnabled()) {
       
   274         plugin = mEapWizard.data();
       
   275         Q_ASSERT(plugin);
       
   276     }
       
   277     
       
   278     OstTrace1( TRACE_NORMAL, WLANWIZARDPRIVATE_WLANWIZARDPLUGIN, 
       
   279         "WlanWizardPrivate::wlanWizardPlugin;plugin=%x", 
       
   280         plugin );
       
   281     
       
   282     return plugin;
       
   283 }
       
   284 
       
   285 /*!
       
   286    Utility method for WLAN Wizard pages to query if EAP mode is active at the
       
   287    moment
       
   288    
       
   289    @return true in case EAP is currently activated.
       
   290  */
       
   291 bool WlanWizardPrivate::isEapEnabled() const
       
   292 {
       
   293     bool ret = false;
       
   294     int secMode = configuration(ConfSecurityMode).toInt();
       
   295 
       
   296     if (((secMode == CMManagerShim::WlanSecModeWpa || 
       
   297           secMode == CMManagerShim::WlanSecModeWpa2) && 
       
   298           !configuration(ConfUsePsk).toBool()) || 
       
   299         secMode == CMManagerShim::WlanSecMode802_1x) {
       
   300         ret = true;
       
   301     }
       
   302 
       
   303     OstTrace1( TRACE_NORMAL, WLANWIZARDPRIVATE_ISEAPENABLED, 
       
   304         "WlanWizardPrivate::isEapEnabled;ret=%u", 
       
   305         ret );
       
   306     
       
   307     return ret;
       
   308 }
       
   309 
       
   310 /*!
       
   311    Creates new iap or updates existing iap.
       
   312    
       
   313    @return false in case IAP creation/update failed.
       
   314  */
       
   315 bool WlanWizardPrivate::handleIap()
       
   316 {
       
   317     OstTrace0( TRACE_FLOW, WLANWIZARDPRIVATE_HANDLEIAP,
       
   318         "WlanWizardPrivate::handleIap" );
       
   319     
       
   320     bool ret = true;
       
   321     bool usePsk = true;
       
   322     int securityMode = configuration(ConfSecurityMode).toInt();
       
   323     WlanQtUtilsAp wlanAp;
       
   324    
       
   325     // Set default values
       
   326     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPsk, QString());
       
   327     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true );
       
   328     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, CMManagerShim::WepKeyIndex1 );
       
   329     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey1, QString());
       
   330     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey2, QString());
       
   331     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey3, QString());
       
   332     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey4, QString());
       
   333     
       
   334     // Set configuration
       
   335     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, configuration(ConfSsid));
       
   336     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, 
       
   337         configuration(ConfNetworkMode));
       
   338     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, securityMode );
       
   339     wlanAp.setValue(WlanQtUtilsAp::ConfIdHidden, configuration(ConfHiddenWlan));
       
   340     
       
   341     switch (securityMode) {
       
   342     case CMManagerShim::WlanSecModeWep:
       
   343         wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey1, configuration(ConfKeyWep1));
       
   344         wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey2, configuration(ConfKeyWep2));
       
   345         wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey3, configuration(ConfKeyWep3));
       
   346         wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey4, configuration(ConfKeyWep4));
       
   347         wlanAp.setValue(
       
   348             WlanQtUtilsAp::ConfIdWepDefaultIndex,
       
   349             configuration(ConfKeyWepDefault));
       
   350         break;
       
   351 
       
   352     case CMManagerShim::WlanSecModeWpa:
       
   353     case CMManagerShim::WlanSecModeWpa2:
       
   354         usePsk = configuration(ConfUsePsk).toBool();
       
   355         wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, usePsk);
       
   356         if (usePsk){
       
   357             wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPsk, configuration(ConfKeyWpa));
       
   358         }
       
   359         break;
       
   360     
       
   361     default:
       
   362         Q_ASSERT(securityMode == CMManagerShim::WlanSecModeOpen ||
       
   363             securityMode == CMManagerShim::WlanSecMode802_1x);
       
   364         // No WLAN Specific configuration
       
   365         break;
       
   366     }
       
   367     
       
   368     // Create IAP if does not exists or update the existing IAP
       
   369     int referenceId = configuration(ConfIapId).toInt();
       
   370     if (referenceId == WlanQtUtils::IapIdNone) {
       
   371         OstTrace0( TRACE_FLOW, WLANWIZARDPRIVATE_HANDLEIAP_CREATE, 
       
   372             "WlanWizardPrivate::handleIap: Create IAP" );
       
   373         
       
   374         referenceId = mWlanQtUtils->createIap(&wlanAp);
       
   375         setConfiguration(ConfIapId, referenceId);
       
   376         
       
   377         if (referenceId == WlanQtUtils::IapIdNone) {
       
   378             ret = false;
       
   379         }
       
   380     } else {
       
   381         OstTrace0( TRACE_FLOW, WLANWIZARDPRIVATE_HANDLEIAP_UPDATE, 
       
   382             "WlanWizardPrivate::handleIap: Update IAP" );
       
   383 
       
   384         ret = mWlanQtUtils->updateIap(referenceId, &wlanAp);
       
   385     }
       
   386    
       
   387     if (ret) {
       
   388         // Store Wizard plugin specific settings here.
       
   389         WlanWizardPlugin* plugin = wlanWizardPlugin();
       
   390         if (plugin) {
       
   391             OstTrace0( TRACE_FLOW, WLANWIZARDPRIVATE_HANDLEIAP_PLUGIN, 
       
   392                 "WlanWizardPrivate::handleIap: Plugin" );
       
   393             // Plugin gets the IAP ID from configuration
       
   394             ret = plugin->storeSettings();
       
   395         }
       
   396     }
       
   397     
       
   398     OstTrace1( TRACE_FLOW, WLANWIZARDPRIVATE_HANDLEIAP_DONE,
       
   399         "WlanWizardPrivate::handleIap: Done;ret=%d",
       
   400         ret );
       
   401     
       
   402     return ret;
       
   403 }
       
   404 
       
   405 /*!
       
   406    See WlanWizardHelper::configuration().
       
   407  */
       
   408 QVariant WlanWizardPrivate::configuration(ConfigurationId confId) const
       
   409 {
       
   410     Q_ASSERT(mConfigurations.contains(confId));
       
   411 
       
   412 #ifdef OST_TRACE_COMPILER_IN_USE
       
   413     QString tmp;
       
   414     QDebug tmpStream(&tmp);
       
   415     tmpStream << mConfigurations[confId];
       
   416     TPtrC16 string( tmp.utf16(), tmp.length() );
       
   417     
       
   418     OstTraceExt2( TRACE_NORMAL, WLANWIZARDPRIVATE_CONFIGURATIONS, 
       
   419         "WlanWizardPrivate::configuration;confId=%{ConfigurationId};string=%S", 
       
   420         (uint)confId, string );
       
   421 #endif
       
   422     
       
   423     return mConfigurations[confId];
       
   424 }
       
   425 
       
   426 /*!
       
   427    See WlanWizardHelper::setConfiguration().
       
   428  */
       
   429 void WlanWizardPrivate::setConfiguration(
       
   430     ConfigurationId confId, 
       
   431     const QVariant &value)
       
   432 {
       
   433 #ifdef OST_TRACE_COMPILER_IN_USE
       
   434     QString tmp;
       
   435     QDebug tmpStream(&tmp);
       
   436     tmpStream << value;
       
   437     TPtrC16 string( tmp.utf16(), tmp.length() );
       
   438     
       
   439     OstTraceExt2( TRACE_NORMAL, WLANWIZARDPRIVATE_SETCONFIGURATION, 
       
   440         "WlanWizardPrivate::setConfiguration;"
       
   441         "confId=%{ConfigurationId};string=%S", 
       
   442         (uint)confId, string );
       
   443 #endif
       
   444 
       
   445     mConfigurations[confId] = value;
       
   446 }
       
   447 
       
   448 /*!
       
   449  * See WlanWizardHelper::clearConfiguration().
       
   450  */
       
   451 void WlanWizardPrivate::clearConfiguration(ConfigurationId confId)
       
   452 {
       
   453     OstTrace1( TRACE_FLOW, WLANWIZARDPRIVATE_CLEARCONFIGURATION,
       
   454         "WlanWizardPrivate::clearConfiguration;confId=%{ConfigurationId}",
       
   455         (uint)confId );
       
   456     
       
   457     mConfigurations.remove(confId);
       
   458 }
       
   459 
       
   460 /*!
       
   461  * See WlanWizardHelper::configurationExists().
       
   462  */
       
   463 bool WlanWizardPrivate::configurationExists(ConfigurationId confId)
       
   464 {
       
   465     OstTrace1( TRACE_DUMP, WLANWIZARDPRIVATE_CONFIGURATIONEXISTS,
       
   466         "WlanWizardPrivate::configurationExists;confId=%{ConfigurationId}",
       
   467         (uint)confId );
       
   468     
       
   469     return mConfigurations[confId].isValid();
       
   470 }
       
   471     
       
   472 /*!
       
   473    See WlanWizardHelper::enableNextButton().
       
   474  */
       
   475 void WlanWizardPrivate::enableNextButton(bool enable)
       
   476 {
       
   477     OstTraceExt2( TRACE_FLOW, WLANWIZARDPRIVATE_ENABLENEXTBUTTON,
       
   478         "WlanWizardPrivate::enableNextButton;this=%x;enable=%x",
       
   479         (unsigned)this, (uint)enable );
       
   480     mActionNext->setEnabled(enable);
       
   481 }
       
   482 
       
   483 /*!
       
   484    See WlanWizardHelper::addPage().
       
   485  */
       
   486 void WlanWizardPrivate::addPage(int pageId, WlanWizardPage *page)
       
   487 {
       
   488     OstTraceExt3( TRACE_FLOW, WLANWIZARDPRIVATE_ADDPAGE, 
       
   489         "WlanWizardPrivate::addPage;this=%x;pageId=%{PageIds};page=%x",
       
   490         (unsigned)this, pageId, (uint)(page) );
       
   491 
       
   492     Q_ASSERT(!mPages.contains(pageId));
       
   493     mPages[pageId] = page;
       
   494 }
       
   495 
       
   496 /*!
       
   497    See WlanWizardHelper::nextPage().
       
   498  */
       
   499 void WlanWizardPrivate::nextPage()
       
   500 {
       
   501     OstTrace1( TRACE_FLOW, WLANWIZARDPRIVATE_NEXTPAGE,
       
   502         "WlanWizardPrivate::nextPage;this=%x",
       
   503         this );
       
   504     
       
   505     mPageFinished = true;
       
   506     toNextPage();
       
   507 }
       
   508 
       
   509 /*!
       
   510    See WlanWizardHelper::mainWindow().
       
   511  */
       
   512 HbMainWindow* WlanWizardPrivate::mainWindow() const
       
   513 {
       
   514     return mMainWindow;
       
   515 }
       
   516 
       
   517 /*!
       
   518    See WlanWizardHelper::isCurrentPage().
       
   519  */
       
   520 bool WlanWizardPrivate::isCurrentPage(const HbWidget *page) const
       
   521 {
       
   522     bool ret = false;
       
   523     if (mStackedWidget->currentWidget() == page) {
       
   524         ret = true;
       
   525     }
       
   526     
       
   527     OstTraceExt2( TRACE_FLOW, WLANWIZARDPRIVATE_ISCURRENTPAGE, 
       
   528         "WlanWizardPrivate::isCurrentPage;page=%x;ret=%d", 
       
   529         (uint)page, ret);
       
   530     
       
   531     return ret;
       
   532 }
       
   533 
       
   534 /*!
       
   535    See WlanWizardHelper::nextPageId()
       
   536  */
       
   537 int WlanWizardPrivate::nextPageId(bool useWps)
       
   538 {
       
   539     int ret;
       
   540     if (useWps) {
       
   541         ret = WlanWizardPage::PageWpsStart;
       
   542     } else {
       
   543         int secMode = configuration(WlanWizardHelper::ConfSecurityMode).toInt();
       
   544         switch (secMode) {
       
   545         case CMManagerShim::WlanSecModeWep:
       
   546             ret = WlanWizardPageInternal::PageKeyQuery;
       
   547             break;
       
   548             
       
   549         case CMManagerShim::WlanSecModeWpa:
       
   550         case CMManagerShim::WlanSecModeWpa2:
       
   551             if (configuration(WlanWizardHelper::ConfUsePsk).toBool()) {
       
   552                 ret = WlanWizardPageInternal::PageKeyQuery;
       
   553             } else {
       
   554                 ret = WlanWizardPage::PageEapStart;
       
   555             }
       
   556             break;
       
   557             
       
   558         case CMManagerShim::WlanSecMode802_1x:
       
   559             ret = WlanWizardPage::PageEapStart;
       
   560             break;
       
   561             
       
   562         default:
       
   563             Q_ASSERT(
       
   564                 secMode == CMManagerShim::WlanSecModeOpen || 
       
   565                 secMode == CMManagerShim::WlanSecModeWapi);
       
   566             
       
   567             setConfiguration(ConfSecurityMode, CMManagerShim::WlanSecModeOpen);
       
   568             ret = WlanWizardPageInternal::PageProcessSettings;
       
   569             break;
       
   570         }
       
   571     }
       
   572 
       
   573     OstTraceExt3( TRACE_NORMAL, WLANWIZARDPRIVATE_NEXTPAGEID,
       
   574         "WlanWizardPrivate::nextPageId;this=%x;useWps=%x;ret=%{PageIds}",
       
   575         ( unsigned )this, ( TUint )( useWps ), ret );
       
   576 
       
   577     return ret;
       
   578 }
       
   579 
       
   580 /*!
       
   581    Called when Cancel toolbar button is pressed. In case IAP has been created
       
   582    it will be disconnected and the IAP settings are deleted and finally the
       
   583    wizard is closed. 
       
   584    
       
   585    Indicates also to the current wizard page that cancel has been pressed.
       
   586  */
       
   587 void WlanWizardPrivate::cancelTriggered()
       
   588 {
       
   589     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_CANCELTRIGGERED,
       
   590         "WlanWizardPrivate::cancelTriggered;this=%x",
       
   591         this );
       
   592     
       
   593     // Disconnect receiving more signals from any actions
       
   594     disconnectActions();
       
   595     
       
   596     mPageTimer->stop();
       
   597 
       
   598     HbWidget *widget = qobject_cast<HbWidget*>(mStackedWidget->currentWidget());
       
   599     Q_ASSERT(widget);
       
   600     mPageMapper[widget]->cancelTriggered();
       
   601 
       
   602     int referenceId = configuration(ConfIapId).toInt();
       
   603     if (referenceId != WlanQtUtils::IapIdNone) {
       
   604         // call disconnect even if
       
   605         // - connection is not open
       
   606         // - connection establishment is ongoing
       
   607         mWlanQtUtils->disconnectIap(referenceId);
       
   608         
       
   609         // if IAP deletion fails, there is nothing we can do with it
       
   610         mWlanQtUtils->deleteIap(referenceId);
       
   611         setConfiguration(ConfIapId, WlanQtUtils::IapIdNone);
       
   612     }
       
   613     closeViews();
       
   614     Q_ASSERT(q_ptr);
       
   615 
       
   616     OstTrace0( TRACE_BORDER, WLANWIZARDPRIVATE_CANCELTRIGGERED_EMIT,
       
   617         "WlanWizardPrivate::cancelTriggered - emit cancelled()" );
       
   618     
       
   619     emit q_ptr->cancelled();
       
   620     
       
   621     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_CANCELTRIGGERED_DONE,
       
   622         "WlanWizardPrivate::cancelTriggered - Done;this=%x", this );
       
   623 }
       
   624 
       
   625 /*!
       
   626    Called when Previous toolbar button is pressed. Shows the previous wizard 
       
   627    page in stacked widget and indicates wizard page that previous has been 
       
   628    pressed.
       
   629  */
       
   630 void WlanWizardPrivate::previousTriggered()
       
   631 {
       
   632     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_PREVIOUSTRIGGERED,
       
   633         "WlanWizardPrivate::previousTriggered;this=%x",
       
   634         this );
       
   635     
       
   636     mPageTimer->stop();
       
   637 
       
   638     int index = mStackedWidget->currentIndex();
       
   639     HbWidget *widget = qobject_cast<HbWidget*>(mStackedWidget->currentWidget());
       
   640     Q_ASSERT(widget);
       
   641     int back = mPageMapper[widget]->previousTriggered();
       
   642 
       
   643     // check that at least one page is left in the stack
       
   644     Q_ASSERT( back < mStackedWidget->count());
       
   645 
       
   646     // When a widget which is last in the stack is removed the currentindex
       
   647     // is automatically updated.
       
   648     for (int i = 0; i < back; ++i) {
       
   649         mStackedWidget->removeAt(index - i);
       
   650     }
       
   651 
       
   652     widget = qobject_cast<HbWidget*> (mStackedWidget->currentWidget());
       
   653     Q_ASSERT(widget);
       
   654     WlanWizardPage* page = mPageMapper[widget];
       
   655     Q_ASSERT(page);
       
   656     // In error case if page (value) is not found default contructed key is 
       
   657     // returned, in this case default value for int is 0 which means PageNone.
       
   658     updateFrame(mPages.key(page));
       
   659     enableNextButton(page->showPage());
       
   660     
       
   661     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_PREVIOUSTRIGGERED_DONE,
       
   662         "WlanWizardPrivate::previousTriggered - Done;this=%x",
       
   663         this );
       
   664 }
       
   665 
       
   666 /*!
       
   667    Next toolbar button has been pressed. Wizard framework asks from the current
       
   668    page what should be the next page id and shows it.
       
   669  */
       
   670 void WlanWizardPrivate::nextTriggered()
       
   671 {
       
   672     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_NEXTTRIGGERED,
       
   673         "WlanWizardPrivate::nextTriggered;this=%x",
       
   674         this );
       
   675     
       
   676     mPageTimer->stop();
       
   677 
       
   678     HbWidget *widget = qobject_cast<HbWidget*>(mStackedWidget->currentWidget());
       
   679     Q_ASSERT(widget);
       
   680 
       
   681     bool removeFromStack;
       
   682     int pageId = mPageMapper[widget]->nextId(removeFromStack);
       
   683     showPage(pageId, removeFromStack);
       
   684     
       
   685     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_NEXTTRIGGERED_DONE,
       
   686         "WlanWizardPrivate::nextTriggered - Done;this=%x",
       
   687         this );
       
   688 }
       
   689 
       
   690 /*!
       
   691    Finish button has been pressed. Closes the wizard and sends finished()
       
   692    signal to the client. 
       
   693  */
       
   694 void WlanWizardPrivate::finishTriggered()
       
   695 {
       
   696     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_FINISHTRIGGERED,
       
   697         "WlanWizardPrivate::finishTriggered;this=%x",
       
   698         this );
       
   699     
       
   700     // Disconnect receiving more signals from any actions
       
   701     disconnectActions();
       
   702     
       
   703     mPageTimer->stop();
       
   704     closeViews();
       
   705 
       
   706     Q_ASSERT(q_ptr);
       
   707     emit q_ptr->finished(
       
   708         configuration(ConfIapId).toInt(), 
       
   709         configuration(ConfConnected).toBool());
       
   710     
       
   711     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_FINISHTRIGGERED_DONE,
       
   712         "WlanWizardPrivate::finishTriggered - Done;this=%x",
       
   713         this );
       
   714 }
       
   715 
       
   716 /*!
       
   717    In case wizard page is using timer protection for the page, this is the
       
   718    slot to handle the callback from the timer.
       
   719  */
       
   720 void WlanWizardPrivate::onTimeOut()
       
   721 {
       
   722     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_ONTIMEOUT,
       
   723         "WlanWizardPrivate::onTimeOut;this=%x",
       
   724         this );
       
   725     
       
   726     toNextPage();
       
   727     
       
   728     OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_ONTIMEOUT_DONE,
       
   729         "WlanWizardPrivate::onTimeOut - Done;this=%x",
       
   730         this );
       
   731 }
       
   732 
       
   733 /*!
       
   734    Slot to start wizard page operation asynchronous. Starts also the timer
       
   735    to protect the wizard page.
       
   736  */
       
   737 void WlanWizardPrivate::startPageOperation()
       
   738 {
       
   739     // Process this if wizard has not been closed
       
   740     if (mClosed == false) {
       
   741         OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_STARTPAGEOPERATION,
       
   742             "WlanWizardPrivate::startPageOperation;this=%x",
       
   743             this );
       
   744         
       
   745         HbWidget *widget = 
       
   746             qobject_cast<HbWidget*>(mStackedWidget->currentWidget());
       
   747         Q_ASSERT(widget);
       
   748         mPageFinished = false;
       
   749         mPageTimer->start(PageTimeout);
       
   750         mPageMapper[widget]->startOperation();
       
   751         
       
   752         OstTrace1( TRACE_BORDER, WLANWIZARDPRIVATE_STARTPAGEOPERATION_DONE,
       
   753             "WlanWizardPrivate::startPageOperation - DONE;this=%x",
       
   754             this );
       
   755     }
       
   756 }
       
   757 
       
   758 /*!
       
   759    In case the wizard page uses timer protection this method determines when
       
   760    the next page is shown.
       
   761  */
       
   762 void WlanWizardPrivate::toNextPage()
       
   763 {
       
   764     if (mPageFinished && !(mPageTimer->isActive())) {
       
   765         OstTrace1( TRACE_FLOW, WLANWIZARDPRIVATE_TONEXTPAGE,
       
   766             "WlanWizardPrivate::toNextPage;this=%x",
       
   767             this );
       
   768         
       
   769         // process this asynchronous. Main purpose is to release the current
       
   770         // call stack and process the page change using new call stack
       
   771         QMetaObject::invokeMethod(this, "nextTriggered", Qt::QueuedConnection);
       
   772     }
       
   773 }
       
   774 
       
   775 /*!
       
   776    Show requested page and removes the current wizard page from the stack if
       
   777    required. This method updates the title and toolbar accordingly.
       
   778    
       
   779    See WlanWizardPage::nextId()
       
   780    
       
   781    @param [in] pageId Wizard Page ID to be shown
       
   782    @param [in] removeFromStack if true the current wizard page is removed from
       
   783                                the stackedwidget. 
       
   784  */
       
   785 void WlanWizardPrivate::showPage(int pageId, bool removeFromStack)
       
   786 {
       
   787     OstTraceExt3( TRACE_FLOW, WLANWIZARDPRIVATE_SHOWPAGE,
       
   788         "WlanWizardPrivate::showPage;this=%x;"
       
   789         "pageId=%{PageIds};removeFromStack=%x",
       
   790         ( unsigned )this, pageId, ( TUint )( removeFromStack ) );
       
   791     
       
   792     // PageNone is returned by wizard pages when some validation of page content
       
   793     // has not passed and the page does not want to process wizard to next page
       
   794     if (pageId == WlanWizardPage::PageNone) {
       
   795         return;
       
   796     }
       
   797     
       
   798     //  PageProcessSettings is shown only when WLAN AP is found in scanning
       
   799     // 1/ when client calls setParameters()
       
   800     // 2/ scanning page has found match with given SSID
       
   801     if (pageId == WlanWizardPage::PageProcessSettings) {
       
   802         if (configuration(ConfProcessSettings).toBool() == false) {
       
   803             if (handleIap()){
       
   804                 pageId = WlanWizardPageInternal::PageSummary;
       
   805             } else {
       
   806                 pageId = WlanWizardPage::PageGenericError;
       
   807                 setConfiguration(
       
   808                     ConfGenericErrorString, 
       
   809                     hbTrId("txt_occ_dialog_unable_to_save_settings_please_ret"));
       
   810                 
       
   811                 setConfiguration(
       
   812                     ConfGenericErrorPageStepsBackwards, 
       
   813                     WlanWizardPage::OneStepBackwards);
       
   814             }
       
   815             OstTraceExt2( TRACE_FLOW, WLANWIZARDPRIVATE_SHOWPAGE_UPDATE,
       
   816                 "WlanWizardPrivate::showPage - change page;this=%x;"
       
   817                 "pageId=%{PageIds}",
       
   818                 ( unsigned )this, pageId);
       
   819         }
       
   820     }
       
   821 
       
   822     // Create visualization of next page and store it to mappers
       
   823     WlanWizardPage* page = mPages[pageId];
       
   824     Q_ASSERT(page);
       
   825     HbWidget* widget = page->initializePage();
       
   826     Q_ASSERT(widget);
       
   827     mPageMapper[widget] = page;
       
   828 
       
   829     // index calculation has to be happened before adding new widget into
       
   830     // the stacked widget. Since the internal implementation of stackedwidget
       
   831     // sets the first widget in the stack to current widget..
       
   832     // and when there are not any widgets in the stack the current index is
       
   833     // -1. Valid index starts from 0.
       
   834     int index = mStackedWidget->currentIndex();
       
   835 
       
   836     if (removeFromStack) {
       
   837         // widget is removed from the stacked widget, not deleted
       
   838         mStackedWidget->removeAt(index);
       
   839     } else {
       
   840         index++;
       
   841     }
       
   842     mStackedWidget->addWidget(widget);
       
   843     mStackedWidget->setCurrentIndex(index);
       
   844     updateFrame(pageId);
       
   845     enableNextButton(page->showPage());    
       
   846 
       
   847     // If wizard page needs to start some control operation trigger it 
       
   848     // asyncronously so that the UI gets more priority to get painted correctly
       
   849     // before any operation takes place in wizard page. This is important for
       
   850     // timer protected pages. Makes wizard to work smother from UI perspective
       
   851     if (page->requiresStartOperation()) {
       
   852         OstTrace0( TRACE_FLOW, WLANWIZARDPRIVATE_SHOWPAGE_INVOKE,
       
   853             "WlanWizardPrivate::showPage - Invoke startOperation" );
       
   854         
       
   855         QMetaObject::invokeMethod(this, "startPageOperation", Qt::QueuedConnection);
       
   856     }
       
   857 }
       
   858 
       
   859 /*!
       
   860    Creates all control objects of WLAN wizard pages which are inherited from
       
   861    WlanWizardPage and adds those into a internal database. 
       
   862  */
       
   863 void WlanWizardPrivate::createPages()
       
   864 {
       
   865     OstTrace0(
       
   866         TRACE_NORMAL,
       
   867         WLANWIZARDPRIVATE_CREATEPAGES,
       
   868         "WlanWizardPrivate::createPages");
       
   869     
       
   870     addPage(
       
   871         WlanWizardPageInternal::PageKeyQuery, 
       
   872         new WlanWizardPageKeyQuery(this));
       
   873     
       
   874     addPage(
       
   875         WlanWizardPageInternal::PageProcessSettings, 
       
   876         new WlanWizardPageProcessingSettings(this));
       
   877     
       
   878     addPage(
       
   879         WlanWizardPageInternal::PageSummary, 
       
   880         new WlanWizardPageSummary(this));
       
   881 
       
   882     addPage(
       
   883         WlanWizardPageInternal::PageGenericError, 
       
   884         new WlanWizardPageGenericError(this));
       
   885     
       
   886     addPage(
       
   887         WlanWizardPageInternal::PageSsid,
       
   888         new WlanWizardPageSsid(this));
       
   889     
       
   890     addPage(
       
   891         WlanWizardPageInternal::PageScanning, 
       
   892         new WlanWizardPageScanning(this));
       
   893     
       
   894     addPage(
       
   895         WlanWizardPageInternal::PageNetworkMode, 
       
   896         new WlanWizardPageNetworkMode(this));
       
   897     
       
   898     addPage(
       
   899         WlanWizardPageInternal::PageNetworkSecurity, 
       
   900         new WlanWizardPageSecurityMode(this));
       
   901 }
       
   902 
       
   903 /*!
       
   904    Called when wizard is closed 
       
   905    - cancelled by the user
       
   906    - finished by the user
       
   907  */
       
   908 void WlanWizardPrivate::closeViews()
       
   909 {
       
   910     mDialog->hide();
       
   911     mClosed = true;
       
   912 }
       
   913 
       
   914 /*!
       
   915    This method takes care of the title of wizard and toolbutton. Correct items
       
   916    are selected based on the \a pageId and the amount of objects in the stacked
       
   917    widget.
       
   918    
       
   919    @param [in] pageId Wizard Page Id
       
   920  */
       
   921 void WlanWizardPrivate::updateFrame(int pageId)
       
   922 {
       
   923     int currentIndex = mStackedWidget->currentIndex();
       
   924 
       
   925     OstTraceExt3( TRACE_FLOW, WLANWIZARDPRIVATE_UPDATEFRAME, 
       
   926         "WlanWizardPrivate::updateFrame;this=%x;pageId=%{PageIds};currentIndex=%d",
       
   927         (unsigned)this, pageId, (uint)(currentIndex) );
       
   928     
       
   929     // For last page (summary) show Finish instead of Next button
       
   930     if (pageId == WlanWizardPageInternal::PageSummary) {
       
   931         mTitle->setPlainText(hbTrId("txt_occ_title_wlan_setup_wizard_summary"));
       
   932         mActionFinish->setVisible(true);
       
   933         mActionNext->setVisible(false);
       
   934         mActionPrevious->setVisible(false);
       
   935     } else {
       
   936         // Index starts from zero, wizard page numbering starts from one.
       
   937         mTitle->setPlainText(
       
   938             hbTrId("txt_occ_title_wlan_setup_wizard_step_l1").arg(
       
   939                 currentIndex + 1));
       
   940         mActionFinish->setVisible(false);
       
   941         mActionNext->setVisible(true);
       
   942 
       
   943         // If first page is shown then Previous button is disabled
       
   944         if (currentIndex < 1) {
       
   945             mActionPrevious->setVisible(false);
       
   946         } else {
       
   947             mActionPrevious->setVisible(true);
       
   948             if (pageId == WlanWizardPage::PageProcessSettings) {
       
   949                 mActionPrevious->setEnabled(false);
       
   950             } else {
       
   951                 mActionPrevious->setEnabled(true);
       
   952             }
       
   953         }
       
   954     }
       
   955 }
       
   956 
       
   957 /*!
       
   958    Loads widgets and objects from the docml file. 
       
   959  */
       
   960 void WlanWizardPrivate::loadDocml()
       
   961 {
       
   962     bool ok = true;
       
   963     
       
   964     mDocLoader->load(":/docml/occ_wlan_wizard_main.docml", &ok);
       
   965     Q_ASSERT(ok);
       
   966 
       
   967     mDialog.reset( qobject_cast<HbDialog*> (mDocLoader->findWidget("dialog")) );
       
   968     Q_ASSERT(mDialog != NULL);
       
   969 
       
   970     mTitle = qobject_cast<HbLabel*> (mDocLoader->findWidget("title"));
       
   971     Q_ASSERT(mTitle != NULL);
       
   972 
       
   973     mStackedWidget = 
       
   974         qobject_cast<HbStackedWidget*> (mDocLoader->findWidget("stackedWidget"));
       
   975     Q_ASSERT(mStackedWidget != NULL);
       
   976 
       
   977     mActionNext = qobject_cast<HbAction*> (mDocLoader->findObject("actionNext"));
       
   978     Q_ASSERT(mActionNext != NULL);
       
   979 
       
   980     mActionPrevious = 
       
   981         qobject_cast<HbAction*> (mDocLoader->findObject("actionPrevious"));
       
   982     Q_ASSERT(mActionPrevious != NULL);
       
   983 
       
   984     mActionFinish = 
       
   985         qobject_cast<HbAction*> (mDocLoader->findObject("actionFinish"));
       
   986     Q_ASSERT(mActionFinish != NULL);
       
   987 
       
   988     mActionCancel = 
       
   989         qobject_cast<HbAction*> (mDocLoader->findObject("actionCancel"));
       
   990     Q_ASSERT(mActionCancel != NULL);
       
   991     
       
   992     // Actions are added from left to right to the toolbar of dialog
       
   993     mDialog->addAction(mActionPrevious);
       
   994     mDialog->addAction(mActionCancel);
       
   995     mDialog->addAction(mActionNext);
       
   996     mDialog->addAction(mActionFinish);
       
   997     
       
   998     // TODO: workaround to prevent action to close the dialog
       
   999     disconnect(mActionPrevious, SIGNAL(triggered()), mDialog.data(), SLOT(close()));
       
  1000     disconnect(mActionCancel, SIGNAL(triggered()), mDialog.data(), SLOT(close()));
       
  1001     disconnect(mActionNext, SIGNAL(triggered()), mDialog.data(), SLOT(close()));
       
  1002     disconnect(mActionFinish, SIGNAL(triggered()), mDialog.data(), SLOT(close()));
       
  1003 
       
  1004     ok = true;
       
  1005     ok = connect(mPageTimer, SIGNAL(timeout()), this, SLOT(onTimeOut()));
       
  1006     Q_ASSERT(ok);
       
  1007     
       
  1008     ok = connect(
       
  1009         mActionNext, SIGNAL(triggered()), 
       
  1010         this, SLOT(nextTriggered()));
       
  1011     Q_ASSERT(ok);
       
  1012     
       
  1013     ok = connect(
       
  1014         mActionPrevious, SIGNAL(triggered()), 
       
  1015         this, SLOT(previousTriggered()));
       
  1016     Q_ASSERT(ok);
       
  1017     
       
  1018     ok = connect(
       
  1019         mActionFinish, SIGNAL(triggered()), 
       
  1020         this, SLOT(finishTriggered()));
       
  1021     Q_ASSERT(ok);
       
  1022     
       
  1023     ok = connect(
       
  1024         mActionCancel, SIGNAL(triggered()), 
       
  1025         this, SLOT(cancelTriggered()));
       
  1026     Q_ASSERT(ok);
       
  1027 
       
  1028     // TODO: workaround for full screen dialog, with docml it is possible to
       
  1029     // define fullscreen dialog, mut resize is not done correctly when orientation
       
  1030     // is changed. See TSW Error: MTAA-854DK8
       
  1031     ok = HbStyleLoader::registerFilePath(":/css/custom.css");
       
  1032     Q_ASSERT(ok);
       
  1033 }
       
  1034 
       
  1035 /*!
       
  1036    Disconnect receiving triggered() signal from any toolbar action.
       
  1037  */
       
  1038 void WlanWizardPrivate::disconnectActions()
       
  1039 {
       
  1040     disconnect(
       
  1041         mActionNext, SIGNAL(triggered()), 
       
  1042         this, SLOT(nextTriggered()));
       
  1043     
       
  1044     disconnect(
       
  1045         mActionPrevious, SIGNAL(triggered()), 
       
  1046         this, SLOT(previousTriggered()));
       
  1047     
       
  1048     disconnect(
       
  1049         mActionFinish, SIGNAL(triggered()), 
       
  1050         this, SLOT(finishTriggered()));
       
  1051 
       
  1052     disconnect(
       
  1053         mActionCancel, SIGNAL(triggered()), 
       
  1054         this, SLOT(cancelTriggered()));
       
  1055 }