SolidModules
accesspoint.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "accesspoint.h"
00022
00023 #include <KDebug>
00024 #include "dbus/nm-access-pointinterface.h"
00025 #include "manager.h"
00026 #include "wirelessnetworkinterface.h"
00027
00028
00029 class NMAccessPoint::Private
00030 {
00031 public:
00032 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)
00033 {
00034 }
00035 OrgFreedesktopNetworkManagerAccessPointInterface iface;
00036 QString uni;
00037 Solid::Control::AccessPoint::Capabilities capabilities;
00038 Solid::Control::AccessPoint::WpaFlags wpaFlags;
00039 Solid::Control::AccessPoint::WpaFlags rsnFlags;
00040 QString ssid;
00041 uint frequency;
00042 QString hardwareAddress;
00043 uint maxBitRate;
00044 Solid::Control::WirelessNetworkInterface::OperationMode mode;
00045 int signalStrength;
00046 };
00047
00048 NMAccessPoint::NMAccessPoint( const QString& path, QObject * parent ) : Solid::Control::Ifaces::AccessPoint(parent), d(new Private( path ))
00049 {
00050 d->uni = path;
00051 d->capabilities = convertCapabilities( d->iface.flags() );
00052 d->wpaFlags = convertWpaFlags( d->iface.wpaFlags() );
00053 d->rsnFlags = convertWpaFlags( d->iface.rsnFlags() );
00054 d->signalStrength = d->iface.strength();
00055 d->ssid = d->iface.ssid();
00056 d->frequency = d->iface.frequency();
00057 d->hardwareAddress = d->iface.hwAddress();
00058 d->maxBitRate = d->iface.maxBitrate();
00059
00060 d->mode = NMWirelessNetworkInterface::convertOperationMode(d->iface.mode());
00061 connect( &d->iface, SIGNAL(PropertiesChanged(const QVariantMap &)),
00062 this, SLOT(propertiesChanged(const QVariantMap &)));
00063 }
00064
00065 NMAccessPoint::~NMAccessPoint()
00066 {
00067 delete d;
00068 }
00069
00070 QString NMAccessPoint::uni() const
00071 {
00072 return d->uni;
00073 }
00074
00075 QString NMAccessPoint::hardwareAddress() const
00076 {
00077 return d->hardwareAddress;
00078 }
00079
00080 Solid::Control::AccessPoint::Capabilities NMAccessPoint::capabilities() const
00081 {
00082 return d->capabilities;
00083 }
00084
00085 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::wpaFlags() const
00086 {
00087 return d->wpaFlags;
00088 }
00089
00090 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::rsnFlags() const
00091 {
00092 return d->rsnFlags;
00093 }
00094
00095 QString NMAccessPoint::ssid() const
00096 {
00097 return d->ssid;
00098 }
00099
00100 uint NMAccessPoint::frequency() const
00101 {
00102 return d->frequency;
00103 }
00104
00105 uint NMAccessPoint::maxBitRate() const
00106 {
00107 return d->maxBitRate;
00108 }
00109
00110 Solid::Control::WirelessNetworkInterface::OperationMode NMAccessPoint::mode() const
00111 {
00112 return d->mode;
00113 }
00114
00115 int NMAccessPoint::signalStrength() const
00116 {
00117 return d->signalStrength;
00118 }
00119
00120 void NMAccessPoint::propertiesChanged(const QVariantMap &properties)
00121 {
00122 QStringList propKeys = properties.keys();
00123
00124 QLatin1String flagsKey("Flags"),
00125 wpaFlagsKey("WpaFlags"),
00126 rsnFlagsKey("RsnFlags"),
00127 ssidKey("Ssid"),
00128 freqKey("Frequency"),
00129 hwAddrKey("HwAddress"),
00130 modeKey("Mode"),
00131 maxBitRateKey("MaxBitrate"),
00132 strengthKey("Strength");
00133 QVariantMap::const_iterator it = properties.find(flagsKey);
00134 if (it != properties.end()) {
00135 d->capabilities = convertCapabilities(it->toUInt());
00136 propKeys.removeOne(flagsKey);
00137 }
00138 it = properties.find(wpaFlagsKey);
00139 if (it != properties.end()) {
00140 d->wpaFlags = convertWpaFlags(it->toUInt());
00141 emit wpaFlagsChanged(d->wpaFlags);
00142 propKeys.removeOne(wpaFlagsKey);
00143 }
00144 it = properties.find(rsnFlagsKey);
00145 if (it != properties.end()) {
00146 d->rsnFlags = convertWpaFlags(it->toUInt());
00147 emit rsnFlagsChanged(d->rsnFlags);
00148 propKeys.removeOne(rsnFlagsKey);
00149 }
00150 it = properties.find(ssidKey);
00151 if (it != properties.end()) {
00152 d->ssid = it->toByteArray();
00153 emit ssidChanged(d->ssid);
00154 propKeys.removeOne(ssidKey);
00155 }
00156 it = properties.find(freqKey);
00157 if (it != properties.end()) {
00158 d->frequency = it->toUInt();
00159 emit frequencyChanged(d->frequency);
00160 propKeys.removeOne(freqKey);
00161 }
00162 it = properties.find(hwAddrKey);
00163 if (it != properties.end()) {
00164 d->hardwareAddress = it->toString();
00165 propKeys.removeOne(hwAddrKey);
00166 }
00167 it = properties.find(modeKey);
00168 if (it != properties.end()) {
00169 d->mode = NMWirelessNetworkInterface::convertOperationMode(it->toUInt());
00170 propKeys.removeOne(modeKey);
00171 }
00172 it = properties.find(maxBitRateKey);
00173 if (it != properties.end()) {
00174 d->maxBitRate = it->toUInt();
00175 emit bitRateChanged(d->maxBitRate);
00176 propKeys.removeOne(maxBitRateKey);
00177 }
00178 it = properties.find(strengthKey);
00179 if (it != properties.end()) {
00180 d->signalStrength = it->toInt();
00181
00182 emit signalStrengthChanged(d->signalStrength);
00183 propKeys.removeOne(strengthKey);
00184 }
00185 if (propKeys.count()) {
00186 kDebug(1441) << "Unhandled properties: " << propKeys;
00187 }
00188 }
00189
00190 Solid::Control::AccessPoint::Capabilities NMAccessPoint::convertCapabilities(int caps)
00191 {
00192 if ( 1 == caps ) {
00193 return Solid::Control::AccessPoint::Privacy;
00194 } else {
00195 return 0;
00196 }
00197 }
00198
00199
00200 #define IW_MODE_AUTO 0
00201 #define IW_MODE_ADHOC 1
00202 #define IW_MODE_INFRA 2
00203 #define IW_MODE_MASTER 3
00204 #define IW_MODE_REPEAT 4
00205 #define IW_MODE_SECOND 5
00206 #define IW_MODE_MONITOR 6
00207
00208 Solid::Control::AccessPoint::WpaFlags NMAccessPoint::convertWpaFlags(uint theirFlags)
00209 {
00210 return (Solid::Control::AccessPoint::WpaFlags)theirFlags;
00211 }
00212
00213 #include "accesspoint.moc"
00214