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

libsolidcontrol

bluetoothmanager.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) 2006 Kévin Ottens <ervin@kde.org>
00004     Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
00005     Copyright (C) 2008 Tom Patzig <tpatzig@suse.de>
00006 
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License version 2 as published by the Free Software Foundation.
00011 
00012     This library 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 GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 
00022 */
00023 
00024 #include <QMap>
00025 #include <QPair>
00026 #include <QStringList>
00027 
00028 #include "ifaces/bluetoothmanager.h"
00029 #include "ifaces/bluetoothinterface.h"
00030 #include "ifaces/bluetoothinputdevice.h"
00031 #include "ifaces/bluetoothsecurity.h"
00032 
00033 #include "soliddefs_p.h"
00034 #include "managerbase_p.h"
00035 
00036 #include "bluetoothinterface.h"
00037 #include "bluetoothmanager.h"
00038 #include "bluetoothsecurity.h"
00039 
00040 #include <kdebug.h>
00041 
00042 namespace Solid
00043 {
00044 namespace Control
00045 {
00046 class BluetoothManagerPrivate : public ManagerBasePrivate
00047 {
00048 public:
00049     BluetoothManagerPrivate(BluetoothManager *parent)
00050         : q(parent) { }
00051 
00052     BluetoothManager * const q;
00053 
00054     QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> findRegisteredBluetoothInterface(const QString &ubi) const;
00055     QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> findRegisteredBluetoothInputDevice(const QString &ubi) const;
00056 
00057     void connectBackend(QObject *newBackend);
00058 
00059     void _k_interfaceAdded(const QString &ubi);
00060     void _k_interfaceRemoved(const QString &ubi);
00061     void _k_defaultInterfaceChanged(const QString &ubi);
00062     void _k_interfaceDestroyed(QObject *object);
00063 /*
00064     void _k_inputDeviceCreated(const QString &ubi);
00065     void _k_inputDeviceRemoved(const QString &ubi);
00066     void _k_inputDeviceDestroyed(QObject *object);
00067 */
00068 
00069     mutable QMap<QString, QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> > bluetoothInterfaceMap;
00070     mutable QMap<QString, QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> > bluetoothInputDeviceMap;
00071 
00072     BluetoothInterface invalidInterface;
00073     BluetoothInputDevice invalidInputDevice;
00074 };
00075 }
00076 }
00077 
00078 SOLID_SINGLETON_IMPLEMENTATION(Solid::Control::BluetoothManager, BluetoothManager)
00079 
00080 
00081 Solid::Control::BluetoothManager::BluetoothManager()
00082         : QObject(), d(new BluetoothManagerPrivate(this))
00083 {
00084     d->loadBackend("Bluetooth Management",
00085                    "SolidBluetoothManager",
00086                    "Solid::Control::Ifaces::BluetoothManager");
00087 
00088     if (d->managerBackend() != 0) {
00089         d->connectBackend(d->managerBackend());
00090     }
00091 }
00092 
00093 Solid::Control::BluetoothManager::~BluetoothManager()
00094 {
00095     // Delete all the interfaces, they are now outdated
00096     typedef QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> BluetoothInterfaceIfacePair;
00097 
00098     // Delete all the devices, they are now outdated
00099     foreach (const BluetoothInterfaceIfacePair &pair, d->bluetoothInterfaceMap.values()) {
00100         delete pair.first;
00101         delete pair.second;
00102     }
00103 
00104     d->bluetoothInterfaceMap.clear();
00105 }
00106 
00107 Solid::Control::BluetoothInterfaceList Solid::Control::BluetoothManager::buildDeviceList(const QStringList  & ubiList) const
00108 {
00109     BluetoothInterfaceList list;
00110     Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(d->managerBackend());
00111 
00112     if (backend == 0) return list;
00113 
00114     kDebug() << "UBI List " << ubiList;
00115 
00116     foreach (const QString &ubi, ubiList) {
00117         QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair = d->findRegisteredBluetoothInterface(ubi);
00118 
00119         if (pair.first != 0) {
00120             list.append(*pair.first);
00121         }
00122     }
00123 
00124     return list;
00125 }
00126 
00127 
00128 Solid::Control::BluetoothInterfaceList Solid::Control::BluetoothManager::bluetoothInterfaces() const
00129 {
00130     Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(d->managerBackend());
00131 
00132     if (backend != 0) {
00133         return buildDeviceList(backend->bluetoothInterfaces());
00134     } else {
00135         return BluetoothInterfaceList();
00136     }
00137 }
00138 /*
00139 QStringList Solid::Control::BluetoothManager::bluetoothInterfaces() const
00140 {
00141     return_SOLID_CALL(Ifaces::BluetoothManager *, d->managerBackend(), QStringList(), bluetoothInterfaces());
00142 }
00143 */
00144 QString Solid::Control::BluetoothManager::defaultInterface() const
00145 {
00146     return_SOLID_CALL(Ifaces::BluetoothManager *, d->managerBackend(), QString(), defaultInterface());
00147 }
00148 
00149 Solid::Control::BluetoothInterface Solid::Control::BluetoothManager::findBluetoothInterface(const QString &ubi) const
00150 {
00151     Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(d->managerBackend());
00152 
00153     if (backend == 0) return d->invalidInterface;
00154 
00155     QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair = d->findRegisteredBluetoothInterface(ubi);
00156 
00157     if (pair.first != 0) {
00158         return *pair.first;
00159     } else {
00160         return d->invalidInterface;
00161     }
00162 }
00163 
00164 QString Solid::Control::BluetoothManager::findInterface(const QString &dev) const
00165 {
00166     return_SOLID_CALL(Ifaces::BluetoothManager *, d->managerBackend(), QString(), findInterface(dev));
00167 }
00168 
00169 /*
00170 Solid::Control::BluetoothInputDevice Solid::Control::BluetoothManager::findBluetoothInputDevice(const QString &ubi) const
00171 {
00172     Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(d->managerBackend());
00173 
00174     if (backend == 0) return d->invalidInputDevice;
00175 
00176     QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> pair = d->findRegisteredBluetoothInputDevice(ubi);
00177 
00178     if (pair.first != 0) {
00179         return *pair.first;
00180     } else {
00181         return d->invalidInputDevice;
00182     }
00183 }
00184 */
00185 
00186 /*
00187 Solid::Control::BluetoothInputDevice* Solid::Control::BluetoothManager::createBluetoothInputDevice(const QString &ubi)
00188 {
00189         Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(d->managerBackend());
00190         Ifaces::BluetoothInputDevice *iface = 0;
00191     if (backend != 0) {
00192         iface = qobject_cast<Ifaces::BluetoothInputDevice *>(backend->createBluetoothInputDevice(ubi));
00193         }
00194     if (iface != 0) {
00195             BluetoothInputDevice *device = new BluetoothInputDevice(iface);
00196         return device;
00197 
00198     } else {
00199         return &d->invalidInputDevice;
00200     }
00201 
00202 }
00203 
00204 KJob *Solid::Control::BluetoothManager::setupInputDevice(const QString &ubi)
00205 {
00206     return_SOLID_CALL(Ifaces::BluetoothManager *, d->managerBackend(), 0, setupInputDevice(ubi));
00207 }
00208 
00209 Solid::Control::BluetoothInputDeviceList Solid::Control::BluetoothManager::bluetoothInputDevices() const
00210 {
00211     BluetoothInputDeviceList list;
00212     Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(d->managerBackend());
00213 
00214     if (backend == 0) return list;
00215 
00216     QStringList ubis = backend->bluetoothInputDevices();
00217 
00218     foreach (const QString &ubi, ubis) {
00219         QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> pair = d->findRegisteredBluetoothInputDevice(ubi);
00220         
00221         if (pair.first != 0) {
00222             list.append(*pair.first);
00223         }
00224     }
00225     return list;
00226 }
00227 
00228 Solid::Control::BluetoothSecurity *Solid::Control::BluetoothManager::security(const QString &interface)
00229 {
00230     Ifaces::BluetoothManager *backendManager = qobject_cast<Ifaces::BluetoothManager*>(d->managerBackend());
00231     if (backendManager!=0) {
00232         Ifaces::BluetoothSecurity *backendSecurity = backendManager->security(interface);
00233         return new Solid::Control::BluetoothSecurity(backendSecurity);
00234     }
00235     return 0;
00236 }
00237 
00238 void Solid::Control::BluetoothManager::removeInputDevice(const QString &ubi)
00239 {
00240     SOLID_CALL(Ifaces::BluetoothManager *, d->managerBackend(), removeInputDevice(ubi));
00241 }
00242 */
00243 void Solid::Control::BluetoothManagerPrivate::_k_interfaceAdded(const QString &ubi)
00244 {
00245     kDebug() << "Size of InterfaceList " << bluetoothInterfaceMap.size();
00246     QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair = findRegisteredBluetoothInterface(ubi);
00247 /*    QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair = bluetoothInterfaceMap.take(ubi);
00248 
00249     if (pair.first != 0) {
00250         // Oops, I'm not sure it should happen...
00251         // But well in this case we'd better kill the old device we got, it's probably outdated
00252 
00253         delete pair.first;
00254         delete pair.second;
00255     }*/
00256 
00257     emit q->interfaceAdded(ubi);
00258 }
00259 
00260 void Solid::Control::BluetoothManagerPrivate::_k_interfaceRemoved(const QString &ubi)
00261 {
00262     QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair = bluetoothInterfaceMap.take(ubi);
00263 
00264     if (pair.first != 0) {
00265         delete pair.first;
00266         delete pair.second;
00267     }
00268 
00269     Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(managerBackend());
00270     backend->removeInterface(ubi);
00271     emit q->interfaceRemoved(ubi);
00272 }
00273 
00274 void Solid::Control::BluetoothManagerPrivate::_k_defaultInterfaceChanged(const QString &ubi)
00275 {
00276     emit q->defaultInterfaceChanged(ubi);
00277 }
00278 
00279 void Solid::Control::BluetoothManagerPrivate::_k_interfaceDestroyed(QObject *object)
00280 {
00281     kDebug() << "Interface detroyed";
00282     Ifaces::BluetoothInterface *device = qobject_cast<Ifaces::BluetoothInterface *>(object);
00283 
00284     if (device != 0) {
00285         QString ubi = device->ubi();
00286         QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair = bluetoothInterfaceMap.take(ubi);
00287         delete pair.first;
00288     }
00289 }
00290 
00291 /*
00292 void Solid::Control::BluetoothManagerPrivate::_k_inputDeviceCreated(const QString &ubi)
00293 {
00294     QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> pair = bluetoothInputDeviceMap.take(ubi);
00295 
00296     if (pair.first != 0) {
00297         // Oops, I'm not sure it should happen...
00298         // But well in this case we'd better kill the old device we got, it's probably outdated
00299 
00300         delete pair.first;
00301         delete pair.second;
00302     }
00303 
00304     emit q->inputDeviceCreated(ubi);
00305 }
00306 
00307 void Solid::Control::BluetoothManagerPrivate::_k_inputDeviceRemoved(const QString &ubi)
00308 {
00309     QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> pair = bluetoothInputDeviceMap.take(ubi);
00310 
00311     if (pair.first != 0) {
00312         delete pair.first;
00313         delete pair.second;
00314     }
00315 
00316     emit q->inputDeviceRemoved(ubi);
00317 }
00318 
00319 void Solid::Control::BluetoothManagerPrivate::_k_inputDeviceDestroyed(QObject *object)
00320 {
00321     Ifaces::BluetoothInputDevice *device = qobject_cast<Ifaces::BluetoothInputDevice *>(object);
00322 
00323     if (device != 0) {
00324         QString ubi = device->ubi();
00325         QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> pair = bluetoothInputDeviceMap.take(ubi);
00326         delete pair.first;
00327     }
00328 }
00329 */
00330 
00331 /***************************************************************************/
00332 
00333 void Solid::Control::BluetoothManagerPrivate::connectBackend(QObject *newBackend)
00334 {
00335     QObject::connect(newBackend, SIGNAL(interfaceAdded(const QString &)),
00336                      q, SLOT(_k_interfaceAdded(const QString &)));
00337     QObject::connect(newBackend, SIGNAL(interfaceRemoved(const QString &)),
00338                      q, SLOT(_k_interfaceRemoved(const QString &)));
00339     QObject::connect(newBackend, SIGNAL(defaultInterfaceChanged(const QString &)),
00340                      q, SLOT(_k_defaultInterfaceChanged(const QString &)));
00341 
00342 /*
00343     QObject::connect(newBackend, SIGNAL(inputDeviceCreated(const QString &)),
00344                      q, SLOT(_k_inputDeviceCreated(const QString &)));
00345     QObject::connect(newBackend, SIGNAL(inputDeviceRemoved(const QString &)),
00346                      q, SLOT(_k_inputDeviceRemoved(const QString &)));
00347 */
00348 
00349 }
00350 
00351 QPair<Solid::Control::BluetoothInterface *, Solid::Control::Ifaces::BluetoothInterface *> Solid::Control::BluetoothManagerPrivate::findRegisteredBluetoothInterface(const QString &ubi) const
00352 {
00353 
00354     kDebug() << "findRegisteredBluetoothInterface " << ubi;
00355     if (bluetoothInterfaceMap.contains(ubi)) {
00356         return bluetoothInterfaceMap[ubi];
00357     } else {
00358         kDebug() << "Creating New Interface " << ubi;
00359         Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(managerBackend());
00360         Ifaces::BluetoothInterface *iface = 0;
00361 
00362         if (backend != 0) {
00363             kDebug() << "Calling Backend to Creating New Interface " << ubi;
00364             iface = qobject_cast<Ifaces::BluetoothInterface *>(backend->createInterface(ubi));
00365         }
00366 
00367         if (iface != 0) {
00368             kDebug() << "BackendIface created ";
00369             BluetoothInterface *device = new BluetoothInterface(iface);
00370             QPair<BluetoothInterface *, Ifaces::BluetoothInterface *> pair(device, iface);
00371             QObject::connect(iface, SIGNAL(destroyed(QObject *)),
00372                              q, SLOT(_k_interfaceDestroyed(QObject *)));
00373             bluetoothInterfaceMap[ubi] = pair;
00374             return pair;
00375         } else {
00376             return QPair<BluetoothInterface *, Ifaces::BluetoothInterface *>(0, 0);
00377         }
00378     }
00379 }
00380 
00381 /*
00382 QPair<Solid::Control::BluetoothInputDevice *, Solid::Control::Ifaces::BluetoothInputDevice *> Solid::Control::BluetoothManagerPrivate::findRegisteredBluetoothInputDevice(const QString &ubi) const
00383 {
00384 
00385     if (bluetoothInputDeviceMap.contains(ubi)) {
00386         return bluetoothInputDeviceMap[ubi];
00387     } else {
00388         Ifaces::BluetoothManager *backend = qobject_cast<Ifaces::BluetoothManager *>(managerBackend());
00389         Ifaces::BluetoothInputDevice *iface = 0;
00390 
00391         if (backend != 0) {
00392         iface = qobject_cast<Ifaces::BluetoothInputDevice *>(backend->createBluetoothInputDevice(ubi));
00393         }
00394 
00395         if (iface != 0) {
00396             BluetoothInputDevice *device = new BluetoothInputDevice(iface);
00397             QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *> pair(device, iface);
00398             bluetoothInputDeviceMap[ubi] = pair;
00399             QObject::connect(iface, SIGNAL(destroyed(QObject *)),
00400                              q, SLOT(_k_inputDeviceDestroyed(QObject *)));
00401             return pair;
00402         } else {
00403             return QPair<BluetoothInputDevice *, Ifaces::BluetoothInputDevice *>(0, 0);
00404         }
00405     }
00406 }
00407 */
00408 
00409 
00410 
00411 
00412 #include "bluetoothmanager.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
  •   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