• Skip to content
  • Skip to link menu
KDE 4.1 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 
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-bluetoothremotedevice.h"
00023 
00024 #include <QQueue>
00025 #include <QTimer>
00026 
00027 #include <kdebug.h>
00028 
00029 #include <solid/control/bluetoothremotedevice.h>
00030 
00031 #include "bluezcalljob.h"
00032 
00033 Q_DECLARE_METATYPE(QList<uint>)
00034 
00035 BluezBluetoothRemoteDevice::BluezBluetoothRemoteDevice(const QString &objectPath)
00036     : BluetoothRemoteDevice(0), m_objectPath(objectPath)
00037 {
00038 
00039     // size("/FF:FF:FF:FF:FF:FF") == 18
00040     Q_ASSERT(objectPath.startsWith('/'));
00041     m_adapter = m_objectPath.left(objectPath.size() - 18);
00042     m_address = m_objectPath.right(17);
00043 
00044 
00045     device = new QDBusInterface("org.bluez", m_adapter,
00046                     "org.bluez.Adapter", QDBusConnection::systemBus());
00047     #define connectAdapterToThis(signal, slot) \
00048         device->connection().connect("org.bluez", \
00049             m_adapter, \
00050             "org.bluez.Adapter", \
00051             signal, this, SLOT(slot))
00052     connectAdapterToThis("RemoteClassUpdated",slotClassChanged(const QString&, uint));
00053     connectAdapterToThis("RemoteNameUpdated",slotNameUpdated(const QString &,const QString &));
00054     connectAdapterToThis("RemoteNameFailed",slotNameResolvingFailed(const QString &));
00055     connectAdapterToThis("RemoteAliasChanged",slotAliasChanged(const QString &,const QString &));
00056     connectAdapterToThis("RemoteAliasCleared",slotAliasCleared(const QString &));
00057     connectAdapterToThis("RemoteDeviceConnected",slotConnected(const QString &));
00058     connectAdapterToThis("RemoteDeviceDisconnectRequested",slotRequestDisconnection(const QString &));
00059     connectAdapterToThis("RemoteDeviceDisconnected",slotDisconnected(const QString &));
00060     connectAdapterToThis("BondingCreated",slotBonded(const QString &));
00061     connectAdapterToThis("BondingRemoved",slotUnbonded(const QString &));
00062 }
00063 
00064 BluezBluetoothRemoteDevice::~BluezBluetoothRemoteDevice()
00065 {
00066     delete device;
00067 }
00068 
00069 QString BluezBluetoothRemoteDevice::ubi() const
00070 {
00071     return m_objectPath;
00072 }
00073 
00074 QString BluezBluetoothRemoteDevice::address() const
00075 {
00076     return m_address;
00077 }
00078 
00079 bool BluezBluetoothRemoteDevice::isConnected() const
00080 {
00081     return boolReply("IsConnected");
00082 }
00083 
00084 QString BluezBluetoothRemoteDevice::name() const
00085 {
00086     return stringReply("GetRemoteName");
00087 }
00088 
00089 QString BluezBluetoothRemoteDevice::version() const
00090 {
00091     return stringReply("GetRemoteVersion");
00092 }
00093 
00094 QString BluezBluetoothRemoteDevice::revision() const
00095 {
00096     return stringReply("GetRemoteRevision");
00097 }
00098 
00099 QString BluezBluetoothRemoteDevice::manufacturer() const
00100 {
00101     return stringReply("GetRemoteManufacturer");
00102 }
00103 
00104 QString BluezBluetoothRemoteDevice::company() const
00105 {
00106     return stringReply("GetRemoteCompany");
00107 }
00108 
00109 QString BluezBluetoothRemoteDevice::majorClass() const
00110 {
00111     return stringReply("GetRemoteMajorClass");
00112 }
00113 
00114 QString BluezBluetoothRemoteDevice::minorClass() const
00115 {
00116     return stringReply("GetRemoteMinorClass");
00117 }
00118 
00119 QStringList BluezBluetoothRemoteDevice::serviceClasses() const
00120 {
00121     return listReply("GetRemoteServiceClasses");
00122 }
00123 
00124 QString BluezBluetoothRemoteDevice::alias() const
00125 {
00126     return stringReply("GetRemoteAlias");
00127 }
00128 
00129 QString BluezBluetoothRemoteDevice::lastSeen() const
00130 {
00131     return stringReply("LastSeen");
00132 }
00133 
00134 QString BluezBluetoothRemoteDevice::lastUsed() const
00135 {
00136     return stringReply("LastUsed");
00137 }
00138 
00139 bool BluezBluetoothRemoteDevice::hasBonding() const
00140 {
00141 
00142     return boolReply("HasBonding");
00143 }
00144 
00145 int BluezBluetoothRemoteDevice::pinCodeLength() const
00146 {
00147     QDBusReply< int > path = device->call("PinCodeLength", m_address);
00148     if (!path.isValid())
00149         return false;
00150 
00151     return path.value();
00152 }
00153 
00154 int BluezBluetoothRemoteDevice::encryptionKeySize() const
00155 {
00156     QDBusReply< int > path = device->call("EncryptionKeySize", m_address);
00157     if (!path.isValid())
00158         return false;
00159 
00160     return path.value();
00161 }
00162 
00163 KJob *BluezBluetoothRemoteDevice::createBonding()
00164 {
00165     QList<QVariant> params;
00166     params << m_address;
00167 
00168     return new BluezCallJob(QDBusConnection::systemBus(), "org.bluez", m_adapter,
00169                 "org.bluez.Adapter", "CreateBonding", params);
00170 }
00171 
00172 void BluezBluetoothRemoteDevice::setAlias(const QString &alias)
00173 {
00174     device->call("SetRemoteAlias",m_address,alias);
00175 }
00176 
00177 void BluezBluetoothRemoteDevice::clearAlias()
00178 {
00179     device->call("ClearRemoteAlias", m_address);
00180 }
00181 
00182 void BluezBluetoothRemoteDevice::disconnect()
00183 {
00184     device->call("DisconnectRemoteDevice", m_address);
00185 }
00186 
00187 void BluezBluetoothRemoteDevice::cancelBondingProcess()
00188 {
00189     device->call("CancelBondingProcess", m_address);
00190 }
00191 
00192 void BluezBluetoothRemoteDevice::removeBonding()
00193 {
00194     device->call("RemoveBonding", m_address);
00195 }
00196 
00197 void BluezBluetoothRemoteDevice::serviceHandles(const QString &filter) const
00198 {
00199     QList<QVariant> args;
00200     args << m_address << filter;
00201     device->callWithCallback("GetRemoteServiceHandles",
00202                  args,
00203                  (QObject*)this,
00204                  SLOT(slotServiceHandles(const QList<uint> &)),
00205                  SLOT(dbusErrorHandles(const QDBusError &)));
00206 
00207 }
00208 
00209 void BluezBluetoothRemoteDevice::serviceRecordAsXml(uint handle) const
00210 {
00211     QList<QVariant> args;
00212     args << m_address << handle;
00213     device->callWithCallback("GetRemoteServiceRecordAsXML",
00214                  args,
00215                  (QObject*)this,
00216                  SLOT(slotServiceRecordAsXml(const QString &)),
00217                  SLOT(dbusErrorRecordAsXml(const QDBusError &)));
00218 }
00219 void BluezBluetoothRemoteDevice::slotServiceHandles(const QList< uint > & handles)
00220 {
00221     emit serviceHandlesAvailable(ubi(),handles);
00222 }
00223 
00224 void BluezBluetoothRemoteDevice::slotServiceRecordAsXml(const QString & record)
00225 {
00226     emit serviceRecordXmlAvailable(ubi(),record);
00227 }
00228 /******************************/
00229 
00230 QStringList BluezBluetoothRemoteDevice::listReply(const QString &method) const
00231 {
00232     QDBusReply< QStringList > reply = device->call(method, m_address);
00233     if (!reply.isValid())
00234         return QStringList();
00235 
00236     return reply.value();
00237 }
00238 
00239 QString BluezBluetoothRemoteDevice::stringReply(const QString &method) const
00240 {
00241     QDBusReply< QString > reply = device->call(method, m_address);
00242     if (!reply.isValid())
00243         return QString();
00244 
00245     return reply.value();
00246 }
00247 
00248 bool BluezBluetoothRemoteDevice::boolReply(const QString &method) const
00249 {
00250     QDBusReply< bool > reply = device->call(method, m_address);
00251     if (!reply.isValid())
00252         return false;
00253 
00254     return reply.value();
00255 }
00256 
00257 void BluezBluetoothRemoteDevice::dbusErrorHandles(const QDBusError &error)
00258 {
00259     kDebug() << "Error on dbus call for handles: " << error.message();
00260     emit serviceHandlesAvailable("failed",QList<uint>());
00261 }
00262 
00263 void BluezBluetoothRemoteDevice::dbusErrorRecordAsXml(const QDBusError & error)
00264 {
00265     kDebug() << "Error on dbus call for record as xml: " << error.message();
00266     emit serviceRecordXmlAvailable("failed","");
00267 }
00268 
00269 void BluezBluetoothRemoteDevice::slotClassChanged(const QString & address, uint newClass)
00270 {
00271     if (address == this->address()) {
00272         emit classChanged(newClass);
00273     }
00274 }
00275 
00276 void BluezBluetoothRemoteDevice::slotNameResolvingFailed(const QString & address)
00277 {
00278     if (address == this->address()) {
00279         emit nameResolvingFailed();
00280     }
00281 }
00282 
00283 void BluezBluetoothRemoteDevice::slotNameUpdated(const QString & address, const QString & newName)
00284 {
00285     if (address == this->address()) {
00286         emit nameChanged(newName);
00287     }
00288 }
00289 
00290 void BluezBluetoothRemoteDevice::slotAliasChanged(const QString & address, const QString & newAlias)
00291 {
00292     if (address == this->address()) {
00293         emit aliasChanged(newAlias);
00294     }
00295 }
00296 
00297 void BluezBluetoothRemoteDevice::slotAliasCleared(const QString & address)
00298 {
00299     if (address == this->address()) {
00300         emit aliasCleared();
00301     }
00302 }
00303 
00304 void BluezBluetoothRemoteDevice::slotConnected(const QString & address)
00305 {
00306     if (address == this->address()) {
00307         emit connected();
00308     }
00309 }
00310 
00311 void BluezBluetoothRemoteDevice::slotRequestDisconnection(const QString & address)
00312 {
00313     if (address == this->address()) {
00314         emit requestDisconnection();
00315     }
00316 }
00317 
00318 void BluezBluetoothRemoteDevice::slotDisconnected(const QString & address)
00319 {
00320     if (address == this->address()) {
00321         emit disconnected();
00322     }
00323 }
00324 
00325 void BluezBluetoothRemoteDevice::slotBonded(const QString & address)
00326 {
00327     if (address == this->address()) {
00328         emit bondingCreated();
00329     }
00330 }
00331 
00332 void BluezBluetoothRemoteDevice::slotUnbonded(const QString & address)
00333 {
00334     if (address == this->address()) {
00335         emit bondingRemoved();
00336     }
00337 }
00338 
00339 #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
  •   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