added support for input devices
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 9 Feb 2011 00:56:21 +0000 (16:56 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 9 Feb 2011 02:05:50 +0000 (18:05 -0800)
bluetooth-qt.pro
bluetoothdevice.cpp
bluetoothdevice.h
btprofiles.h
input.xml [new file with mode: 0644]

index ae2e89d..5c6e83b 100644 (file)
@@ -1,10 +1,11 @@
-!exists(bluemanager.h):system(qdbusxml2cpp -p bluemanager.h:bluemanager.cpp manager.xml)
-!exists(blueadapter.h):system(qdbusxml2cpp -p blueadapter.h:blueadapter.cpp adapter.xml)
-!exists(bluedevice.h):system(qdbusxml2cpp -p bluedevice.h:bluedevice.cpp -i devicetypes.h device.xml)
-!exists(audio.h):system(qdbusxml2cpp -p audio.h:audio.cpp audio.xml)
-!exists(audiosink.h):system(qdbusxml2cpp -p audiosink.h:audiosink.cpp audiosink.xml)
-!exists(audiosource.h):system(qdbusxml2cpp -p audiosource.h:audiosource.cpp audiosrc.xml)
-!exists(headset.h):system(qdbusxml2cpp -p headset.h:headset.cpp headset.xml)
+system(qdbusxml2cpp -p bluemanager.h:bluemanager.cpp manager.xml)
+system(qdbusxml2cpp -p blueadapter.h:blueadapter.cpp adapter.xml)
+system(qdbusxml2cpp -p bluedevice.h:bluedevice.cpp -i devicetypes.h device.xml)
+system(qdbusxml2cpp -p audio.h:audio.cpp audio.xml)
+system(qdbusxml2cpp -p audiosink.h:audiosink.cpp audiosink.xml)
+system(qdbusxml2cpp -p audiosource.h:audiosource.cpp audiosrc.xml)
+system(qdbusxml2cpp -p headset.h:headset.cpp headset.xml)
+system(qdbusxml2cpp -p input.h:input.cpp input.xml)
 include(obex/obex.pri)
 
 VERSION+= 0.0.4
@@ -20,7 +21,8 @@ OTHER_FILES += bluetooth-qt.conf \
        audiosrc.xml \
        audiosink.xml \
        adapter.xml \
-       headset.xml
+       headset.xml \
+    input.xml
 HEADERS += agentadaptor.h \
        bluemanager.h \
        bluedevice.h \
@@ -35,7 +37,8 @@ HEADERS += agentadaptor.h \
        devicetypes.h \
     bluetoothdevice.h \
        bluetoothdevicemodel.h \
-       audio.h
+       audio.h \
+       input.h
 SOURCES += agentadaptor.cpp \
        bluemanager.cpp \
        bluedevice.cpp \
@@ -46,9 +49,10 @@ SOURCES += agentadaptor.cpp \
        nearbydevicesmodel.cpp \
        bluetoothbaseagent.cpp \
        asyncagent.cpp \
-    bluetoothdevice.cpp \
+       bluetoothdevice.cpp \
        bluetoothdevicemodel.cpp \
-       audio.cpp
+       audio.cpp \
+       input.cpp
 
 target.path = $$INSTALL_ROOT/usr/lib
 headers.path = $$INSTALL_ROOT/usr/include/bluetooth-qt/
index 0930763..d2183da 100644 (file)
 #include "audiosource.h"
 #include "headset.h"
 #include "audio.h"
+#include "input.h"
 
 BluetoothDevice::BluetoothDevice(QDBusObjectPath path, QObject *parent) :
-               QObject(parent),m_device(new OrgBluezDeviceInterface("org.bluez",path.path(),QDBusConnection::systemBus(),this)),audio(NULL)
+       QObject(parent),m_device(new OrgBluezDeviceInterface("org.bluez",path.path(),QDBusConnection::systemBus(),this)),audio(NULL),input(NULL)
 {
-       if(!m_device->isValid())
-               return;
-       QObject::connect(m_device,SIGNAL(PropertyChanged(QString,QDBusVariant)),
-                                        this,SLOT(propertyChanged(QString,QDBusVariant)));
+    if(!m_device->isValid())
+       return;
+    QObject::connect(m_device,SIGNAL(PropertyChanged(QString,QDBusVariant)),
+                    this,SLOT(propertyChanged(QString,QDBusVariant)));
 }
 
 void BluetoothDevice::unpair()
 {
-       OrgBluezManagerInterface manager(
-                       "org.bluez",
-                       "/", QDBusConnection::systemBus());
+    OrgBluezManagerInterface manager(
+           "org.bluez",
+           "/", QDBusConnection::systemBus());
 
-       QDBusObjectPath adapterpath = manager.DefaultAdapter();
+    QDBusObjectPath adapterpath = manager.DefaultAdapter();
 
-       if(adapterpath.path().isEmpty()) return;
+    if(adapterpath.path().isEmpty()) return;
 
-       OrgBluezAdapterInterface adapter(
-                       "org.bluez",
-                       adapterpath.path(),
-                       QDBusConnection::systemBus());
+    OrgBluezAdapterInterface adapter(
+           "org.bluez",
+           adapterpath.path(),
+           QDBusConnection::systemBus());
 
-       adapter.RemoveDevice(QDBusObjectPath(m_device->path()));
+    adapter.RemoveDevice(QDBusObjectPath(m_device->path()));
 }
 
 void BluetoothDevice::connectAudio()
 {
-       if(isProfileSupported(BluetoothProfiles::a2sink) || isProfileSupported(BluetoothProfiles::hs))
-       {
-               if(!audio) audio = new OrgBluezAudioInterface("org.bluez", m_device->path(), QDBusConnection::systemBus(), this);
+    if(isProfileSupported(BluetoothProfiles::a2sink) || isProfileSupported(BluetoothProfiles::hs))
+    {
+       if(!audio) audio = new OrgBluezAudioInterface("org.bluez", m_device->path(), QDBusConnection::systemBus(), this);
 
-               audio->Connect();
+       audio->Connect();
 
-               connect(audio,SIGNAL(PropertyChanged(QString,QDBusVariant)),this,SLOT(audioPropertiesChanged(QString,QDBusVariant)));
-       }
+       connect(audio,SIGNAL(PropertyChanged(QString,QDBusVariant)),this,SLOT(audioPropertiesChanged(QString,QDBusVariant)));
+    }
 }
 void BluetoothDevice::connectAudioSrc()
 {
 
-       if(isProfileSupported(BluetoothProfiles::a2src))
-       {
-               OrgBluezAudioSourceInterface source("org.bluez",m_device->path(),
-                                                                               QDBusConnection::systemBus());
-               source.Connect();
-       }
+    if(isProfileSupported(BluetoothProfiles::a2src))
+    {
+       OrgBluezAudioSourceInterface source("org.bluez",m_device->path(),
+                                           QDBusConnection::systemBus());
+       source.Connect();
+    }
 }
 
 QString BluetoothDevice::connectSerial()
 {
-       if(isProfileSupported(BluetoothProfiles::spp))
-       {
-               QDBusInterface interface("org.bluez",m_device->path(),"org.bluez.Serial",QDBusConnection::systemBus());
-               QDBusReply<QString> reply = interface.call(QDBus::AutoDetect, "Connect","spp");
+    if(isProfileSupported(BluetoothProfiles::spp))
+    {
+       QDBusInterface interface("org.bluez",m_device->path(),"org.bluez.Serial",QDBusConnection::systemBus());
+       QDBusReply<QString> reply = interface.call(QDBus::AutoDetect, "Connect","spp");
 
-               if(reply.isValid()) return reply;
-               else qDebug()<<"Error connecting spp profile: "<<reply.error().message();
-       }
+       if(reply.isValid()) return reply;
+       else qDebug()<<"Error connecting spp profile: "<<reply.error().message();
+    }
 
-       return "";
+    return "";
+}
+
+void BluetoothDevice::connectInput()
+{
+    if(isProfileSupported(BluetoothProfiles::hid))
+    {
+       if(!input)
+       {
+           input = new OrgBluezInputInterface("org.bluez", m_device->path(),
+                                              QDBusConnection::systemBus(), this);
+           connect(input,SIGNAL(PropertyChanged(QString,QDBusVariant)),this,
+                   SLOT(inputPropertiesChanged(QString,QDBusVariant)));
+       }
+       input->Connect();
+    }
 }
 
 void BluetoothDevice::disconnect()
 {
-       m_device->Disconnect();
+    m_device->Disconnect();
 }
 
 void BluetoothDevice::disconnectAudio()
 {
-       if(!audio) audio = new OrgBluezAudioInterface("org.bluez", m_device->path(), QDBusConnection::systemBus(), this);
+    if(!audio) audio = new OrgBluezAudioInterface("org.bluez", m_device->path(), QDBusConnection::systemBus(), this);
 
-       audio->Disconnect();
+    audio->Disconnect();
 }
 
 QStringList BluetoothDevice::profiles()
 {
-       QVariantMap props = m_device->GetProperties();
+    QVariantMap props = m_device->GetProperties();
 
-       QStringList uuidlist = props["UUIDs"].toStringList();
+    QStringList uuidlist = props["UUIDs"].toStringList();
 
-       return uuidlist;
+    return uuidlist;
 }
 
 bool BluetoothDevice::isProfileSupported(QString profile)
 {
-       QVariantMap props = m_device->GetProperties();
+    QVariantMap props = m_device->GetProperties();
 
-       QStringList uuidlist = props["UUIDs"].toStringList();
+    QStringList uuidlist = props["UUIDs"].toStringList();
 
-       return uuidlist.contains(profile.toLower());
+    return uuidlist.contains(profile.toLower());
 }
 
 bool BluetoothDevice::connected()
 {
-       QVariantMap props = m_device->GetProperties();
-       return props["Connected"].toBool();
+    QVariantMap props = m_device->GetProperties();
+    return props["Connected"].toBool();
 }
 
 bool BluetoothDevice::audioConnected()
 {
-       if(!audio)
-       {
-               audio = new OrgBluezAudioInterface("org.bluez",m_device->path(), QDBusConnection::systemBus(),this);
-               connect(audio,SIGNAL(PropertyChanged(QString,QDBusVariant)),this,SLOT(audioPropertiesChanged(QString,QDBusVariant)));
-       }
+    if(!audio)
+    {
+       audio = new OrgBluezAudioInterface("org.bluez",m_device->path(), QDBusConnection::systemBus(),this);
+       connect(audio,SIGNAL(PropertyChanged(QString,QDBusVariant)),this,SLOT(audioPropertiesChanged(QString,QDBusVariant)));
+    }
 
-       QVariantMap props = audio->GetProperties();
-       return props["State"].toString() == "connected";
+    QVariantMap props = audio->GetProperties();
+    return props["State"].toString() == "connected";
+}
+
+bool BluetoothDevice::inputConnected()
+{
+    if(!input)
+    {
+       input = new OrgBluezInputInterface("org.bluez",m_device->path(), QDBusConnection::systemBus(),this);
+       connect(input,SIGNAL(PropertyChanged(QString,QDBusVariant)),this, SLOT(inputPropertiesChanged(QString,QDBusVariant)));
+    }
+
+    QVariantMap props = input->GetProperties();
+    return props["Connected"].toBool();
 }
 
 QString BluetoothDevice::alias()
 {
-       QVariantMap props = m_device->GetProperties();
-       return props["Alias"].toString();
+    QVariantMap props = m_device->GetProperties();
+    return props["Alias"].toString();
 }
 
 QString BluetoothDevice::name()
 {
-       QVariantMap props = m_device->GetProperties();
-       return props["Name"].toString();
+    QVariantMap props = m_device->GetProperties();
+    return props["Name"].toString();
 }
 
 QString BluetoothDevice::address()
 {
-       QVariantMap props = m_device->GetProperties();
-       return props["Address"].toString();
+    QVariantMap props = m_device->GetProperties();
+    return props["Address"].toString();
 }
 
 QString BluetoothDevice::icon()
 {
-       QVariantMap props = m_device->GetProperties();
-       return props["Icon"].toString();
+    QVariantMap props = m_device->GetProperties();
+    return props["Icon"].toString();
 }
 
 QString BluetoothDevice::path()
 {
-       return m_device->path();
+    return m_device->path();
 }
 
 void BluetoothDevice::propertyChanged(QString name,QDBusVariant value)
 {
-       emit propertyChanged(name,value.variant());
+    emit propertyChanged(name,value.variant());
 
-       if(name == "Connected")
-       {
-               emit connectedChanged(value.variant().toBool());
-       }
-       ///TODO: create individual signals for each property
+    if(name == "Connected")
+    {
+       emit connectedChanged(value.variant().toBool());
+    }
+    ///TODO: create individual signals for each property
 }
 
 void BluetoothDevice::audioPropertiesChanged(QString name,QDBusVariant value)
 {
-       emit propertyChanged(name, value.variant());
+    ///don't think i need to be doing this:
+    //emit propertyChanged(name, value.variant());
 
-       if(name == "State")
-       {
-               emit audioConnectedChanged(value.variant().toString() == "connected");
-       }
+    if(name == "State")
+    {
+       emit audioConnectedChanged(value.variant().toString() == "connected");
+    }
+}
+
+void BluetoothDevice::inputPropertiesChanged(QString name, QDBusVariant value)
+{
+    qDebug()<<"Input properties changed: "<<name<<" "<<value.variant();
+    if(name == "Connected")
+    {
+       emit inputConnectedChanged(value.variant().toBool());
+    }
 }
index 6f9efdf..eb4ac15 100644 (file)
@@ -6,12 +6,14 @@
 #include <bluedevice.h>
 
 class OrgBluezAudioInterface;
+class OrgBluezInputInterface;
 
 class BluetoothDevice : public QObject
 {
     Q_OBJECT   
        Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged);
        Q_PROPERTY(bool audioConnected READ audioConnected NOTIFY audioConnectedChanged)
+       Q_PROPERTY(bool inputConnected READ inputConnected NOTIFY inputConnectedChanged)
        Q_PROPERTY(QStringList profiles READ profiles)
        Q_PROPERTY(QString alias READ alias)
        Q_PROPERTY(QString name READ name)
@@ -25,6 +27,7 @@ public:
 signals:
        void connectedChanged(bool isConnected);
        void audioConnectedChanged(bool isConnected);
+       void inputConnectedChanged(bool isConnected);
        void propertyChanged(QString name, QVariant value);
 
 public slots:
@@ -32,6 +35,7 @@ public slots:
        void connectAudio();
        void connectAudioSrc();
        QString connectSerial();
+       void connectInput();
        void disconnect();
        void disconnectAudio();
 
@@ -41,6 +45,7 @@ public slots:
        ///properties:
        bool connected();
        bool audioConnected();
+       bool inputConnected();
        QString alias();
        QString name();
        QString address();
@@ -50,10 +55,12 @@ public slots:
 private slots:
        void propertyChanged(QString name,QDBusVariant value);
        void audioPropertiesChanged(QString name, QDBusVariant value);
+       void inputPropertiesChanged(QString name, QDBusVariant value);
 
 private:
        OrgBluezDeviceInterface *m_device;
        OrgBluezAudioInterface *audio;
+       OrgBluezInputInterface *input;
 };
 
 #endif // BLUETOOTHDEVICE_H
index 9a551b0..e6afd01 100644 (file)
@@ -29,5 +29,6 @@ namespace BluetoothProfiles
        const char panu[] = "00001115-0000-1000-8000-00805f9b34fb";
        const char nap[] = "00001116-0000-1000-8000-00805f9b34fb";
        const char spp[] = "00001101-0000-1000-8000-00805f9b34fb";
+       const char hid[] = "00001124-0000-1000-8000-00805f9b34fb";
 }
 #endif // BTPROFILES_H
diff --git a/input.xml b/input.xml
new file mode 100644 (file)
index 0000000..d49aac9
--- /dev/null
+++ b/input.xml
@@ -0,0 +1,16 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+          "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.bluez.Input">
+  <method name="Connect"/>
+  <method name="Disconnect"/>
+  <method name="GetProperties">
+   <arg type="a{sv}" direction="out"/>
+   <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
+  </method>
+  <signal name="PropertyChanged">
+    <arg type="s"/>
+    <arg type="v"/>
+    </signal>
+ </interface>
+</node>