From 47e8c037f730a5a6187f84f9b3b5d48952dfd1af Mon Sep 17 00:00:00 2001 From: Nikolay Tischenko Date: Sat, 20 Nov 2010 03:11:31 +0600 Subject: [PATCH] Added Bluetooth AVRCP support via HAL/DBus --- src/dbusadaptor.cpp | 24 ++++++++++++++++++++++++ src/dbusadaptor.h | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/src/dbusadaptor.cpp b/src/dbusadaptor.cpp index 25b90e0..64a9d91 100644 --- a/src/dbusadaptor.cpp +++ b/src/dbusadaptor.cpp @@ -25,6 +25,7 @@ #include #include #include +#include /* * 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; +} + diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h index 30ebd0b..9c82b67 100644 --- a/src/dbusadaptor.h +++ b/src/dbusadaptor.h @@ -22,6 +22,10 @@ #include #include +#include + +#define _DBUS_ACTION_TIMEOUT_ (500) + class QByteArray; template class QList; template 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 -- 1.7.9.5