3 * meego handset bluetooth
4 * Copyright © 2010, Intel Corporation.
6 * This program is licensed under the terms and conditions of the
7 * Apache License, version 2.0. The full text of the Apache License is at
8 * http://www.apache.org/licenses/LICENSE-2.0
12 #include "bluetoothdevice.h"
13 #include "blueadapter.h"
14 #include "bluemanager.h"
15 #include "btprofiles.h"
16 #include "audiosink.h"
17 #include "audiosource.h"
20 BluetoothDevice::BluetoothDevice(QDBusObjectPath path, QObject *parent) :
21 QObject(parent),m_device(new OrgBluezDeviceInterface("org.bluez",path.path(),QDBusConnection::systemBus(),this))
23 if(!m_device->isValid())
25 QObject::connect(m_device,SIGNAL(PropertyChanged(QString,QDBusVariant)),
26 this,SLOT(propertyChanged(QString,QDBusVariant)));
29 void BluetoothDevice::unpair()
31 OrgBluezManagerInterface manager(
33 "/", QDBusConnection::systemBus());
35 QDBusObjectPath adapterpath = manager.DefaultAdapter();
37 if(adapterpath.path().isEmpty()) return;
39 OrgBluezAdapterInterface adapter(
42 QDBusConnection::systemBus());
44 adapter.RemoveDevice(QDBusObjectPath(m_device->path()));
47 void BluetoothDevice::connect(QString profile)
49 if(profile == BluetoothProfiles::a2sink)
51 OrgBluezAudioSinkInterface sink("org.bluez",m_device->path(),
52 QDBusConnection::systemBus());
55 else if(profile == BluetoothProfiles::a2src)
57 OrgBluezAudioSourceInterface source("org.bluez",m_device->path(),
58 QDBusConnection::systemBus());
61 else if(profile == BluetoothProfiles::hs)
63 OrgBluezHeadsetInterface headset("org.bluez",m_device->path(),
64 QDBusConnection::systemBus());
67 else if(profile == BluetoothProfiles::spp)
69 QDBusInterface interface("org.bluez",m_device->path(),"org.bluez.Serial",QDBusConnection::systemBus());
70 interface.call(QDBus::AutoDetect, "Connect","spp");
74 void BluetoothDevice::disconnect()
76 m_device->Disconnect();
79 QStringList BluetoothDevice::profiles()
81 QVariantMap props = m_device->GetProperties();
83 QStringList uuidlist = props["UUIDs"].toStringList();
88 bool BluetoothDevice::isProfileSupported(QString profile)
90 QVariantMap props = m_device->GetProperties();
92 QStringList uuidlist = props["UUIDs"].toStringList();
94 return uuidlist.contains(profile.toLower());
97 bool BluetoothDevice::connected()
99 QVariantMap props = m_device->GetProperties();
100 return props["Connected"].toBool();
103 QString BluetoothDevice::alias()
105 QVariantMap props = m_device->GetProperties();
106 return props["Alias"].toString();
109 QString BluetoothDevice::name()
111 QVariantMap props = m_device->GetProperties();
112 return props["Name"].toString();
115 QString BluetoothDevice::address()
117 QVariantMap props = m_device->GetProperties();
118 return props["Address"].toString();
121 QString BluetoothDevice::icon()
123 QVariantMap props = m_device->GetProperties();
124 return props["Icon"].toString();
127 QString BluetoothDevice::path()
129 return m_device->path();
132 void BluetoothDevice::propertyChanged(QString name,QDBusVariant value)
134 emit propertyChanged(name,value.variant());
136 if(name == "Connected")
138 emit connetedChanged();