• Skip to content
  • Skip to link menu
KDE 4.2 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     connect( &d->wirelessIface, SIGNAL(AccessPointAdded(const QDBusObjectPath &)),
00059                 this, SLOT(accessPointAdded(const QDBusObjectPath &)));
00060     connect( &d->wirelessIface, SIGNAL(AccessPointRemoved(const QDBusObjectPath &)),
00061                 this, SLOT(accessPointRemoved(const QDBusObjectPath &)));
00062 
00063 
00064     qDBusRegisterMetaType<QList<QDBusObjectPath> >();
00065     QDBusReply< QList <QDBusObjectPath> > apPathList = d->wirelessIface.GetAccessPoints();
00066     if (apPathList.isValid())
00067     {
00068         kDebug(1441) << "Got device list";
00069         QList <QDBusObjectPath> aps = apPathList.value();
00070         foreach (QDBusObjectPath op, aps)
00071         {
00072             d->accessPoints.append(op.path());
00073             kDebug(1441) << "  " << op.path();
00074         }
00075     }
00076     else
00077         kDebug(1441) << "Error getting access point list: " << apPathList.error().name() << ": " << apPathList.error().message();
00078 }
00079 
00080 NMWirelessNetworkInterface::~NMWirelessNetworkInterface()
00081 {
00082 
00083 }
00084 
00085 MacAddressList NMWirelessNetworkInterface::accessPoints() const
00086 {
00087     Q_D(const NMWirelessNetworkInterface);
00088     return d->accessPoints;
00089 }
00090 
00091 QString NMWirelessNetworkInterface::activeAccessPoint() const
00092 {
00093     Q_D(const NMWirelessNetworkInterface);
00094     return d->activeAccessPoint;
00095 }
00096 
00097 QString NMWirelessNetworkInterface::hardwareAddress() const
00098 {
00099     Q_D(const NMWirelessNetworkInterface);
00100     return d->hardwareAddress;
00101 }
00102 
00103 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::mode() const
00104 {
00105     Q_D(const NMWirelessNetworkInterface);
00106     return d->mode;
00107 }
00108 
00109 int NMWirelessNetworkInterface::bitRate() const
00110 {
00111     Q_D(const NMWirelessNetworkInterface);
00112     return d->bitRate;
00113 }
00114 
00115 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::wirelessCapabilities() const
00116 {
00117     Q_D(const NMWirelessNetworkInterface);
00118     return d->wirelessCapabilities;
00119 }
00120 
00121 QObject * NMWirelessNetworkInterface::createAccessPoint(const QString & uni)
00122 {
00123     return new NMAccessPoint(uni, 0);
00124 }
00125 
00126 void NMWirelessNetworkInterface::wirelessPropertiesChanged(const QVariantMap & changedProperties)
00127 {
00128     kDebug(1441) << changedProperties.keys();
00129     QStringList propKeys = changedProperties.keys();
00130     Q_D(NMWirelessNetworkInterface);
00131     QLatin1String activeApKey("ActiveAccessPoint"),
00132                   hwAddrKey("HwAddress"),
00133                   bitRateKey("Bitrate"),
00134                   modeKey("Mode"),
00135                   wirelessCapsKey("WirelessCapabilities");
00136     QVariantMap::const_iterator it = changedProperties.find(activeApKey);
00137     if (it != changedProperties.end()) {
00138         d->activeAccessPoint = qdbus_cast<QDBusObjectPath>(*it).path();
00139         emit activeAccessPointChanged(d->activeAccessPoint);
00140         propKeys.removeOne(activeApKey);
00141     }
00142     it = changedProperties.find(hwAddrKey);
00143     if (it != changedProperties.end()) {
00144         d->hardwareAddress = it->toString();
00145         propKeys.removeOne(hwAddrKey);
00146     }
00147     it = changedProperties.find(bitRateKey);
00148     if (it != changedProperties.end()) {
00149         d->bitRate = it->toUInt();
00150         emit bitRateChanged(d->bitRate);
00151         propKeys.removeOne(bitRateKey);
00152     }
00153     it = changedProperties.find(modeKey);
00154     if (it != changedProperties.end()) {
00155         d->mode = convertOperationMode(it->toUInt());
00156         emit modeChanged(d->mode);
00157         propKeys.removeOne(modeKey);
00158     }
00159     it = changedProperties.find(wirelessCapsKey);
00160     if (it != changedProperties.end()) {
00161         d->wirelessCapabilities = convertCapabilities(it->toUInt());
00162         propKeys.removeOne(wirelessCapsKey);
00163     }
00164     if (propKeys.count()) {
00165         kDebug(1441) << "Unhandled properties: " << propKeys;
00166     }
00167 }
00168 
00169 void NMWirelessNetworkInterface::accessPointAdded(const QDBusObjectPath &apPath)
00170 {
00171     kDebug(1441) << apPath.path();
00172     Q_D(NMWirelessNetworkInterface);
00173     if (!d->accessPoints.contains(apPath.path())) {
00174         d->accessPoints.append(apPath.path());
00175         emit accessPointAppeared(apPath.path());
00176     }
00177 }
00178 
00179 void NMWirelessNetworkInterface::accessPointRemoved(const QDBusObjectPath &apPath)
00180 {
00181     kDebug(1441) << apPath.path();
00182     Q_D(NMWirelessNetworkInterface);
00183     if (!d->accessPoints.contains(apPath.path())) {
00184         kDebug(1441) << "Access point list lookup failed for " << apPath.path();
00185     }
00186     d->accessPoints.removeAll(apPath.path());
00187     emit accessPointDisappeared(apPath.path());
00188 }
00189 
00190 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::convertOperationMode(uint theirMode)
00191 {
00192     Solid::Control::WirelessNetworkInterface::OperationMode ourMode;
00193     switch ( theirMode ) {
00194         case IW_MODE_AUTO:
00195             ourMode = Solid::Control::WirelessNetworkInterface::Managed;
00196             break;
00197         case IW_MODE_ADHOC:
00198             ourMode = Solid::Control::WirelessNetworkInterface::Adhoc;
00199             break;
00200         case IW_MODE_INFRA:
00201         case IW_MODE_MASTER:
00202             ourMode = Solid::Control::WirelessNetworkInterface::Master;
00203             break;
00204         case IW_MODE_REPEAT:
00205             ourMode = Solid::Control::WirelessNetworkInterface::Repeater;
00206             break;
00207         case IW_MODE_SECOND:
00208         case IW_MODE_MONITOR:
00209             ourMode = (Solid::Control::WirelessNetworkInterface::OperationMode)0;
00210             break;
00211     }
00212     return ourMode;
00213 }
00214 
00215 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::convertCapabilities(uint caps)
00216 {
00217     return (Solid::Control::WirelessNetworkInterface::Capabilities)caps;
00218 }
00219 

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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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