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