1 /* |
|
2 * Copyright (c) 2009-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 Sniffer List View. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 #include <QGraphicsWidget> |
|
21 #include <QSharedPointer> |
|
22 #include <QObjectList> |
|
23 |
|
24 #include <HbLabel> |
|
25 #include <HbPushButton> |
|
26 #include <HbMenu> |
|
27 #include <HbAction> |
|
28 #include <HbListWidget> |
|
29 #include <HbListWidgetItem> |
|
30 #include <HbDocumentLoader> |
|
31 #include <HbInstance> |
|
32 #include <HbMessageBox> |
|
33 #include <HbParameterLengthLimiter> |
|
34 |
|
35 #include <xqserviceutil.h> |
|
36 |
|
37 // User includes |
|
38 |
|
39 #include "wlanqtutils.h" |
|
40 #include "wlanqtutilsap.h" |
|
41 #include "wlanqtutilsiap.h" |
|
42 |
|
43 #include "wlansnifferengine.h" |
|
44 #include "wlansniffermainwindow.h" |
|
45 #include "wlansnifferlistview.h" |
|
46 #include "wlansnifferlistitem.h" |
|
47 #include "wlansnifferlistwidget.h" |
|
48 |
|
49 #include "OstTraceDefinitions.h" |
|
50 #ifdef OST_TRACE_COMPILER_IN_USE |
|
51 #include "wlansnifferlistviewTraces.h" |
|
52 #endif |
|
53 |
|
54 /*! |
|
55 \class WlanSnifferListView |
|
56 \brief WLAN Sniffer application's list view implementation. |
|
57 */ |
|
58 |
|
59 // External function prototypes |
|
60 |
|
61 // Local constants |
|
62 |
|
63 //! WLAN Sniffer list view docml file location |
|
64 static const QString WlanSnifferListViewDocml(":/docml/wlansnifferlistview.docml"); |
|
65 |
|
66 //! WLAN Sniffer list view object name |
|
67 static const QString WlanSnifferListViewName("occ_list"); |
|
68 |
|
69 // ======== LOCAL FUNCTIONS ======== |
|
70 |
|
71 // ======== MEMBER FUNCTIONS ======== |
|
72 |
|
73 /*! |
|
74 Constructor. |
|
75 |
|
76 @param [in] engine WLAN Sniffer application engine. |
|
77 @param [in] mainWindow WLAN Sniffer main window. |
|
78 */ |
|
79 |
|
80 WlanSnifferListView::WlanSnifferListView( |
|
81 WlanSnifferEngine *engine, |
|
82 WlanSnifferMainWindow *mainWindow) : |
|
83 HbView(), |
|
84 mDocLoader(new HbDocumentLoader(mainWindow)), |
|
85 mWlanListWidget(), |
|
86 mContextMenu(), |
|
87 mContextMenuData(), |
|
88 mWlanEnableDialog(), |
|
89 mIgnoreWlanScanResults(false), |
|
90 mConnectingIapId(WlanQtUtils::IapIdNone), |
|
91 mEngine(engine), |
|
92 mSwitchWlanAction(0), |
|
93 mAddWlanAction(0), |
|
94 mWlanList(0), |
|
95 mStatusLabel(0), |
|
96 mWlanButton(0) |
|
97 { |
|
98 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_WLANSNIFFERLISTVIEW_ENTRY); |
|
99 |
|
100 // Initialize UI from the docml based on standalone/embedded status |
|
101 loadDocml(mEngine->isEmbedded()); |
|
102 |
|
103 if (mEngine->isEmbedded()) { |
|
104 // We need to create a custom navigation action and handle exiting |
|
105 // from the application differently in case the application was |
|
106 // launched as embedded via QtHighway |
|
107 HbAction *completeAction = new HbAction(Hb::BackNaviAction, this); |
|
108 setNavigationAction(completeAction); |
|
109 bool connectStatus = connect( |
|
110 completeAction, |
|
111 SIGNAL(triggered(bool)), |
|
112 mEngine, |
|
113 SLOT(completeService())); |
|
114 Q_ASSERT(connectStatus); |
|
115 } |
|
116 |
|
117 // Connect WLAN network open & close signals |
|
118 bool connectStatus = connect( |
|
119 mEngine->wlanQtUtils(), |
|
120 SIGNAL(wlanNetworkOpened(int)), |
|
121 this, |
|
122 SLOT(updateConnectionOpened(int))); |
|
123 Q_ASSERT(connectStatus); |
|
124 connectStatus = connect( |
|
125 mEngine->wlanQtUtils(), |
|
126 SIGNAL(wlanNetworkClosed(int, int)), |
|
127 this, |
|
128 SLOT(updateConnectionClosed(int))); // "reason" parameter ignored |
|
129 Q_ASSERT(connectStatus); |
|
130 |
|
131 // Connect WLAN ON/OFF setting change signal |
|
132 connectStatus = connect( |
|
133 mEngine, |
|
134 SIGNAL(masterWlanStatus(bool)), |
|
135 this, |
|
136 SLOT(updateWlanEnabled())); |
|
137 Q_ASSERT(connectStatus); |
|
138 |
|
139 // Connect Force Disable WLAN setting change signal |
|
140 connectStatus = connect( |
|
141 mEngine, |
|
142 SIGNAL(forceDisableWlanStatus(bool)), |
|
143 this, |
|
144 SLOT(updateWlanEnabled())); |
|
145 Q_ASSERT(connectStatus); |
|
146 |
|
147 // Connect signals to catch user interaction with the WLAN network list |
|
148 connectStatus = connect( |
|
149 mWlanList, |
|
150 SIGNAL(activated(HbListWidgetItem *)), |
|
151 this, |
|
152 SLOT(handleListItemActivated(HbListWidgetItem *))); |
|
153 Q_ASSERT(connectStatus); |
|
154 connectStatus = connect( |
|
155 mWlanList, |
|
156 SIGNAL(longPressed(HbListWidgetItem *, QPointF)), |
|
157 this, |
|
158 SLOT(handleListItemLongPressed(HbListWidgetItem *, QPointF))); |
|
159 Q_ASSERT(connectStatus); |
|
160 |
|
161 // Connect signals to catch user interaction with WLAN ON/OFF switching |
|
162 connectStatus = connect( |
|
163 mWlanButton, |
|
164 SIGNAL(clicked(bool)), |
|
165 this, |
|
166 SLOT(handleWlanToggled())); |
|
167 Q_ASSERT(connectStatus); |
|
168 connectStatus = connect( |
|
169 mSwitchWlanAction, |
|
170 SIGNAL(triggered(bool)), |
|
171 this, |
|
172 SLOT(handleWlanToggled())); |
|
173 Q_ASSERT(connectStatus); |
|
174 |
|
175 // Connect adding WLAN manually |
|
176 connectStatus = connect( |
|
177 mAddWlanAction, |
|
178 SIGNAL(triggered(bool)), |
|
179 this, |
|
180 SLOT(startWlanWizard())); |
|
181 Q_ASSERT(connectStatus); |
|
182 |
|
183 // Connect WLAN scan results signal |
|
184 connectStatus = connect( |
|
185 mEngine, |
|
186 SIGNAL(wlanScanReady()), |
|
187 this, |
|
188 SLOT(updateListContent())); |
|
189 Q_ASSERT(connectStatus); |
|
190 |
|
191 // Set the initial value of WLAN state |
|
192 updateWlanEnabled(); |
|
193 |
|
194 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_WLANSNIFFERLISTVIEW_EXIT); |
|
195 } |
|
196 |
|
197 /*! |
|
198 Destructor. |
|
199 */ |
|
200 |
|
201 WlanSnifferListView::~WlanSnifferListView() |
|
202 { |
|
203 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_WLANSNIFFERLISTVIEWDESTR_ENTRY); |
|
204 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_WLANSNIFFERLISTVIEWDESTR_EXIT); |
|
205 } |
|
206 |
|
207 /*! |
|
208 Loading of WLAN Sniffer List View docml. |
|
209 |
|
210 @param [in] isEmbedded TRUE if WLAN Sniffer is launched as embedded. |
|
211 */ |
|
212 |
|
213 void WlanSnifferListView::loadDocml(bool isEmbedded) |
|
214 { |
|
215 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_LOADDOCML_ENTRY); |
|
216 |
|
217 // Pass the view to the document loader. Document loader uses this view |
|
218 // when docml is parsed, instead of creating a new view. |
|
219 setObjectName(WlanSnifferListViewName); |
|
220 QObjectList objectList; |
|
221 objectList.append(this); |
|
222 mDocLoader->setObjectTree(objectList); |
|
223 |
|
224 // First load the common section |
|
225 bool ok = false; |
|
226 mDocLoader->load(WlanSnifferListViewDocml, &ok); |
|
227 Q_ASSERT(ok); |
|
228 |
|
229 // Then load the mode specific section |
|
230 if (isEmbedded) { |
|
231 mDocLoader->load(WlanSnifferListViewDocml, "embedded", &ok); |
|
232 } else { |
|
233 mDocLoader->load(WlanSnifferListViewDocml, "standalone", &ok); |
|
234 } |
|
235 Q_ASSERT(ok); |
|
236 |
|
237 // Load the view by name from the xml file |
|
238 QGraphicsWidget *widget = mDocLoader->findWidget(WlanSnifferListViewName); |
|
239 Q_ASSERT(widget); |
|
240 |
|
241 // Set view menu |
|
242 HbMenu *viewMenu = qobject_cast<HbMenu *>(mDocLoader->findWidget("viewMenu")); |
|
243 Q_ASSERT(viewMenu); |
|
244 setMenu(viewMenu); |
|
245 |
|
246 // WLAN Sniffer list widget takes responsibility of the list widget behaviour |
|
247 mWlanList = qobject_cast<HbListWidget *>(mDocLoader->findWidget("listWidget")); |
|
248 Q_ASSERT(mWlanList); |
|
249 mWlanListWidget = QSharedPointer<WlanSnifferListWidget>(new WlanSnifferListWidget(mWlanList)); |
|
250 |
|
251 // Retrieve pointers to widgets we need to access from the code |
|
252 mSwitchWlanAction = qobject_cast<HbAction *>(mDocLoader->findObject("switchWlanAction")); |
|
253 Q_ASSERT(mSwitchWlanAction); |
|
254 |
|
255 mAddWlanAction = qobject_cast<HbAction *>(mDocLoader->findObject("addWlanAction")); |
|
256 Q_ASSERT(mAddWlanAction); |
|
257 |
|
258 mWlanButton = qobject_cast<HbPushButton *>(mDocLoader->findWidget("wlanButton")); |
|
259 Q_ASSERT(mWlanButton); |
|
260 |
|
261 mStatusLabel = qobject_cast<HbLabel *>(mDocLoader->findWidget("statusLabel")); |
|
262 Q_ASSERT(mStatusLabel); |
|
263 |
|
264 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_LOADDOCML_EXIT); |
|
265 } |
|
266 |
|
267 /*! |
|
268 Updates WLAN status label based on current WLAN status. |
|
269 |
|
270 @param [in] enabled True if WLAN is enabled. |
|
271 */ |
|
272 |
|
273 void WlanSnifferListView::updateWlanStatusLabel(bool enabled) |
|
274 { |
|
275 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_UPDATEWLANSTATUSLABEL_ENTRY); |
|
276 |
|
277 QString status; |
|
278 if (!enabled) { |
|
279 // WLAN is OFF |
|
280 status = hbTrId("txt_occ_grid_wlan_is_switched_off"); |
|
281 } else { |
|
282 int iapId = mEngine->wlanQtUtils()->activeIap(); |
|
283 |
|
284 switch (mEngine->wlanQtUtils()->connectionStatus()) { |
|
285 case WlanQtUtils::ConnStatusConnecting: |
|
286 // WLAN is connecting |
|
287 Q_ASSERT(iapId != WlanQtUtils::IapIdNone); |
|
288 status = HbParameterLengthLimiter( |
|
289 "txt_occ_grid_connecting_to_1").arg( |
|
290 mEngine->wlanQtUtils()->iapName(iapId)); |
|
291 break; |
|
292 |
|
293 case WlanQtUtils::ConnStatusConnected: |
|
294 // WLAN is connected |
|
295 Q_ASSERT(iapId != WlanQtUtils::IapIdNone); |
|
296 status = HbParameterLengthLimiter( |
|
297 "txt_occ_grid_connected_to_1").arg( |
|
298 mEngine->wlanQtUtils()->iapName(iapId)); |
|
299 break; |
|
300 |
|
301 default: |
|
302 // WLAN is disconnected |
|
303 status = hbTrId("txt_occ_grid_not_connected"); |
|
304 break; |
|
305 } |
|
306 } |
|
307 mStatusLabel->setPlainText(status); |
|
308 |
|
309 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_UPDATEWLANSTATUSLABEL_EXIT); |
|
310 } |
|
311 |
|
312 /*! |
|
313 Handles a "Connect" action for the selected IAP or AP item. |
|
314 |
|
315 @param data IAP ID (int), or AP class (WlanQtUtilsAp) to connect. |
|
316 */ |
|
317 |
|
318 void WlanSnifferListView::handleConnect(QVariant data) |
|
319 { |
|
320 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLECONNECT_ENTRY); |
|
321 |
|
322 // Check whether we need to disconnect a previous connection first |
|
323 int activeWlanId = mEngine->wlanQtUtils()->activeIap(); |
|
324 |
|
325 // Get IAP ID if IAP is available |
|
326 int iapId = WlanQtUtils::IapIdNone; |
|
327 if (data.canConvert<int>()) { |
|
328 iapId = data.toInt(); |
|
329 } |
|
330 OstTraceExt2( |
|
331 TRACE_NORMAL, |
|
332 WLANSNIFFERLISTVIEW_HANDLECONNECT, |
|
333 "WlanSnifferListView::handleConnect;activeWlanId=%d;iapId=%d", |
|
334 activeWlanId, |
|
335 iapId); |
|
336 |
|
337 // Skip connecting if the IAP is already connected |
|
338 if (activeWlanId != WlanQtUtils::IapIdNone && iapId == activeWlanId) { |
|
339 return; |
|
340 } |
|
341 |
|
342 if (activeWlanId != WlanQtUtils::IapIdNone) { |
|
343 mEngine->wlanQtUtils()->disconnectIap(activeWlanId); |
|
344 |
|
345 // Update list widget so that the IAP is no longer connected |
|
346 updateListContent(); |
|
347 } |
|
348 |
|
349 if (iapId != WlanQtUtils::IapIdNone) { |
|
350 // Item was an IAP, connect it. |
|
351 mConnectingIapId = iapId; |
|
352 mStatusLabel->setPlainText( |
|
353 HbParameterLengthLimiter( |
|
354 "txt_occ_grid_connecting_to_1").arg( |
|
355 mEngine->wlanQtUtils()->iapName(iapId))); |
|
356 mEngine->wlanQtUtils()->connectIap(iapId); |
|
357 } else { |
|
358 // Item is a WLAN AP. Summon the Wlan Wizard to handle creation |
|
359 // of the IAP and connecting it. |
|
360 Q_ASSERT(data.canConvert<WlanQtUtilsAp>()); |
|
361 WlanQtUtilsAp ap = data.value<WlanQtUtilsAp>(); |
|
362 emit wizardTriggered(&ap); |
|
363 } |
|
364 |
|
365 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLECONNECT_EXIT); |
|
366 } |
|
367 |
|
368 /*! |
|
369 Updates WLAN list widget with new WLAN scan results. |
|
370 */ |
|
371 |
|
372 void WlanSnifferListView::updateListContent() |
|
373 { |
|
374 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_UPDATELISTCONTENT_ENTRY); |
|
375 |
|
376 if (!mIgnoreWlanScanResults) { |
|
377 // Get the latest scan results |
|
378 QList< QSharedPointer<WlanQtUtilsIap> > iaps; |
|
379 QList< QSharedPointer<WlanQtUtilsAp> > aps; |
|
380 mEngine->wlanQtUtils()->availableWlans(iaps, aps); |
|
381 |
|
382 // Check for connected IAP |
|
383 int iapId = WlanQtUtils::IapIdNone; |
|
384 if (mEngine->wlanQtUtils()->connectionStatus() == |
|
385 WlanQtUtils::ConnStatusConnected) { |
|
386 iapId = mEngine->wlanQtUtils()->activeIap(); |
|
387 } |
|
388 |
|
389 // Let the list widget class update the list content |
|
390 mWlanListWidget->updateContent(iaps, aps, iapId); |
|
391 } |
|
392 |
|
393 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_UPDATELISTCONTENT_EXIT); |
|
394 } |
|
395 |
|
396 /*! |
|
397 WLAN state settings change handler. This slot handles both the |
|
398 WLAN ON/OFF setting and WLAN forced OFF setting. |
|
399 Updates all WLAN ON/OFF related (UI) elements. |
|
400 */ |
|
401 |
|
402 void WlanSnifferListView::updateWlanEnabled() |
|
403 { |
|
404 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_UPDATEWLANENABLED_ENTRY); |
|
405 |
|
406 // Check the updated setting status |
|
407 bool forcedOff = mEngine->forceDisableWlan(); |
|
408 bool enabled = mEngine->masterWlan() && !forcedOff; |
|
409 |
|
410 // Update the WLAN status label |
|
411 updateWlanStatusLabel(enabled); |
|
412 |
|
413 // Set the WLAN ON/OFF button state |
|
414 mWlanButton->setChecked(enabled); |
|
415 |
|
416 // Select the right WLAN button icon and menu action text |
|
417 if (enabled) { |
|
418 mWlanButton->setIcon(HbIcon("qtg_mono_wlan")); |
|
419 mSwitchWlanAction->setText(hbTrId("txt_occ_opt_switch_wlan_off")); |
|
420 } else { |
|
421 mWlanButton->setIcon(HbIcon("qtg_mono_wlan_offline")); |
|
422 mSwitchWlanAction->setText(hbTrId("txt_occ_opt_switch_wlan_on")); |
|
423 } |
|
424 |
|
425 // Set triggable WLAN UI elements disabled if WLAN is forced OFF |
|
426 mWlanButton->setEnabled(!forcedOff); |
|
427 mSwitchWlanAction->setEnabled(!forcedOff); |
|
428 |
|
429 // Disable manual WLAN IAP creation when WLAN is switched OFF |
|
430 mAddWlanAction->setEnabled(enabled); |
|
431 |
|
432 // Switch WLAN scanning ON/OFF |
|
433 if (enabled) { |
|
434 mEngine->startWlanScanning(); |
|
435 } else { |
|
436 mEngine->stopWlanScanning(); |
|
437 // Clear the network list when going to offline |
|
438 mWlanList->clear(); |
|
439 } |
|
440 |
|
441 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_UPDATEWLANENABLED_EXIT); |
|
442 } |
|
443 |
|
444 /*! |
|
445 Connection opened slot. Updates connection status. |
|
446 |
|
447 @param [in] iapId IAP ID of the connected WLAN IAP. |
|
448 */ |
|
449 |
|
450 void WlanSnifferListView::updateConnectionOpened(int iapId) |
|
451 { |
|
452 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_UPDATECONNECTIONOPENED_ENTRY); |
|
453 |
|
454 mConnectingIapId = WlanQtUtils::IapIdNone; |
|
455 mStatusLabel->setPlainText( |
|
456 HbParameterLengthLimiter( |
|
457 "txt_occ_grid_connected_to_1").arg( |
|
458 mEngine->wlanQtUtils()->iapName(iapId))); |
|
459 |
|
460 // Update the list widget content |
|
461 updateListContent(); |
|
462 |
|
463 // Scroll to the top of the list |
|
464 mWlanListWidget->scrollTo(0); |
|
465 |
|
466 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_UPDATECONNECTIONOPENED_EXIT); |
|
467 } |
|
468 |
|
469 /*! |
|
470 Connection closing handler. Updates connection status. |
|
471 |
|
472 @param [in] iapId Disconnected IAP ID. |
|
473 */ |
|
474 |
|
475 void WlanSnifferListView::updateConnectionClosed(int iapId) |
|
476 { |
|
477 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_UPDATECONNECTIONCLOSED_ENTRY); |
|
478 |
|
479 if (mEngine->masterWlan() && !mEngine->forceDisableWlan()) { |
|
480 // Check whether we can update the status text to "Not connected" |
|
481 if (mConnectingIapId == WlanQtUtils::IapIdNone || |
|
482 mConnectingIapId == iapId) { |
|
483 mStatusLabel->setPlainText(hbTrId("txt_occ_grid_not_connected")); |
|
484 } |
|
485 // else: we are already connecting to another network so don't touch |
|
486 // the status label |
|
487 |
|
488 // Update the list widget content |
|
489 updateListContent(); |
|
490 } |
|
491 |
|
492 if (mConnectingIapId == iapId) { |
|
493 // Not connecting to this network anymore |
|
494 mConnectingIapId = WlanQtUtils::IapIdNone; |
|
495 } |
|
496 |
|
497 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_UPDATECONNECTIONCLOSED_EXIT); |
|
498 } |
|
499 |
|
500 /*! |
|
501 Context menu closing handler. |
|
502 */ |
|
503 |
|
504 void WlanSnifferListView::handleContextMenuClosed() |
|
505 { |
|
506 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLECONTEXTMENUCLOSED_ENTRY); |
|
507 |
|
508 // Let list updating start again |
|
509 mIgnoreWlanScanResults = false; |
|
510 |
|
511 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLECONTEXTMENUCLOSED_EXIT); |
|
512 } |
|
513 |
|
514 /*! |
|
515 List item activation handler. Connects the WLAN network, and if there |
|
516 is no IAP yet for it, starts WLAN Wizard. |
|
517 |
|
518 @param [in] item Selected WLAN network list item. |
|
519 */ |
|
520 |
|
521 void WlanSnifferListView::handleListItemActivated(HbListWidgetItem *item) |
|
522 { |
|
523 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLELISTITEMACTIVATED_ENTRY); |
|
524 |
|
525 handleConnect(item->data()); |
|
526 |
|
527 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLELISTITEMACTIVATED_EXIT); |
|
528 } |
|
529 |
|
530 /*! |
|
531 WLAN List item long press handler. |
|
532 The long press of a list item (i.e. WLAN IAP) opens a context menu that |
|
533 is populated depending on the state of the WLAN network in case. |
|
534 |
|
535 @param [in] item Selected list item. |
|
536 @param [in] coords Coordinates of the long press. |
|
537 */ |
|
538 |
|
539 void WlanSnifferListView::handleListItemLongPressed( |
|
540 HbListWidgetItem *item, |
|
541 const QPointF &coords) |
|
542 { |
|
543 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLELISTITEMLONGPRESSED_ENTRY); |
|
544 |
|
545 mContextMenu = QSharedPointer<HbMenu>(new HbMenu()); |
|
546 |
|
547 int activeIap = mEngine->wlanQtUtils()->activeIap(); |
|
548 |
|
549 // Remember the item that was long pressed |
|
550 mContextMenuData = item->data(); |
|
551 if (mContextMenuData.canConvert<int>() |
|
552 && mContextMenuData.toInt() == activeIap) { |
|
553 // Connected IAP, add "Disconnect" action |
|
554 mContextMenu->addAction( |
|
555 hbTrId("txt_common_menu_disconnect"), |
|
556 this, |
|
557 SLOT(handleListItemDisconnect())); |
|
558 } else { |
|
559 // Not connected IAP or AP, add "Connect" action |
|
560 mContextMenu->addAction( |
|
561 hbTrId("txt_common_menu_connect"), |
|
562 this, |
|
563 SLOT(handleListItemConnect())); |
|
564 } |
|
565 |
|
566 // Show the menu and connect closure signal (to re-enable list refreshing) |
|
567 bool connectStatus = connect( |
|
568 mContextMenu.data(), |
|
569 SIGNAL(aboutToClose()), |
|
570 this, |
|
571 SLOT(handleContextMenuClosed())); |
|
572 Q_ASSERT(connectStatus); |
|
573 mContextMenu->setTimeout(HbPopup::ContextMenuTimeout); |
|
574 mContextMenu->setPreferredPos(coords); |
|
575 mContextMenu->show(); |
|
576 |
|
577 // Skip WLAN scan result updates during context menu handling |
|
578 mIgnoreWlanScanResults = true; |
|
579 |
|
580 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLELISTITEMLONGPRESSED_EXIT); |
|
581 } |
|
582 |
|
583 /*! |
|
584 Handles the "Connect" action selected from the context menu for a list item. |
|
585 */ |
|
586 |
|
587 void WlanSnifferListView::handleListItemConnect() |
|
588 { |
|
589 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLELISTITEMCONNECT_ENTRY); |
|
590 |
|
591 handleConnect(mContextMenuData); |
|
592 |
|
593 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLELISTITEMCONNECT_EXIT); |
|
594 } |
|
595 |
|
596 /*! |
|
597 Handles the "Disconnect" action selected from the context menu for a list item. |
|
598 */ |
|
599 |
|
600 void WlanSnifferListView::handleListItemDisconnect() |
|
601 { |
|
602 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLELISTITEMDISCONNECT_ENTRY); |
|
603 |
|
604 // "Disconnect" was only added, if the item was an IAP and data was |
|
605 // the IAP ID. |
|
606 Q_ASSERT(mContextMenuData.canConvert<int>()); |
|
607 mEngine->wlanQtUtils()->disconnectIap(mContextMenuData.toInt()); |
|
608 |
|
609 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLELISTITEMDISCONNECT_EXIT); |
|
610 } |
|
611 |
|
612 /*! |
|
613 Function for handling WLAN ON/OFF switch initiation. |
|
614 */ |
|
615 |
|
616 void WlanSnifferListView::handleWlanToggled() |
|
617 { |
|
618 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLEWLANTOGGLED_ENTRY); |
|
619 |
|
620 // Toggle the new WLAN ON/OFF value |
|
621 bool wlanOn = mEngine->masterWlan(); |
|
622 OstTraceExt1( |
|
623 TRACE_NORMAL, |
|
624 WLANSNIFFERLISTVIEW_HANDLEWLANTOGGLED, |
|
625 "WlanSnifferListView::handleWlanToggled;wlan=%hhu", |
|
626 wlanOn); |
|
627 |
|
628 // We have to check whether the offline mode is ON. If it is, then the |
|
629 // user needs to be queried whether WLAN will be used in offline mode. |
|
630 if (!wlanOn && mEngine->offlineMode()) { |
|
631 // Show the dialog and wait for user input. |
|
632 mWlanEnableDialog = QSharedPointer<HbMessageBox>( |
|
633 new HbMessageBox(HbMessageBox::MessageTypeQuestion)); |
|
634 mWlanEnableDialog->setTimeout(HbPopup::StandardTimeout); |
|
635 mWlanEnableDialog->setText(hbTrId("txt_occ_info_activate_wlan_in_airplane_mode")); |
|
636 // Open the dialog and connect the result to the handleWlanEnableDialogClosed slot |
|
637 mWlanEnableDialog->open(this, SLOT(handleWlanEnableDialogClosed(HbAction*))); |
|
638 } else { |
|
639 // Stop WLAN scanning immediately when switching WLAN OFF. |
|
640 // WLAN might have sent scan results just before disabling WLAN. |
|
641 if (wlanOn) { |
|
642 mEngine->stopWlanScanning(); |
|
643 } |
|
644 mEngine->setMasterWlan(!wlanOn); |
|
645 } |
|
646 |
|
647 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLEWLANTOGGLED_EXIT); |
|
648 } |
|
649 |
|
650 /*! |
|
651 Function for handling WLAN Wizard starting when adding WLAN manually. |
|
652 */ |
|
653 |
|
654 void WlanSnifferListView::startWlanWizard() |
|
655 { |
|
656 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_STARTWLANWIZARD_ENTRY); |
|
657 |
|
658 // TODO: Stop connections & do other cleanup before wizard can start? |
|
659 |
|
660 emit wizardTriggered(NULL); |
|
661 |
|
662 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_STARTWLANWIZARD_EXIT); |
|
663 } |
|
664 |
|
665 /*! |
|
666 Function to handle the input received when the wlan enabling |
|
667 query is closed. |
|
668 |
|
669 @param [in] action The user action received from the dialog. |
|
670 */ |
|
671 |
|
672 void WlanSnifferListView::handleWlanEnableDialogClosed(HbAction *action) |
|
673 { |
|
674 OstTraceFunctionEntry0(WLANSNIFFERLISTVIEW_HANDLEWLANENABLEDIALOGCLOSED_ENTRY); |
|
675 |
|
676 // The dialog must exist |
|
677 Q_ASSERT(mWlanEnableDialog); |
|
678 |
|
679 // If the user selected yes, then the wlan value is toggled, |
|
680 // otherwise nothing needs to be done. |
|
681 // TODO: Update actions().at(0) when a better solution is provided by orbit |
|
682 if (action == mWlanEnableDialog->actions().at(0)) { |
|
683 mEngine->setMasterWlan(true); |
|
684 } |
|
685 |
|
686 OstTraceFunctionExit0(WLANSNIFFERLISTVIEW_HANDLEWLANENABLEDIALOGCLOSED_EXIT); |
|
687 } |
|