add more spacing
[personal-kdebase.git] / workspace / solid / networkmanager-0.7 / accesspoint.cpp
blob6e15db074884de5fda9472189787472cce8ee891
1 /*
2 Copyright 2008 Will Stephenson <wstephenson@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License or (at your option) version 3 or any later version
8 accepted by the membership of KDE e.V. (or its successor approved
9 by the membership of KDE e.V.), which shall act as a proxy
10 defined in Section 14 of version 3 of the license.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "accesspoint.h"
23 #include <KDebug>
24 #include "dbus/nm-access-pointinterface.h"
25 #include "manager.h"
26 #include "wirelessnetworkinterface.h"
29 class NMAccessPoint::Private
31 public:
32 Private( const QString & path ) : iface( NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus()), capabilities(0), wpaFlags(0), rsnFlags(0), frequency(0), hardwareAddress(0), maxBitRate(0), mode((Solid::Control::WirelessNetworkInterface::OperationMode)0), signalStrength(0)
35 OrgFreedesktopNetworkManagerAccessPointInterface iface;
36 QString uni;
37 Solid::Control::AccessPoint::Capabilities capabilities;
38 Solid::Control::AccessPoint::WpaFlags wpaFlags;
39 Solid::Control::AccessPoint::WpaFlags rsnFlags;
40 QString ssid;
41 uint frequency;
42 QString hardwareAddress;
43 uint maxBitRate;
44 Solid::Control::WirelessNetworkInterface::OperationMode mode;
45 int signalStrength;
48 NMAccessPoint::NMAccessPoint( const QString& path, QObject * parent ) : Solid::Control::Ifaces::AccessPoint(parent), d(new Private( path ))
50 d->uni = path;
51 d->capabilities = convertCapabilities( d->iface.flags() );
52 d->wpaFlags = convertWpaFlags( d->iface.wpaFlags() );
53 d->rsnFlags = convertWpaFlags( d->iface.rsnFlags() );
54 d->signalStrength = d->iface.strength();
55 d->ssid = d->iface.ssid();
56 d->frequency = d->iface.frequency();
57 d->hardwareAddress = d->iface.hwAddress();
58 d->maxBitRate = d->iface.maxBitrate();
59 // make this a static on WirelessNetworkInterface
60 d->mode = NMWirelessNetworkInterface::convertOperationMode(d->iface.mode());
61 connect( &d->iface, SIGNAL(PropertiesChanged(const QVariantMap &)),
62 this, SLOT(propertiesChanged(const QVariantMap &)));
65 NMAccessPoint::~NMAccessPoint()
67 delete d;
70 QString NMAccessPoint::uni() const
72 return d->uni;
75 QString NMAccessPoint::hardwareAddress() const
77 return d->hardwareAddress;
80 Solid::Control::AccessPoint::Capabilities NMAccessPoint::capabilities() const
82 return d->capabilities;
85 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::wpaFlags() const
87 return d->wpaFlags;
90 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::rsnFlags() const
92 return d->rsnFlags;
95 QString NMAccessPoint::ssid() const
97 return d->ssid;
100 uint NMAccessPoint::frequency() const
102 return d->frequency;
105 uint NMAccessPoint::maxBitRate() const
107 return d->maxBitRate;
110 Solid::Control::WirelessNetworkInterface::OperationMode NMAccessPoint::mode() const
112 return d->mode;
115 int NMAccessPoint::signalStrength() const
117 return d->signalStrength;
120 void NMAccessPoint::propertiesChanged(const QVariantMap &properties)
122 QStringList propKeys = properties.keys();
123 //kDebug(1441) << propKeys;
124 QLatin1String flagsKey("Flags"),
125 wpaFlagsKey("WpaFlags"),
126 rsnFlagsKey("RsnFlags"),
127 ssidKey("Ssid"),
128 freqKey("Frequency"),
129 hwAddrKey("HwAddress"),
130 modeKey("Mode"),
131 maxBitRateKey("MaxBitrate"),
132 strengthKey("Strength");
133 QVariantMap::const_iterator it = properties.find(flagsKey);
134 if (it != properties.end()) {
135 d->capabilities = convertCapabilities(it->toUInt());
136 propKeys.removeOne(flagsKey);
138 it = properties.find(wpaFlagsKey);
139 if (it != properties.end()) {
140 d->wpaFlags = convertWpaFlags(it->toUInt());
141 emit wpaFlagsChanged(d->wpaFlags);
142 propKeys.removeOne(wpaFlagsKey);
144 it = properties.find(rsnFlagsKey);
145 if (it != properties.end()) {
146 d->rsnFlags = convertWpaFlags(it->toUInt());
147 emit rsnFlagsChanged(d->rsnFlags);
148 propKeys.removeOne(rsnFlagsKey);
150 it = properties.find(ssidKey);
151 if (it != properties.end()) {
152 d->ssid = it->toByteArray();
153 emit ssidChanged(d->ssid);
154 propKeys.removeOne(ssidKey);
156 it = properties.find(freqKey);
157 if (it != properties.end()) {
158 d->frequency = it->toUInt();
159 emit frequencyChanged(d->frequency);
160 propKeys.removeOne(freqKey);
162 it = properties.find(hwAddrKey);
163 if (it != properties.end()) {
164 d->hardwareAddress = it->toString();
165 propKeys.removeOne(hwAddrKey);
167 it = properties.find(modeKey);
168 if (it != properties.end()) {
169 d->mode = NMWirelessNetworkInterface::convertOperationMode(it->toUInt());
170 propKeys.removeOne(modeKey);
172 it = properties.find(maxBitRateKey);
173 if (it != properties.end()) {
174 d->maxBitRate = it->toUInt();
175 emit bitRateChanged(d->maxBitRate);
176 propKeys.removeOne(maxBitRateKey);
178 it = properties.find(strengthKey);
179 if (it != properties.end()) {
180 d->signalStrength = it->toInt();
181 //kDebug(1441) << "UNI: " << d->uni << "MAC: " << d->hardwareAddress << "SignalStrength: " << d->signalStrength;
182 emit signalStrengthChanged(d->signalStrength);
183 propKeys.removeOne(strengthKey);
185 if (propKeys.count()) {
186 kDebug(1441) << "Unhandled properties: " << propKeys;
190 Solid::Control::AccessPoint::Capabilities NMAccessPoint::convertCapabilities(int caps)
192 if ( 1 == caps ) {
193 return Solid::Control::AccessPoint::Privacy;
194 } else {
195 return 0;
198 // Copied from wireless.h
199 // /* Modes of operation */
200 #define IW_MODE_AUTO 0 /* Let the driver decides */
201 #define IW_MODE_ADHOC 1 /* Single cell network */
202 #define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */
203 #define IW_MODE_MASTER 3 /* Synchronization master or Access Point */
204 #define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */
205 #define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */
206 #define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */
208 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::convertWpaFlags(uint theirFlags)
210 return (Solid::Control::AccessPoint::WpaFlags)theirFlags;
213 #include "accesspoint.moc"