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

SolidModules

bluez-bluetoothinterface.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-bluetoothinterface.h"
00024 
00025 #include <solid/control/bluetoothinterface.h>
00026 
00027 #include "bluez-bluetoothremotedevice.h"
00028 #include "bluez-bluetoothinputdevice.h"
00029 #include <KDebug>
00030 
00031 
00032 
00033 class BluezBluetoothInterfacePrivate
00034 {
00035 public:
00036     BluezBluetoothInterfacePrivate(const QString  & objPath)
00037             : iface("org.bluez",
00038                     objPath,
00039                     "org.bluez.Adapter",
00040                     QDBusConnection::systemBus()),
00041             objectPath(objPath)
00042     { }
00043     QDBusInterface iface;
00044     QString objectPath;
00045 
00046     QMap<QString, BluezBluetoothRemoteDevice *> devices;
00047     QMap<QString, BluezBluetoothInputDevice *> inputDevices;
00048 };
00049 
00050 
00051 
00052 BluezBluetoothInterface::BluezBluetoothInterface(const QString  & objectPath)
00053         : BluetoothInterface(0), d(new BluezBluetoothInterfacePrivate(objectPath))
00054 {
00055 
00056 #define connectInterfaceToThis(signal, slot) \
00057     d->iface.connection().connect("org.bluez", \
00058                                    objectPath, \
00059                                    "org.bluez.Adapter", \
00060                                    signal, this, SLOT(slot));
00061 
00062     connectInterfaceToThis("PropertyChanged", slotPropertyChanged(const QString &, const QVariant &));
00063     connectInterfaceToThis("DeviceCreated", slotDeviceCreated(const QDBusObjectPath &));
00064     connectInterfaceToThis("DeviceRemoved", slotDeviceRemoved(const QDBusObjectPath &));
00065     connectInterfaceToThis("DeviceDisappeared", slotDeviceDisappeared(const QString &));
00066     connectInterfaceToThis("DeviceFound", slotDeviceFound(const QString &, const QMap< QString,QVariant > &));
00067 
00068 
00069 }
00070 
00071 BluezBluetoothInterface::~BluezBluetoothInterface()
00072 {
00073     delete d;
00074 }
00075 
00076 QString BluezBluetoothInterface::ubi() const
00077 {
00078     return d->objectPath;
00079 }
00080 
00081 void BluezBluetoothInterface::cancelDeviceCreation(const QString &addr)
00082 {
00083     d->iface.call("CancelDeviceCreation",addr);
00084 }
00085 
00086 void BluezBluetoothInterface::createDevice(const QString &addr) const
00087 {
00088     d->iface.call("CreateDevice",addr);
00089 }
00090 
00091 void BluezBluetoothInterface::createPairedDevice(const QString &addr, const QString &agentUBI, const QString &capab) const
00092 {
00093     d->iface.call("CreatePairedDevice",addr,qVariantFromValue(QDBusObjectPath(agentUBI)),capab);
00094 }
00095 
00096 QString BluezBluetoothInterface::findDevice(const QString &addr) const
00097 {
00098     QDBusObjectPath path = objectReply("FindDevice",addr);
00099     return path.path();
00100 }
00101 
00102 
00103 QMap<QString, QVariant> BluezBluetoothInterface::getProperties() const
00104 {
00105     QDBusReply< QMap<QString,QVariant> > prop = d->iface.call("GetProperties");
00106     if (!prop.isValid()) {
00107         return QMap< QString,QVariant >();
00108     }
00109     return prop.value();
00110 }
00111 
00112 QStringList BluezBluetoothInterface::listDevices() const
00113 {
00114     QStringList deviceList;
00115 
00116     QDBusReply< QList<QDBusObjectPath> > devices = d->iface.call("ListDevices");
00117     if(!devices.isValid()) {
00118         return QStringList();
00119     }
00120     foreach(QDBusObjectPath path, devices.value()) {
00121         deviceList.append(path.path());
00122     }
00123     return deviceList;
00124 }
00125 
00126 void BluezBluetoothInterface::registerAgent(const QString &agentUBI, const QString &capab)
00127 {
00128     d->iface.call("RegisterAgent",qVariantFromValue(QDBusObjectPath(agentUBI)),capab);
00129 }
00130 
00131 void BluezBluetoothInterface::releaseSession()
00132 {
00133     d->iface.call("ReleaseSession");
00134 }
00135 
00136 void BluezBluetoothInterface::removeDevice(const QString &deviceUBI )
00137 {
00138     d->iface.call("RemoveDevice",qVariantFromValue(QDBusObjectPath(deviceUBI)));
00139 }
00140 
00141 void BluezBluetoothInterface::requestSession()
00142 {
00143     d->iface.call("RequestSession");
00144 }
00145 
00146 void BluezBluetoothInterface::setProperty(const QString &property, const QVariant &value)
00147 {
00148     d->iface.call("SetProperty",property, qVariantFromValue(QDBusVariant(value)));
00149 }
00150 
00151 
00152 void BluezBluetoothInterface::startDiscovery()
00153 {
00154     d->iface.call("StartDiscovery");
00155 }
00156 
00157 void BluezBluetoothInterface::stopDiscovery()
00158 {
00159     d->iface.call("StopDiscovery");
00160 }
00161 
00162 void BluezBluetoothInterface::unregisterAgent(const QString &agentUBI)
00163 {
00164     d->iface.call("UnregisterAgent",qVariantFromValue(QDBusObjectPath(agentUBI)));
00165 }
00166 
00167 
00168 
00169 void BluezBluetoothInterface::slotDeviceCreated(const QDBusObjectPath &path)
00170 {
00171     kDebug() << "device created";
00172 
00173     if (!d->devices.contains(path.path())) {
00174         BluezBluetoothRemoteDevice* bluetoothRemoteDev = new BluezBluetoothRemoteDevice(path.path());
00175         d->devices.insert(path.path(), bluetoothRemoteDev);
00176     }
00177 
00178     emit deviceCreated(path.path());
00179 }
00180 
00181 void BluezBluetoothInterface::slotDeviceDisappeared(const QString &address)
00182 {
00183     kDebug() << "device disappeared";
00184     emit deviceDisappeared(address);
00185 }
00186 
00187 void BluezBluetoothInterface::slotDeviceFound(const QString &address, const QMap< QString, QVariant > &properties)
00188 {
00189     kDebug() << "device found " << address << " " << properties["Name"];
00190     emit deviceFound(address,properties);
00191 }
00192 
00193 void BluezBluetoothInterface::slotDeviceRemoved(const QDBusObjectPath &path)
00194 {
00195     kDebug() << "device removed";
00196     emit deviceRemoved(path.path());
00197 }
00198 
00199 void BluezBluetoothInterface::slotPropertyChanged(const QString & property, const QVariant &value)
00200 {
00201     kDebug() << "Property " << property << " changed to " << value;
00202     emit propertyChanged(property,value);
00203 }
00204 
00205 
00206 
00207 QObject *BluezBluetoothInterface::createBluetoothRemoteDevice(const QString &ubi)
00208 {
00209     BluezBluetoothRemoteDevice *bluetoothInterface;
00210     if (d->devices.contains(ubi)) {
00211         bluetoothInterface = d->devices[ubi];
00212     } else {
00213         bluetoothInterface = new BluezBluetoothRemoteDevice(ubi);
00214         d->devices.insert(ubi, bluetoothInterface);
00215     }
00216     return bluetoothInterface;
00217 }
00218 
00219 QObject *BluezBluetoothInterface::createBluetoothInputDevice(const QString &ubi)
00220 {
00221     BluezBluetoothInputDevice *bluetoothInputDev;
00222     if (d->inputDevices.contains(ubi)) {
00223         bluetoothInputDev = d->inputDevices[ubi];
00224     } else {
00225         bluetoothInputDev = new BluezBluetoothInputDevice(ubi);
00226         d->inputDevices.insert(ubi, bluetoothInputDev);
00227     }
00228     return bluetoothInputDev;
00229 }
00230 
00231 
00232 
00233 /******************* DBus Calls *******************************/
00234 
00235 QStringList BluezBluetoothInterface::listReply(const QString &method) const
00236 {
00237     QDBusReply< QStringList > list = d->iface.call(method);
00238     if (!list.isValid()) {
00239         return QStringList();
00240     }
00241 
00242     return list.value();
00243 }
00244 
00245 QString BluezBluetoothInterface::stringReply(const QString &method, const QString &param) const
00246 {
00247     QDBusReply< QString > reply;
00248 
00249     if (param.isEmpty())
00250         reply = d->iface.call(method);
00251     else
00252         reply = d->iface.call(method, param);
00253             
00254     if (reply.isValid()) {
00255         return reply.value();
00256     }
00257 
00258     return QString();
00259 }
00260 
00261 bool BluezBluetoothInterface::boolReply(const QString &method, const QString &param) const
00262 {
00263     QDBusReply< bool > reply; 
00264 
00265     if (param.isEmpty())
00266         reply = d->iface.call(method);
00267     else
00268         reply = d->iface.call(method, param);
00269 
00270     if (reply.isValid()) {
00271         return reply.value();
00272     }
00273 
00274     return false;
00275 }
00276 
00277 QDBusObjectPath BluezBluetoothInterface::objectReply(const QString &method, const QString &param) const
00278 {
00279     QDBusReply< QDBusObjectPath > reply;
00280 
00281     if (param.isEmpty())
00282         reply = d->iface.call(method);
00283     else {
00284             qDebug() << "ObjectReply calling: " << method << " " << param;
00285         reply = d->iface.call(method, param);
00286     }
00287             
00288     if (reply.isValid()) {
00289         qDebug() << "ObjectReply Valid? "<<  reply.value().path();
00290         return reply.value();
00291     }
00292 
00293     return QDBusObjectPath();
00294 }
00295 
00296 #include "bluez-bluetoothinterface.moc"

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