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

libsolidcontrol

bluetoothinterface.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006 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 <QMap>
00023 #include <QPair>
00024 #include <QStringList>
00025 
00026 #include <kdebug.h>
00027 
00028 #include "ifaces/bluetoothinterface.h"
00029 
00030 #include "frontendobject_p.h"
00031 
00032 #include "soliddefs_p.h"
00033 #include "bluetoothmanager.h"
00034 #include "bluetoothinterface.h"
00035 #include "bluetoothremotedevice.h"
00036 
00037 namespace Solid
00038 {
00039 namespace Control
00040 {
00041 class BluetoothInterfacePrivate : public FrontendObjectPrivate
00042 {
00043 public:
00044     BluetoothInterfacePrivate(QObject *parent)
00045         : FrontendObjectPrivate(parent) { }
00046 
00047     void setBackendObject(QObject *object);
00048 
00049     QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *> findRegisteredBluetoothRemoteDevice(const QString &ubi) const;
00050 
00051     mutable QMap<QString, QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *> > remoteDeviceMap;
00052     mutable BluetoothRemoteDevice invalidDevice;
00053 };
00054 }
00055 }
00056 
00057 Solid::Control::BluetoothInterface::BluetoothInterface()
00058         : QObject(), d(new BluetoothInterfacePrivate(this))
00059 {}
00060 
00061 Solid::Control::BluetoothInterface::BluetoothInterface(const QString &ubi)
00062         : QObject(), d(new BluetoothInterfacePrivate(this))
00063 {
00064     const BluetoothInterface &device = BluetoothManager::self().findBluetoothInterface(ubi);
00065     d->setBackendObject(device.d->backendObject());
00066 }
00067 
00068 Solid::Control::BluetoothInterface::BluetoothInterface(QObject *backendObject)
00069         : QObject(), d(new BluetoothInterfacePrivate(this))
00070 {
00071     d->setBackendObject(backendObject);
00072 }
00073 
00074 Solid::Control::BluetoothInterface::BluetoothInterface(const BluetoothInterface &device)
00075         : QObject(), d(new BluetoothInterfacePrivate(this))
00076 {
00077     d->setBackendObject(device.d->backendObject());
00078 }
00079 
00080 Solid::Control::BluetoothInterface::~BluetoothInterface()
00081 {
00082     // Delete all the interfaces, they are now outdated
00083     typedef QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *> BluetoothRemoteDeviceIfacePair;
00084 
00085     // Delete all the devices, they are now outdated
00086     foreach (const BluetoothRemoteDeviceIfacePair &pair, d->remoteDeviceMap.values()) {
00087         delete pair.first;
00088         delete pair.second;
00089     }
00090 }
00091 
00092 Solid::Control::BluetoothInterface &Solid::Control::BluetoothInterface::operator=(const Solid::Control::BluetoothInterface  & dev)
00093 {
00094     d->setBackendObject(dev.d->backendObject());
00095 
00096     return *this;
00097 }
00098 
00099 QString Solid::Control::BluetoothInterface::ubi() const
00100 {
00101     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), ubi());
00102 }
00103 
00104 Solid::Control::BluetoothRemoteDevice Solid::Control::BluetoothInterface::findBluetoothRemoteDevice(const QString &ubi) const
00105 {
00106     QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *> pair = d->findRegisteredBluetoothRemoteDevice(ubi);
00107 
00108     if (pair.first != 0) {
00109         return *pair.first;
00110     } else {
00111         return d->invalidDevice;
00112     }
00113 }
00114 
00115 Solid::Control::BluetoothRemoteDevice * Solid::Control::BluetoothInterface::createBluetoothRemoteDevice(const QString &address)
00116 {
00117     QString ubi;
00118     if (address.startsWith("/org/bluez"))
00119     ubi = address;
00120     else
00121         ubi = this->ubi() + "/" + address;
00122    
00123     kDebug() << "UBI iam using: " << ubi; 
00124     QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *> pair = d->findRegisteredBluetoothRemoteDevice(ubi);
00125     return pair.first;
00126 
00127 }
00128 QString Solid::Control::BluetoothInterface::address() const
00129 {
00130     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), address());
00131 }
00132 
00133 QString Solid::Control::BluetoothInterface::version() const
00134 {
00135     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), version());
00136 }
00137 
00138 QString Solid::Control::BluetoothInterface::revision() const
00139 {
00140     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), revision());
00141 }
00142 
00143 QString Solid::Control::BluetoothInterface::manufacturer() const
00144 {
00145     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), manufacturer());
00146 }
00147 
00148 QString Solid::Control::BluetoothInterface::company() const
00149 {
00150     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), company());
00151 }
00152 
00153 Solid::Control::BluetoothInterface::Mode Solid::Control::BluetoothInterface::mode() const
00154 {
00155     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), Solid::Control::BluetoothInterface::Off, mode());
00156 }
00157 
00158 int Solid::Control::BluetoothInterface::discoverableTimeout() const
00159 {
00160     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), 0, discoverableTimeout());
00161 }
00162 
00163 bool Solid::Control::BluetoothInterface::isDiscoverable() const
00164 {
00165     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), false, isDiscoverable());
00166 }
00167 
00168 Solid::Control::BluetoothRemoteDeviceList Solid::Control::BluetoothInterface::listConnections() const
00169 {
00170     BluetoothRemoteDeviceList list;
00171     Ifaces::BluetoothInterface *backend = qobject_cast<Ifaces::BluetoothInterface *>(d->backendObject());
00172 
00173     if (backend == 0) return list;
00174 
00175     QStringList ubis = backend->listConnections();
00176 
00177     foreach (const QString &ubi, ubis) {
00178         BluetoothRemoteDevice remoteDevice = findBluetoothRemoteDevice(ubi);
00179         list.append(remoteDevice);
00180     }
00181 
00182     return list;
00183 }
00184 
00185 QString Solid::Control::BluetoothInterface::majorClass() const
00186 {
00187     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), majorClass());
00188 }
00189 
00190 QStringList Solid::Control::BluetoothInterface::listAvailableMinorClasses() const
00191 {
00192     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QStringList(), listAvailableMinorClasses());
00193 }
00194 
00195 QString Solid::Control::BluetoothInterface::minorClass() const
00196 {
00197     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), minorClass());
00198 }
00199 
00200 QStringList Solid::Control::BluetoothInterface::serviceClasses() const
00201 {
00202     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QStringList(), serviceClasses());
00203 }
00204 
00205 QString Solid::Control::BluetoothInterface::name() const
00206 {
00207     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), name());
00208 }
00209 
00210 QString Solid::Control::BluetoothInterface::getRemoteName(const QString &mac)
00211 {
00212     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QString(), getRemoteName(mac));
00213 }
00214 
00215 QStringList Solid::Control::BluetoothInterface::listBondings() const
00216 {
00217     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QStringList(), listBondings());
00218 }
00219 
00220 bool Solid::Control::BluetoothInterface::isPeriodicDiscoveryActive() const
00221 {
00222     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), false, isPeriodicDiscoveryActive());
00223 }
00224 
00225 bool Solid::Control::BluetoothInterface::isPeriodicDiscoveryNameResolvingActive() const
00226 {
00227     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), false,
00228                       isPeriodicDiscoveryNameResolvingActive());
00229 }
00230 
00231 bool  Solid::Control::BluetoothInterface::isTrusted(const QString& address)
00232 {
00233     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), false, isTrusted(address));
00234 }
00235 
00236 // TODO: QStringList or BluetoothRemoteDeviceList?
00237 QStringList Solid::Control::BluetoothInterface::listRemoteDevices() const
00238 {
00239     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QStringList(),
00240                       listRemoteDevices());
00241 }
00242 
00243 // TODO: QStringList or BluetoothRemoteDeviceList?
00244 QStringList Solid::Control::BluetoothInterface::listRecentRemoteDevices(const QDateTime &date) const
00245 {
00246     return_SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), QStringList(),
00247                       listRecentRemoteDevices(date));
00248 }
00249 
00250 /***************************************************************/
00251 
00252 void Solid::Control::BluetoothInterface::setMode(const Solid::Control::BluetoothInterface::Mode mode)
00253 {
00254     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), setMode(mode));
00255 }
00256 
00257 void Solid::Control::BluetoothInterface::setDiscoverableTimeout(int timeout)
00258 {
00259     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), setDiscoverableTimeout(timeout));
00260 }
00261 
00262 void Solid::Control::BluetoothInterface::setMinorClass(const QString &minor)
00263 {
00264     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), setMinorClass(minor));
00265 }
00266 
00267 void Solid::Control::BluetoothInterface::setName(const QString &name)
00268 {
00269     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), setName(name));
00270 }
00271 
00272 void Solid::Control::BluetoothInterface::discoverDevices()
00273 {
00274     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), discoverDevices());
00275 }
00276 
00277 void Solid::Control::BluetoothInterface::discoverDevicesWithoutNameResolving()
00278 {
00279     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), discoverDevicesWithoutNameResolving());
00280 }
00281 
00282 void Solid::Control::BluetoothInterface::cancelDiscovery()
00283 {
00284     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), cancelDiscovery());
00285 }
00286 
00287 void Solid::Control::BluetoothInterface::startPeriodicDiscovery()
00288 {
00289     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), startPeriodicDiscovery());
00290 }
00291 
00292 void Solid::Control::BluetoothInterface::stopPeriodicDiscovery()
00293 {
00294     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), stopPeriodicDiscovery());
00295 }
00296 
00297 void Solid::Control::BluetoothInterface::setPeriodicDiscoveryNameResolving(bool resolveNames)
00298 {
00299     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), setPeriodicDiscoveryNameResolving(resolveNames));
00300 }
00301 
00302 void Solid::Control::BluetoothInterface::setTrusted(const QString& address)
00303 {
00304     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), setTrusted(address));
00305 }
00306 
00307 void Solid::Control::BluetoothInterface::removeTrust(const QString& address)
00308 {
00309     SOLID_CALL(Ifaces::BluetoothInterface *, d->backendObject(), removeTrust(address));
00310 }
00311 
00312 void Solid::Control::BluetoothInterfacePrivate::setBackendObject(QObject *object)
00313 {
00314     FrontendObjectPrivate::setBackendObject(object);
00315 
00316     if (object) {
00317         QObject::connect(object, SIGNAL(modeChanged(Solid::Control::BluetoothInterface::Mode)),parent(), SIGNAL(modeChanged(Solid::Control::BluetoothInterface::Mode)));
00318         QObject::connect(object, SIGNAL(discoverableTimeoutChanged(int)),
00319                          parent(), SIGNAL(discoverableTimeoutChanged(int)));
00320         QObject::connect(object, SIGNAL(minorClassChanged(const QString &)),
00321                          parent(), SIGNAL(minorClassChanged(const QString &)));
00322         QObject::connect(object, SIGNAL(nameChanged(const QString &)),
00323                          parent(), SIGNAL(nameChanged(const QString &)));
00324         QObject::connect(object, SIGNAL(discoveryStarted()),
00325                          parent(), SIGNAL(discoveryStarted()));
00326         QObject::connect(object, SIGNAL(discoveryCompleted()),
00327                          parent(), SIGNAL(discoveryCompleted()));
00328         QObject::connect(object, SIGNAL(remoteDeviceFound(const QString &, int, int)),
00329                          parent(), SIGNAL(remoteDeviceFound(const QString &, int, int)));
00330         QObject::connect(object, SIGNAL(remoteDeviceDisappeared(const QString &)),
00331                          parent(), SIGNAL(remoteDeviceDisappeared(const QString &)));
00332         QObject::connect(object, SIGNAL(remoteNameUpdated(const QString &,const QString &)),
00333                          parent(), SIGNAL(remoteNameUpdated(const QString &,const QString &)));
00334         QObject::connect(object, SIGNAL(remoteDeviceConnected(const QString &)),
00335                          parent(), SIGNAL(remoteDeviceConnected(const QString &)));
00336         QObject::connect(object, SIGNAL(remoteDeviceDisconnected(const QString &)),
00337                          parent(), SIGNAL(remoteDeviceDisconnected(const QString &)));
00338         QObject::connect(object, SIGNAL(trustAdded(const QString &)),
00339                          parent(), SIGNAL(trustAdded(const QString &)));
00340         QObject::connect(object, SIGNAL(trustRemoved(const QString &)),
00341                          parent(), SIGNAL(trustRemoved(const QString &)));
00342         QObject::connect(object, SIGNAL(bondingCreated(const QString &)),
00343                          parent(), SIGNAL(bondingCreated(const QString &)));
00344         QObject::connect(object, SIGNAL(bondingRemoved(const QString &)),
00345                          parent(), SIGNAL(bondingRemoved(const QString &)));
00346 
00347     }
00348 }
00349 
00350 QPair<Solid::Control::BluetoothRemoteDevice *, Solid::Control::Ifaces::BluetoothRemoteDevice *> Solid::Control::BluetoothInterfacePrivate::findRegisteredBluetoothRemoteDevice(const QString &ubi) const
00351 {
00352     if (remoteDeviceMap.contains(ubi)) {
00353         return remoteDeviceMap[ubi];
00354     } else {
00355         Ifaces::BluetoothInterface *backend = qobject_cast<Ifaces::BluetoothInterface *>(backendObject());
00356         Ifaces::BluetoothRemoteDevice *iface = 0;
00357 
00358         if (backend != 0) {
00359             iface = qobject_cast<Ifaces::BluetoothRemoteDevice *>(backend->createBluetoothRemoteDevice(ubi));
00360         }
00361 
00362         if (iface != 0) {
00363             BluetoothRemoteDevice *device = new BluetoothRemoteDevice(iface);
00364 
00365             QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *> pair(device, iface);
00366             remoteDeviceMap[ubi] = pair;
00367 
00368             return pair;
00369         } else {
00370             return QPair<BluetoothRemoteDevice *, Ifaces::BluetoothRemoteDevice *>(0, 0);
00371         }
00372 
00373     }
00374 }
00375 
00376 #include "bluetoothinterface.moc"

libsolidcontrol

Skip menu "libsolidcontrol"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

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