Added Bluetooth AVRCP support via HAL/DBus
authorNikolay Tischenko <niktischenko@gmail.com>
Fri, 19 Nov 2010 21:11:31 +0000 (03:11 +0600)
committerNikolay Tischenko <niktischenko@gmail.com>
Fri, 19 Nov 2010 21:11:31 +0000 (03:11 +0600)
src/dbusadaptor.cpp
src/dbusadaptor.h

index 25b90e0..64a9d91 100644 (file)
@@ -25,6 +25,7 @@
 #include <QtCore/QString>
 #include <QtCore/QStringList>
 #include <QtCore/QVariant>
+#include <QDebug>
 
 /*
  * Implementation of adaptor class DBusAdaptop
@@ -35,6 +36,12 @@ DBusAdaptop::DBusAdaptop(QObject *parent)
 {
     // constructor
     setAutoRelaySignals(true);
+    // handling signals from bluetooth headset
+    _time = QTime::currentTime();
+    if (!QDBusConnection::systemBus().connect(QString(), QString(),
+       "org.freedesktop.Hal.Device", "Condition", this, SLOT(processBTSignal(QString, QString)))) {
+           qWarning() << "Can not connect to HAL";
+    }
 }
 
 DBusAdaptop::~DBusAdaptop()
@@ -90,3 +97,20 @@ void DBusAdaptop::toggle()
     QMetaObject::invokeMethod(parent(), "toggle");
 }
 
+void DBusAdaptop::processBTSignal(QString event, QString state) {
+       QTime t = QTime::currentTime();
+       long msec = _time.msecsTo(t);
+       if (msec > _DBUS_ACTION_TIMEOUT_) {
+               if (event == "ButtonPressed") {
+                       if (state == "next-song") {
+                               QMetaObject::invokeMethod(parent(), "next");
+                       } else if (state == "previous-song") {
+                               QMetaObject::invokeMethod(parent(), "prev");
+                       } else if (state == "play-cd" || state == "pause-cd") {
+                               QMetaObject::invokeMethod(parent(), "toggle");
+                       }
+               }
+       }
+       _time = t;
+}
+
index 30ebd0b..9c82b67 100644 (file)
 
 #include <QtCore/QObject>
 #include <QtDBus/QtDBus>
+#include <QTime>
+
+#define _DBUS_ACTION_TIMEOUT_ (500)
+
 class QByteArray;
 template<class T> class QList;
 template<class Key, class Value> class QMap;
@@ -74,7 +78,11 @@ public Q_SLOTS: // METHODS
     Q_NOREPLY void stop();
     QString title();
     Q_NOREPLY void toggle();
+
+    void processBTSignal(QString, QString);
 Q_SIGNALS: // SIGNALS
+private:
+       QTime _time;
 };
 
 #endif