not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / solid / bluez / bluez-bluetoothremotedevice.cpp
bloba1d90847f54ea1dc7408fe1f613e33ad0d39fc6f
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>
3 Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
4 Copyright (C) 2008 Tom Patzig <tpatzig@suse.de>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
23 #include "bluez-bluetoothremotedevice.h"
25 #include <QQueue>
26 #include <QTimer>
28 #include <kdebug.h>
30 #include <solid/control/bluetoothremotedevice.h>
32 #include "bluezcalljob.h"
34 Q_DECLARE_METATYPE(QList<uint>)
36 BluezBluetoothRemoteDevice::BluezBluetoothRemoteDevice(const QString &objectPath)
37 : BluetoothRemoteDevice(0), m_objectPath(objectPath)
40 // size("/FF:FF:FF:FF:FF:FF") == 18
41 //Q_ASSERT(objectPath.startsWith('/'));
42 m_adapter = m_objectPath.left(objectPath.size() - 18);
43 m_address = m_objectPath.right(17);
45 kdDebug() << "Connecting to ObjectPath: " << objectPath;
47 device = new QDBusInterface("org.bluez", objectPath,
48 "org.bluez.Device", QDBusConnection::systemBus());
49 #define connectDeviceToThis(signal, slot) \
50 device->connection().connect("org.bluez", \
51 objectPath, \
52 "org.bluez.Device", \
53 signal, this, SLOT(slot))
54 connectDeviceToThis("PropertyChanged",slotPropertyChanged(const QString &,const QDBusVariant &));
55 connectDeviceToThis("DisconnectRequested",slotDisconnectRequested());
56 connectDeviceToThis("NodeCreated",slotNodeCreated(const QDBusObjectPath &));
57 connectDeviceToThis("NodeRemoved",slotNodeRemoved(const QDBusObjectPath &));
62 BluezBluetoothRemoteDevice::~BluezBluetoothRemoteDevice()
64 delete device;
67 QString BluezBluetoothRemoteDevice::ubi() const
69 return device->path();
72 QMap<QString,QVariant> BluezBluetoothRemoteDevice::getProperties() const
74 QDBusReply< QMap<QString,QVariant> > path = device->call("GetProperties");
75 if (!path.isValid())
76 return QMap<QString,QVariant>();
78 return path.value();
81 void BluezBluetoothRemoteDevice::setProperty(const QString &name, const QVariant &value)
83 device->call("SetProperty",name,qVariantFromValue(QDBusVariant(value)));
86 void BluezBluetoothRemoteDevice::discoverServices(const QString& pattern) const
88 QList<QVariant> args;
89 args << pattern;
90 device->callWithCallback("DiscoverServices",
91 args,
92 (QObject*)this,
93 SLOT(slotServiceDiscover(const QMap<uint,QString> &)),
94 SLOT(dbusErrorServiceDiscover(const QDBusError &)));
98 void BluezBluetoothRemoteDevice::cancelDiscovery()
100 device->call("CancelDiscovery");
103 void BluezBluetoothRemoteDevice::disconnect()
105 device->call("Disconnect");
108 QStringList BluezBluetoothRemoteDevice::listNodes() const
110 QStringList list;
111 QDBusReply< QList<QDBusObjectPath> > path = device->call("ListNodes");
112 if (path.isValid()) {
113 foreach(QDBusObjectPath objectPath, path.value()) {
114 list.append(objectPath.path());
116 return list;
119 return QStringList();
123 KJob *BluezBluetoothRemoteDevice::createBonding()
125 QList<QVariant> params;
126 params << m_address;
128 return new BluezCallJob(QDBusConnection::systemBus(), "org.bluez", m_adapter,
129 "org.bluez.Adapter", "CreateBonding", params);
133 void BluezBluetoothRemoteDevice::serviceHandles(const QString &filter) const
135 QList<QVariant> args;
136 args << m_address << filter;
137 device->callWithCallback("GetRemoteServiceHandles",
138 args,
139 (QObject*)this,
140 SLOT(slotServiceHandles(const QList<uint> &)),
141 SLOT(dbusErrorHandles(const QDBusError &)));
145 void BluezBluetoothRemoteDevice::serviceRecordAsXml(uint handle) const
147 QList<QVariant> args;
148 args << m_address << handle;
149 device->callWithCallback("GetRemoteServiceRecordAsXML",
150 args,
151 (QObject*)this,
152 SLOT(slotServiceRecordAsXml(const QString &)),
153 SLOT(dbusErrorRecordAsXml(const QDBusError &)));
156 void BluezBluetoothRemoteDevice::slotServiceRecordAsXml(const QString & record)
158 emit serviceRecordXmlAvailable(ubi(),record);
161 void BluezBluetoothRemoteDevice::slotServiceDiscover(const QMap< uint,QString > & handles)
163 emit serviceDiscoverAvailable("success",handles);
167 /******************************/
169 QStringList BluezBluetoothRemoteDevice::listReply(const QString &method) const
171 QDBusReply< QStringList > reply = device->call(method, m_address);
172 if (!reply.isValid())
173 return QStringList();
175 return reply.value();
178 QString BluezBluetoothRemoteDevice::stringReply(const QString &method) const
180 QDBusReply< QString > reply = device->call(method, m_address);
181 if (!reply.isValid())
182 return QString();
184 return reply.value();
187 bool BluezBluetoothRemoteDevice::boolReply(const QString &method) const
189 QDBusReply< bool > reply = device->call(method, m_address);
190 if (!reply.isValid())
191 return false;
193 return reply.value();
196 void BluezBluetoothRemoteDevice::dbusErrorServiceDiscover(const QDBusError &error)
198 kDebug() << "Error on dbus call for DiscoverServices: " << error.message();
199 emit serviceDiscoverAvailable("failed",QMap<uint,QString>());
202 void BluezBluetoothRemoteDevice::slotPropertyChanged(const QString &prop, const QDBusVariant &value)
204 emit propertyChanged(prop, value.variant());
207 void BluezBluetoothRemoteDevice::slotDisconnectRequested()
209 emit disconnectRequested();
212 void BluezBluetoothRemoteDevice::slotNodeCreated(const QDBusObjectPath &path)
214 emit nodeCreated(path.path());
217 void BluezBluetoothRemoteDevice::slotNodeRemoved(const QDBusObjectPath &path)
219 emit nodeRemoved(path.path());
223 #include "bluez-bluetoothremotedevice.moc"