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

libsolidcontrol

fakebluetoothmanager.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
00003 
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 #include <QFile>
00021 #include <QtXml/QtXml>
00022 #include <QLatin1String>
00023 
00024 #include <kstandarddirs.h>
00025 #include <kdebug.h>
00026 
00027 #include "fakebluetoothmanager.h"
00028 
00029 FakeBluetoothManager::FakeBluetoothManager(QObject * parent, const QStringList &) : Solid::Control::Ifaces::BluetoothManager(parent)
00030 {
00031     kDebug() ;
00032 
00033     mXmlFile = KStandardDirs::locate("data", "solidfakebackend/fakebluetooth.xml");
00034 
00035 //     QDBusConnection::sessionBus().registerObject("/org/kde/solid/fake", this, QDBusConnection::ExportNonScriptableSlots);
00036 
00037     parseBluetoothFile();
00038 }
00039 
00040 FakeBluetoothManager::FakeBluetoothManager(QObject * parent, const QStringList &, const QString &xmlFile) : Solid::Control::Ifaces::BluetoothManager(parent)
00041 {
00042     kDebug() ;
00043     mXmlFile = xmlFile;
00044     if (mXmlFile.isEmpty()) {
00045         kDebug() << "Falling back to installed bluetoothing xml";
00046         mXmlFile = KStandardDirs::locate("data", "solidfakebackend/fakebluetooth.xml");
00047     }
00048     parseBluetoothFile();
00049 }
00050 
00051 FakeBluetoothManager::~FakeBluetoothManager()
00052 {
00053     foreach (FakeBluetoothInterface *interface, mBluetoothInterfaces) {
00054         delete interface;
00055     }
00056 
00057     mBluetoothInterfaces.clear();
00058 }
00059 
00060 QStringList FakeBluetoothManager::bluetoothInterfaces() const
00061 {
00062     return mBluetoothInterfaces.keys();
00063 }
00064 
00065 QObject * FakeBluetoothManager::createInterface(const QString  & ubi)
00066 {
00067     if (mBluetoothInterfaces.contains(ubi))
00068         return mBluetoothInterfaces[ubi];
00069     else
00070         return 0;
00071 }
00072 
00073 QString FakeBluetoothManager::defaultInterface() const
00074 {
00075     return "";
00076 }
00077 
00078 void FakeBluetoothManager::parseBluetoothFile()
00079 {
00080     QFile machineFile(mXmlFile);
00081     if (!machineFile.open(QIODevice::ReadOnly)) {
00082         kDebug() << "Error while opening " << mXmlFile;
00083         return;
00084     }
00085 
00086     QDomDocument fakeDocument;
00087     QString error;
00088     int line;
00089     if (!fakeDocument.setContent(&machineFile, &error, &line)) {
00090         kDebug() << "Error while creating the QDomDocument: " << error << " line: " <<
00091         line <<  endl;
00092         machineFile.close();
00093         return;
00094     }
00095     machineFile.close();
00096 
00097     kDebug() << "Parsing fake computer XML: " << mXmlFile;
00098     QDomElement mainElement = fakeDocument.documentElement();
00099     QDomNode node = mainElement.firstChild();
00100     while (!node.isNull()) {
00101         QDomElement tempElement = node.toElement();
00102         if (!tempElement.isNull() && tempElement.tagName() == QLatin1String("interface")) {
00103             FakeBluetoothInterface *tempDevice = parseDeviceElement(tempElement);
00104             if (tempDevice) {
00105                 mBluetoothInterfaces.insert(tempDevice->ubi(), tempDevice);
00106 // Use the DeviceManager for now, the udi/ubi should
00107 //                emit deviceAdded(tempDevice->ubi());
00108             }
00109         }
00110         node = node.nextSibling();
00111     }
00112 }
00113 
00114 FakeBluetoothInterface *FakeBluetoothManager::parseDeviceElement(const QDomElement &deviceElement)
00115 {
00116     FakeBluetoothInterface *interface = 0;
00117     QMap<QString, QVariant> propertyMap;
00118     QString ubi = deviceElement.attribute("ubi");
00119     propertyMap.insert("ubi", ubi);
00120     kDebug() << "Listing device: " << ubi;
00121     propertyMap.insert("ubi", QVariant(ubi));
00122 
00123     QDomNode childNode = deviceElement.firstChild();
00124     while (!childNode.isNull()) {
00125         QDomElement childElement = childNode.toElement();
00126         //kDebug() << "found child=" << childElement.tagName();
00127         if (!childElement.isNull() && childElement.tagName() == QLatin1String("property")) {
00128             QString propertyKey;
00129             QVariant propertyValue;
00130 
00131             propertyKey = childElement.attribute("key");
00132             propertyValue = QVariant(childElement.text());
00133             //    kDebug() << "Got property key=" << propertyKey << ", value=" << propertyValue.toString();
00134             propertyMap.insert(propertyKey, propertyValue);
00135         } else if (!childElement.isNull() && childElement.tagName() == QLatin1String("device")) {
00136             QString ubi = childElement.attribute("ubi");
00137             kDebug() << "Listing properties: " << ubi;
00138             FakeBluetoothRemoteDevice * remoteDevice = new FakeBluetoothRemoteDevice(parseBluetoothElement(childElement));
00139             mBluetoothRemoteDevices.insert(ubi, remoteDevice);
00140         }
00141         childNode = childNode.nextSibling();
00142     }
00143     //kDebug() << "Done listing. ";
00144 
00145     kDebug() << "Creating FakeBluetoothInterface for " << ubi;
00146     interface = new FakeBluetoothInterface(propertyMap);
00147 
00148     // Inject Remote devices....
00149     foreach (FakeBluetoothRemoteDevice *device, mBluetoothRemoteDevices) {
00150         kDebug() << "Injecting " << device->name();
00151         interface->injectDevice(device->ubi(), device);
00152     }
00153 
00154     mBluetoothRemoteDevices.clear();
00155 
00156     return interface;
00157 }
00158 
00159 QMap<QString, QVariant> FakeBluetoothManager::parseBluetoothElement(const QDomElement &deviceElement)
00160 {
00161     QMap<QString, QVariant> propertyMap;
00162 
00163     QString ubi = deviceElement.attribute("ubi");
00164     propertyMap.insert("ubi", ubi);
00165 
00166     QDomNode propertyNode = deviceElement.firstChild();
00167     while (!propertyNode.isNull()) {
00168         QDomElement propertyElement = propertyNode.toElement();
00169         if (!propertyElement.isNull() && propertyElement.tagName() == QLatin1String("property")) {
00170             QString propertyKey;
00171             QVariant propertyValue;
00172 
00173             propertyKey = propertyElement.attribute("key");
00174             propertyValue = QVariant(propertyElement.text());
00175 //            kDebug() << "Got property key=" << propertyKey << ", value=" << propertyValue.toString();
00176             propertyMap.insert(propertyKey, propertyValue);
00177         }
00178 
00179         propertyNode = propertyNode.nextSibling();
00180     }
00181     return propertyMap;
00182 }
00183 
00184 FakeBluetoothInterface *FakeBluetoothManager::createBluetoothInterface(const QString &ubi)
00185 {
00186     if (mBluetoothInterfaces.contains(ubi))
00187         return mBluetoothInterfaces[ubi];
00188     else
00189         return 0;
00190 }
00191 
00192 QStringList FakeBluetoothManager::bluetoothInputDevices() const
00193 {
00194     return QStringList();
00195 }
00196 
00197 FakeBluetoothInputDevice *FakeBluetoothManager::createBluetoothInputDevice(const QString &ubi)
00198 {
00199     if (mBluetoothInputDevices.contains(ubi))
00200         return mBluetoothInputDevices[ubi];
00201     else
00202         return 0;
00203 }
00204 
00205 KJob *FakeBluetoothManager::setupInputDevice(const QString  & /*ubi */)
00206 {
00207     // TODO
00208     return NULL;
00209 }
00210 Solid::Control::Ifaces::BluetoothSecurity *FakeBluetoothManager::security(const QString &/*interface*/)
00211 {
00212     return NULL;
00213 }
00214 
00215 void FakeBluetoothManager::removeInputDevice(const QString  & /*ubi */)
00216 {
00217     //TODO
00218 }
00219 
00220 
00221 #include "fakebluetoothmanager.moc"
00222 

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
  •   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