wlanutilities/wlanwizard/src/wlanwizardpagescanning.cpp
author hgs
Thu, 24 Jun 2010 10:49:51 +0300
changeset 39 7b3e49e4608a
parent 31 e8f4211554fb
child 43 72ebcbb64834
child 50 d4198dcb9983
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
39
hgs
parents: 31
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 31
diff changeset
     3
* All rights reserved.
hgs
parents: 31
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents: 31
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents: 31
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents: 31
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 31
diff changeset
     8
*
hgs
parents: 31
diff changeset
     9
* Initial Contributors:
hgs
parents: 31
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents: 31
diff changeset
    11
*
hgs
parents: 31
diff changeset
    12
* Contributors:
hgs
parents: 31
diff changeset
    13
*
hgs
parents: 31
diff changeset
    14
* Description: 
hgs
parents: 31
diff changeset
    15
* WLAN Wizard Page: Scan processing.
hgs
parents: 31
diff changeset
    16
*/
31
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// System includes
39
hgs
parents: 31
diff changeset
    19
#include <HbParameterLengthLimiter>
31
hgs
parents:
diff changeset
    20
#include <HbMainWindow>
hgs
parents:
diff changeset
    21
#include <HbDocumentLoader>
hgs
parents:
diff changeset
    22
#include <HbWidget>
hgs
parents:
diff changeset
    23
#include <HbLabel>
hgs
parents:
diff changeset
    24
#include <HbProgressBar>
hgs
parents:
diff changeset
    25
#include <cmmanagerdefines_shim.h>
hgs
parents:
diff changeset
    26
#include <wlanqtutils.h>
hgs
parents:
diff changeset
    27
#include <wlanqtutilsap.h>
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// User includes
hgs
parents:
diff changeset
    30
#include "wlanwizard_p.h"
hgs
parents:
diff changeset
    31
#include "wlanwizardpagescanning.h"
hgs
parents:
diff changeset
    32
#include "OstTraceDefinitions.h"
hgs
parents:
diff changeset
    33
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
    34
#include "wlanwizardpagescanningTraces.h"
hgs
parents:
diff changeset
    35
#endif
hgs
parents:
diff changeset
    36
39
hgs
parents: 31
diff changeset
    37
// Local constants
hgs
parents: 31
diff changeset
    38
31
hgs
parents:
diff changeset
    39
/*!
39
hgs
parents: 31
diff changeset
    40
 * Constructor method for the scanning view object.
hgs
parents: 31
diff changeset
    41
 * @param [in] parent pointer to parent object.
31
hgs
parents:
diff changeset
    42
 */
hgs
parents:
diff changeset
    43
WlanWizardPageScanning::WlanWizardPageScanning(WlanWizardPrivate* parent) :
hgs
parents:
diff changeset
    44
    WlanWizardPageInternal(parent),
hgs
parents:
diff changeset
    45
    mWidget(NULL),
hgs
parents:
diff changeset
    46
    mLabel(NULL),
hgs
parents:
diff changeset
    47
    mLoader(NULL),
hgs
parents:
diff changeset
    48
    mNextPageId(WlanWizardPage::PageNone),
39
hgs
parents: 31
diff changeset
    49
    mScanResultsAvailable(false),
hgs
parents: 31
diff changeset
    50
    mScanStatus(WlanQtUtils::ScanStatusOk)
31
hgs
parents:
diff changeset
    51
{
hgs
parents:
diff changeset
    52
    WlanQtUtils* utils = mWizard->wlanQtUtils();
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
    // Connect normal scan completion signal from wlanQtUtils to result
hgs
parents:
diff changeset
    55
    // handler. Connect here instead of initializePage, since this signal may
hgs
parents:
diff changeset
    56
    // need to be caught event if the window is not active.
39
hgs
parents: 31
diff changeset
    57
    bool ok = connect(
hgs
parents: 31
diff changeset
    58
        utils,
hgs
parents: 31
diff changeset
    59
        SIGNAL(wlanScanApReady(int)),
hgs
parents: 31
diff changeset
    60
        this,
hgs
parents: 31
diff changeset
    61
        SLOT(wlanScanResultPreCheck(int)));
hgs
parents: 31
diff changeset
    62
    
hgs
parents: 31
diff changeset
    63
    Q_ASSERT(ok);
31
hgs
parents:
diff changeset
    64
}
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
/*!
hgs
parents:
diff changeset
    67
 * Destructor. Loader widget is deleted.
hgs
parents:
diff changeset
    68
 * All document widgets are deleted by wlanwizard_p destructor.
hgs
parents:
diff changeset
    69
 */
hgs
parents:
diff changeset
    70
WlanWizardPageScanning::~WlanWizardPageScanning()
hgs
parents:
diff changeset
    71
{
hgs
parents:
diff changeset
    72
    delete mLoader;
hgs
parents:
diff changeset
    73
}
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
/*!
39
hgs
parents: 31
diff changeset
    76
 * Page initialization. If view is already loaded, does nothing. Inherited from
hgs
parents: 31
diff changeset
    77
 * WlanWizardPage.
hgs
parents: 31
diff changeset
    78
 * @return pointer to widget "occ_add_wlan_06".
31
hgs
parents:
diff changeset
    79
 */
hgs
parents:
diff changeset
    80
HbWidget* WlanWizardPageScanning::initializePage()
hgs
parents:
diff changeset
    81
{
39
hgs
parents: 31
diff changeset
    82
    OstTrace0(
hgs
parents: 31
diff changeset
    83
        TRACE_NORMAL,
hgs
parents: 31
diff changeset
    84
        WLANWIZARDPAGESCANNING_INITIALIZEPAGE,
hgs
parents: 31
diff changeset
    85
        "WlanWizardPageScanning::initializePage");
31
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
    // Next page id is reset with each initialization.    
hgs
parents:
diff changeset
    88
    mNextPageId = WlanWizardPage::PageNone;
hgs
parents:
diff changeset
    89
hgs
parents:
diff changeset
    90
    if (mWidget == NULL) {
hgs
parents:
diff changeset
    91
        mLoader = new HbDocumentLoader(mWizard->mainWindow());
hgs
parents:
diff changeset
    92
hgs
parents:
diff changeset
    93
        bool ok;
hgs
parents:
diff changeset
    94
hgs
parents:
diff changeset
    95
        mLoader->load(":/docml/occ_add_wlan_06.docml", &ok);
39
hgs
parents: 31
diff changeset
    96
        Q_ASSERT(ok);
31
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
        // Initialize orientation
39
hgs
parents: 31
diff changeset
    99
        loadDocmlSection(mWizard->mainWindow()->orientation());
31
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
        // Load widgets
hgs
parents:
diff changeset
   102
        mWidget = qobject_cast<HbWidget*> (mLoader->findWidget(
hgs
parents:
diff changeset
   103
            "occ_add_wlan_06"));
39
hgs
parents: 31
diff changeset
   104
        Q_ASSERT(mWidget != NULL);
31
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
        mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog"));
39
hgs
parents: 31
diff changeset
   107
        Q_ASSERT(mLabel != NULL);
31
hgs
parents:
diff changeset
   108
hgs
parents:
diff changeset
   109
        WlanQtUtils* utils = mWizard->wlanQtUtils();
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
        // Connect orientation signal from the main window to orientation
hgs
parents:
diff changeset
   112
        // loader.
39
hgs
parents: 31
diff changeset
   113
        ok = connect(
hgs
parents: 31
diff changeset
   114
            mWizard->mainWindow(),
hgs
parents: 31
diff changeset
   115
            SIGNAL(orientationChanged(Qt::Orientation)),
hgs
parents: 31
diff changeset
   116
            this,
hgs
parents: 31
diff changeset
   117
            SLOT(loadDocmlSection(Qt::Orientation)));
hgs
parents: 31
diff changeset
   118
        Q_ASSERT(ok);
31
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
        // Connect direct scan completion signal from wlanQtUtils to result
hgs
parents:
diff changeset
   121
        // handler.
39
hgs
parents: 31
diff changeset
   122
        ok = connect(
hgs
parents: 31
diff changeset
   123
            utils,
hgs
parents: 31
diff changeset
   124
            SIGNAL(wlanScanDirectReady(int)),
hgs
parents: 31
diff changeset
   125
            this,
hgs
parents: 31
diff changeset
   126
            SLOT(wlanScanDirectReady(int)));
31
hgs
parents:
diff changeset
   127
        Q_ASSERT(ok);
hgs
parents:
diff changeset
   128
    }
hgs
parents:
diff changeset
   129
39
hgs
parents: 31
diff changeset
   130
    mLabel->setPlainText(HbParameterLengthLimiter(
hgs
parents: 31
diff changeset
   131
        hbTrId("txt_occ_dialog_searching")).arg(mWizard->configuration(
hgs
parents: 31
diff changeset
   132
            WlanWizardPrivate::ConfSsid).toString()));
hgs
parents: 31
diff changeset
   133
31
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
    return mWidget;
hgs
parents:
diff changeset
   136
}
hgs
parents:
diff changeset
   137
hgs
parents:
diff changeset
   138
/*!
hgs
parents:
diff changeset
   139
 * Sends the user to the next page.
39
hgs
parents: 31
diff changeset
   140
 * @param [out] removeFromStack is always true: this page is removed from the 
hgs
parents: 31
diff changeset
   141
 * stacked widget after "Next" button is pressed.
hgs
parents: 31
diff changeset
   142
 * @return the id value of the next page.
31
hgs
parents:
diff changeset
   143
 */
hgs
parents:
diff changeset
   144
int WlanWizardPageScanning::nextId(bool &removeFromStack) const
hgs
parents:
diff changeset
   145
{
hgs
parents:
diff changeset
   146
    removeFromStack = true;
hgs
parents:
diff changeset
   147
hgs
parents:
diff changeset
   148
    return mNextPageId;
hgs
parents:
diff changeset
   149
}
hgs
parents:
diff changeset
   150
hgs
parents:
diff changeset
   151
/*!
39
hgs
parents: 31
diff changeset
   152
 * This function reimplements WlanWizardPage::previousTriggered. When going
hgs
parents: 31
diff changeset
   153
 * back from scanning view, the ongoing scan operation is also stopped. Since
hgs
parents: 31
diff changeset
   154
 * there is no need to react to following the acknowledgement signal from
hgs
parents: 31
diff changeset
   155
 * wlanQtUtils, the corresponding handler slots are disconnected before the
hgs
parents: 31
diff changeset
   156
 * opration and immediately connected again.
hgs
parents: 31
diff changeset
   157
 * @return one step backwards value.
hgs
parents: 31
diff changeset
   158
 */
hgs
parents: 31
diff changeset
   159
int WlanWizardPageScanning::previousTriggered()
hgs
parents: 31
diff changeset
   160
{
hgs
parents: 31
diff changeset
   161
    disconnect(this, SLOT(wlanScanDirectReady(int)));
hgs
parents: 31
diff changeset
   162
    disconnect(this, SLOT(wlanScanResultPreCheck(int)));
hgs
parents: 31
diff changeset
   163
    
hgs
parents: 31
diff changeset
   164
    WlanQtUtils* utils = mWizard->wlanQtUtils();
hgs
parents: 31
diff changeset
   165
    
hgs
parents: 31
diff changeset
   166
    utils->stopWlanScan();
hgs
parents: 31
diff changeset
   167
hgs
parents: 31
diff changeset
   168
    bool ok = connect(
hgs
parents: 31
diff changeset
   169
        utils,
hgs
parents: 31
diff changeset
   170
        SIGNAL(wlanScanApReady(int)),
hgs
parents: 31
diff changeset
   171
        this,
hgs
parents: 31
diff changeset
   172
        SLOT(wlanScanResultPreCheck(int)));
hgs
parents: 31
diff changeset
   173
    Q_ASSERT(ok);
hgs
parents: 31
diff changeset
   174
    
hgs
parents: 31
diff changeset
   175
    ok = connect(
hgs
parents: 31
diff changeset
   176
        utils,
hgs
parents: 31
diff changeset
   177
        SIGNAL(wlanScanDirectReady(int)),
hgs
parents: 31
diff changeset
   178
        this,
hgs
parents: 31
diff changeset
   179
        SLOT(wlanScanDirectReady(int)));
hgs
parents: 31
diff changeset
   180
    Q_ASSERT(ok);
hgs
parents: 31
diff changeset
   181
    
hgs
parents: 31
diff changeset
   182
    return OneStepBackwards;
hgs
parents: 31
diff changeset
   183
    
hgs
parents: 31
diff changeset
   184
}
hgs
parents: 31
diff changeset
   185
hgs
parents: 31
diff changeset
   186
/*!
hgs
parents: 31
diff changeset
   187
 * This method is overrides the default implementation from WlanWizardPage.
hgs
parents: 31
diff changeset
   188
 * It indicates whether the Next-button should be enabled or not. It also resets
hgs
parents: 31
diff changeset
   189
 * the ConfProcessSettings-configuration to false - meaning that if no scan
hgs
parents: 31
diff changeset
   190
 * results are available, no iap is created.
hgs
parents: 31
diff changeset
   191
 * @return always false - the scanning proceeds to next window
hgs
parents: 31
diff changeset
   192
 * automatically or not at all.
31
hgs
parents:
diff changeset
   193
 */
hgs
parents:
diff changeset
   194
bool WlanWizardPageScanning::showPage()
hgs
parents:
diff changeset
   195
{
39
hgs
parents: 31
diff changeset
   196
    mWizard->setConfiguration(WlanWizardHelper::ConfProcessSettings, false);
31
hgs
parents:
diff changeset
   197
    return false;
hgs
parents:
diff changeset
   198
}
hgs
parents:
diff changeset
   199
hgs
parents:
diff changeset
   200
/*!
39
hgs
parents: 31
diff changeset
   201
 * Reimplements the default function in WlanWizardPage. Indicates to the
hgs
parents: 31
diff changeset
   202
 * framework that startOperation() function must be executed.
hgs
parents: 31
diff changeset
   203
 * @return true
hgs
parents: 31
diff changeset
   204
 * @see WlanWizardPage
31
hgs
parents:
diff changeset
   205
 */
hgs
parents:
diff changeset
   206
bool WlanWizardPageScanning::requiresStartOperation()
hgs
parents:
diff changeset
   207
{
hgs
parents:
diff changeset
   208
    return true;
hgs
parents:
diff changeset
   209
}
hgs
parents:
diff changeset
   210
hgs
parents:
diff changeset
   211
/*!
hgs
parents:
diff changeset
   212
 * Wlan scan is performed as a "post-initialization" which is executed in a
39
hgs
parents: 31
diff changeset
   213
 * separate scheduler loop. If scan results are available, starts reading them.
31
hgs
parents:
diff changeset
   214
 */
hgs
parents:
diff changeset
   215
void WlanWizardPageScanning::startOperation()
hgs
parents:
diff changeset
   216
{
hgs
parents:
diff changeset
   217
    OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_STARTOPERATION,
hgs
parents:
diff changeset
   218
        "WlanWizardPageScanning::startOperation - start AP scan if results"
hgs
parents:
diff changeset
   219
        " are available." );
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
    if (mScanResultsAvailable) {
hgs
parents:
diff changeset
   222
        mScanResultsAvailable = false;
hgs
parents:
diff changeset
   223
        wlanScanApReady();
hgs
parents:
diff changeset
   224
    }
hgs
parents:
diff changeset
   225
}
hgs
parents:
diff changeset
   226
39
hgs
parents: 31
diff changeset
   227
/*!
hgs
parents: 31
diff changeset
   228
 * Loads the document orientation information from occ_add_wlan_06.docml
hgs
parents: 31
diff changeset
   229
 * This is called each time phone orientation changes.
hgs
parents: 31
diff changeset
   230
 * @param [in] orientation indicates whether the phone is in portrait or
hgs
parents: 31
diff changeset
   231
 * landscape mode.
hgs
parents: 31
diff changeset
   232
 */
hgs
parents: 31
diff changeset
   233
void WlanWizardPageScanning::loadDocmlSection(Qt::Orientation orientation)
hgs
parents: 31
diff changeset
   234
{
hgs
parents: 31
diff changeset
   235
    OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESCANNING_LOADDOCML,
hgs
parents: 31
diff changeset
   236
        "WlanWizardPageScanning::loadDocml - orientation ;orientation=%x",
hgs
parents: 31
diff changeset
   237
        ( TUint )( orientation ) );
hgs
parents: 31
diff changeset
   238
hgs
parents: 31
diff changeset
   239
    WlanWizardPageInternal::loadDocmlSection(
hgs
parents: 31
diff changeset
   240
        mLoader,
hgs
parents: 31
diff changeset
   241
        orientation,
hgs
parents: 31
diff changeset
   242
        ":/docml/occ_add_wlan_06.docml", 
hgs
parents: 31
diff changeset
   243
        "portrait_section",
hgs
parents: 31
diff changeset
   244
        "landscape_section");
hgs
parents: 31
diff changeset
   245
}
hgs
parents: 31
diff changeset
   246
hgs
parents: 31
diff changeset
   247
/*!
hgs
parents: 31
diff changeset
   248
 * Checks whether the view is active. If it is, execute wlanScanApReady. If
hgs
parents: 31
diff changeset
   249
 * not, set mScanResultsAvailable to true.
hgs
parents: 31
diff changeset
   250
 * @param [in] scanStatus indicates whether the scan was succesful, cancelled of
hgs
parents: 31
diff changeset
   251
 * failed. The argument is saved to a member variable.
hgs
parents: 31
diff changeset
   252
 */
hgs
parents: 31
diff changeset
   253
void WlanWizardPageScanning::wlanScanResultPreCheck(int scanStatus)
hgs
parents: 31
diff changeset
   254
{
hgs
parents: 31
diff changeset
   255
    mScanStatus = scanStatus;
hgs
parents: 31
diff changeset
   256
    
hgs
parents: 31
diff changeset
   257
    if (!mWidget) {
hgs
parents: 31
diff changeset
   258
        OstTrace1( TRACE_BORDER, WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK,
hgs
parents: 31
diff changeset
   259
            "WlanWizardPageScanning::wlanScanResultPreCheck no widget;this=%x",
hgs
parents: 31
diff changeset
   260
            this );
hgs
parents: 31
diff changeset
   261
hgs
parents: 31
diff changeset
   262
        mScanResultsAvailable = true;
hgs
parents: 31
diff changeset
   263
    } else {
hgs
parents: 31
diff changeset
   264
        if (mWizard->isCurrentPage(mWidget)) {
hgs
parents: 31
diff changeset
   265
            OstTrace0( TRACE_BORDER,
hgs
parents: 31
diff changeset
   266
                DUP1_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK,
hgs
parents: 31
diff changeset
   267
                "WlanWizardPageScanning::wlanScanResultPreCheck go to results");
hgs
parents: 31
diff changeset
   268
hgs
parents: 31
diff changeset
   269
            wlanScanApReady();
hgs
parents: 31
diff changeset
   270
        } else {
hgs
parents: 31
diff changeset
   271
            OstTrace0( TRACE_BORDER,
hgs
parents: 31
diff changeset
   272
                DUP2_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK,
hgs
parents: 31
diff changeset
   273
                "WlanWizardPageScanning::wlanScanResultPreCheck"
hgs
parents: 31
diff changeset
   274
                " not current widget" );
hgs
parents: 31
diff changeset
   275
hgs
parents: 31
diff changeset
   276
            mScanResultsAvailable = true;
hgs
parents: 31
diff changeset
   277
        }
hgs
parents: 31
diff changeset
   278
    }
hgs
parents: 31
diff changeset
   279
}
hgs
parents: 31
diff changeset
   280
hgs
parents: 31
diff changeset
   281
/*!
hgs
parents: 31
diff changeset
   282
 * Processes the direct scan results.
hgs
parents: 31
diff changeset
   283
 * @param [in] scanStatus indicates whether the scan was succesful, canceled or
hgs
parents: 31
diff changeset
   284
 * failed. In case the scan was not succesful, always proceed to manual wizard.
hgs
parents: 31
diff changeset
   285
 */
hgs
parents: 31
diff changeset
   286
void WlanWizardPageScanning::wlanScanDirectReady(int scanStatus)
hgs
parents: 31
diff changeset
   287
{
hgs
parents: 31
diff changeset
   288
    OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANDIRECTREADY,
hgs
parents: 31
diff changeset
   289
        "WlanWizardPageScanning::wlanScanDirectReady" );
hgs
parents: 31
diff changeset
   290
hgs
parents: 31
diff changeset
   291
    WlanQtUtils* utils = mWizard->wlanQtUtils();
hgs
parents: 31
diff changeset
   292
hgs
parents: 31
diff changeset
   293
    Q_ASSERT(utils);
hgs
parents: 31
diff changeset
   294
hgs
parents: 31
diff changeset
   295
    QList<WlanScanResult> filteredResults;
hgs
parents: 31
diff changeset
   296
hgs
parents: 31
diff changeset
   297
    if (scanStatus == WlanQtUtils::ScanStatusOk) {
hgs
parents: 31
diff changeset
   298
        QList<QSharedPointer<WlanQtUtilsAp> > directScanResults;
hgs
parents: 31
diff changeset
   299
        // Read the directed scan results from Qt Utils
hgs
parents: 31
diff changeset
   300
        utils->availableWlanAps(directScanResults);
hgs
parents: 31
diff changeset
   301
hgs
parents: 31
diff changeset
   302
        // Identify open and hidden networks.
hgs
parents: 31
diff changeset
   303
        getFinalScanResults(directScanResults, mWlanApList, filteredResults);
hgs
parents: 31
diff changeset
   304
    }
hgs
parents: 31
diff changeset
   305
hgs
parents: 31
diff changeset
   306
    // Process the scan results. If scan status is not ok, feed an empty
hgs
parents: 31
diff changeset
   307
    // result table to the selection function.
hgs
parents: 31
diff changeset
   308
    selectNextPageActions(filteredResults);
hgs
parents: 31
diff changeset
   309
}
hgs
parents: 31
diff changeset
   310
hgs
parents: 31
diff changeset
   311
/*!
hgs
parents: 31
diff changeset
   312
 * All wlan channels have been scanned for public networks. After processing the
hgs
parents: 31
diff changeset
   313
 * results a direct scan is initiated. This function also checks whether the
hgs
parents: 31
diff changeset
   314
 * scan was succesful, canceled or failed. In case the scan was not succesful,
hgs
parents: 31
diff changeset
   315
 * always proceed to manual wizard.
hgs
parents: 31
diff changeset
   316
 */
hgs
parents: 31
diff changeset
   317
void WlanWizardPageScanning::wlanScanApReady()
hgs
parents: 31
diff changeset
   318
{
hgs
parents: 31
diff changeset
   319
    OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANAPREADY,
hgs
parents: 31
diff changeset
   320
        "WlanWizardPageScanning::wlanScanApReady" );
hgs
parents: 31
diff changeset
   321
hgs
parents: 31
diff changeset
   322
    if (mScanStatus == WlanQtUtils::ScanStatusOk) {
hgs
parents: 31
diff changeset
   323
        WlanQtUtils* utils = mWizard->wlanQtUtils();
hgs
parents: 31
diff changeset
   324
        Q_ASSERT(utils);
hgs
parents: 31
diff changeset
   325
hgs
parents: 31
diff changeset
   326
        QList<QSharedPointer<WlanQtUtilsAp> > openScanResults;
hgs
parents: 31
diff changeset
   327
hgs
parents: 31
diff changeset
   328
        // Fetch the list of scan results.
hgs
parents: 31
diff changeset
   329
        utils->availableWlanAps(openScanResults);
hgs
parents: 31
diff changeset
   330
hgs
parents: 31
diff changeset
   331
        // The name of the network that we are looking for.
hgs
parents: 31
diff changeset
   332
        QString ssid =
hgs
parents: 31
diff changeset
   333
            mWizard->configuration(WlanWizardPrivate::ConfSsid).toString();
hgs
parents: 31
diff changeset
   334
hgs
parents: 31
diff changeset
   335
        // Store matching scan results.
hgs
parents: 31
diff changeset
   336
        getSsidMatchList(ssid, openScanResults);
hgs
parents: 31
diff changeset
   337
hgs
parents: 31
diff changeset
   338
        // Next directed scan.
hgs
parents: 31
diff changeset
   339
        utils->scanWlanDirect(ssid);
hgs
parents: 31
diff changeset
   340
    }
hgs
parents: 31
diff changeset
   341
    else {
hgs
parents: 31
diff changeset
   342
        mWizard->clearConfiguration(WlanWizardHelper::ConfAvailableNetworkOptions);
hgs
parents: 31
diff changeset
   343
        mNextPageId = WlanWizardPageInternal::PageNetworkMode;
hgs
parents: 31
diff changeset
   344
        mWizard->nextPage();
hgs
parents: 31
diff changeset
   345
    }
hgs
parents: 31
diff changeset
   346
}
hgs
parents: 31
diff changeset
   347
hgs
parents: 31
diff changeset
   348
/*!
hgs
parents: 31
diff changeset
   349
 * This function stores all the APs that match ssid parameter to mWlanApList
hgs
parents: 31
diff changeset
   350
 * member list.
hgs
parents: 31
diff changeset
   351
 * @param [in] ssid is the name of the network we are interested in.
hgs
parents: 31
diff changeset
   352
 * @param [in] matchList is the list of all APs that were revealed in the scan.
hgs
parents: 31
diff changeset
   353
 */
hgs
parents: 31
diff changeset
   354
void WlanWizardPageScanning::getSsidMatchList(
hgs
parents: 31
diff changeset
   355
    QString ssid,
hgs
parents: 31
diff changeset
   356
    const QList<QSharedPointer<WlanQtUtilsAp> > &matchList)
hgs
parents: 31
diff changeset
   357
{
hgs
parents: 31
diff changeset
   358
    mWlanApList.clear();
hgs
parents: 31
diff changeset
   359
    QSharedPointer<WlanQtUtilsAp> item;
hgs
parents: 31
diff changeset
   360
hgs
parents: 31
diff changeset
   361
    for (int i = 0; i < matchList.size(); i++) {
hgs
parents: 31
diff changeset
   362
        item = matchList.at(i);
hgs
parents: 31
diff changeset
   363
        if (item->value(WlanQtUtilsAp::ConfIdSsid).toString() == ssid) {
hgs
parents: 31
diff changeset
   364
            mWlanApList.append(item);
hgs
parents: 31
diff changeset
   365
        }
hgs
parents: 31
diff changeset
   366
    }
hgs
parents: 31
diff changeset
   367
}
hgs
parents: 31
diff changeset
   368
hgs
parents: 31
diff changeset
   369
/*
hgs
parents: 31
diff changeset
   370
 * Find out which of the direct scan results are open networks by comparing
hgs
parents: 31
diff changeset
   371
 * result to open scan results. Return finalResults.
hgs
parents: 31
diff changeset
   372
 * @param [in] directScanResults are the results of a directed scan.
hgs
parents: 31
diff changeset
   373
 * @param [in] openScanResults are the results of a scan inquiring any APs.
hgs
parents: 31
diff changeset
   374
 * @param [out] finalResults is a list of APs with visibility flag included.
hgs
parents: 31
diff changeset
   375
 */
hgs
parents: 31
diff changeset
   376
void WlanWizardPageScanning::getFinalScanResults(
hgs
parents: 31
diff changeset
   377
    const QList<QSharedPointer<WlanQtUtilsAp> > &directScanResults,
hgs
parents: 31
diff changeset
   378
    const QList<QSharedPointer<WlanQtUtilsAp> > &openScanResults,
hgs
parents: 31
diff changeset
   379
    QList<WlanScanResult> &finalResults)
hgs
parents: 31
diff changeset
   380
{
hgs
parents: 31
diff changeset
   381
    finalResults.clear();
hgs
parents: 31
diff changeset
   382
hgs
parents: 31
diff changeset
   383
    // The key assumption of this algorithm is that both direct and public scan
hgs
parents: 31
diff changeset
   384
    // reveal the same set of AP:s with the exception of hidden AP:s.
hgs
parents: 31
diff changeset
   385
    // In other words: Direct scan result set is the whole set with each AP 
hgs
parents: 31
diff changeset
   386
    // marked as hidden by default. If an AP has been revealed also by public
hgs
parents: 31
diff changeset
   387
    // scan, it is changed to visible.
hgs
parents: 31
diff changeset
   388
    for (int i = 0; i < directScanResults.size(); i++) {
hgs
parents: 31
diff changeset
   389
        WlanScanResult resultItem;
hgs
parents: 31
diff changeset
   390
hgs
parents: 31
diff changeset
   391
        resultItem.scanResult = directScanResults.at(i);
hgs
parents: 31
diff changeset
   392
        
hgs
parents: 31
diff changeset
   393
        // Initialize as hidden.
hgs
parents: 31
diff changeset
   394
        resultItem.networkHidden = true;
hgs
parents: 31
diff changeset
   395
         
hgs
parents: 31
diff changeset
   396
        for (int j = 0; j < openScanResults.size(); j++) {
hgs
parents: 31
diff changeset
   397
            if (WlanQtUtilsAp::compare(
hgs
parents: 31
diff changeset
   398
                openScanResults.at(j).data(), 
hgs
parents: 31
diff changeset
   399
                directScanResults.at(i).data()) == 0) {
hgs
parents: 31
diff changeset
   400
                // Mark open, if a public scan revealed the same AP
hgs
parents: 31
diff changeset
   401
                resultItem.networkHidden = false;
hgs
parents: 31
diff changeset
   402
            }
hgs
parents: 31
diff changeset
   403
        }
hgs
parents: 31
diff changeset
   404
hgs
parents: 31
diff changeset
   405
        finalResults.append(resultItem);
hgs
parents: 31
diff changeset
   406
    }
hgs
parents: 31
diff changeset
   407
}
hgs
parents: 31
diff changeset
   408
hgs
parents: 31
diff changeset
   409
/*!
hgs
parents: 31
diff changeset
   410
 * This function processes the scan results in case multiple results were
hgs
parents: 31
diff changeset
   411
 * acquired with matching SSIDs.
hgs
parents: 31
diff changeset
   412
 * @param [in] finalResults is the list of APs revealed by the last scans.
hgs
parents: 31
diff changeset
   413
 * @return the identifier of the next page.
hgs
parents: 31
diff changeset
   414
 */
hgs
parents: 31
diff changeset
   415
int WlanWizardPageScanning::processMultipleScanResults(
hgs
parents: 31
diff changeset
   416
    const QList<WlanScanResult> &finalResults)
hgs
parents: 31
diff changeset
   417
{
hgs
parents: 31
diff changeset
   418
    WlanWizardScanList networkOptions;
hgs
parents: 31
diff changeset
   419
    int nextPage;
hgs
parents: 31
diff changeset
   420
hgs
parents: 31
diff changeset
   421
    // Build the list of results to be placed in the configuration.
hgs
parents: 31
diff changeset
   422
    networkOptions.build(finalResults);
hgs
parents: 31
diff changeset
   423
    
hgs
parents: 31
diff changeset
   424
    QVariant tmp;
hgs
parents: 31
diff changeset
   425
    tmp.setValue(networkOptions);
hgs
parents: 31
diff changeset
   426
hgs
parents: 31
diff changeset
   427
    mWizard->setConfiguration(
hgs
parents: 31
diff changeset
   428
        WlanWizardHelper::ConfAvailableNetworkOptions, tmp);
hgs
parents: 31
diff changeset
   429
hgs
parents: 31
diff changeset
   430
    // If there are more than one network mode choices, go to manual selection
hgs
parents: 31
diff changeset
   431
    // of network mode.
hgs
parents: 31
diff changeset
   432
    if (networkOptions.netModes() > SingleResult) {
hgs
parents: 31
diff changeset
   433
        nextPage = WlanWizardPageInternal::PageNetworkMode;
hgs
parents: 31
diff changeset
   434
    } else {
hgs
parents: 31
diff changeset
   435
        // if only a single network mode option is available, the mode query
hgs
parents: 31
diff changeset
   436
        // may be skipped and the next page is set to security mode query.
hgs
parents: 31
diff changeset
   437
        WlanNetworkSetting setting = networkOptions.getNetModes().at(0);
hgs
parents: 31
diff changeset
   438
        mWizard->setConfiguration(WlanWizardHelper::ConfNetworkMode, setting.mode);
hgs
parents: 31
diff changeset
   439
        mWizard->setConfiguration(WlanWizardHelper::ConfHiddenWlan, setting.hidden);
hgs
parents: 31
diff changeset
   440
        nextPage = WlanWizardPageInternal::PageNetworkSecurity;
hgs
parents: 31
diff changeset
   441
    }
hgs
parents: 31
diff changeset
   442
    
hgs
parents: 31
diff changeset
   443
    return nextPage;
hgs
parents: 31
diff changeset
   444
}
hgs
parents: 31
diff changeset
   445
hgs
parents: 31
diff changeset
   446
/*!
hgs
parents: 31
diff changeset
   447
 * This function decides what to do with the scan results.
hgs
parents: 31
diff changeset
   448
 * @param [in] finalResults is the list of APs revealed by the last scans.
hgs
parents: 31
diff changeset
   449
 */
hgs
parents: 31
diff changeset
   450
void WlanWizardPageScanning::selectNextPageActions(
hgs
parents: 31
diff changeset
   451
    const QList<WlanScanResult> &finalResults)
hgs
parents: 31
diff changeset
   452
{
hgs
parents: 31
diff changeset
   453
    mWizard->clearConfiguration(WlanWizardHelper::ConfAvailableNetworkOptions);
hgs
parents: 31
diff changeset
   454
    
hgs
parents: 31
diff changeset
   455
    if (finalResults.isEmpty()) {
hgs
parents: 31
diff changeset
   456
        // In case of no results at all were found.
hgs
parents: 31
diff changeset
   457
        mNextPageId = WlanWizardPageInternal::PageNetworkMode;
hgs
parents: 31
diff changeset
   458
    } else if (finalResults.size() == SingleResult) {
hgs
parents: 31
diff changeset
   459
        // In case there is only a single result.
hgs
parents: 31
diff changeset
   460
        WlanScanResult item = finalResults.first();
hgs
parents: 31
diff changeset
   461
        mNextPageId = mWizard->getNextPageId(
hgs
parents: 31
diff changeset
   462
            item.scanResult->value(WlanQtUtilsAp::ConfIdSsid).toString(),
hgs
parents: 31
diff changeset
   463
            item.scanResult->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(),
hgs
parents: 31
diff changeset
   464
            item.scanResult->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(),
hgs
parents: 31
diff changeset
   465
            item.scanResult->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(),
hgs
parents: 31
diff changeset
   466
            item.networkHidden,
hgs
parents: 31
diff changeset
   467
            item.scanResult->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool());
hgs
parents: 31
diff changeset
   468
    } else {
hgs
parents: 31
diff changeset
   469
        // In case more than one result is available.
hgs
parents: 31
diff changeset
   470
        mWizard->setConfiguration(WlanWizardHelper::ConfProcessSettings, true);
hgs
parents: 31
diff changeset
   471
        mNextPageId = processMultipleScanResults(finalResults);
hgs
parents: 31
diff changeset
   472
    }
hgs
parents: 31
diff changeset
   473
hgs
parents: 31
diff changeset
   474
    mWizard->nextPage();
hgs
parents: 31
diff changeset
   475
}