add more spacing
[personal-kdebase.git] / workspace / solid / networkmanager-0.7 / wirelessnetworkinterface.cpp
blob36c5209a026c8baf9fcae86e064cfb6e33050c52
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 // Copied from wireless.h
22 /* Modes of operation */
23 #define IW_MODE_AUTO 0 /* Let the driver decides */
24 #define IW_MODE_ADHOC 1 /* Single cell network */
25 #define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */
26 #define IW_MODE_MASTER 3 /* Synchronization master or Access Point */
27 #define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */
28 #define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */
29 #define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */
31 #include "wirelessnetworkinterface.h"
32 #include "wirelessnetworkinterface_p.h"
34 #include <KDebug>
36 #include "accesspoint.h"
37 #include "manager.h"
39 NMWirelessNetworkInterfacePrivate::NMWirelessNetworkInterfacePrivate(const QString & path, QObject * owner)
40 : NMNetworkInterfacePrivate(path, owner), wirelessIface(NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus())
41 , bitRate(0)
46 NMWirelessNetworkInterface::NMWirelessNetworkInterface(const QString & path, NMNetworkManager * manager, QObject * parent)
47 : NMNetworkInterface(*new NMWirelessNetworkInterfacePrivate(path, this), manager, parent)
49 Q_D(NMWirelessNetworkInterface);
50 d->hardwareAddress = d->wirelessIface.hwAddress();
51 d->mode = convertOperationMode(d->wirelessIface.mode());
52 d->bitRate = d->wirelessIface.bitrate();
53 d->activeAccessPoint = d->wirelessIface.activeAccessPoint().path();
54 d->wirelessCapabilities = convertCapabilities(d->wirelessIface.wirelessCapabilities());
56 connect( &d->wirelessIface, SIGNAL(PropertiesChanged(const QVariantMap &)),
57 this, SLOT(wirelessPropertiesChanged(const QVariantMap &)));
58 connect( &d->wirelessIface, SIGNAL(AccessPointAdded(const QDBusObjectPath &)),
59 this, SLOT(accessPointAdded(const QDBusObjectPath &)));
60 connect( &d->wirelessIface, SIGNAL(AccessPointRemoved(const QDBusObjectPath &)),
61 this, SLOT(accessPointRemoved(const QDBusObjectPath &)));
64 qDBusRegisterMetaType<QList<QDBusObjectPath> >();
65 QDBusReply< QList <QDBusObjectPath> > apPathList = d->wirelessIface.GetAccessPoints();
66 if (apPathList.isValid())
68 kDebug(1441) << "Got device list";
69 QList <QDBusObjectPath> aps = apPathList.value();
70 foreach (QDBusObjectPath op, aps)
72 d->accessPoints.append(op.path());
73 kDebug(1441) << " " << op.path();
76 else
77 kDebug(1441) << "Error getting access point list: " << apPathList.error().name() << ": " << apPathList.error().message();
80 NMWirelessNetworkInterface::~NMWirelessNetworkInterface()
85 MacAddressList NMWirelessNetworkInterface::accessPoints() const
87 Q_D(const NMWirelessNetworkInterface);
88 return d->accessPoints;
91 QString NMWirelessNetworkInterface::activeAccessPoint() const
93 Q_D(const NMWirelessNetworkInterface);
94 return d->activeAccessPoint;
97 QString NMWirelessNetworkInterface::hardwareAddress() const
99 Q_D(const NMWirelessNetworkInterface);
100 return d->hardwareAddress;
103 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::mode() const
105 Q_D(const NMWirelessNetworkInterface);
106 return d->mode;
109 int NMWirelessNetworkInterface::bitRate() const
111 Q_D(const NMWirelessNetworkInterface);
112 return d->bitRate;
115 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::wirelessCapabilities() const
117 Q_D(const NMWirelessNetworkInterface);
118 return d->wirelessCapabilities;
121 QObject * NMWirelessNetworkInterface::createAccessPoint(const QString & uni)
123 return new NMAccessPoint(uni, 0);
126 void NMWirelessNetworkInterface::wirelessPropertiesChanged(const QVariantMap & changedProperties)
128 kDebug(1441) << changedProperties.keys();
129 QStringList propKeys = changedProperties.keys();
130 Q_D(NMWirelessNetworkInterface);
131 QLatin1String activeApKey("ActiveAccessPoint"),
132 hwAddrKey("HwAddress"),
133 bitRateKey("Bitrate"),
134 modeKey("Mode"),
135 wirelessCapsKey("WirelessCapabilities");
136 QVariantMap::const_iterator it = changedProperties.find(activeApKey);
137 if (it != changedProperties.end()) {
138 d->activeAccessPoint = qdbus_cast<QDBusObjectPath>(*it).path();
139 emit activeAccessPointChanged(d->activeAccessPoint);
140 propKeys.removeOne(activeApKey);
142 it = changedProperties.find(hwAddrKey);
143 if (it != changedProperties.end()) {
144 d->hardwareAddress = it->toString();
145 propKeys.removeOne(hwAddrKey);
147 it = changedProperties.find(bitRateKey);
148 if (it != changedProperties.end()) {
149 d->bitRate = it->toUInt();
150 emit bitRateChanged(d->bitRate);
151 propKeys.removeOne(bitRateKey);
153 it = changedProperties.find(modeKey);
154 if (it != changedProperties.end()) {
155 d->mode = convertOperationMode(it->toUInt());
156 emit modeChanged(d->mode);
157 propKeys.removeOne(modeKey);
159 it = changedProperties.find(wirelessCapsKey);
160 if (it != changedProperties.end()) {
161 d->wirelessCapabilities = convertCapabilities(it->toUInt());
162 propKeys.removeOne(wirelessCapsKey);
164 if (propKeys.count()) {
165 kDebug(1441) << "Unhandled properties: " << propKeys;
169 void NMWirelessNetworkInterface::accessPointAdded(const QDBusObjectPath &apPath)
171 kDebug(1441) << apPath.path();
172 Q_D(NMWirelessNetworkInterface);
173 if (!d->accessPoints.contains(apPath.path())) {
174 d->accessPoints.append(apPath.path());
175 emit accessPointAppeared(apPath.path());
179 void NMWirelessNetworkInterface::accessPointRemoved(const QDBusObjectPath &apPath)
181 kDebug(1441) << apPath.path();
182 Q_D(NMWirelessNetworkInterface);
183 if (!d->accessPoints.contains(apPath.path())) {
184 kDebug(1441) << "Access point list lookup failed for " << apPath.path();
186 d->accessPoints.removeAll(apPath.path());
187 emit accessPointDisappeared(apPath.path());
190 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::convertOperationMode(uint theirMode)
192 Solid::Control::WirelessNetworkInterface::OperationMode ourMode;
193 switch ( theirMode ) {
194 case IW_MODE_AUTO:
195 ourMode = Solid::Control::WirelessNetworkInterface::Managed;
196 break;
197 case IW_MODE_ADHOC:
198 ourMode = Solid::Control::WirelessNetworkInterface::Adhoc;
199 break;
200 case IW_MODE_INFRA:
201 case IW_MODE_MASTER:
202 ourMode = Solid::Control::WirelessNetworkInterface::Master;
203 break;
204 case IW_MODE_REPEAT:
205 ourMode = Solid::Control::WirelessNetworkInterface::Repeater;
206 break;
207 case IW_MODE_SECOND:
208 case IW_MODE_MONITOR:
209 ourMode = (Solid::Control::WirelessNetworkInterface::OperationMode)0;
210 break;
212 return ourMode;
215 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::convertCapabilities(uint caps)
217 return (Solid::Control::WirelessNetworkInterface::Capabilities)caps;