wlanutilities/wlansniffer/wlansnifferapplication/src/wlansnifferlistwidget.cpp
changeset 31 e8f4211554fb
child 39 7b3e49e4608a
equal deleted inserted replaced
30:ab513c8439db 31:e8f4211554fb
       
     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 widget class.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <QSharedPointer>
       
    21 #include <HbListWidget>
       
    22 #include <HbListWidgetItem>
       
    23 #include <HbAbstractViewItem>
       
    24 #include <HbStyleLoader>
       
    25 #include <HbStringUtil>
       
    26 #include <cmmanagerdefines_shim.h>
       
    27 
       
    28 // User includes
       
    29 
       
    30 #include "wlanqtutils.h"
       
    31 #include "wlanqtutilsap.h"
       
    32 #include "wlanqtutilsiap.h"
       
    33 
       
    34 #include "wlansniffer.h"
       
    35 #include "wlansnifferlistitem.h"
       
    36 #include "wlansnifferlistwidget.h"
       
    37 
       
    38 #include "OstTraceDefinitions.h"
       
    39 #ifdef OST_TRACE_COMPILER_IN_USE
       
    40 #include "wlansnifferlistwidgetTraces.h"
       
    41 #endif
       
    42 
       
    43 /*!
       
    44     \class WlanSnifferListWidget
       
    45     \brief WLAN Sniffer Custom List Widget implementation. 
       
    46 */
       
    47 
       
    48 // External function prototypes
       
    49 
       
    50 // Local constants
       
    51 
       
    52 //! Location of WLAN Sniffer List Layout definitions
       
    53 static const QString WlanSnifferLayoutPath(":/wlansnifferlistlayout/");
       
    54 
       
    55 // ======== LOCAL FUNCTIONS ========
       
    56 
       
    57 // ======== MEMBER FUNCTIONS ========
       
    58 
       
    59 /*!
       
    60     Constructor.
       
    61     
       
    62     @param [in] listWidget List Widget created to customize.
       
    63 */
       
    64 
       
    65 WlanSnifferListWidget::WlanSnifferListWidget(HbListWidget *listWidget) :
       
    66     mListWidget(listWidget)
       
    67 {
       
    68     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY);
       
    69     
       
    70     // Register custom layout location
       
    71     HbStyleLoader::registerFilePath(WlanSnifferLayoutPath);
       
    72     
       
    73     // Set custom WLAN list item layout
       
    74     mListWidget->setLayoutName("wlanlistitem");
       
    75     
       
    76     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT);
       
    77 }
       
    78 
       
    79 /*!
       
    80     Destructor.
       
    81 */
       
    82 
       
    83 WlanSnifferListWidget::~WlanSnifferListWidget()
       
    84 {
       
    85     OstTraceFunctionEntry0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY);
       
    86     
       
    87     HbStyleLoader::unregisterFilePath(WlanSnifferLayoutPath);
       
    88     
       
    89     OstTraceFunctionExit0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT);
       
    90 }
       
    91 
       
    92 /*!
       
    93     Updates the list widget content with the given IAPs and APs.
       
    94     
       
    95     @param [in] iaps New WLAN IAP list.
       
    96     @param [in] aps New WLAN AP list.
       
    97     @param [in] connectedIapId IAP ID of the connected WLAN or
       
    98                 IapIdNone if not connected.
       
    99  */
       
   100 
       
   101 void WlanSnifferListWidget::updateContent(
       
   102     QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
       
   103     QList< QSharedPointer<WlanQtUtilsAp> > &aps,
       
   104     int connectedIapId)
       
   105 {
       
   106     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_UPDATESCANSTATUS_ENTRY);
       
   107     
       
   108     traceListContent();
       
   109     
       
   110     // Sort the scan result lists
       
   111     sortIaps(iaps, connectedIapId);
       
   112     sortAps(aps);
       
   113     
       
   114     // Remove items, which are not present in new IAP or AP lists
       
   115     removeLostItems(iaps, aps);
       
   116 
       
   117     // Add items, which are only found in the new IAP and AP lists.
       
   118     // Also update the icons of existing items (connection mode and
       
   119     // signal strength may have changed)
       
   120     addDiscoveredItemsAndUpdateRest(iaps, aps, connectedIapId);
       
   121 
       
   122     traceListContent();
       
   123     
       
   124     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_UPDATESCANSTATUS_EXIT);
       
   125 }
       
   126 
       
   127 /*!
       
   128     Scroll the list widget to given row.
       
   129     
       
   130     @param [in] row Row to scroll to. Indexing starts from zero. 
       
   131  */
       
   132 
       
   133 void WlanSnifferListWidget::scrollTo(int row)
       
   134 {
       
   135     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SCROLLTO_ENTRY);
       
   136 
       
   137     OstTrace1(
       
   138         TRACE_NORMAL,
       
   139         WLANSNIFFERLISTWIDGET_SCROLLTO,
       
   140         "WlanSnifferListWidget::scrollTo;row=%d",
       
   141         row);
       
   142 
       
   143     // Check that the row exists
       
   144     if (row < mListWidget->count()) {
       
   145         // Do the scrolling
       
   146         QModelIndex index = mListWidget->model()->index(row, 0);
       
   147         mListWidget->scrollTo(index);
       
   148     }
       
   149 
       
   150     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SCROLLTO_EXIT);
       
   151 }
       
   152 
       
   153 /*!
       
   154     IAP list sorting. Sorts IAPs into alphabetical order taking localization
       
   155     into account.
       
   156     
       
   157     @param [in,out] iaps WLAN IAP list.
       
   158     @param [in] connectedIapId IAP ID of the connected WLAN or
       
   159                 IapIdNone if not connected.
       
   160 */
       
   161 
       
   162 void WlanSnifferListWidget::sortIaps(
       
   163     QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
       
   164     int connectedIapId)
       
   165 {
       
   166     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SORTIAPS_ENTRY);
       
   167     
       
   168     // Order the list by IAP name
       
   169     qSort(
       
   170         iaps.begin(),
       
   171         iaps.end(),
       
   172         WlanSnifferListWidget::iapLessThan);
       
   173 
       
   174     // Find the possible connected IAP
       
   175     int connectedIndex = 0;
       
   176     for (int i = 0; i < iaps.size(); i++) {
       
   177         if (iaps[i]->value(WlanQtUtilsIap::ConfIdIapId).toInt() == connectedIapId) {
       
   178             connectedIndex = i;
       
   179             break;
       
   180         }
       
   181     }
       
   182 
       
   183     // Move the possible connected IAP to the beginning
       
   184     if (connectedIndex) {
       
   185         OstTraceExt2(
       
   186             TRACE_NORMAL,
       
   187             WLANSNIFFERLISTWIDGET_SORTIAPS_MOVE_CONNECTED,
       
   188             "WlanSnifferListWidget::sortIaps Moving connected IAP to top;connectedIapId=%d;connectedIndex=%d",
       
   189             connectedIapId,
       
   190             connectedIndex);
       
   191         
       
   192         iaps.move(connectedIndex, 0);
       
   193     }
       
   194 
       
   195     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SORTIAPS_EXIT);
       
   196 }
       
   197 
       
   198 /*!
       
   199     AP list sorting. Sorts APs into alphabetical order taking localization
       
   200     into account.
       
   201     
       
   202     @param [in,out] aps WLAN AP list.
       
   203 */
       
   204 
       
   205 void WlanSnifferListWidget::sortAps(
       
   206     QList< QSharedPointer<WlanQtUtilsAp> > &aps)
       
   207 {
       
   208     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SORTAPS_ENTRY);
       
   209     
       
   210     // Order the list by AP SSID
       
   211     qSort(
       
   212         aps.begin(),
       
   213         aps.end(),
       
   214         WlanSnifferListWidget::apLessThan);
       
   215 
       
   216     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SORTAPS_EXIT);
       
   217 }
       
   218 
       
   219 /*!
       
   220     Compares two WLAN IAPs. Comparison is done with the IAP name.
       
   221     
       
   222     @param[in] iap1 IAP to compare with.
       
   223     @param[in] iap2 IAP to compare.
       
   224     
       
   225     @return Returns true if the first iap is "less than" the second one.
       
   226  */
       
   227 
       
   228 bool WlanSnifferListWidget::iapLessThan(
       
   229     const QSharedPointer<WlanQtUtilsIap> iap1,
       
   230     const QSharedPointer<WlanQtUtilsIap> iap2)
       
   231 {
       
   232     // Primary comparison is based on the name
       
   233     int result = HbStringUtil::compareC(
       
   234         iap1->value(WlanQtUtilsIap::ConfIdName).toString(),
       
   235         iap2->value(WlanQtUtilsIap::ConfIdName).toString());
       
   236     
       
   237     // If name is equal, compare based on security mode
       
   238     if (result == 0) {
       
   239         result =
       
   240             iap1->value(WlanQtUtilsIap::ConfIdSecurityMode).toInt() -
       
   241             iap2->value(WlanQtUtilsIap::ConfIdSecurityMode).toInt();
       
   242     }
       
   243     
       
   244     return (result < 0) ? true : false;
       
   245 }
       
   246 
       
   247 /*!
       
   248     Compares two WLAN APs. Comparison is done with the AP SSID.
       
   249     
       
   250     @param[in] ap1 AP to compare with.
       
   251     @param[in] ap2 AP to compare.
       
   252     
       
   253     @return Returns true if the first ap is "less than" the second one.
       
   254  */
       
   255 
       
   256 bool WlanSnifferListWidget::apLessThan(
       
   257     const QSharedPointer<WlanQtUtilsAp> ap1,
       
   258     const QSharedPointer<WlanQtUtilsAp> ap2)
       
   259 {
       
   260     // Primary comparison is based on the SSID
       
   261     int result = HbStringUtil::compareC(
       
   262         ap1->value(WlanQtUtilsAp::ConfIdSsid).toString(),
       
   263         ap2->value(WlanQtUtilsAp::ConfIdSsid).toString());
       
   264 
       
   265     // If SSID is equal, compare based on security mode
       
   266     if (result == 0) {
       
   267         result =
       
   268             ap1->value(WlanQtUtilsIap::ConfIdSecurityMode).toInt() -
       
   269             ap2->value(WlanQtUtilsIap::ConfIdSecurityMode).toInt();
       
   270     }
       
   271 
       
   272     return (result < 0) ? true : false;
       
   273 }
       
   274 
       
   275 /*!
       
   276     Function for finding the given IAP from the old Wlan list.
       
   277     
       
   278     @param [in] iap IAP to find.
       
   279     
       
   280     @return Found WLAN List Widget item, 0 if not found.
       
   281 */
       
   282 
       
   283 WlanSnifferListItem *WlanSnifferListWidget::findFromOldList(
       
   284     QSharedPointer<WlanQtUtilsIap> iap)
       
   285 {
       
   286     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP_ENTRY);
       
   287 
       
   288     WlanSnifferListItem *result = NULL;
       
   289     QVariant iapData = iap->value(WlanQtUtilsIap::ConfIdIapId);
       
   290     for (int row = 0; row < mListWidget->count(); row++) {
       
   291         HbListWidgetItem *item = mListWidget->item(row);
       
   292         if (item->data() == iapData) {
       
   293             result = static_cast<WlanSnifferListItem *>(item);
       
   294             break;
       
   295         }
       
   296     }
       
   297 
       
   298     OstTraceExt2(
       
   299         TRACE_DUMP,
       
   300         WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP,
       
   301         "WlanSnifferListWidget::findFromOldList;iapId=%d;found=%hhu",
       
   302         iapData.toInt(),
       
   303         (result != NULL) ? true : false);
       
   304     
       
   305     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP_EXIT);
       
   306     return result;
       
   307 }
       
   308 
       
   309 /*!
       
   310     Function for finding the given AP from the old Wlan list.
       
   311     
       
   312     @param [in] ap AP to find. 
       
   313     
       
   314     @return Found WLAN List Widget item, 0 if not found.
       
   315 */
       
   316 
       
   317 WlanSnifferListItem *WlanSnifferListWidget::findFromOldList(
       
   318     QSharedPointer<WlanQtUtilsAp> ap)
       
   319 {
       
   320     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP_ENTRY);
       
   321     
       
   322     WlanSnifferListItem *result = NULL;
       
   323     for (int row = 0; row < mListWidget->count(); row++) {
       
   324         HbListWidgetItem *item = mListWidget->item(row);
       
   325         if (item->data().canConvert<WlanQtUtilsAp>()) {
       
   326             WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>();
       
   327             if (WlanQtUtilsAp::compare(ap.data(), &oldAp) == true) {
       
   328                 result = static_cast<WlanSnifferListItem *>(item);
       
   329                 break;
       
   330             }
       
   331         }
       
   332     }
       
   333     
       
   334 #ifdef OST_TRACE_COMPILER_IN_USE
       
   335     QString tmp(ap.data()->value(WlanQtUtilsAp::ConfIdSsid).toString());
       
   336     TPtrC16 ssid(tmp.utf16(), tmp.length());
       
   337     OstTraceExt2(
       
   338         TRACE_NORMAL,
       
   339         WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP,
       
   340         "WlanSnifferListWidget::findFromOldList;found=%hhu;ssid=%S",
       
   341         (result != NULL) ? true : false,
       
   342         ssid);
       
   343 #endif
       
   344     
       
   345     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP_EXIT);
       
   346     return result;
       
   347 }
       
   348 
       
   349 /*!
       
   350     Function for creating a new list item from the given IAP.
       
   351     
       
   352     @param [in] iap WLAN IAP to create.
       
   353     @param [in] connectedIapId IAP ID of the connected WLAN or
       
   354                 IapIdNone if not connected.
       
   355     
       
   356     @return New WLAN List Widget item.
       
   357 */
       
   358 
       
   359 HbListWidgetItem *WlanSnifferListWidget::listItemCreate(
       
   360     QSharedPointer<WlanQtUtilsIap> iap,
       
   361     int connectedIapId)
       
   362 {
       
   363     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_ENTRY);
       
   364     
       
   365     WlanSnifferListItem *item = new WlanSnifferListItem();
       
   366     item->setNetworkName(iap->value(WlanQtUtilsIap::ConfIdName).toString());
       
   367     if (iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() !=
       
   368         CMManagerShim::WlanSecModeOpen) {
       
   369         item->setSecureIcon("qtg_small_secure");
       
   370         // TODO: Handle WPS case - it uses a different icon!
       
   371         // Will be implemented with "Adding WLAN IAP manually" subfeature.
       
   372     }
       
   373 
       
   374     item->setLeftIcon(
       
   375         leftIconChoose(
       
   376             iap->value(WlanQtUtilsIap::ConfIdIapId).toInt(),
       
   377             connectedIapId));
       
   378     item->setSignalIcon(
       
   379         signalStrengthIconChoose(
       
   380             iap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
       
   381     
       
   382     item->setData(iap->value(WlanQtUtilsIap::ConfIdIapId));
       
   383     
       
   384     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_EXIT);
       
   385     return item;
       
   386 }
       
   387 
       
   388 /*!
       
   389     Function for creating a new list item from the given AP.
       
   390     
       
   391     @param [in] ap WLAN AP to create.
       
   392     
       
   393     @return New WLAN List Widget item.
       
   394 */
       
   395 
       
   396 HbListWidgetItem *WlanSnifferListWidget::listItemCreate(
       
   397     QSharedPointer<WlanQtUtilsAp> ap)
       
   398 {
       
   399     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_ENTRY);
       
   400     
       
   401     WlanSnifferListItem *item = new WlanSnifferListItem();
       
   402     item->setNetworkName(ap->value(WlanQtUtilsAp::ConfIdSsid).toString());
       
   403     if (ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() 
       
   404         != CMManagerShim::WlanSecModeOpen) {
       
   405         item->setSecureIcon("qtg_small_secure");
       
   406         // TODO: Handle WPS case - it uses a different icon!
       
   407         // Will be implemented with "Adding WLAN IAP manually" subfeature.
       
   408     }
       
   409     item->setSignalIcon(
       
   410         signalStrengthIconChoose(
       
   411             ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
       
   412     
       
   413     QVariant data;
       
   414     data.setValue(*ap);
       
   415     item->setData(data);
       
   416     
       
   417     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_EXIT);
       
   418     return item;
       
   419 }
       
   420 
       
   421 /*!
       
   422     Function for selecting the correct signal strength icon.
       
   423     
       
   424     @param [in] signalStrength Signal strength.
       
   425     
       
   426     @return Signal strength icon logical name.
       
   427 */
       
   428 
       
   429 QString WlanSnifferListWidget::signalStrengthIconChoose(int signalStrength)
       
   430 {
       
   431     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SIGNALSTRENGTHICONCHOOSE_ENTRY);
       
   432     
       
   433     QString iconName;
       
   434     if (signalStrength <= SignalStrengthHigh) {
       
   435         iconName = "qtg_small_signal_good";
       
   436     } else if (signalStrength <= SignalStrengthMedium) {
       
   437         iconName = "qtg_small_signal_medium";
       
   438     } else {
       
   439         iconName = "qtg_small_signal_low";
       
   440     }
       
   441     
       
   442     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SIGNALSTRENGTHICONCHOOSE_EXIT);
       
   443     return iconName;
       
   444 }
       
   445 
       
   446 /*!
       
   447     Function for selecting the correct "left" icon, which is different for
       
   448     connected and not connected IAPs.
       
   449     
       
   450     @param [in] iapId IAP ID of the WLAN IAP.
       
   451     @param [in] connectedIapId IAP ID of the connected WLAN or
       
   452                 IapIdNone if not connected.
       
   453                 
       
   454     @return Icon logical name of the "left" icon.
       
   455 */
       
   456 
       
   457 QString WlanSnifferListWidget::leftIconChoose(
       
   458     int iapId,
       
   459     int connectedIapId)
       
   460 {
       
   461     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LEFTICONCHOOSE_ENTRY);
       
   462     
       
   463     QString iconName;
       
   464     if (iapId == connectedIapId) {
       
   465         iconName = "qtg_small_connection";
       
   466     } else {
       
   467         iconName = "qtg_small_wlan";
       
   468     }
       
   469     
       
   470     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LEFTICONCHOOSE_EXIT);
       
   471     return iconName;
       
   472 }
       
   473 
       
   474 /*!
       
   475     Function for removing from the old Wlan list those items, which are
       
   476     not present in the given new lists.
       
   477     
       
   478     @param [in] iaps New WLAN IAP list.
       
   479     @param [in] aps New WLAN AP list.
       
   480 */
       
   481 
       
   482 void WlanSnifferListWidget::removeLostItems(
       
   483     const QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
       
   484     const QList< QSharedPointer<WlanQtUtilsAp> > &aps)
       
   485 {
       
   486     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_ENTRY);
       
   487     
       
   488     int row = 0;
       
   489     // Loop through all rows in the current list and try to find the items from
       
   490     // the new lists
       
   491     while (row < mListWidget->count()) {
       
   492         bool found = false;
       
   493         const HbListWidgetItem *item = mListWidget->item(row);
       
   494         if (item->data().canConvert<int>()) {
       
   495             // Item was an IAP, try to find it from the new IAP list
       
   496             foreach (QSharedPointer<WlanQtUtilsIap> iap, iaps) {
       
   497                 if (iap->value(WlanQtUtilsIap::ConfIdIapId) == 
       
   498                     item->data()) {
       
   499                     found = true;
       
   500                     break;
       
   501                 }
       
   502             }
       
   503         } else {
       
   504             // Item has to be an AP, try to find it from the new AP list
       
   505             Q_ASSERT(item->data().canConvert<WlanQtUtilsAp>());
       
   506             WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>();
       
   507             foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) {
       
   508                 if (WlanQtUtilsAp::compare(newAp.data(), &oldAp) == true) {
       
   509                     found = true;
       
   510                     break;
       
   511                 }
       
   512             }
       
   513         }
       
   514         if (found == false) {
       
   515             // Item was lost. Remove this row and delete it. Don't increment
       
   516             // row index, because the next item now has the same row index
       
   517             // as this one had
       
   518             delete mListWidget->takeItem(row);
       
   519 
       
   520             OstTrace1(
       
   521                 TRACE_NORMAL,
       
   522                 WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS,
       
   523                 "WlanSnifferListWidget::removeLostItems Removed;row=%d",
       
   524                 row);
       
   525         } else {
       
   526             // Item still exists, move on to next row
       
   527             row++;
       
   528         }
       
   529     }
       
   530     
       
   531     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_EXIT);
       
   532 }
       
   533 
       
   534 /*!
       
   535     Function for adding to the Wlan list those items, which are new
       
   536     in the given new lists. Also, icons and order of the existing list
       
   537     items are updated.
       
   538     
       
   539     @param [in] iaps New WLAN IAP list.
       
   540     @param [in] aps New WLAN AP list.
       
   541     @param [in] connectedIapId IAP ID of the connected WLAN or
       
   542                 IapIdNone if not connected.
       
   543 */
       
   544 
       
   545 void WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest(
       
   546     const QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
       
   547     const QList< QSharedPointer<WlanQtUtilsAp> > &aps,
       
   548     int connectedIapId)
       
   549 {
       
   550     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ENTRY);
       
   551     
       
   552     int row = 0;
       
   553     // Loop through new IAPs and try to find them from the old list
       
   554     foreach (QSharedPointer<WlanQtUtilsIap> newIap, iaps) {
       
   555         WlanSnifferListItem *oldItem = findFromOldList(newIap);
       
   556         if (oldItem != NULL) {
       
   557             // Match found, update icons
       
   558             oldItem->setLeftIcon(
       
   559                 leftIconChoose(
       
   560                     newIap->value(WlanQtUtilsIap::ConfIdIapId).toInt(),
       
   561                     connectedIapId));
       
   562             oldItem->setSignalIcon(
       
   563                 signalStrengthIconChoose(
       
   564                     newIap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
       
   565             // Also move the IAP to new row, if necessary (IAP order changes
       
   566             // when IAPs are connected/disconnected)
       
   567             int oldRow = mListWidget->row(oldItem);
       
   568             if (row != oldRow) {
       
   569                 OstTraceExt2(
       
   570                     TRACE_NORMAL,
       
   571                     WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_MOVE,
       
   572                     "WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest Moved;oldRow=%d;row=%d",
       
   573                     oldRow,
       
   574                     row);
       
   575                 mListWidget->takeItem(oldRow);
       
   576                 mListWidget->insertItem(row, oldItem);
       
   577             }
       
   578         } else {
       
   579             // New item discovered, add it to the list. Row is the same as the
       
   580             // index of the item in the new scan list
       
   581             OstTrace1(
       
   582                 TRACE_NORMAL,
       
   583                 WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ADD_IAP,
       
   584                 "WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest Added IAP;row=%d",
       
   585                 row);
       
   586             mListWidget->insertItem(row, listItemCreate(newIap, connectedIapId));
       
   587         }
       
   588         // Move to next row
       
   589         row++;
       
   590     }
       
   591     // Repeat the same for new APs. Notice that row index continues from
       
   592     // previous loop
       
   593     foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) {
       
   594         WlanSnifferListItem *oldItem = findFromOldList(newAp);
       
   595         if (oldItem != NULL) {
       
   596             oldItem->setSignalIcon(
       
   597                 signalStrengthIconChoose(
       
   598                     newAp->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
       
   599             // Notice that AP order may not change, they are always in
       
   600             // alphabetical order
       
   601         } else {
       
   602             OstTrace1(
       
   603                 TRACE_NORMAL,
       
   604                 WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ADD_AP,
       
   605                 "WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest Added AP;row=%d",
       
   606                 row);
       
   607             mListWidget->insertItem(row, listItemCreate(newAp));
       
   608         }
       
   609         row++;
       
   610     }
       
   611     
       
   612     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_EXIT);
       
   613 }
       
   614 
       
   615 /*!
       
   616     This function traces the contents of the list.
       
   617 */
       
   618 
       
   619 void WlanSnifferListWidget::traceListContent() const
       
   620 {
       
   621 #ifdef OST_TRACE_COMPILER_IN_USE
       
   622     for (int row = 0; row < mListWidget->count(); row++) {
       
   623         HbListWidgetItem *item = mListWidget->item(row);
       
   624         if (item->data().canConvert<int>()) {
       
   625             OstTraceExt2(
       
   626                 TRACE_DUMP,
       
   627                 WLANSNIFFERLISTWIDGET_TRACELISTCONTENT_IAP,
       
   628                 "WlanSnifferListWidget::traceListContent IAP;row=%d;id=%d",
       
   629                 row,
       
   630                 item->data().toInt());
       
   631         } else {
       
   632             Q_ASSERT(item->data().canConvert<WlanQtUtilsAp>());
       
   633             WlanQtUtilsAp ap = item->data().value<WlanQtUtilsAp>();
       
   634             QString tmp(ap.value(WlanQtUtilsAp::ConfIdSsid).toString());
       
   635             TPtrC16 ssid(tmp.utf16(), tmp.length());
       
   636             OstTraceExt2(
       
   637                 TRACE_DUMP,
       
   638                 WLANSNIFFERLISTWIDGET_TRACELISTCONTENT_AP,
       
   639                 "WlanSnifferListWidget::traceListContent AP;row=%d;ssid=%S",
       
   640                 row,
       
   641                 ssid);
       
   642         }
       
   643     }
       
   644 #endif
       
   645 }