wlanutilities/wlansniffer/wlansnifferapplication/src/wlansnifferlistwidget.cpp
changeset 58 301aeb18ae47
parent 46 2fbd1d709fe7
equal deleted inserted replaced
56:de27cc8389dd 58:301aeb18ae47
    26 
    26 
    27 // User includes
    27 // User includes
    28 
    28 
    29 #include "wlanqtutils.h"
    29 #include "wlanqtutils.h"
    30 #include "wlanqtutilsap.h"
    30 #include "wlanqtutilsap.h"
    31 #include "wlanqtutilsiap.h"
       
    32 
    31 
    33 #include "wlansniffer.h"
    32 #include "wlansniffer.h"
    34 #include "wlansnifferlistitem.h"
    33 #include "wlansnifferlistitem.h"
    35 #include "wlansnifferlistwidget.h"
    34 #include "wlansnifferlistwidget.h"
    36 
    35 
   106     @param [in] connectedIapId IAP ID of the connected WLAN or
   105     @param [in] connectedIapId IAP ID of the connected WLAN or
   107                 IapIdNone if not connected.
   106                 IapIdNone if not connected.
   108  */
   107  */
   109 
   108 
   110 void WlanSnifferListWidget::updateContent(
   109 void WlanSnifferListWidget::updateContent(
   111     QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
   110     QList< QSharedPointer<WlanQtUtilsAp> > &iaps,
   112     QList< QSharedPointer<WlanQtUtilsAp> > &aps,
   111     QList< QSharedPointer<WlanQtUtilsAp> > &aps,
   113     int connectedIapId)
   112     int connectedIapId)
   114 {
   113 {
   115     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_UPDATESCANSTATUS_ENTRY);
   114     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_UPDATESCANSTATUS_ENTRY);
   116     
   115     
   167     @param [in] connectedIapId IAP ID of the connected WLAN or
   166     @param [in] connectedIapId IAP ID of the connected WLAN or
   168                 IapIdNone if not connected.
   167                 IapIdNone if not connected.
   169 */
   168 */
   170 
   169 
   171 void WlanSnifferListWidget::sortIaps(
   170 void WlanSnifferListWidget::sortIaps(
   172     QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
   171     QList< QSharedPointer<WlanQtUtilsAp> > &iaps,
   173     int connectedIapId)
   172     int connectedIapId)
   174 {
   173 {
   175     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SORTIAPS_ENTRY);
   174     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SORTIAPS_ENTRY);
   176     
   175     
   177     // Order the list by IAP name
   176     // Order the list by IAP name
   181         WlanSnifferListWidget::iapLessThan);
   180         WlanSnifferListWidget::iapLessThan);
   182 
   181 
   183     // Find the possible connected IAP
   182     // Find the possible connected IAP
   184     int connectedIndex = 0;
   183     int connectedIndex = 0;
   185     for (int i = 0; i < iaps.size(); i++) {
   184     for (int i = 0; i < iaps.size(); i++) {
   186         if (iaps[i]->value(WlanQtUtilsIap::ConfIdIapId).toInt() == connectedIapId) {
   185         if (iaps[i]->value(WlanQtUtilsAp::ConfIdIapId).toInt() == connectedIapId) {
   187             connectedIndex = i;
   186             connectedIndex = i;
   188             break;
   187             break;
   189         }
   188         }
   190     }
   189     }
   191 
   190 
   233     
   232     
   234     @return Returns true if the first iap is "less than" the second one.
   233     @return Returns true if the first iap is "less than" the second one.
   235  */
   234  */
   236 
   235 
   237 bool WlanSnifferListWidget::iapLessThan(
   236 bool WlanSnifferListWidget::iapLessThan(
   238     const QSharedPointer<WlanQtUtilsIap> iap1,
   237     const QSharedPointer<WlanQtUtilsAp> iap1,
   239     const QSharedPointer<WlanQtUtilsIap> iap2)
   238     const QSharedPointer<WlanQtUtilsAp> iap2)
   240 {
   239 {
   241     // Primary comparison is based on the name
   240     // Primary comparison is based on the name
   242     int result = HbStringUtil::compareC(
   241     int result = HbStringUtil::compareC(
   243         iap1->value(WlanQtUtilsIap::ConfIdName).toString(),
   242         iap1->value(WlanQtUtilsAp::ConfIdName).toString(),
   244         iap2->value(WlanQtUtilsIap::ConfIdName).toString());
   243         iap2->value(WlanQtUtilsAp::ConfIdName).toString());
   245 
   244 
   246     return (result < 0) ? true : false;
   245     return (result < 0) ? true : false;
   247 }
   246 }
   248 
   247 
   249 /*!
   248 /*!
   274     @param [in] iap IAP to find.
   273     @param [in] iap IAP to find.
   275     
   274     
   276     @return Found WLAN List Widget item, 0 if not found.
   275     @return Found WLAN List Widget item, 0 if not found.
   277 */
   276 */
   278 
   277 
   279 WlanSnifferListItem *WlanSnifferListWidget::findFromOldList(
   278 WlanSnifferListItem *WlanSnifferListWidget::findFromOldIapList(
   280     QSharedPointer<WlanQtUtilsIap> iap)
   279     QSharedPointer<WlanQtUtilsAp> iap)
   281 {
   280 {
   282     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP_ENTRY);
   281     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDIAPLIST_IAP_ENTRY);
   283 
   282 
   284     WlanSnifferListItem *result = NULL;
   283     WlanSnifferListItem *result = NULL;
   285     QVariant iapData = iap->value(WlanQtUtilsIap::ConfIdIapId);
   284     QVariant iapData = iap->value(WlanQtUtilsAp::ConfIdIapId);
   286     for (int row = 0; row < mListWidget->count(); row++) {
   285     for (int row = 0; row < mListWidget->count(); row++) {
   287         HbListWidgetItem *item = mListWidget->item(row);
   286         HbListWidgetItem *item = mListWidget->item(row);
   288         if (item->data() == iapData) {
   287         if (item->data() == iapData) {
   289             result = static_cast<WlanSnifferListItem *>(item);
   288             result = static_cast<WlanSnifferListItem *>(item);
   290             break;
   289             break;
   291         }
   290         }
   292     }
   291     }
   293 
   292 
   294     OstTraceExt2(
   293     OstTraceExt2(
   295         TRACE_DUMP,
   294         TRACE_DUMP,
   296         WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP,
   295         WLANSNIFFERLISTWIDGET_FINDFROMOLDIAPLIST_IAP,
   297         "WlanSnifferListWidget::findFromOldList;iapId=%d;found=%hhu",
   296         "WlanSnifferListWidget::findFromOldIapList;iapId=%d;found=%hhu",
   298         iapData.toInt(),
   297         iapData.toInt(),
   299         (result != NULL) ? true : false);
   298         (result != NULL) ? true : false);
   300     
   299     
   301     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP_EXIT);
   300     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDIAPLIST_IAP_EXIT);
   302     return result;
   301     return result;
   303 }
   302 }
   304 
   303 
   305 /*!
   304 /*!
   306     Function for finding the given AP from the old Wlan list.
   305     Function for finding the given AP from the old Wlan list.
   308     @param [in] ap AP to find. 
   307     @param [in] ap AP to find. 
   309     
   308     
   310     @return Found WLAN List Widget item, 0 if not found.
   309     @return Found WLAN List Widget item, 0 if not found.
   311 */
   310 */
   312 
   311 
   313 WlanSnifferListItem *WlanSnifferListWidget::findFromOldList(
   312 WlanSnifferListItem *WlanSnifferListWidget::findFromOldApList(
   314     QSharedPointer<WlanQtUtilsAp> ap)
   313     QSharedPointer<WlanQtUtilsAp> ap)
   315 {
   314 {
   316     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP_ENTRY);
   315     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDAPLIST_ENTRY);
   317     
   316     
   318     WlanSnifferListItem *result = NULL;
   317     WlanSnifferListItem *result = NULL;
   319     for (int row = 0; row < mListWidget->count(); row++) {
   318     for (int row = 0; row < mListWidget->count(); row++) {
   320         HbListWidgetItem *item = mListWidget->item(row);
   319         HbListWidgetItem *item = mListWidget->item(row);
   321         if (item->data().canConvert<WlanQtUtilsAp>()) {
   320         if (item->data().canConvert<WlanQtUtilsAp>()) {
   330 #ifdef OST_TRACE_COMPILER_IN_USE
   329 #ifdef OST_TRACE_COMPILER_IN_USE
   331     QString tmp(ap.data()->value(WlanQtUtilsAp::ConfIdSsid).toString());
   330     QString tmp(ap.data()->value(WlanQtUtilsAp::ConfIdSsid).toString());
   332     TPtrC16 ssid(tmp.utf16(), tmp.length());
   331     TPtrC16 ssid(tmp.utf16(), tmp.length());
   333     OstTraceExt2(
   332     OstTraceExt2(
   334         TRACE_NORMAL,
   333         TRACE_NORMAL,
   335         WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP,
   334         WLANSNIFFERLISTWIDGET_FINDFROMOLDAPLIST,
   336         "WlanSnifferListWidget::findFromOldList;found=%hhu;ssid=%S",
   335         "WlanSnifferListWidget::findFromOldApList;found=%hhu;ssid=%S",
   337         (result != NULL) ? true : false,
   336         (result != NULL) ? true : false,
   338         ssid);
   337         ssid);
   339 #endif
   338 #endif
   340     
   339     
   341     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP_EXIT);
   340     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDAPLIST_EXIT);
   342     return result;
   341     return result;
   343 }
   342 }
   344 
   343 
   345 /*!
   344 /*!
   346     Function for creating a new list item from the given IAP.
   345     Function for creating a new list item from the given IAP.
   351     
   350     
   352     @return New WLAN List Widget item.
   351     @return New WLAN List Widget item.
   353 */
   352 */
   354 
   353 
   355 HbListWidgetItem *WlanSnifferListWidget::listItemCreate(
   354 HbListWidgetItem *WlanSnifferListWidget::listItemCreate(
   356     QSharedPointer<WlanQtUtilsIap> iap,
   355     QSharedPointer<WlanQtUtilsAp> iap,
   357     int connectedIapId)
   356     int connectedIapId)
   358 {
   357 {
   359     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_ENTRY);
   358     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_ENTRY);
   360     
   359     
   361     WlanSnifferListItem *item = new WlanSnifferListItem();
   360     WlanSnifferListItem *item = new WlanSnifferListItem();
   362     item->setNetworkName(iap->value(WlanQtUtilsIap::ConfIdName).toString());
   361     item->setNetworkName(iap->value(WlanQtUtilsAp::ConfIdName).toString());
   363     // Note: WPS icon is needed only in IAP setup, no longer here
   362     // Note: WPS icon is needed only in IAP setup, no longer here
   364     if (iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() !=
   363     if (iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() !=
   365         CMManagerShim::WlanSecModeOpen) {
   364         CMManagerShim::WlanSecModeOpen) {
   366         item->setSecureIcon("qtg_small_lock");
   365         item->setSecureIcon("qtg_small_lock");
   367     }
   366     }
   368 
   367 
   369     item->setLeftIcon(
   368     item->setLeftIcon(
   370         leftIconChoose(
   369         leftIconChoose(
   371             iap->value(WlanQtUtilsIap::ConfIdIapId).toInt(),
   370             iap->value(WlanQtUtilsAp::ConfIdIapId).toInt(),
   372             connectedIapId));
   371             connectedIapId));
   373     item->setSignalIcon(
   372     item->setSignalIcon(
   374         signalStrengthIconChoose(
   373         signalStrengthIconChoose(
   375             iap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   374             iap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   376     
   375     
   377     item->setData(iap->value(WlanQtUtilsIap::ConfIdIapId));
   376     item->setData(iap->value(WlanQtUtilsAp::ConfIdIapId));
   378     
   377     
   379     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_EXIT);
   378     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_EXIT);
   380     return item;
   379     return item;
   381 }
   380 }
   382 
   381 
   392     QSharedPointer<WlanQtUtilsAp> ap)
   391     QSharedPointer<WlanQtUtilsAp> ap)
   393 {
   392 {
   394     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_ENTRY);
   393     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_ENTRY);
   395     
   394     
   396     WlanSnifferListItem *item = new WlanSnifferListItem();
   395     WlanSnifferListItem *item = new WlanSnifferListItem();
   397     item->setNetworkName(ap->value(WlanQtUtilsAp::ConfIdSsid).toString());
   396     item->setNetworkName(ap->value(WlanQtUtilsAp::ConfIdName).toString());
   398     if (ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()) {
   397     if (ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()) {
   399         // WPS is supported, use a dedicated security icon
   398         // WPS is supported, use a dedicated security icon
   400         item->setSecureIcon("qtg_small_wifi");
   399         item->setSecureIcon("qtg_small_wifi");
   401     } else if (ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() 
   400     } else if (ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() 
   402         != CMManagerShim::WlanSecModeOpen) {
   401         != CMManagerShim::WlanSecModeOpen) {
   404         item->setSecureIcon("qtg_small_lock");
   403         item->setSecureIcon("qtg_small_lock");
   405     }
   404     }
   406     item->setSignalIcon(
   405     item->setSignalIcon(
   407         signalStrengthIconChoose(
   406         signalStrengthIconChoose(
   408             ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   407             ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   409     
   408 
   410     QVariant data;
   409     QVariant data;
   411     data.setValue(*ap);
   410     data.setValue(*ap);
   412     item->setData(data);
   411     item->setData(data);
   413     
   412 
   414     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_EXIT);
   413     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_EXIT);
   415     return item;
   414     return item;
   416 }
   415 }
   417 
   416 
   418 /*!
   417 /*!
   475     @param [in] iaps New WLAN IAP list.
   474     @param [in] iaps New WLAN IAP list.
   476     @param [in] aps New WLAN AP list.
   475     @param [in] aps New WLAN AP list.
   477 */
   476 */
   478 
   477 
   479 void WlanSnifferListWidget::removeLostItems(
   478 void WlanSnifferListWidget::removeLostItems(
   480     const QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
   479     const QList< QSharedPointer<WlanQtUtilsAp> > &iaps,
   481     const QList< QSharedPointer<WlanQtUtilsAp> > &aps)
   480     const QList< QSharedPointer<WlanQtUtilsAp> > &aps)
   482 {
   481 {
   483     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_ENTRY);
   482     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_ENTRY);
   484     
   483     
   485     int row = 0;
   484     int row = 0;
   488     while (row < mListWidget->count()) {
   487     while (row < mListWidget->count()) {
   489         bool found = false;
   488         bool found = false;
   490         const HbListWidgetItem *item = mListWidget->item(row);
   489         const HbListWidgetItem *item = mListWidget->item(row);
   491         if (item->data().canConvert<int>()) {
   490         if (item->data().canConvert<int>()) {
   492             // Item was an IAP, try to find it from the new IAP list
   491             // Item was an IAP, try to find it from the new IAP list
   493             foreach (QSharedPointer<WlanQtUtilsIap> iap, iaps) {
   492             foreach (QSharedPointer<WlanQtUtilsAp> iap, iaps) {
   494                 if (iap->value(WlanQtUtilsIap::ConfIdIapId) == 
   493                 if (iap->value(WlanQtUtilsAp::ConfIdIapId) == 
   495                     item->data()) {
   494                     item->data()) {
   496                     found = true;
   495                     found = true;
   497                     break;
   496                     break;
   498                 }
   497                 }
   499             }
   498             }
   538     @param [in] connectedIapId IAP ID of the connected WLAN or
   537     @param [in] connectedIapId IAP ID of the connected WLAN or
   539                 IapIdNone if not connected.
   538                 IapIdNone if not connected.
   540 */
   539 */
   541 
   540 
   542 void WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest(
   541 void WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest(
   543     const QList< QSharedPointer<WlanQtUtilsIap> > &iaps,
   542     const QList< QSharedPointer<WlanQtUtilsAp> > &iaps,
   544     const QList< QSharedPointer<WlanQtUtilsAp> > &aps,
   543     const QList< QSharedPointer<WlanQtUtilsAp> > &aps,
   545     int connectedIapId)
   544     int connectedIapId)
   546 {
   545 {
   547     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ENTRY);
   546     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ENTRY);
   548     
   547     
   549     int row = 0;
   548     int row = 0;
   550     // Loop through new IAPs and try to find them from the old list
   549     // Loop through new IAPs and try to find them from the old list
   551     foreach (QSharedPointer<WlanQtUtilsIap> newIap, iaps) {
   550     foreach (QSharedPointer<WlanQtUtilsAp> newIap, iaps) {
   552         WlanSnifferListItem *oldItem = findFromOldList(newIap);
   551         WlanSnifferListItem *oldItem = findFromOldIapList(newIap);
   553         if (oldItem != NULL) {
   552         if (oldItem != NULL) {
   554             // Match found, update icons
   553             // Match found, update icons
   555             oldItem->setLeftIcon(
   554             oldItem->setLeftIcon(
   556                 leftIconChoose(
   555                 leftIconChoose(
   557                     newIap->value(WlanQtUtilsIap::ConfIdIapId).toInt(),
   556                     newIap->value(WlanQtUtilsAp::ConfIdIapId).toInt(),
   558                     connectedIapId));
   557                     connectedIapId));
   559             oldItem->setSignalIcon(
   558             oldItem->setSignalIcon(
   560                 signalStrengthIconChoose(
   559                 signalStrengthIconChoose(
   561                     newIap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   560                     newIap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   562             // Also move the IAP to new row, if necessary (IAP order changes
   561             // Also move the IAP to new row, if necessary (IAP order changes
   586         row++;
   585         row++;
   587     }
   586     }
   588     // Repeat the same for new APs. Notice that row index continues from
   587     // Repeat the same for new APs. Notice that row index continues from
   589     // previous loop
   588     // previous loop
   590     foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) {
   589     foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) {
   591         WlanSnifferListItem *oldItem = findFromOldList(newAp);
   590         WlanSnifferListItem *oldItem = findFromOldApList(newAp);
   592         if (oldItem != NULL) {
   591         if (oldItem != NULL) {
   593             oldItem->setSignalIcon(
   592             oldItem->setSignalIcon(
   594                 signalStrengthIconChoose(
   593                 signalStrengthIconChoose(
   595                     newAp->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   594                     newAp->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   596             // Notice that AP order may not change, they are always in
   595             // Notice that AP order may not change, they are always in