• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

wirelessnetworkinterface.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2008 Will Stephenson <wstephenson@kde.org>
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License as
00006 published by the Free Software Foundation; either version 2 of
00007 the License or (at your option) version 3 or any later version
00008 accepted by the membership of KDE e.V. (or its successor approved
00009 by the membership of KDE e.V.), which shall act as a proxy
00010 defined in Section 14 of version 3 of the license.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 // Copied from wireless.h
00022 /* Modes of operation */
00023 #define IW_MODE_AUTO    0   /* Let the driver decides */
00024 #define IW_MODE_ADHOC   1   /* Single cell network */
00025 #define IW_MODE_INFRA   2   /* Multi cell network, roaming, ... */
00026 #define IW_MODE_MASTER  3   /* Synchronization master or Access Point */
00027 #define IW_MODE_REPEAT  4   /* Wireless Repeater (forwarder) */
00028 #define IW_MODE_SECOND  5   /* Secondary master/repeater (backup) */
00029 #define IW_MODE_MONITOR 6   /* Passive monitor (listen only) */
00030 
00031 #include "wirelessnetworkinterface.h"
00032 #include "wirelessnetworkinterface_p.h"
00033 
00034 #include <KDebug>
00035 
00036 #include "accesspoint.h"
00037 #include "manager.h"
00038 
00039 NMWirelessNetworkInterfacePrivate::NMWirelessNetworkInterfacePrivate(const QString & path, QObject * owner)
00040     : NMNetworkInterfacePrivate(path, owner), wirelessIface(NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus())
00041       , bitRate(0)
00042 {
00043 
00044 }
00045 
00046 NMWirelessNetworkInterface::NMWirelessNetworkInterface(const QString & path, NMNetworkManager * manager, QObject * parent)
00047     : NMNetworkInterface(*new NMWirelessNetworkInterfacePrivate(path, this), manager, parent)
00048 {
00049     Q_D(NMWirelessNetworkInterface);
00050     d->hardwareAddress = d->wirelessIface.hwAddress();
00051     d->mode = convertOperationMode(d->wirelessIface.mode());
00052     d->bitRate = d->wirelessIface.bitrate();
00053     d->activeAccessPoint = d->wirelessIface.activeAccessPoint().path();
00054     d->wirelessCapabilities = convertCapabilities(d->wirelessIface.wirelessCapabilities());
00055 
00056     connect( &d->wirelessIface, SIGNAL(PropertiesChanged(const QVariantMap &)),
00057                 this, SLOT(wirelessPropertiesChanged(const QVariantMap &)));
00058 
00059     qDBusRegisterMetaType<QList<QDBusObjectPath> >();
00060     QDBusReply< QList <QDBusObjectPath> > apPathList = d->wirelessIface.GetAccessPoints();
00061     if (apPathList.isValid())
00062     {
00063         kDebug(1441) << "Got device list";
00064         QList <QDBusObjectPath> aps = apPathList.value();
00065         foreach (QDBusObjectPath op, aps)
00066         {
00067             d->accessPoints.append(op.path());
00068             kDebug(1441) << "  " << op.path();
00069         }
00070     }
00071     else
00072         kDebug(1441) << "Error getting access point list: " << apPathList.error().name() << ": " << apPathList.error().message();
00073 }
00074 
00075 NMWirelessNetworkInterface::~NMWirelessNetworkInterface()
00076 {
00077 
00078 }
00079 
00080 MacAddressList NMWirelessNetworkInterface::accessPoints() const
00081 {
00082     Q_D(const NMWirelessNetworkInterface);
00083     return d->accessPoints;
00084 }
00085 
00086 QString NMWirelessNetworkInterface::activeAccessPoint() const
00087 {
00088     Q_D(const NMWirelessNetworkInterface);
00089     return d->activeAccessPoint;
00090 }
00091 
00092 QString NMWirelessNetworkInterface::hardwareAddress() const
00093 {
00094     Q_D(const NMWirelessNetworkInterface);
00095     return d->hardwareAddress;
00096 }
00097 
00098 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::mode() const
00099 {
00100     Q_D(const NMWirelessNetworkInterface);
00101     return d->mode;
00102 }
00103 
00104 int NMWirelessNetworkInterface::bitRate() const
00105 {
00106     Q_D(const NMWirelessNetworkInterface);
00107     return d->bitRate;
00108 }
00109 
00110 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::wirelessCapabilities() const
00111 {
00112     Q_D(const NMWirelessNetworkInterface);
00113     return d->wirelessCapabilities;
00114 }
00115 
00116 QObject * NMWirelessNetworkInterface::createAccessPoint(const QString & uni)
00117 {
00118     return new NMAccessPoint(uni, 0);
00119 }
00120 
00121 void NMWirelessNetworkInterface::wirelessPropertiesChanged(const QVariantMap & changedProperties)
00122 {
00123     kDebug(1441) << changedProperties.keys();
00124     QStringList propKeys = changedProperties.keys();
00125     Q_D(NMWirelessNetworkInterface);
00126     QLatin1String activeApKey("ActiveAccessPoint"),
00127                   hwAddrKey("HwAddress"),
00128                   bitRateKey("Bitrate"),
00129                   modeKey("Mode"),
00130                   wirelessCapsKey("WirelessCapabilities");
00131     QVariantMap::const_iterator it = changedProperties.find(activeApKey);
00132     if (it != changedProperties.end()) {
00133         d->activeAccessPoint = qdbus_cast<QDBusObjectPath>(*it).path();
00134         emit activeAccessPointChanged(d->activeAccessPoint);
00135         propKeys.removeOne(activeApKey);
00136     }
00137     it = changedProperties.find(hwAddrKey);
00138     if (it != changedProperties.end()) {
00139         d->hardwareAddress = it->toString();
00140         propKeys.removeOne(hwAddrKey);
00141     }
00142     it = changedProperties.find(bitRateKey);
00143     if (it != changedProperties.end()) {
00144         d->bitRate = it->toUInt();
00145         emit bitRateChanged(d->bitRate);
00146         propKeys.removeOne(bitRateKey);
00147     }
00148     it = changedProperties.find(modeKey);
00149     if (it != changedProperties.end()) {
00150         d->mode = convertOperationMode(it->toUInt());
00151         emit modeChanged(d->mode);
00152         propKeys.removeOne(modeKey);
00153     }
00154     it = changedProperties.find(wirelessCapsKey);
00155     if (it != changedProperties.end()) {
00156         d->wirelessCapabilities = convertCapabilities(it->toUInt());
00157         propKeys.removeOne(wirelessCapsKey);
00158     }
00159     if (propKeys.count()) {
00160         kDebug(1441) << "Unhandled properties: " << propKeys;
00161     }
00162 }
00163 
00164 void NMWirelessNetworkInterface::accessPointAdded(const QDBusObjectPath &apPath)
00165 {
00166     kDebug(1441) << apPath.path();
00167     Q_D(NMWirelessNetworkInterface);
00168     d->accessPoints.append(apPath.path());
00169     emit accessPointAppeared(apPath.path());
00170 }
00171 
00172 void NMWirelessNetworkInterface::accessPointRemoved(const QDBusObjectPath &apPath)
00173 {
00174     kDebug(1441) << apPath.path();
00175     Q_D(NMWirelessNetworkInterface);
00176     if (!d->accessPoints.contains(apPath.path())) {
00177         kDebug(1441) << "Access point list lookup failed for " << apPath.path();
00178     }
00179     d->accessPoints.removeAll(apPath.path());
00180     emit accessPointDisappeared(apPath.path());
00181 }
00182 
00183 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::convertOperationMode(uint theirMode)
00184 {
00185     Solid::Control::WirelessNetworkInterface::OperationMode ourMode;
00186     switch ( theirMode ) {
00187         case IW_MODE_AUTO:
00188             ourMode = Solid::Control::WirelessNetworkInterface::Managed;
00189             break;
00190         case IW_MODE_ADHOC:
00191             ourMode = Solid::Control::WirelessNetworkInterface::Adhoc;
00192             break;
00193         case IW_MODE_INFRA:
00194         case IW_MODE_MASTER:
00195             ourMode = Solid::Control::WirelessNetworkInterface::Master;
00196             break;
00197         case IW_MODE_REPEAT:
00198             ourMode = Solid::Control::WirelessNetworkInterface::Repeater;
00199             break;
00200         case IW_MODE_SECOND:
00201         case IW_MODE_MONITOR:
00202             ourMode = (Solid::Control::WirelessNetworkInterface::OperationMode)0;
00203             break;
00204     }
00205     return ourMode;
00206 }
00207 
00208 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::convertCapabilities(uint caps)
00209 {
00210     return (Solid::Control::WirelessNetworkInterface::Capabilities)caps;
00211 }
00212 

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal