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

libsolidcontrol

fakenetworkmanager.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006,2008 Will Stephenson <wstephenson@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 #include "fakenetworkmanager.h"
00020 
00021 #include <QFile>
00022 #include <QtXml/QtXml>
00023 #include <QLatin1String>
00024 
00025 #include <kstandarddirs.h>
00026 #include <kdebug.h>
00027 
00028 #include "fakeaccesspoint.h"
00029 #include "fakewirednetworkinterface.h"
00030 #include "fakewirelessnetworkinterface.h"
00031 
00032 FakeNetworkManager::FakeNetworkManager(QObject * parent, const QStringList  &) : Solid::Control::Ifaces::NetworkManager(parent)
00033 {
00034     mUserNetworkingEnabled = true;
00035     mUserWirelessEnabled = true;
00036     mRfKillEnabled = false;
00037 
00038     mXmlFile = KStandardDirs::locate("data", "solidfakebackend/fakenetworking.xml");
00039 
00040 //     QDBusConnection::sessionBus().registerObject("/org/kde/solid/fake", this, QDBusConnection::ExportNonScriptableSlots);
00041 
00042     parseNetworkingFile();
00043 }
00044 
00045 FakeNetworkManager::FakeNetworkManager(QObject * parent, const QStringList &, const QString &xmlFile) : Solid::Control::Ifaces::NetworkManager(parent)
00046 {
00047     mUserNetworkingEnabled = true;
00048     mUserWirelessEnabled = true;
00049 
00050     mXmlFile = xmlFile;
00051     if (mXmlFile.isEmpty())
00052     {
00053        kDebug() << "Falling back to installed networking xml";
00054        mXmlFile = KStandardDirs::locate("data", "solidfakebackend/fakenetworking.xml");
00055     }
00056     parseNetworkingFile();
00057 }
00058 
00059 FakeNetworkManager::~FakeNetworkManager()
00060 {
00061 }
00062 
00063 Solid::Networking::Status FakeNetworkManager::status() const
00064 {
00065     return Solid::Networking::Unknown;
00066 }
00067 
00068 QStringList FakeNetworkManager::networkInterfaces() const
00069 {
00070     return mNetworkInterfaces.keys();
00071 }
00072 
00073 QStringList FakeNetworkManager::activeNetworkInterfaces() const
00074 {
00075     QStringList activeDevices;
00076     QMapIterator<QString, FakeNetworkInterface *> it(mNetworkInterfaces);
00077     while (it.hasNext())
00078     {
00079         it.next();
00080         FakeNetworkInterface * netDevice = it.value();
00081         if (netDevice->isActive())
00082             activeDevices.append(netDevice->uni());
00083     }
00084     return activeDevices;
00085 }
00086 
00087 QObject * FakeNetworkManager::createNetworkInterface(const QString  & undi)
00088 {
00089     if (mNetworkInterfaces.contains(undi))
00090         return mNetworkInterfaces[undi];
00091     else
00092         return 0;
00093 }
00094 
00095 bool FakeNetworkManager::isWirelessEnabled() const
00096 {
00097     return mUserWirelessEnabled;
00098 }
00099 
00100 bool FakeNetworkManager::isNetworkingEnabled() const
00101 {
00102     QMapIterator<QString, FakeNetworkInterface *> it(mNetworkInterfaces);
00103     while (it.hasNext())
00104     {
00105         it.next();
00106         FakeNetworkInterface * netDevice = it.value();
00107         if (netDevice->isActive())
00108             return true;
00109     }
00110     return false;
00111 }
00112 
00113 bool FakeNetworkManager::isWirelessHardwareEnabled() const
00114 {
00115     return mRfKillEnabled;
00116 }
00117 
00118 void FakeNetworkManager::setWirelessEnabled(bool enabled)
00119 {
00120     mUserWirelessEnabled = enabled;
00121 }
00122 
00123 void FakeNetworkManager::setNetworkingEnabled(bool enabled)
00124 {
00125     QMapIterator<QString, FakeNetworkInterface *> it(mNetworkInterfaces);
00126     while (it.hasNext())
00127     {
00128         it.next();
00129         FakeNetworkInterface * netDevice = it.value();
00130     //    if ((netDevice->type() == Solid::Control::NetworkInterface::Ieee80211 && mUserWirelessEnabled)
00131       //     || netDevice->type() == Solid::Control::NetworkInterface::Ieee8023)
00132         //    netDevice->setActive(enabled);
00133     }
00134     mUserNetworkingEnabled = enabled;
00135 }
00136 
00137 void FakeNetworkManager::parseNetworkingFile()
00138 {
00139     QFile machineFile(mXmlFile);
00140     if (!machineFile.open(QIODevice::ReadOnly))
00141     {
00142         kDebug() << "Error while opening " << mXmlFile;
00143         return;
00144     }
00145 
00146     QDomDocument fakeDocument;
00147     if (!fakeDocument.setContent(&machineFile))
00148     {
00149         kDebug() << "Error while creating the QDomDocument.";
00150         machineFile.close();
00151         return;
00152     }
00153     machineFile.close();
00154 
00155     kDebug() << "Parsing fake computer XML: " << mXmlFile;
00156     QDomElement mainElement = fakeDocument.documentElement();
00157     QDomNode node = mainElement.firstChild();
00158     while (!node.isNull())
00159     {
00160         QDomElement tempElement = node.toElement();
00161         if (!tempElement.isNull() && tempElement.tagName() == QLatin1String("device"))
00162         {
00163             FakeNetworkInterface *tempDevice = parseDeviceElement(tempElement);
00164             if(tempDevice)
00165             {
00166                mNetworkInterfaces.insert(tempDevice->uni(), tempDevice);
00167 // Use the DeviceManager for now, the udi/uni should
00168 //                emit deviceAdded(tempDevice->uni());
00169             }
00170         } else if (tempElement.tagName() == QLatin1String("property")) {
00171             QString propertyKey = tempElement.attribute("key");
00172             QVariant propertyValue = QVariant(tempElement.text());
00173             if ( propertyKey== QLatin1String("networking")) {
00174                 mUserNetworkingEnabled = propertyValue.toBool();
00175             } else if ( propertyKey== QLatin1String("wireless")) {
00176                 mUserWirelessEnabled = propertyValue.toBool();
00177             } else if ( propertyKey== QLatin1String("rfkill")) {
00178                 mRfKillEnabled = propertyValue.toBool();
00179             }
00180         }
00181         node = node.nextSibling();
00182     }
00183 }
00184 
00185 FakeNetworkInterface *FakeNetworkManager::parseDeviceElement(const QDomElement &deviceElement)
00186 {
00187     FakeNetworkInterface *device = 0;
00188     QMap<QString,QVariant> propertyMap;
00189     QString uni = deviceElement.attribute("uni");
00190     propertyMap.insert("uni", uni);
00191     kDebug() << "Listing device: " << uni;
00192     propertyMap.insert("uni", QVariant(uni));
00193     QList< FakeAccessPoint * > networks;
00194     bool wireless = false;
00195     QDomNode childNode = deviceElement.firstChild();
00196     while (!childNode.isNull())
00197     {
00198         QDomElement childElement = childNode.toElement();
00199         //kDebug() << "found child=" << childElement.tagName();
00200         if (!childElement.isNull() && childElement.tagName() == QLatin1String("property"))
00201         {
00202             QString propertyKey;
00203             QVariant propertyValue;
00204 
00205             propertyKey = childElement.attribute("key");
00206             propertyValue = QVariant(childElement.text());
00207             if ( propertyValue == "ieee80211" ) {
00208                 wireless = true;
00209             }
00210             //kDebug() << "Got property key=" << propertyKey << ", value=" << propertyValue.toString();
00211             propertyMap.insert(propertyKey, propertyValue);
00212         }
00213         else if (!childElement.isNull() && childElement.tagName() == QLatin1String("accesspoint"))
00214         {
00215             QString uni = childElement.attribute("uni");
00216             kDebug() << "Listing properties: " << uni;
00217             FakeAccessPoint * wifi = new FakeAccessPoint(parseAPElement(childElement), this);
00218             networks.append(wifi);
00219         }
00220         childNode = childNode.nextSibling();
00221     }
00222     //kDebug() << "Done listing. ";
00223 
00224 /*    if (!propertyMap.isEmpty())
00225     { */
00226         kDebug() << "Creating FakeNetworkDevice for " << uni;
00227         if (wireless) {
00228             FakeWirelessNetworkInterface * wifi = new FakeWirelessNetworkInterface(propertyMap);
00229             foreach( FakeAccessPoint * net, networks)
00230             {
00231                 kDebug() << "Injecting " << net->uni();
00232                 wifi->injectAccessPoint(net);
00233             }
00234             device = wifi;
00235         } else {
00236             device = new FakeWiredNetworkInterface(propertyMap);
00237         }
00238 
00239 
00240 //     }
00241 
00242     return device;
00243 }
00244 
00245 QMap<QString,QVariant> FakeNetworkManager::parseAPElement(const QDomElement &deviceElement)
00246 {
00247     QMap<QString,QVariant> propertyMap;
00248 
00249     QDomNode propertyNode = deviceElement.firstChild();
00250     while (!propertyNode.isNull())
00251     {
00252         QDomElement propertyElement = propertyNode.toElement();
00253         if (!propertyElement.isNull() && propertyElement.tagName() == QLatin1String("property"))
00254         {
00255             QString propertyKey;
00256             QVariant propertyValue;
00257 
00258             propertyKey = propertyElement.attribute("key");
00259             propertyValue = QVariant(propertyElement.text());
00260             //kDebug() << "Got property key=" << propertyKey << ", value=" << propertyValue.toString();
00261             propertyMap.insert(propertyKey, propertyValue);
00262         }
00263 
00264         propertyNode = propertyNode.nextSibling();
00265     }
00266     return propertyMap;
00267 }
00268 
00269 void FakeNetworkManager::activateConnection(const QString & interfaceUni, const QString & connectionUni, const QVariantMap & connectionParameters)
00270 {
00271 
00272 }
00273 
00274 void FakeNetworkManager::deactivateConnection(const QString & activeConnection)
00275 {
00276 
00277 }
00278 
00279 
00280 #include "fakenetworkmanager.moc"
00281 

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