not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / solid / networkmanager-0.6 / NetworkManager-wirelessaccesspoint.cpp
bloba2a38c4257962c014215ac648d2d7e964a039aaa
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>
3 Copyright (C) 2008 Pino Toscano <pino@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "NetworkManager-wirelessaccesspoint.h"
23 #include <QtDBus/QDBusInterface>
24 #include <QtDBus/QDBusMessage>
26 #include <kdebug.h>
28 #include <NetworkManager/NetworkManager.h>
30 extern Solid::Control::WirelessNetworkInterface::OperationMode getOperationMode(const int nm);
32 namespace AP
35 Solid::Control::AccessPoint::WpaFlags getWpaFlags(int netflags)
37 Solid::Control::AccessPoint::WpaFlags f = (Solid::Control::AccessPoint::WpaFlags)0;
38 if (netflags & NM_802_11_CAP_KEY_MGMT_PSK)
39 f |= Solid::Control::AccessPoint::KeyMgmtPsk;
40 if (netflags & NM_802_11_CAP_KEY_MGMT_802_1X)
41 f |= Solid::Control::AccessPoint::KeyMgmt8021x;
42 if (netflags & NM_802_11_CAP_CIPHER_WEP40)
43 f |= Solid::Control::AccessPoint::PairWep40;
44 if (netflags & NM_802_11_CAP_CIPHER_WEP104)
45 f |= Solid::Control::AccessPoint::PairWep104;
46 if (netflags & NM_802_11_CAP_CIPHER_TKIP)
47 f |= Solid::Control::AccessPoint::GroupTkip;
48 if (netflags & NM_802_11_CAP_CIPHER_CCMP)
49 f |= Solid::Control::AccessPoint::GroupCcmp;
50 return f;
56 class NMAccessPointPrivate
58 public:
59 NMAccessPointPrivate(const QString & networkPath);
61 void deserialize(const QDBusMessage & message);
63 QString netPath;
64 Solid::Control::AccessPoint::Capabilities capabilities;
65 Solid::Control::AccessPoint::WpaFlags wpaFlags;
66 Solid::Control::AccessPoint::WpaFlags rsnFlags;
67 QString ssid;
68 uint frequency;
69 QString hardwareAddress;
70 uint maxBitRate;
71 Solid::Control::WirelessNetworkInterface::OperationMode mode;
72 int signalStrength;
73 bool broadcast;
76 NMAccessPointPrivate::NMAccessPointPrivate(const QString & networkPath)
77 : netPath(networkPath)
78 , capabilities(0)
79 , wpaFlags(0)
80 , rsnFlags(0)
81 , frequency(0)
82 , maxBitRate(0)
83 , mode(static_cast<Solid::Control::WirelessNetworkInterface::OperationMode>(0))
84 , signalStrength(0)
85 , broadcast(false)
89 void NMAccessPointPrivate::deserialize(const QDBusMessage &message)
91 const QList<QVariant> args = message.arguments();
92 if (args.size() > 1) ssid = args[1].toString();
93 if (args.size() > 2) hardwareAddress = args[2].toString();
94 if (args.size() > 3) signalStrength = args[3].toInt();
95 // frequency: NM 0.6 provides it in Hz, while we need MHz
96 if (args.size() > 4) frequency = static_cast<uint>(args[4].toDouble() / 1000000);
97 if (args.size() > 5) maxBitRate = args[5].toUInt();
98 if (args.size() > 6) mode = getOperationMode(args[6].toInt());
99 if (args.size() > 7) wpaFlags = AP::getWpaFlags(args[7].toInt());
100 if (args.size() > 8) broadcast = args[8].toBool();
104 NMAccessPoint::NMAccessPoint(const QString & netPath)
105 : Solid::Control::Ifaces::AccessPoint(0), d(new NMAccessPointPrivate(netPath))
107 QDBusInterface iface(NM_DBUS_SERVICE, netPath, NM_DBUS_INTERFACE_DEVICES,
108 QDBusConnection::systemBus());
109 QDBusMessage reply = iface.call("getProperties");
110 d->deserialize(reply);
112 if (d->wpaFlags)
113 d->capabilities |= Solid::Control::AccessPoint::Privacy;
116 NMAccessPoint::~NMAccessPoint()
118 delete d;
121 QString NMAccessPoint::uni() const
123 return d->netPath;
126 Solid::Control::AccessPoint::Capabilities NMAccessPoint::capabilities() const
128 return d->capabilities;
131 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::wpaFlags() const
133 return d->wpaFlags;
136 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::rsnFlags() const
138 return d->rsnFlags;
141 QString NMAccessPoint::ssid() const
143 return d->ssid;
146 uint NMAccessPoint::frequency() const
148 return d->frequency;
151 QString NMAccessPoint::hardwareAddress() const
153 return d->hardwareAddress;
156 uint NMAccessPoint::maxBitRate() const
158 return d->maxBitRate;
161 Solid::Control::WirelessNetworkInterface::OperationMode NMAccessPoint::mode() const
163 return d->mode;
166 void NMAccessPoint::setSignalStrength(int strength)
168 if (strength == d->signalStrength)
169 return;
171 d->signalStrength = strength;
172 emit signalStrengthChanged(d->signalStrength);
175 int NMAccessPoint::signalStrength() const
177 return d->signalStrength;
180 #include "NetworkManager-wirelessaccesspoint.moc"