|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * WLAN Wizard Page: Scan processing. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <HbMainWindow> |
|
20 #include <HbDocumentLoader> |
|
21 #include <HbWidget> |
|
22 #include <HbLabel> |
|
23 #include <HbProgressBar> |
|
24 #include <QDebug> |
|
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 |
|
37 /*! |
|
38 * Constructor. Member initialization. |
|
39 */ |
|
40 WlanWizardPageScanning::WlanWizardPageScanning(WlanWizardPrivate* parent) : |
|
41 WlanWizardPageInternal(parent), |
|
42 mWidget(NULL), |
|
43 mLabel(NULL), |
|
44 mBar(NULL), |
|
45 mLoader(NULL), |
|
46 mNextPageId(WlanWizardPage::PageNone), |
|
47 mScanResultsAvailable(false) |
|
48 { |
|
49 WlanQtUtils* utils = mWizard->wlanQtUtils(); |
|
50 |
|
51 // Connect normal scan completion signal from wlanQtUtils to result |
|
52 // handler. Connect here instead of initializePage, since this signal may |
|
53 // need to be caught event if the window is not active. |
|
54 bool ok = connect(utils, SIGNAL(wlanScanApReady()), this, |
|
55 SLOT(wlanScanResultPreCheck())); |
|
56 } |
|
57 |
|
58 /*! |
|
59 * Destructor. Loader widget is deleted. |
|
60 * All document widgets are deleted by wlanwizard_p destructor. |
|
61 */ |
|
62 WlanWizardPageScanning::~WlanWizardPageScanning() |
|
63 { |
|
64 delete mLoader; |
|
65 } |
|
66 |
|
67 /*! |
|
68 * Page initialization. If view is already loaded, does nothing. |
|
69 */ |
|
70 HbWidget* WlanWizardPageScanning::initializePage() |
|
71 { |
|
72 OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_INITIALIZEPAGE, |
|
73 "WlanWizardPageScanning::initializePage" ); |
|
74 |
|
75 // Next page id is reset with each initialization. |
|
76 mNextPageId = WlanWizardPage::PageNone; |
|
77 |
|
78 if (mWidget == NULL) { |
|
79 |
|
80 mLoader = new HbDocumentLoader(mWizard->mainWindow()); |
|
81 |
|
82 bool ok; |
|
83 |
|
84 mLoader->load(":/docml/occ_add_wlan_06.docml", &ok); |
|
85 Q_ASSERT_X(ok, "WlanWizardPageScanning", "Invalid docml file"); |
|
86 |
|
87 // Initialize orientation |
|
88 loadDocml(mWizard->mainWindow()->orientation()); |
|
89 |
|
90 // Load widgets |
|
91 mWidget = qobject_cast<HbWidget*> (mLoader->findWidget( |
|
92 "occ_add_wlan_06")); |
|
93 Q_ASSERT_X(mWidget != NULL, "WlanWizardPageScanning", "View not found"); |
|
94 |
|
95 mLabel = qobject_cast<HbLabel*> (mLoader->findWidget("dialog")); |
|
96 Q_ASSERT_X(mLabel != NULL, "WlanWizardPageScanning", |
|
97 "textLabel not found"); |
|
98 |
|
99 mBar = qobject_cast<HbProgressBar*> (mLoader->findWidget("progressBar")); |
|
100 Q_ASSERT_X(mBar != NULL, "WlanWizardPageScanning", |
|
101 "progressBar not found"); |
|
102 |
|
103 WlanQtUtils* utils = mWizard->wlanQtUtils(); |
|
104 |
|
105 // Connect orientation signal from the main window to orientation |
|
106 // loader. |
|
107 ok &= connect(mWizard->mainWindow(), |
|
108 SIGNAL(orientationChanged(Qt::Orientation)), this, |
|
109 SLOT(loadDocml(Qt::Orientation))); |
|
110 |
|
111 // Connect direct scan completion signal from wlanQtUtils to result |
|
112 // handler. |
|
113 ok &= connect(utils, SIGNAL(wlanScanDirectReady()), this, |
|
114 SLOT(wlanScanDirectReady())); |
|
115 |
|
116 Q_ASSERT(ok); |
|
117 |
|
118 } |
|
119 |
|
120 mLabel->setPlainText(hbTrId("txt_occ_dialog_searching").arg( |
|
121 mWizard->configuration(WlanWizardPrivate::ConfSsid).toString())); |
|
122 |
|
123 return mWidget; |
|
124 } |
|
125 |
|
126 /*! |
|
127 * Sends the user to the next page. |
|
128 */ |
|
129 int WlanWizardPageScanning::nextId(bool &removeFromStack) const |
|
130 { |
|
131 removeFromStack = true; |
|
132 |
|
133 return mNextPageId; |
|
134 } |
|
135 |
|
136 /*! |
|
137 * Always false. Moving to next page is not done manually. |
|
138 * @see WlanWizardPage |
|
139 */ |
|
140 bool WlanWizardPageScanning::showPage() |
|
141 { |
|
142 return false; |
|
143 } |
|
144 |
|
145 /*! |
|
146 * Loads the document orientation-specific parameters. |
|
147 */ |
|
148 void WlanWizardPageScanning::loadDocml(Qt::Orientation orientation) |
|
149 { |
|
150 OstTrace1( TRACE_NORMAL, WLANWIZARDPAGESCANNING_LOADDOCML, |
|
151 "WlanWizardPageScanning::loadDocml - orientation ;orientation=%x", |
|
152 ( TUint )( orientation ) ); |
|
153 |
|
154 bool ok; |
|
155 // Then load the orientation specific section |
|
156 if (orientation == Qt::Horizontal) { |
|
157 mLoader->load(":/docml/occ_add_wlan_06.docml", "landscape_section", &ok); |
|
158 Q_ASSERT(ok); |
|
159 } else { |
|
160 Q_ASSERT(orientation == Qt::Vertical); |
|
161 mLoader->load(":/docml/occ_add_wlan_06.docml", "portrait_section", &ok); |
|
162 Q_ASSERT(ok); |
|
163 } |
|
164 } |
|
165 |
|
166 void WlanWizardPageScanning::wlanScanResultPreCheck() |
|
167 { |
|
168 if (!mWidget) { |
|
169 OstTrace1( TRACE_BORDER, WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, |
|
170 "WlanWizardPageScanning::wlanScanResultPreCheck no widget;this=%x", |
|
171 this ); |
|
172 |
|
173 mScanResultsAvailable = true; |
|
174 } |
|
175 else { |
|
176 if (mWizard->isCurrentPage(mWidget)) { |
|
177 OstTrace0( TRACE_BORDER, |
|
178 DUP1_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, |
|
179 "WlanWizardPageScanning::wlanScanResultPreCheck go to results"); |
|
180 |
|
181 wlanScanApReady(); |
|
182 } |
|
183 else { |
|
184 OstTrace0( TRACE_BORDER, |
|
185 DUP2_WLANWIZARDPAGESCANNING_WLANSCANRESULTPRECHECK, |
|
186 "WlanWizardPageScanning::wlanScanResultPreCheck" |
|
187 " not current widget" ); |
|
188 |
|
189 mScanResultsAvailable = true; |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 /*! |
|
195 * Public networks did not reveal matches. Direct scan has been performed to |
|
196 * find out if the network is hidden but in range. If network is found, proceed |
|
197 * to next page according to scan results. |
|
198 * If nothing is found, proceed to manual network |
|
199 * mode selection page. |
|
200 */ |
|
201 void WlanWizardPageScanning::wlanScanDirectReady() |
|
202 { |
|
203 OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANDIRECTREADY, |
|
204 "WlanWizardPageScanning::wlanScanDirectReady" ); |
|
205 |
|
206 WlanQtUtils* utils = mWizard->wlanQtUtils(); |
|
207 |
|
208 Q_ASSERT(utils); |
|
209 |
|
210 QList<QSharedPointer<WlanQtUtilsAp> > wlanApList; |
|
211 |
|
212 utils->availableWlanAps(wlanApList); |
|
213 |
|
214 qDebug("WlanWizardPageScanning::wlanScanDirectReady - results read"); |
|
215 |
|
216 QSharedPointer<WlanQtUtilsAp> item; |
|
217 |
|
218 qDebug("%d APs found", wlanApList.size()); |
|
219 if(wlanApList.isEmpty()) { |
|
220 qDebug("Match not found. Go to manual settings."); |
|
221 mNextPageId = WlanWizardPageInternal::PageNetworkMode; |
|
222 } |
|
223 else { |
|
224 int strongestSignal = 0; |
|
225 int strongestIndex = 0; |
|
226 |
|
227 for (int i = 0; i < wlanApList.size(); i++) { |
|
228 // All direct scan results are matches. No need to compare ssids. |
|
229 // In case there are multiple matches to direct scan, use the |
|
230 // strongest signal on the result list. |
|
231 item = wlanApList.at(i); |
|
232 int str = item->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt(); |
|
233 if (str > strongestSignal) { |
|
234 qDebug("Strongest signal %d at %d", str, i); |
|
235 strongestSignal = str; |
|
236 strongestIndex = i; |
|
237 } |
|
238 } |
|
239 |
|
240 item = wlanApList.at(strongestIndex); |
|
241 qDebug("Select AP at %d", strongestIndex); |
|
242 mNextPageId = mWizard->getNextPageId( |
|
243 item->value(WlanQtUtilsAp::ConfIdSsid).toString(), |
|
244 item->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), |
|
245 item->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), |
|
246 item->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), |
|
247 true, // hidden |
|
248 item->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()); |
|
249 } |
|
250 |
|
251 mWizard->nextPage(); |
|
252 |
|
253 } |
|
254 |
|
255 /*! |
|
256 * All wlan channels have been scanned for public networks. Now process the |
|
257 * results. If a network is found which matches the ssid set by the user, |
|
258 * proceed to next page according to the network attributes. |
|
259 * If no ssid match is found, proceed to a direct scan. |
|
260 */ |
|
261 void WlanWizardPageScanning::wlanScanApReady() |
|
262 { |
|
263 OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_WLANSCANAPREADY, |
|
264 "WlanWizardPageScanning::wlanScanApReady" ); |
|
265 |
|
266 WlanQtUtils* utils = mWizard->wlanQtUtils(); |
|
267 Q_ASSERT(utils); |
|
268 |
|
269 QList<QSharedPointer<WlanQtUtilsAp> > wlanApList; |
|
270 |
|
271 // Fetch the list of scan results. |
|
272 utils->availableWlanAps(wlanApList); |
|
273 |
|
274 qDebug("WlanWizardPageScanning::wlanScanApReady - results read"); |
|
275 |
|
276 QString ssid = |
|
277 mWizard->configuration(WlanWizardPrivate::ConfSsid).toString(); |
|
278 qDebug() << "SSID scanned by user " << ssid; |
|
279 |
|
280 bool matchFound = false; |
|
281 int strongestSignal = -1; |
|
282 int strongestIndex = 0; |
|
283 QSharedPointer<WlanQtUtilsAp> item; |
|
284 |
|
285 qDebug("%d APs found", wlanApList.size()); |
|
286 |
|
287 for (int i = 0; i < wlanApList.size(); i++) { |
|
288 // In case there are multiple matches to direct scan, use the |
|
289 // strongest signal on the result list. |
|
290 item = wlanApList.at(i); |
|
291 if (item->value(WlanQtUtilsAp::ConfIdSsid).toString() == ssid) { |
|
292 qDebug("Match found"); |
|
293 matchFound = true; |
|
294 |
|
295 int str = item->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt(); |
|
296 if (str > strongestSignal) { |
|
297 qDebug("Strongest signal %d at %d", str, i); |
|
298 strongestSignal = str; |
|
299 strongestIndex = i; |
|
300 } |
|
301 } |
|
302 } |
|
303 |
|
304 if (matchFound) { |
|
305 qDebug("Select AP at %d", strongestIndex); |
|
306 item = wlanApList.at(strongestIndex); |
|
307 mNextPageId = mWizard->getNextPageId( |
|
308 item->value(WlanQtUtilsAp::ConfIdSsid).toString(), |
|
309 item->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), |
|
310 item->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), |
|
311 item->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), |
|
312 false, // public |
|
313 item->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()); |
|
314 // The ssid indicated by the user was found. Proceed to next page. |
|
315 mWizard->nextPage(); |
|
316 } |
|
317 else { |
|
318 qDebug("Match not found. Perform direct scan."); |
|
319 utils->scanWlanDirect(ssid); |
|
320 } |
|
321 |
|
322 } |
|
323 |
|
324 /*! |
|
325 * Overloaded function from WlanWizardPage. Indicates that this window requires |
|
326 * post-initialization start operations. |
|
327 */ |
|
328 bool WlanWizardPageScanning::requiresStartOperation() |
|
329 { |
|
330 return true; |
|
331 } |
|
332 |
|
333 /*! |
|
334 * Wlan scan is performed as a "post-initialization" which is executed in a |
|
335 * separate scheduler loop. |
|
336 */ |
|
337 void WlanWizardPageScanning::startOperation() |
|
338 { |
|
339 OstTrace0( TRACE_NORMAL, WLANWIZARDPAGESCANNING_STARTOPERATION, |
|
340 "WlanWizardPageScanning::startOperation - start AP scan if results" |
|
341 " are available." ); |
|
342 |
|
343 if (mScanResultsAvailable) { |
|
344 mScanResultsAvailable = false; |
|
345 wlanScanApReady(); |
|
346 } |
|
347 } |
|
348 |