diff -r 682dd021f9be -r 7b3e49e4608a wlanutilities/wlanwizard/src/wlanwizardpagescanning.cpp --- a/wlanutilities/wlanwizard/src/wlanwizardpagescanning.cpp Thu Jun 10 15:44:54 2010 +0300 +++ b/wlanutilities/wlanwizard/src/wlanwizardpagescanning.cpp Thu Jun 24 10:49:51 2010 +0300 @@ -1,27 +1,27 @@ /* - * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). - * All rights reserved. - * This component and the accompanying materials are made available - * under the terms of "Eclipse Public License v1.0" - * which accompanies this distribution, and is available - * at the URL "http://www.eclipse.org/legal/epl-v10.html". - * - * Initial Contributors: - * Nokia Corporation - initial contribution. - * - * Contributors: - * - * Description: - * WLAN Wizard Page: Scan processing. - */ +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* WLAN Wizard Page: Scan processing. +*/ // System includes +#include #include #include #include #include #include -#include #include #include #include @@ -34,25 +34,33 @@ #include "wlanwizardpagescanningTraces.h" #endif +// Local constants + /*! - * Constructor. Member initialization. + * Constructor method for the scanning view object. + * @param [in] parent pointer to parent object. */ WlanWizardPageScanning::WlanWizardPageScanning(WlanWizardPrivate* parent) : WlanWizardPageInternal(parent), mWidget(NULL), mLabel(NULL), - mBar(NULL), mLoader(NULL), mNextPageId(WlanWizardPage::PageNone), - mScanResultsAvailable(false) + mScanResultsAvailable(false), + mScanStatus(WlanQtUtils::ScanStatusOk) { WlanQtUtils* utils = mWizard->wlanQtUtils(); // Connect normal scan completion signal from wlanQtUtils to result // handler. Connect here instead of initializePage, since this signal may // need to be caught event if the window is not active. - bool ok = connect(utils, SIGNAL(wlanScanApReady()), this, - SLOT(wlanScanResultPreCheck())); + bool ok = connect( + utils, + SIGNAL(wlanScanApReady(int)), + this, + SLOT(wlanScanResultPreCheck(int))); + + Q_ASSERT(ok); } /*! @@ -65,66 +73,73 @@ } /*! - * Page initialization. If view is already loaded, does nothing. + * Page initialization. If view is already loaded, does nothing. Inherited from + * WlanWizardPage. + * @return pointer to widget "occ_add_wlan_06". */ HbWidget* WlanWizardPageScanning::initializePage() { - OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_INITIALIZEPAGE, - "WlanWizardPageScanning::initializePage" ); + OstTrace0( + TRACE_NORMAL, + WLANWIZARDPAGESCANNING_INITIALIZEPAGE, + "WlanWizardPageScanning::initializePage"); // Next page id is reset with each initialization. mNextPageId = WlanWizardPage::PageNone; if (mWidget == NULL) { - mLoader = new HbDocumentLoader(mWizard->mainWindow()); bool ok; mLoader->load(":/docml/occ_add_wlan_06.docml", &ok); - Q_ASSERT_X(ok, "WlanWizardPageScanning", "Invalid docml file"); + Q_ASSERT(ok); // Initialize orientation - loadDocml(mWizard->mainWindow()->orientation()); + loadDocmlSection(mWizard->mainWindow()->orientation()); // Load widgets mWidget = qobject_cast (mLoader->findWidget( "occ_add_wlan_06")); - Q_ASSERT_X(mWidget != NULL, "WlanWizardPageScanning", "View not found"); + Q_ASSERT(mWidget != NULL); mLabel = qobject_cast (mLoader->findWidget("dialog")); - Q_ASSERT_X(mLabel != NULL, "WlanWizardPageScanning", - "textLabel not found"); - - mBar = qobject_cast (mLoader->findWidget("progressBar")); - Q_ASSERT_X(mBar != NULL, "WlanWizardPageScanning", - "progressBar not found"); + Q_ASSERT(mLabel != NULL); WlanQtUtils* utils = mWizard->wlanQtUtils(); // Connect orientation signal from the main window to orientation // loader. - ok &= connect(mWizard->mainWindow(), - SIGNAL(orientationChanged(Qt::Orientation)), this, - SLOT(loadDocml(Qt::Orientation))); + ok = connect( + mWizard->mainWindow(), + SIGNAL(orientationChanged(Qt::Orientation)), + this, + SLOT(loadDocmlSection(Qt::Orientation))); + Q_ASSERT(ok); // Connect direct scan completion signal from wlanQtUtils to result // handler. - ok &= connect(utils, SIGNAL(wlanScanDirectReady()), this, - SLOT(wlanScanDirectReady())); - + ok = connect( + utils, + SIGNAL(wlanScanDirectReady(int)), + this, + SLOT(wlanScanDirectReady(int))); Q_ASSERT(ok); - } - mLabel->setPlainText(hbTrId("txt_occ_dialog_searching").arg( - mWizard->configuration(WlanWizardPrivate::ConfSsid).toString())); + mLabel->setPlainText(HbParameterLengthLimiter( + hbTrId("txt_occ_dialog_searching")).arg(mWizard->configuration( + WlanWizardPrivate::ConfSsid).toString())); + return mWidget; } /*! * Sends the user to the next page. + * @param [out] removeFromStack is always true: this page is removed from the + * stacked widget after "Next" button is pressed. + * @return the id value of the next page. */ int WlanWizardPageScanning::nextId(bool &removeFromStack) const { @@ -134,196 +149,59 @@ } /*! - * Always false. Moving to next page is not done manually. - * @see WlanWizardPage + * This function reimplements WlanWizardPage::previousTriggered. When going + * back from scanning view, the ongoing scan operation is also stopped. Since + * there is no need to react to following the acknowledgement signal from + * wlanQtUtils, the corresponding handler slots are disconnected before the + * opration and immediately connected again. + * @return one step backwards value. + */ +int WlanWizardPageScanning::previousTriggered() +{ + disconnect(this, SLOT(wlanScanDirectReady(int))); + disconnect(this, SLOT(wlanScanResultPreCheck(int))); + + WlanQtUtils* utils = mWizard->wlanQtUtils(); + + utils->stopWlanScan(); + + bool ok = connect( + utils, + SIGNAL(wlanScanApReady(int)), + this, + SLOT(wlanScanResultPreCheck(int))); + Q_ASSERT(ok); + + ok = connect( + utils, + SIGNAL(wlanScanDirectReady(int)), + this, + SLOT(wlanScanDirectReady(int))); + Q_ASSERT(ok); + + return OneStepBackwards; + +} + +/*! + * This method is overrides the default implementation from WlanWizardPage. + * It indicates whether the Next-button should be enabled or not. It also resets + * the ConfProcessSettings-configuration to false - meaning that if no scan + * results are available, no iap is created. + * @return always false - the scanning proceeds to next window + * automatically or not at all. */ bool WlanWizardPageScanning::showPage() { + mWizard->setConfiguration(WlanWizardHelper::ConfProcessSettings, false); return false; } /*! - * Loads the document orientation-specific parameters. - */ -void WlanWizardPageScanning::loadDocml(Qt::Orientation orientation) -{ - OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESCANNING_LOADDOCML, - "WlanWizardPageScanning::loadDocml - orientation ;orientation=%x", - ( TUint )( orientation ) ); - - bool ok; - // Then load the orientation specific section - if (orientation == Qt::Horizontal) { - mLoader->load(":/docml/occ_add_wlan_06.docml", "landscape_section", &ok); - Q_ASSERT(ok); - } else { - Q_ASSERT(orientation == Qt::Vertical); - mLoader->load(":/docml/occ_add_wlan_06.docml", "portrait_section", &ok); - Q_ASSERT(ok); - } -} - -void WlanWizardPageScanning::wlanScanResultPreCheck() -{ - if (!mWidget) { - OstTrace1( TRACE_BORDER, WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, - "WlanWizardPageScanning::wlanScanResultPreCheck no widget;this=%x", - this ); - - mScanResultsAvailable = true; - } - else { - if (mWizard->isCurrentPage(mWidget)) { - OstTrace0( TRACE_BORDER, - DUP1_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, - "WlanWizardPageScanning::wlanScanResultPreCheck go to results"); - - wlanScanApReady(); - } - else { - OstTrace0( TRACE_BORDER, - DUP2_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, - "WlanWizardPageScanning::wlanScanResultPreCheck" - " not current widget" ); - - mScanResultsAvailable = true; - } - } -} - -/*! - * Public networks did not reveal matches. Direct scan has been performed to - * find out if the network is hidden but in range. If network is found, proceed - * to next page according to scan results. - * If nothing is found, proceed to manual network - * mode selection page. - */ -void WlanWizardPageScanning::wlanScanDirectReady() -{ - OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANDIRECTREADY, - "WlanWizardPageScanning::wlanScanDirectReady" ); - - WlanQtUtils* utils = mWizard->wlanQtUtils(); - - Q_ASSERT(utils); - - QList > wlanApList; - - utils->availableWlanAps(wlanApList); - - qDebug("WlanWizardPageScanning::wlanScanDirectReady - results read"); - - QSharedPointer item; - - qDebug("%d APs found", wlanApList.size()); - if(wlanApList.isEmpty()) { - qDebug("Match not found. Go to manual settings."); - mNextPageId = WlanWizardPageInternal::PageNetworkMode; - } - else { - int strongestSignal = 0; - int strongestIndex = 0; - - for (int i = 0; i < wlanApList.size(); i++) { - // All direct scan results are matches. No need to compare ssids. - // In case there are multiple matches to direct scan, use the - // strongest signal on the result list. - item = wlanApList.at(i); - int str = item->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt(); - if (str > strongestSignal) { - qDebug("Strongest signal %d at %d", str, i); - strongestSignal = str; - strongestIndex = i; - } - } - - item = wlanApList.at(strongestIndex); - qDebug("Select AP at %d", strongestIndex); - mNextPageId = mWizard->getNextPageId( - item->value(WlanQtUtilsAp::ConfIdSsid).toString(), - item->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), - item->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), - item->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), - true, // hidden - item->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()); - } - - mWizard->nextPage(); - -} - -/*! - * All wlan channels have been scanned for public networks. Now process the - * results. If a network is found which matches the ssid set by the user, - * proceed to next page according to the network attributes. - * If no ssid match is found, proceed to a direct scan. - */ -void WlanWizardPageScanning::wlanScanApReady() -{ - OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANAPREADY, - "WlanWizardPageScanning::wlanScanApReady" ); - - WlanQtUtils* utils = mWizard->wlanQtUtils(); - Q_ASSERT(utils); - - QList > wlanApList; - - // Fetch the list of scan results. - utils->availableWlanAps(wlanApList); - - qDebug("WlanWizardPageScanning::wlanScanApReady - results read"); - - QString ssid = - mWizard->configuration(WlanWizardPrivate::ConfSsid).toString(); - qDebug() << "SSID scanned by user " << ssid; - - bool matchFound = false; - int strongestSignal = -1; - int strongestIndex = 0; - QSharedPointer item; - - qDebug("%d APs found", wlanApList.size()); - - for (int i = 0; i < wlanApList.size(); i++) { - // In case there are multiple matches to direct scan, use the - // strongest signal on the result list. - item = wlanApList.at(i); - if (item->value(WlanQtUtilsAp::ConfIdSsid).toString() == ssid) { - qDebug("Match found"); - matchFound = true; - - int str = item->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt(); - if (str > strongestSignal) { - qDebug("Strongest signal %d at %d", str, i); - strongestSignal = str; - strongestIndex = i; - } - } - } - - if (matchFound) { - qDebug("Select AP at %d", strongestIndex); - item = wlanApList.at(strongestIndex); - mNextPageId = mWizard->getNextPageId( - item->value(WlanQtUtilsAp::ConfIdSsid).toString(), - item->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), - item->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), - item->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), - false, // public - item->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()); - // The ssid indicated by the user was found. Proceed to next page. - mWizard->nextPage(); - } - else { - qDebug("Match not found. Perform direct scan."); - utils->scanWlanDirect(ssid); - } - -} - -/*! - * Overloaded function from WlanWizardPage. Indicates that this window requires - * post-initialization start operations. + * Reimplements the default function in WlanWizardPage. Indicates to the + * framework that startOperation() function must be executed. + * @return true + * @see WlanWizardPage */ bool WlanWizardPageScanning::requiresStartOperation() { @@ -332,7 +210,7 @@ /*! * Wlan scan is performed as a "post-initialization" which is executed in a - * separate scheduler loop. + * separate scheduler loop. If scan results are available, starts reading them. */ void WlanWizardPageScanning::startOperation() { @@ -346,3 +224,252 @@ } } +/*! + * Loads the document orientation information from occ_add_wlan_06.docml + * This is called each time phone orientation changes. + * @param [in] orientation indicates whether the phone is in portrait or + * landscape mode. + */ +void WlanWizardPageScanning::loadDocmlSection(Qt::Orientation orientation) +{ + OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESCANNING_LOADDOCML, + "WlanWizardPageScanning::loadDocml - orientation ;orientation=%x", + ( TUint )( orientation ) ); + + WlanWizardPageInternal::loadDocmlSection( + mLoader, + orientation, + ":/docml/occ_add_wlan_06.docml", + "portrait_section", + "landscape_section"); +} + +/*! + * Checks whether the view is active. If it is, execute wlanScanApReady. If + * not, set mScanResultsAvailable to true. + * @param [in] scanStatus indicates whether the scan was succesful, cancelled of + * failed. The argument is saved to a member variable. + */ +void WlanWizardPageScanning::wlanScanResultPreCheck(int scanStatus) +{ + mScanStatus = scanStatus; + + if (!mWidget) { + OstTrace1( TRACE_BORDER, WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, + "WlanWizardPageScanning::wlanScanResultPreCheck no widget;this=%x", + this ); + + mScanResultsAvailable = true; + } else { + if (mWizard->isCurrentPage(mWidget)) { + OstTrace0( TRACE_BORDER, + DUP1_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, + "WlanWizardPageScanning::wlanScanResultPreCheck go to results"); + + wlanScanApReady(); + } else { + OstTrace0( TRACE_BORDER, + DUP2_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, + "WlanWizardPageScanning::wlanScanResultPreCheck" + " not current widget" ); + + mScanResultsAvailable = true; + } + } +} + +/*! + * Processes the direct scan results. + * @param [in] scanStatus indicates whether the scan was succesful, canceled or + * failed. In case the scan was not succesful, always proceed to manual wizard. + */ +void WlanWizardPageScanning::wlanScanDirectReady(int scanStatus) +{ + OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANDIRECTREADY, + "WlanWizardPageScanning::wlanScanDirectReady" ); + + WlanQtUtils* utils = mWizard->wlanQtUtils(); + + Q_ASSERT(utils); + + QList filteredResults; + + if (scanStatus == WlanQtUtils::ScanStatusOk) { + QList > directScanResults; + // Read the directed scan results from Qt Utils + utils->availableWlanAps(directScanResults); + + // Identify open and hidden networks. + getFinalScanResults(directScanResults, mWlanApList, filteredResults); + } + + // Process the scan results. If scan status is not ok, feed an empty + // result table to the selection function. + selectNextPageActions(filteredResults); +} + +/*! + * All wlan channels have been scanned for public networks. After processing the + * results a direct scan is initiated. This function also checks whether the + * scan was succesful, canceled or failed. In case the scan was not succesful, + * always proceed to manual wizard. + */ +void WlanWizardPageScanning::wlanScanApReady() +{ + OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANAPREADY, + "WlanWizardPageScanning::wlanScanApReady" ); + + if (mScanStatus == WlanQtUtils::ScanStatusOk) { + WlanQtUtils* utils = mWizard->wlanQtUtils(); + Q_ASSERT(utils); + + QList > openScanResults; + + // Fetch the list of scan results. + utils->availableWlanAps(openScanResults); + + // The name of the network that we are looking for. + QString ssid = + mWizard->configuration(WlanWizardPrivate::ConfSsid).toString(); + + // Store matching scan results. + getSsidMatchList(ssid, openScanResults); + + // Next directed scan. + utils->scanWlanDirect(ssid); + } + else { + mWizard->clearConfiguration(WlanWizardHelper::ConfAvailableNetworkOptions); + mNextPageId = WlanWizardPageInternal::PageNetworkMode; + mWizard->nextPage(); + } +} + +/*! + * This function stores all the APs that match ssid parameter to mWlanApList + * member list. + * @param [in] ssid is the name of the network we are interested in. + * @param [in] matchList is the list of all APs that were revealed in the scan. + */ +void WlanWizardPageScanning::getSsidMatchList( + QString ssid, + const QList > &matchList) +{ + mWlanApList.clear(); + QSharedPointer item; + + for (int i = 0; i < matchList.size(); i++) { + item = matchList.at(i); + if (item->value(WlanQtUtilsAp::ConfIdSsid).toString() == ssid) { + mWlanApList.append(item); + } + } +} + +/* + * Find out which of the direct scan results are open networks by comparing + * result to open scan results. Return finalResults. + * @param [in] directScanResults are the results of a directed scan. + * @param [in] openScanResults are the results of a scan inquiring any APs. + * @param [out] finalResults is a list of APs with visibility flag included. + */ +void WlanWizardPageScanning::getFinalScanResults( + const QList > &directScanResults, + const QList > &openScanResults, + QList &finalResults) +{ + finalResults.clear(); + + // The key assumption of this algorithm is that both direct and public scan + // reveal the same set of AP:s with the exception of hidden AP:s. + // In other words: Direct scan result set is the whole set with each AP + // marked as hidden by default. If an AP has been revealed also by public + // scan, it is changed to visible. + for (int i = 0; i < directScanResults.size(); i++) { + WlanScanResult resultItem; + + resultItem.scanResult = directScanResults.at(i); + + // Initialize as hidden. + resultItem.networkHidden = true; + + for (int j = 0; j < openScanResults.size(); j++) { + if (WlanQtUtilsAp::compare( + openScanResults.at(j).data(), + directScanResults.at(i).data()) == 0) { + // Mark open, if a public scan revealed the same AP + resultItem.networkHidden = false; + } + } + + finalResults.append(resultItem); + } +} + +/*! + * This function processes the scan results in case multiple results were + * acquired with matching SSIDs. + * @param [in] finalResults is the list of APs revealed by the last scans. + * @return the identifier of the next page. + */ +int WlanWizardPageScanning::processMultipleScanResults( + const QList &finalResults) +{ + WlanWizardScanList networkOptions; + int nextPage; + + // Build the list of results to be placed in the configuration. + networkOptions.build(finalResults); + + QVariant tmp; + tmp.setValue(networkOptions); + + mWizard->setConfiguration( + WlanWizardHelper::ConfAvailableNetworkOptions, tmp); + + // If there are more than one network mode choices, go to manual selection + // of network mode. + if (networkOptions.netModes() > SingleResult) { + nextPage = WlanWizardPageInternal::PageNetworkMode; + } else { + // if only a single network mode option is available, the mode query + // may be skipped and the next page is set to security mode query. + WlanNetworkSetting setting = networkOptions.getNetModes().at(0); + mWizard->setConfiguration(WlanWizardHelper::ConfNetworkMode, setting.mode); + mWizard->setConfiguration(WlanWizardHelper::ConfHiddenWlan, setting.hidden); + nextPage = WlanWizardPageInternal::PageNetworkSecurity; + } + + return nextPage; +} + +/*! + * This function decides what to do with the scan results. + * @param [in] finalResults is the list of APs revealed by the last scans. + */ +void WlanWizardPageScanning::selectNextPageActions( + const QList &finalResults) +{ + mWizard->clearConfiguration(WlanWizardHelper::ConfAvailableNetworkOptions); + + if (finalResults.isEmpty()) { + // In case of no results at all were found. + mNextPageId = WlanWizardPageInternal::PageNetworkMode; + } else if (finalResults.size() == SingleResult) { + // In case there is only a single result. + WlanScanResult item = finalResults.first(); + mNextPageId = mWizard->getNextPageId( + item.scanResult->value(WlanQtUtilsAp::ConfIdSsid).toString(), + item.scanResult->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), + item.scanResult->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), + item.scanResult->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), + item.networkHidden, + item.scanResult->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()); + } else { + // In case more than one result is available. + mWizard->setConfiguration(WlanWizardHelper::ConfProcessSettings, true); + mNextPageId = processMultipleScanResults(finalResults); + } + + mWizard->nextPage(); +}