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

SolidModules

bluez-bluetoothremotedevice.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-bluetoothremotedevice.h"
00024 
00025 #include <QQueue>
00026 #include <QTimer>
00027 
00028 #include <kdebug.h>
00029 
00030 #include <solid/control/bluetoothremotedevice.h>
00031 
00032 #include "bluezcalljob.h"
00033 
00034 Q_DECLARE_METATYPE(QList<uint>)
00035 
00036 BluezBluetoothRemoteDevice::BluezBluetoothRemoteDevice(const QString &objectPath)
00037     : BluetoothRemoteDevice(0), m_objectPath(objectPath)
00038 {
00039 
00040     // size("/FF:FF:FF:FF:FF:FF") == 18
00041     //Q_ASSERT(objectPath.startsWith('/'));
00042     m_adapter = m_objectPath.left(objectPath.size() - 18);
00043     m_address = m_objectPath.right(17);
00044 
00045         kdDebug() << "Connecting to ObjectPath: " << objectPath;
00046 
00047     device = new QDBusInterface("org.bluez", objectPath,
00048                     "org.bluez.Device", QDBusConnection::systemBus());
00049     #define connectDeviceToThis(signal, slot) \
00050         device->connection().connect("org.bluez", \
00051             objectPath, \
00052             "org.bluez.Device", \
00053             signal, this, SLOT(slot))
00054         connectDeviceToThis("PropertyChanged",slotPropertyChanged(const QString &,const QDBusVariant &));
00055         connectDeviceToThis("DisconnectRequested",slotDisconnectRequested());
00056         connectDeviceToThis("NodeCreated",slotNodeCreated(const QDBusObjectPath &));
00057         connectDeviceToThis("NodeRemoved",slotNodeRemoved(const QDBusObjectPath &));
00058 
00059 
00060 }
00061 
00062 BluezBluetoothRemoteDevice::~BluezBluetoothRemoteDevice()
00063 {
00064     delete device;
00065 }
00066 
00067 QString BluezBluetoothRemoteDevice::ubi() const
00068 {
00069     return device->path();
00070 }
00071 
00072 QMap<QString,QVariant> BluezBluetoothRemoteDevice::getProperties() const
00073 {
00074     QDBusReply< QMap<QString,QVariant> > path = device->call("GetProperties");
00075         if (!path.isValid())
00076         return QMap<QString,QVariant>();
00077 
00078     return path.value();
00079 }
00080 
00081 void BluezBluetoothRemoteDevice::setProperty(const QString &name, const QVariant &value)
00082 {
00083     device->call("SetProperty",name,qVariantFromValue(QDBusVariant(value)));
00084 }
00085 
00086 void BluezBluetoothRemoteDevice::discoverServices(const QString& pattern) const
00087 {
00088     QList<QVariant> args;
00089     args << pattern;
00090     device->callWithCallback("DiscoverServices",
00091             args,
00092             (QObject*)this,
00093             SLOT(slotServiceDiscover(const QMap<uint,QString> &)),
00094             SLOT(dbusErrorServiceDiscover(const QDBusError &)));
00095    
00096 }
00097 
00098 void BluezBluetoothRemoteDevice::cancelDiscovery()
00099 {
00100     device->call("CancelDiscovery");
00101 }
00102 
00103 void BluezBluetoothRemoteDevice::disconnect()
00104 {
00105     device->call("Disconnect");
00106 }
00107 
00108 QStringList BluezBluetoothRemoteDevice::listNodes() const
00109 {
00110     QStringList list;
00111     QDBusReply< QList<QDBusObjectPath> > path = device->call("ListNodes");
00112         if (path.isValid()) {
00113             foreach(QDBusObjectPath objectPath, path.value()) {
00114                 list.append(objectPath.path());
00115             }
00116         return list;
00117         }
00118 
00119     return QStringList();
00120 }
00121 
00122 /*
00123 KJob *BluezBluetoothRemoteDevice::createBonding()
00124 {
00125     QList<QVariant> params;
00126     params << m_address;
00127 
00128     return new BluezCallJob(QDBusConnection::systemBus(), "org.bluez", m_adapter,
00129                 "org.bluez.Adapter", "CreateBonding", params);
00130 }
00131 
00132 
00133 void BluezBluetoothRemoteDevice::serviceHandles(const QString &filter) const
00134 {
00135     QList<QVariant> args;
00136     args << m_address << filter;
00137     device->callWithCallback("GetRemoteServiceHandles",
00138                  args,
00139                  (QObject*)this,
00140                  SLOT(slotServiceHandles(const QList<uint> &)),
00141                  SLOT(dbusErrorHandles(const QDBusError &)));
00142 
00143 }
00144 
00145 void BluezBluetoothRemoteDevice::serviceRecordAsXml(uint handle) const
00146 {
00147     QList<QVariant> args;
00148     args << m_address << handle;
00149     device->callWithCallback("GetRemoteServiceRecordAsXML",
00150                  args,
00151                  (QObject*)this,
00152                  SLOT(slotServiceRecordAsXml(const QString &)),
00153                  SLOT(dbusErrorRecordAsXml(const QDBusError &)));
00154 }
00155 
00156 void BluezBluetoothRemoteDevice::slotServiceRecordAsXml(const QString & record)
00157 {
00158     emit serviceRecordXmlAvailable(ubi(),record);
00159 }
00160 */
00161 void BluezBluetoothRemoteDevice::slotServiceDiscover(const QMap< uint,QString > & handles)
00162 {
00163     emit serviceDiscoverAvailable("success",handles);
00164 }
00165 
00166 
00167 /******************************/
00168 
00169 QStringList BluezBluetoothRemoteDevice::listReply(const QString &method) const
00170 {
00171     QDBusReply< QStringList > reply = device->call(method, m_address);
00172     if (!reply.isValid())
00173         return QStringList();
00174 
00175     return reply.value();
00176 }
00177 
00178 QString BluezBluetoothRemoteDevice::stringReply(const QString &method) const
00179 {
00180     QDBusReply< QString > reply = device->call(method, m_address);
00181     if (!reply.isValid())
00182         return QString();
00183 
00184     return reply.value();
00185 }
00186 
00187 bool BluezBluetoothRemoteDevice::boolReply(const QString &method) const
00188 {
00189     QDBusReply< bool > reply = device->call(method, m_address);
00190     if (!reply.isValid())
00191         return false;
00192 
00193     return reply.value();
00194 }
00195 
00196 void BluezBluetoothRemoteDevice::dbusErrorServiceDiscover(const QDBusError &error)
00197 {
00198     kDebug() << "Error on dbus call for DiscoverServices: " << error.message();
00199     emit serviceDiscoverAvailable("failed",QMap<uint,QString>());
00200 }
00201 
00202 void BluezBluetoothRemoteDevice::slotPropertyChanged(const QString &prop, const QDBusVariant &value)
00203 {
00204     emit propertyChanged(prop, value.variant());
00205 }
00206 
00207 void BluezBluetoothRemoteDevice::slotDisconnectRequested()
00208 {
00209     emit disconnectRequested();
00210 }
00211 
00212 void BluezBluetoothRemoteDevice::slotNodeCreated(const QDBusObjectPath &path)
00213 {
00214     emit nodeCreated(path.path());
00215 }
00216 
00217 void BluezBluetoothRemoteDevice::slotNodeRemoved(const QDBusObjectPath &path)
00218 {
00219     emit nodeRemoved(path.path());
00220 }
00221 
00222 
00223 #include "bluez-bluetoothremotedevice.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