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

libsolidcontrol

wirelessnetworkinterface.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
00003     Copyright (C) 2007 Kevin Ottens <ervin@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License version 2 as published by the Free Software Foundation.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 
00019 */
00020 
00021 #include "wirelessnetworkinterface.h"
00022 #include "wirelessnetworkinterface_p.h"
00023 
00024 #include "soliddefs_p.h"
00025 #include "wirelessaccesspoint.h"
00026 #include "ifaces/wirelessaccesspoint.h"
00027 #include "ifaces/wirelessnetworkinterface.h"
00028 
00029 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(QObject *backendObject)
00030     : NetworkInterface(*new WirelessNetworkInterfacePrivate(this), backendObject)
00031 {
00032     Q_D(WirelessNetworkInterface);
00033     d->setBackendObject(backendObject);
00034     makeConnections( backendObject );
00035     d->readAccessPoints();
00036 }
00037 
00038 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(const WirelessNetworkInterface &networkinterface)
00039     : NetworkInterface(*new WirelessNetworkInterfacePrivate(this), networkinterface)
00040 {
00041     Q_D(WirelessNetworkInterface);
00042     d->setBackendObject(networkinterface.d_ptr->backendObject());
00043     makeConnections( networkinterface.d_ptr->backendObject() );
00044     d->readAccessPoints();
00045 }
00046 
00047 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(WirelessNetworkInterfacePrivate &dd, QObject *backendObject)
00048     : NetworkInterface(dd, backendObject)
00049 {
00050     Q_D(WirelessNetworkInterface);
00051     makeConnections( backendObject );
00052     d->readAccessPoints();
00053 }
00054 
00055 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(WirelessNetworkInterfacePrivate &dd, const WirelessNetworkInterface &networkinterface)
00056     : NetworkInterface(dd, networkinterface.d_ptr->backendObject())
00057 {
00058     Q_D(WirelessNetworkInterface);
00059     makeConnections( networkinterface.d_ptr->backendObject() );
00060     d->readAccessPoints();
00061 }
00062 
00063 Solid::Control::WirelessNetworkInterface::~WirelessNetworkInterface()
00064 {
00065 
00066 }
00067 
00068 Solid::Control::NetworkInterface::Type Solid::Control::WirelessNetworkInterface::type() const
00069 {
00070     return Ieee80211;
00071 }
00072 
00073 void Solid::Control::WirelessNetworkInterface::makeConnections(QObject * source)
00074 {
00075     connect(source, SIGNAL(accessPointAppeared(const QString &)),
00076             this, SLOT(_k_accessPointAdded(const QString &)));
00077     connect(source, SIGNAL(accessPointDisappeared(const QString &)),
00078             this, SLOT(_k_accessPointRemoved(const QString &)));
00079 }
00080 
00081 QString Solid::Control::WirelessNetworkInterface::hardwareAddress() const
00082 {
00083     Q_D(const WirelessNetworkInterface);
00084     return_SOLID_CALL(Ifaces::WirelessNetworkInterface *, d->backendObject(), QString(), hardwareAddress());
00085 }
00086 
00087 QString Solid::Control::WirelessNetworkInterface::activeAccessPoint() const
00088 {
00089     Q_D(const WirelessNetworkInterface);
00090     return_SOLID_CALL(Ifaces::WirelessNetworkInterface *, d->backendObject(), QString(), activeAccessPoint());
00091 }
00092 
00093 int Solid::Control::WirelessNetworkInterface::bitRate() const
00094 {
00095     Q_D(const WirelessNetworkInterface);
00096     return_SOLID_CALL(Ifaces::WirelessNetworkInterface *, d->backendObject(), 0, bitRate());
00097 }
00098 
00099 Solid::Control::WirelessNetworkInterface::OperationMode Solid::Control::WirelessNetworkInterface::mode() const
00100 {
00101     Q_D(const WirelessNetworkInterface);
00102     return_SOLID_CALL(Ifaces::WirelessNetworkInterface *, d->backendObject(), (Solid::Control::WirelessNetworkInterface::OperationMode)0, mode());
00103 }
00104 
00105 Solid::Control::WirelessNetworkInterface::Capabilities Solid::Control::WirelessNetworkInterface::wirelessCapabilities() const
00106 {
00107     Q_D(const WirelessNetworkInterface);
00108     return_SOLID_CALL(Ifaces::WirelessNetworkInterface *, d->backendObject(), (Solid::Control::WirelessNetworkInterface::Capabilities)0, wirelessCapabilities());
00109 }
00110 
00111 Solid::Control::AccessPoint * Solid::Control::WirelessNetworkInterface::findAccessPoint(const QString  & uni) const
00112 {
00113     const AccessPointPair pair = findRegisteredAccessPoint(uni);
00114     return pair.first;
00115 }
00116 
00117 void Solid::Control::WirelessNetworkInterfacePrivate::setBackendObject(QObject *object)
00118 {
00119     NetworkInterfacePrivate::setBackendObject(object);
00120 
00121     if (object) {
00122         QObject::connect(object, SIGNAL(bitRateChanged(int)),
00123                          parent(), SIGNAL(bitRateChanged(int)));
00124         QObject::connect(object, SIGNAL(activeAccessPointChanged(const QString&)),
00125                          parent(), SIGNAL(activeAccessPointChanged(const QString&)));
00126         QObject::connect(object, SIGNAL(modeChanged(Solid::Control::WirelessNetworkInterface::OperationMode)),
00127                          parent(), SIGNAL(modeChanged(Solid::Control::WirelessNetworkInterface::OperationMode)));
00128         QObject::connect(object, SIGNAL(accessPointAppeared(const QString&)),
00129                          parent(), SIGNAL(accessPointAppeared(const QString&)));
00130         QObject::connect(object, SIGNAL(accessPointDisappeared(const QString&)),
00131                          parent(), SIGNAL(accessPointDisappeared(const QString&)));
00132     }
00133 }
00134 
00135 Solid::Control::AccessPointList Solid::Control::WirelessNetworkInterface::accessPoints() const
00136 {
00137     Q_D(const WirelessNetworkInterface);
00138     return d->apMap.keys();
00139 }
00140 
00141 void Solid::Control::WirelessNetworkInterface::_k_accessPointAdded(const QString & uni)
00142 {
00143     Q_D(WirelessNetworkInterface);
00144     AccessPointMap::Iterator mapIt = d->apMap.find(uni);
00145 
00146     if (mapIt != d->apMap.end())
00147     {
00148         // Oops, I'm not sure it should happen...
00149         // But well in this case we'd better kill the old device we got, it's probably outdated
00150         AccessPointPair pair = mapIt.value();
00151 
00152         delete pair.first;
00153         delete pair.second;
00154     } else {
00155         mapIt = d->apMap.insert(uni, AccessPointPair(0, 0));
00156     }
00157 
00158     emit accessPointAppeared(uni);
00159 }
00160 
00161 void Solid::Control::WirelessNetworkInterface::_k_accessPointRemoved(const QString & uni)
00162 {
00163     Q_D(WirelessNetworkInterface);
00164     AccessPointPair pair = d->apMap.take(uni);
00165 
00166     if (pair.first!= 0)
00167     {
00168         delete pair.first;
00169         delete pair.second;
00170     }
00171 
00172     emit accessPointDisappeared(uni);
00173 }
00174 
00175 void Solid::Control::WirelessNetworkInterface::_k_destroyed(QObject *object)
00176 {
00177     Q_D(WirelessNetworkInterface);
00178     Ifaces::AccessPoint *ap = qobject_cast<Ifaces::AccessPoint *>(object);
00179 
00180     if (ap!=0)
00181     {
00182         QString uni = ap->uni();
00183         AccessPointPair pair = d->apMap.take(uni);
00184         delete pair.first;
00185     }
00186 }
00187 
00188 Solid::Control::AccessPointPair
00189 Solid::Control::WirelessNetworkInterface::findRegisteredAccessPoint(const QString &uni) const
00190 {
00191     Q_D(const WirelessNetworkInterface);
00192 
00193     AccessPointMap::ConstIterator mapIt = d->apMap.find(uni);
00194     if (mapIt != d->apMap.end() && mapIt.value().second) {
00195         return mapIt.value();
00196     } else {
00197         AccessPointPair pair = d->createAP(uni);
00198         if (pair.first && pair.second) {
00199             d->apMap[uni] = pair;
00200         }
00201         return pair;
00202     }
00203 
00204     return AccessPointPair(0, 0);
00205 }
00206 
00207 void Solid::Control::WirelessNetworkInterfacePrivate::readAccessPoints()
00208 {
00209     Ifaces::WirelessNetworkInterface * t = qobject_cast<Ifaces::WirelessNetworkInterface *>(backendObject());
00210     if (t != 0)
00211     {
00212         const MacAddressList unis = t->accessPoints();
00213         Q_FOREACH (const QString & uni, unis) {
00214             apMap[uni] = AccessPointPair(0, 0);
00215         }
00216     }
00217 }
00218 
00219 Solid::Control::AccessPointPair
00220 Solid::Control::WirelessNetworkInterfacePrivate::createAP(const QString &uni) const
00221 {
00222     Ifaces::WirelessNetworkInterface *device = qobject_cast<Ifaces::WirelessNetworkInterface *>(backendObject());
00223     AccessPoint *ap = 0;
00224 
00225     if (device!=0) {
00226         Ifaces::AccessPoint *iface = qobject_cast<Ifaces::AccessPoint *>(device->createAccessPoint(uni));
00227 
00228         if (qobject_cast<Ifaces::AccessPoint *>(iface)!=0) {
00229             ap = new AccessPoint(iface);
00230         }
00231 
00232         if (ap != 0) {
00233             AccessPointPair pair(ap, iface);
00234             QObject::connect(iface, SIGNAL(destroyed(QObject *)),
00235                              parent(), SLOT(_k_destroyed(QObject *)));
00236 
00237             return pair;
00238         }
00239     }
00240     return AccessPointPair(0, 0);
00241 }
00242 
00243 #include "wirelessnetworkinterface.moc"

libsolidcontrol

Skip menu "libsolidcontrol"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

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