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

SolidModules

bluez-bluetoothmanager.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>
00003     Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
00004 
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 
00020 */
00021 
00022 #include "bluez-bluetoothmanager.h"
00023 
00024 #include <QtDBus>
00025 
00026 #include <kdebug.h>
00027 
00028 #include "bluez-bluetoothinterface.h"
00029 #include "bluez-bluetoothinputdevice.h"
00030 #include "bluez-bluetoothsecurity.h"
00031 #include "bluez-bluetoothsecurityadaptor.h"
00032 #include "bluezcalljob.h"
00033 
00034 class BluezBluetoothManagerPrivate
00035 {
00036 public:
00037 
00038 
00039     BluezBluetoothManagerPrivate() : manager("org.bluez", "/org/bluez", "org.bluez.Manager", QDBusConnection::systemBus())
00040     {}
00041 
00042     QDBusInterface manager;
00043     QDBusInterface *inputManager;
00044 
00045     QMap<QString, BluezBluetoothInterface *> interfaces;
00046     QMap<QString, BluezBluetoothInputDevice *> inputDevices;
00047 
00048 };
00049 
00050 BluezBluetoothManager::BluezBluetoothManager(QObject * parent, const QStringList  & /*args */)
00051         : BluetoothManager(parent), d(new BluezBluetoothManagerPrivate)
00052 {
00053 #define connectManagerToThis(signal, slot) \
00054     d->manager.connection().connect("org.bluez", \
00055                                      "/org/bluez", \
00056                                      "org.bluez.Manager", \
00057                                      signal, this, SLOT(slot));
00058     connectManagerToThis("AdapterAdded", slotDeviceAdded(const QString &));
00059     connectManagerToThis("AdapterRemoved", slotDeviceRemoved(const QString &));
00060     connectManagerToThis("DefaultAdapterChanged", slotDefaultDeviceChanged(const QString &));
00061 
00062 
00063     QDBusReply< QString > busId = d->manager.call("ActivateService", "input");
00064     if (busId.isValid()) {
00065         m_inputManagerDest = busId.value();
00066     }
00067 
00068     d->inputManager = new QDBusInterface(m_inputManagerDest, "/org/bluez/input",
00069                                          "org.bluez.input.Manager", QDBusConnection::systemBus());
00070 
00071 #define connectInputManagerToThis(signal, slot) \
00072     d->inputManager->connection().connect(m_inputManagerDest, \
00073                                            "/org/bluez/input", \
00074                                            "org.bluez.input.Manager", \
00075                                            signal, this, SLOT(slot));
00076 
00077     connectInputManagerToThis("DeviceCreated", inputDeviceCreated(const QString &));
00078     connectInputManagerToThis("DeviceRemoved", inputDeviceRemoved(const QString &));
00079 }
00080 
00081 BluezBluetoothManager::~BluezBluetoothManager()
00082 {
00083     delete d->inputManager;
00084     delete d;
00085 }
00086 
00087 QStringList BluezBluetoothManager::bluetoothInterfaces() const
00088 {
00089     QStringList bluetoothInterfaces;
00090 
00091     QDBusReply< QStringList > deviceList = d->manager.call("ListAdapters");
00092     if (deviceList.isValid()) {
00093         QStringList devices = deviceList.value();
00094         foreach (QString path, devices) {
00095             bluetoothInterfaces.append(path);
00096         }
00097     }
00098     return bluetoothInterfaces;
00099 }
00100 
00101 QString BluezBluetoothManager::defaultInterface() const
00102 {
00103     QDBusReply< QString > path = d->manager.call("DefaultAdapter");
00104     if (!path.isValid())
00105         return QString();
00106 
00107     return path.value();
00108 }
00109 
00110 QObject * BluezBluetoothManager::createInterface(const QString  & ubi)
00111 {
00112     BluezBluetoothInterface * bluetoothInterface;
00113     if (d->interfaces.contains(ubi)) {
00114         bluetoothInterface = d->interfaces[ubi];
00115     } else {
00116         bluetoothInterface = new BluezBluetoothInterface(ubi);
00117         d->interfaces.insert(ubi, bluetoothInterface);
00118     }
00119     return bluetoothInterface;
00120 }
00121 
00122 KJob *BluezBluetoothManager::setupInputDevice(const QString &ubi)
00123 {
00124     QString address = ubi.right(17);
00125 
00126     QList<QVariant> params;
00127     params << address;
00128 
00129     return new BluezCallJob(QDBusConnection::systemBus(), m_inputManagerDest, "/org/bluez/input", "org.bluez.input.Manager",
00130                             "CreateDevice", params);
00131 }
00132 
00133 QStringList BluezBluetoothManager::bluetoothInputDevices() const
00134 {
00135     QStringList bluetoothInputDevices;
00136 
00137     QDBusReply< QStringList > deviceList = d->inputManager->call("ListDevices");
00138     if (deviceList.isValid()) {
00139         QStringList devices = deviceList.value();
00140         foreach (QString path, devices) {
00141             bluetoothInputDevices.append(path);
00142         }
00143     }
00144     return bluetoothInputDevices;
00145 }
00146 
00147 void BluezBluetoothManager::removeInputDevice(const QString &ubi)
00148 {
00149     d->inputManager->call("RemoveDevice", ubi);
00150 }
00151 
00152 QObject *BluezBluetoothManager::createBluetoothInputDevice(QString const &ubi)
00153 {
00154     BluezBluetoothInputDevice *bluetoothInputDevice;
00155     if (d->inputDevices.contains(ubi)) {
00156         bluetoothInputDevice = d->inputDevices[ubi];
00157     } else {
00158         bluetoothInputDevice = new BluezBluetoothInputDevice(ubi, m_inputManagerDest);
00159         d->inputDevices.insert(ubi, bluetoothInputDevice);
00160     }
00161     return bluetoothInputDevice;
00162 }
00163 
00164 void BluezBluetoothManager::slotDeviceAdded(const QString &adapter)
00165 {
00166     // TODO free the adapter device...
00167     emit interfaceAdded(adapter);
00168 }
00169 
00170 void BluezBluetoothManager::slotDeviceRemoved(const QString &adapter)
00171 {
00172     emit interfaceRemoved(adapter);
00173 }
00174 
00175 void BluezBluetoothManager::slotDefaultDeviceChanged(const QString &adapter)
00176 {
00177     emit defaultInterfaceChanged(adapter);
00178 }
00179 
00180 void BluezBluetoothManager::slotInputDeviceCreated(const QString &path)
00181 {
00182     emit inputDeviceCreated(path);
00183 }
00184 
00185 void BluezBluetoothManager::slotInputDeviceRemoved(const QString &path)
00186 {
00187     // TODO free the input device...
00188     emit inputDeviceRemoved(path);
00189 }
00190 
00191 Solid::Control::Ifaces::BluetoothSecurity *BluezBluetoothManager::security(const QString &interface)
00192 {
00193     BluezBluetoothSecurity *out;
00194     if (interface.isEmpty()) {
00195         out = new BluezBluetoothSecurity(this);
00196     } else {
00197         out = new BluezBluetoothSecurity(interface,this);
00198     }
00199     new BluezBluetoothSecurityPasskeyAgentAdaptor(out);
00200     new BluezBluetoothSecurityAuthorizationAgentAdaptor(out);
00201     return out;
00202 }
00203 
00204 #include "bluez-bluetoothmanager.moc"
00205 
00206 

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