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