wlanutilities/wlanqtutilities/base/src/wlanqtutilsap.cpp
changeset 39 7b3e49e4608a
parent 31 e8f4211554fb
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
    19 
    19 
    20 #include <QString>
    20 #include <QString>
    21 #include <QHash>
    21 #include <QHash>
    22 #include <QVariant>
    22 #include <QVariant>
    23 #include <QDebug>
    23 #include <QDebug>
       
    24 #include <cmmanagerdefines_shim.h>
    24 
    25 
    25 // User includes
    26 // User includes
    26 
    27 
    27 #include "wlanqtutilsap.h"
    28 #include "wlanqtutilsap.h"
    28 
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "wlanqtutilsapTraces.h"
       
    32 #endif
       
    33 
    29 
    34 /*!
    30 /*!
    35     \class WlanQtUtilsApPrivate
    31     \class WlanQtUtilsApPrivate
    36     \brief Private implementation of WlanQtUtilsAp.
    32     \brief Private implementation of WlanQtUtilsAp.
    37 */
    33 */
    97     @return Value.
    93     @return Value.
    98 */
    94 */
    99 
    95 
   100 QVariant WlanQtUtilsAp::value(int identifier) const
    96 QVariant WlanQtUtilsAp::value(int identifier) const
   101 {
    97 {
       
    98     // The configuration must exist
   102     Q_ASSERT(d_ptr->mConfigurations.contains(identifier));
    99     Q_ASSERT(d_ptr->mConfigurations.contains(identifier));
   103     Q_ASSERT(d_ptr->mConfigurations[identifier].isValid());
   100     Q_ASSERT(d_ptr->mConfigurations[identifier].isValid());
   104     
       
   105 #ifdef OST_TRACE_COMPILER_IN_USE
       
   106     QString tmp;
       
   107     QDebug tmpStream(&tmp);
       
   108     tmpStream << d_ptr->mConfigurations[identifier];
       
   109     TPtrC16 string(tmp.utf16(), tmp.length());
       
   110     
       
   111     OstTraceExt2(
       
   112         TRACE_DUMP,
       
   113         WLANQTUTILSAP_VALUE,
       
   114         "WlanQtUtilsAp::value;identifier=%{ConfId};string=%S",
       
   115         (TUint)identifier,
       
   116         string);
       
   117 #endif
       
   118     
       
   119     return d_ptr->mConfigurations[identifier];
   101     return d_ptr->mConfigurations[identifier];
   120 }
   102 }
   121 
   103 
   122 /*!
   104 /*!
   123     Setter for AP data.
   105     Setter for AP data.
   126     @param [in] value Value to set.
   108     @param [in] value Value to set.
   127 */
   109 */
   128 
   110 
   129 void WlanQtUtilsAp::setValue(int identifier, QVariant value)
   111 void WlanQtUtilsAp::setValue(int identifier, QVariant value)
   130 {
   112 {
   131 #ifdef OST_TRACE_COMPILER_IN_USE
       
   132     QString tmp;
       
   133     QDebug tmpStream(&tmp);
       
   134     tmpStream << value;
       
   135     TPtrC16 string(tmp.utf16(), tmp.length());
       
   136     
       
   137     OstTraceExt2(
       
   138         TRACE_DUMP,
       
   139         WLANQTUTILSAP_SETVALUE,
       
   140         "WlanQtUtilsAp::setValue;identifier=%{ConfId};string=%S",
       
   141         (TUint)identifier,
       
   142         string);
       
   143 #endif
       
   144     
       
   145     d_ptr->mConfigurations[identifier] = value;
   113     d_ptr->mConfigurations[identifier] = value;
   146 }
   114 }
   147 
   115 
   148 /*!
   116 /*!
   149     AP comparison function.
   117     AP comparison function. Does AP comparison based on following configs:
       
   118     -SSID.
       
   119     -Security mode.
       
   120     -WPA PSK usage.
       
   121     -Connection mode.
   150 
   122 
   151     @param [in] ap1 First AP to compare.
   123     @param [in] ap1 First AP to compare.
   152     @param [in] ap2 Second AP to compare.
   124     @param [in] ap2 Second AP to compare.
       
   125     @param [in] comparator String comparator for SSID.
       
   126                 Default comparator is QString::compare() direct memory
       
   127                 comparison which does not take the localization into account.
   153 
   128 
   154     @return TRUE, if APs are considered to be same.
   129     @return Zero (0), if APs are considered to be same,
       
   130             Negative (>0) if ap1 is considered to be "greater than" ap2. 
       
   131             Negative (<0) if ap1 is considered to be "less than" ap2. 
   155 */
   132 */
   156 
   133 
   157 bool WlanQtUtilsAp::compare(
   134 int WlanQtUtilsAp::compare(
   158     const WlanQtUtilsAp *ap1,
   135     const WlanQtUtilsAp *ap1,
   159     const WlanQtUtilsAp *ap2)
   136     const WlanQtUtilsAp *ap2,
       
   137     StringComparator comparator)
   160 {
   138 {
   161     bool equal = false;
   139     int result = 0;
   162     
   140 
   163     // SSID (case sensitive) and security mode (with or without PSK)
   141     // Compare SSID
   164     // are the values, which identify a unique access point.
   142     QString ssid1 = ap1->value(WlanQtUtilsAp::ConfIdSsid).toString();
   165     if (ap1->value(WlanQtUtilsAp::ConfIdSsid) ==
   143     QString ssid2 = ap2->value(WlanQtUtilsAp::ConfIdSsid).toString();
   166         ap2->value(WlanQtUtilsAp::ConfIdSsid)
   144     if (comparator != NULL) {
   167         && ap1->value(WlanQtUtilsAp::ConfIdSecurityMode) == 
   145         result = comparator(ssid1, ssid2);
   168            ap2->value(WlanQtUtilsAp::ConfIdSecurityMode)
   146     } else {
   169            && ap1->value(WlanQtUtilsAp::ConfIdWpaPskUse) ==
   147         result = QString::compare(ssid1, ssid2);
   170               ap2->value(WlanQtUtilsAp::ConfIdWpaPskUse)) {
       
   171         equal = true;
       
   172     }
   148     }
   173     
   149 
   174     return equal;
   150     // Compare security mode
       
   151     if (result == 0) {
       
   152         result = ap1->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
       
   153         result -= ap2->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
       
   154     }
       
   155 
       
   156     // Compare WPA PSK usage
       
   157     int secMode = ap1->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(); 
       
   158     if (result == 0 &&
       
   159         (secMode == CMManagerShim::WlanSecModeWpa ||
       
   160          secMode == CMManagerShim::WlanSecModeWpa2)) {
       
   161         // WPA PSK value is boolean, but it can be converted to integer
       
   162         result = ap1->value(WlanQtUtilsAp::ConfIdWpaPskUse).toInt();
       
   163         result -= ap2->value(WlanQtUtilsAp::ConfIdWpaPskUse).toInt();
       
   164     }
       
   165 
       
   166     // Compare connection mode
       
   167     if (result == 0) {
       
   168         result = ap1->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
       
   169         result -= ap2->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
       
   170     }
       
   171 
       
   172     return result;
   175 }
   173 }