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

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