31
|
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 AP (Access Point, unknown network) class.
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
|
|
20 |
#include <QString>
|
|
21 |
#include <QHash>
|
|
22 |
#include <QVariant>
|
|
23 |
#include <QDebug>
|
39
|
24 |
#include <cmmanagerdefines_shim.h>
|
31
|
25 |
|
|
26 |
// User includes
|
|
27 |
|
|
28 |
#include "wlanqtutilsap.h"
|
|
29 |
|
|
30 |
/*!
|
|
31 |
\class WlanQtUtilsApPrivate
|
|
32 |
\brief Private implementation of WlanQtUtilsAp.
|
|
33 |
*/
|
|
34 |
|
|
35 |
class WlanQtUtilsApPrivate
|
|
36 |
{
|
|
37 |
private:
|
|
38 |
//! Access Point configuration data
|
|
39 |
QHash<int, QVariant> mConfigurations;
|
|
40 |
|
|
41 |
friend class WlanQtUtilsAp;
|
|
42 |
};
|
|
43 |
|
|
44 |
/*!
|
|
45 |
\class WlanQtUtilsAp
|
|
46 |
\brief WLAN Access Point class.
|
|
47 |
|
|
48 |
Contains the information related to unknown WLAN access points.
|
|
49 |
*/
|
|
50 |
|
|
51 |
// External function prototypes
|
|
52 |
|
|
53 |
// Local constants
|
|
54 |
|
|
55 |
// ======== LOCAL FUNCTIONS ========
|
|
56 |
|
|
57 |
// ======== MEMBER FUNCTIONS ========
|
|
58 |
|
|
59 |
/*!
|
|
60 |
Constructor.
|
|
61 |
*/
|
|
62 |
|
|
63 |
WlanQtUtilsAp::WlanQtUtilsAp() :
|
|
64 |
d_ptr(new WlanQtUtilsApPrivate())
|
|
65 |
{
|
|
66 |
}
|
|
67 |
|
|
68 |
/*!
|
|
69 |
Copy constructor.
|
|
70 |
|
|
71 |
@param [in] ref AP to create a copy of.
|
|
72 |
*/
|
|
73 |
|
|
74 |
WlanQtUtilsAp::WlanQtUtilsAp(const WlanQtUtilsAp &ref) :
|
|
75 |
d_ptr(new WlanQtUtilsApPrivate())
|
|
76 |
{
|
|
77 |
d_ptr->mConfigurations = ref.d_ptr->mConfigurations;
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
|
81 |
Destructor.
|
|
82 |
*/
|
|
83 |
|
|
84 |
WlanQtUtilsAp::~WlanQtUtilsAp()
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
/*!
|
|
89 |
Getter for AP data.
|
|
90 |
|
|
91 |
@param [in] identifier Identifier of value to get.
|
|
92 |
|
|
93 |
@return Value.
|
|
94 |
*/
|
|
95 |
|
|
96 |
QVariant WlanQtUtilsAp::value(int identifier) const
|
|
97 |
{
|
39
|
98 |
// The configuration must exist
|
31
|
99 |
Q_ASSERT(d_ptr->mConfigurations.contains(identifier));
|
|
100 |
Q_ASSERT(d_ptr->mConfigurations[identifier].isValid());
|
|
101 |
return d_ptr->mConfigurations[identifier];
|
|
102 |
}
|
|
103 |
|
|
104 |
/*!
|
|
105 |
Setter for AP data.
|
|
106 |
|
|
107 |
@param [in] identifier Identifier of value to set.
|
|
108 |
@param [in] value Value to set.
|
|
109 |
*/
|
|
110 |
|
|
111 |
void WlanQtUtilsAp::setValue(int identifier, QVariant value)
|
|
112 |
{
|
|
113 |
d_ptr->mConfigurations[identifier] = value;
|
|
114 |
}
|
|
115 |
|
|
116 |
/*!
|
39
|
117 |
AP comparison function. Does AP comparison based on following configs:
|
|
118 |
-SSID.
|
|
119 |
-Security mode.
|
|
120 |
-WPA PSK usage.
|
|
121 |
-Connection mode.
|
31
|
122 |
|
|
123 |
@param [in] ap1 First AP to compare.
|
|
124 |
@param [in] ap2 Second AP to compare.
|
39
|
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.
|
31
|
128 |
|
39
|
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.
|
31
|
132 |
*/
|
|
133 |
|
39
|
134 |
int WlanQtUtilsAp::compare(
|
31
|
135 |
const WlanQtUtilsAp *ap1,
|
39
|
136 |
const WlanQtUtilsAp *ap2,
|
|
137 |
StringComparator comparator)
|
31
|
138 |
{
|
39
|
139 |
int result = 0;
|
|
140 |
|
|
141 |
// Compare SSID
|
|
142 |
QString ssid1 = ap1->value(WlanQtUtilsAp::ConfIdSsid).toString();
|
|
143 |
QString ssid2 = ap2->value(WlanQtUtilsAp::ConfIdSsid).toString();
|
|
144 |
if (comparator != NULL) {
|
|
145 |
result = comparator(ssid1, ssid2);
|
|
146 |
} else {
|
|
147 |
result = QString::compare(ssid1, ssid2);
|
|
148 |
}
|
|
149 |
|
|
150 |
// Compare security mode
|
|
151 |
if (result == 0) {
|
|
152 |
result = ap1->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
|
|
153 |
result -= ap2->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
|
31
|
154 |
}
|
39
|
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;
|
31
|
173 |
}
|