wlanutilities/wlansniffer/wlansnifferapplication/src/wlansnifferlistwidget.cpp
changeset 46 2fbd1d709fe7
parent 38 2dc6da6fb431
child 58 301aeb18ae47
equal deleted inserted replaced
45:d9ec2b8c6bad 46:2fbd1d709fe7
    19 
    19 
    20 #include <QSharedPointer>
    20 #include <QSharedPointer>
    21 #include <HbListWidget>
    21 #include <HbListWidget>
    22 #include <HbListWidgetItem>
    22 #include <HbListWidgetItem>
    23 #include <HbAbstractViewItem>
    23 #include <HbAbstractViewItem>
    24 #include <HbStyleLoader>
       
    25 #include <HbStringUtil>
    24 #include <HbStringUtil>
    26 #include <cmmanagerdefines_shim.h>
    25 #include <cmmanagerdefines_shim.h>
    27 
    26 
    28 // User includes
    27 // User includes
    29 
    28 
    47 
    46 
    48 // External function prototypes
    47 // External function prototypes
    49 
    48 
    50 // Local constants
    49 // Local constants
    51 
    50 
    52 //! Location of WLAN Sniffer List Layout definitions
       
    53 static const QString WlanSnifferLayoutPath(":/wlansnifferlistlayout/");
       
    54 
       
    55 // ======== LOCAL FUNCTIONS ========
    51 // ======== LOCAL FUNCTIONS ========
       
    52 
       
    53 /*!
       
    54     String comparator for list view. Used for locale-aware SSID comparison
       
    55     in list view.
       
    56     
       
    57     @param [in] string1 String #1 to compare.
       
    58     @param [in] string2 String #2 to compare.
       
    59 
       
    60     @return Zero (0), if strings are considered to be same,
       
    61             Positive (>0) if string1 is considered to be "greater than" string2. 
       
    62             Negative (<0) if string1 is considered to be "less than" string2. 
       
    63 */
       
    64 
       
    65 static int WlanSsidStringComparator(
       
    66     const QString &string1,
       
    67     const QString &string2)
       
    68 {
       
    69     return HbStringUtil::compareC(string1, string2);    
       
    70 }
    56 
    71 
    57 // ======== MEMBER FUNCTIONS ========
    72 // ======== MEMBER FUNCTIONS ========
    58 
    73 
    59 /*!
    74 /*!
    60     Constructor.
    75     Constructor.
    65 WlanSnifferListWidget::WlanSnifferListWidget(HbListWidget *listWidget) :
    80 WlanSnifferListWidget::WlanSnifferListWidget(HbListWidget *listWidget) :
    66     mListWidget(listWidget)
    81     mListWidget(listWidget)
    67 {
    82 {
    68     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY);
    83     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY);
    69     
    84     
    70     // Register custom layout location
       
    71     HbStyleLoader::registerFilePath(WlanSnifferLayoutPath);
       
    72     
       
    73     // Set custom WLAN list item layout
    85     // Set custom WLAN list item layout
    74     mListWidget->setLayoutName("wlanlistitem");
    86     mListWidget->setLayoutName("wlanlistitem");
    75     
    87 
    76     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT);
    88     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT);
    77 }
    89 }
    78 
    90 
    79 /*!
    91 /*!
    80     Destructor.
    92     Destructor.
    81 */
    93 */
    82 
    94 
    83 WlanSnifferListWidget::~WlanSnifferListWidget()
    95 WlanSnifferListWidget::~WlanSnifferListWidget()
    84 {
    96 {
    85     OstTraceFunctionEntry0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY);
    97     OstTraceFunctionEntry0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY);
    86     
       
    87     HbStyleLoader::unregisterFilePath(WlanSnifferLayoutPath);
       
    88     
       
    89     OstTraceFunctionExit0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT);
    98     OstTraceFunctionExit0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT);
    90 }
    99 }
    91 
   100 
    92 /*!
   101 /*!
    93     Updates the list widget content with the given IAPs and APs.
   102     Updates the list widget content with the given IAPs and APs.
   231 {
   240 {
   232     // Primary comparison is based on the name
   241     // Primary comparison is based on the name
   233     int result = HbStringUtil::compareC(
   242     int result = HbStringUtil::compareC(
   234         iap1->value(WlanQtUtilsIap::ConfIdName).toString(),
   243         iap1->value(WlanQtUtilsIap::ConfIdName).toString(),
   235         iap2->value(WlanQtUtilsIap::ConfIdName).toString());
   244         iap2->value(WlanQtUtilsIap::ConfIdName).toString());
   236     
   245 
   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;
   246     return (result < 0) ? true : false;
   245 }
   247 }
   246 
   248 
   247 /*!
   249 /*!
   248     Compares two WLAN APs. Comparison is done with the AP SSID.
   250     Compares two WLAN APs. Comparison is done with the AP SSID.
   255 
   257 
   256 bool WlanSnifferListWidget::apLessThan(
   258 bool WlanSnifferListWidget::apLessThan(
   257     const QSharedPointer<WlanQtUtilsAp> ap1,
   259     const QSharedPointer<WlanQtUtilsAp> ap1,
   258     const QSharedPointer<WlanQtUtilsAp> ap2)
   260     const QSharedPointer<WlanQtUtilsAp> ap2)
   259 {
   261 {
   260     // Primary comparison is based on the SSID
   262     // Use AP comparison function with localized SSID comparison
   261     int result = HbStringUtil::compareC(
   263     int result = WlanQtUtilsAp::compare(
   262         ap1->value(WlanQtUtilsAp::ConfIdSsid).toString(),
   264         ap1.data(),
   263         ap2->value(WlanQtUtilsAp::ConfIdSsid).toString());
   265         ap2.data(),
   264 
   266         WlanSsidStringComparator);
   265     // If SSID is equal, compare based on security mode
   267         
   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;
   268     return (result < 0) ? true : false;
   273 }
   269 }
   274 
   270 
   275 /*!
   271 /*!
   276     Function for finding the given IAP from the old Wlan list.
   272     Function for finding the given IAP from the old Wlan list.
   322     WlanSnifferListItem *result = NULL;
   318     WlanSnifferListItem *result = NULL;
   323     for (int row = 0; row < mListWidget->count(); row++) {
   319     for (int row = 0; row < mListWidget->count(); row++) {
   324         HbListWidgetItem *item = mListWidget->item(row);
   320         HbListWidgetItem *item = mListWidget->item(row);
   325         if (item->data().canConvert<WlanQtUtilsAp>()) {
   321         if (item->data().canConvert<WlanQtUtilsAp>()) {
   326             WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>();
   322             WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>();
   327             if (WlanQtUtilsAp::compare(ap.data(), &oldAp) == true) {
   323             if (WlanQtUtilsAp::compare(ap.data(), &oldAp) == 0) {
   328                 result = static_cast<WlanSnifferListItem *>(item);
   324                 result = static_cast<WlanSnifferListItem *>(item);
   329                 break;
   325                 break;
   330             }
   326             }
   331         }
   327         }
   332     }
   328     }
   362 {
   358 {
   363     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_ENTRY);
   359     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_ENTRY);
   364     
   360     
   365     WlanSnifferListItem *item = new WlanSnifferListItem();
   361     WlanSnifferListItem *item = new WlanSnifferListItem();
   366     item->setNetworkName(iap->value(WlanQtUtilsIap::ConfIdName).toString());
   362     item->setNetworkName(iap->value(WlanQtUtilsIap::ConfIdName).toString());
       
   363     // Note: WPS icon is needed only in IAP setup, no longer here
   367     if (iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() !=
   364     if (iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() !=
   368         CMManagerShim::WlanSecModeOpen) {
   365         CMManagerShim::WlanSecModeOpen) {
   369         item->setSecureIcon("qtg_small_secure");
   366         item->setSecureIcon("qtg_small_lock");
   370         // TODO: Handle WPS case - it uses a different icon!
       
   371         // Will be implemented with "Adding WLAN IAP manually" subfeature.
       
   372     }
   367     }
   373 
   368 
   374     item->setLeftIcon(
   369     item->setLeftIcon(
   375         leftIconChoose(
   370         leftIconChoose(
   376             iap->value(WlanQtUtilsIap::ConfIdIapId).toInt(),
   371             iap->value(WlanQtUtilsIap::ConfIdIapId).toInt(),
   398 {
   393 {
   399     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_ENTRY);
   394     OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_ENTRY);
   400     
   395     
   401     WlanSnifferListItem *item = new WlanSnifferListItem();
   396     WlanSnifferListItem *item = new WlanSnifferListItem();
   402     item->setNetworkName(ap->value(WlanQtUtilsAp::ConfIdSsid).toString());
   397     item->setNetworkName(ap->value(WlanQtUtilsAp::ConfIdSsid).toString());
   403     if (ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() 
   398     if (ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()) {
       
   399         // WPS is supported, use a dedicated security icon
       
   400         item->setSecureIcon("qtg_small_wifi");
       
   401     } else if (ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() 
   404         != CMManagerShim::WlanSecModeOpen) {
   402         != CMManagerShim::WlanSecModeOpen) {
   405         item->setSecureIcon("qtg_small_secure");
   403         // Other secure networks
   406         // TODO: Handle WPS case - it uses a different icon!
   404         item->setSecureIcon("qtg_small_lock");
   407         // Will be implemented with "Adding WLAN IAP manually" subfeature.
       
   408     }
   405     }
   409     item->setSignalIcon(
   406     item->setSignalIcon(
   410         signalStrengthIconChoose(
   407         signalStrengthIconChoose(
   411             ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   408             ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt()));
   412     
   409     
   503         } else {
   500         } else {
   504             // Item has to be an AP, try to find it from the new AP list
   501             // Item has to be an AP, try to find it from the new AP list
   505             Q_ASSERT(item->data().canConvert<WlanQtUtilsAp>());
   502             Q_ASSERT(item->data().canConvert<WlanQtUtilsAp>());
   506             WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>();
   503             WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>();
   507             foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) {
   504             foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) {
   508                 if (WlanQtUtilsAp::compare(newAp.data(), &oldAp) == true) {
   505                 if (WlanQtUtilsAp::compare(newAp.data(), &oldAp) == 0) {
   509                     found = true;
   506                     found = true;
   510                     break;
   507                     break;
   511                 }
   508                 }
   512             }
   509             }
   513         }
   510         }
   525         } else {
   522         } else {
   526             // Item still exists, move on to next row
   523             // Item still exists, move on to next row
   527             row++;
   524             row++;
   528         }
   525         }
   529     }
   526     }
   530     
   527 
   531     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_EXIT);
   528     OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_EXIT);
   532 }
   529 }
   533 
   530 
   534 /*!
   531 /*!
   535     Function for adding to the Wlan list those items, which are new
   532     Function for adding to the Wlan list those items, which are new