Processing BT audio disconnecting
[someplayer] / src / dbusadaptor.cpp
index 72a61a1..a6264f0 100644 (file)
@@ -27,7 +27,6 @@
 #include <QtCore/QVariant>
 #include <QDebug>
 #include "config.h"
-#include "player/player.h"
 
 /*
  * Implementation of adaptor class DBusAdaptop
@@ -44,6 +43,9 @@ DBusAdaptop::DBusAdaptop(QObject *parent)
                                                  "org.freedesktop.Hal.Device", "Condition", this, SLOT(processBTSignal(QString, QString)))) {
                qWarning() << "Can not connect to HAL";
        }
+       if (!QDBusConnection::systemBus().connect(QString(), QString(), "org.bluez.AudioSink", "PropertyChanged", this, SLOT(processBTConnect(QString, QDBusVariant)))) {
+               qWarning() << "Can not connect to HAL 2";
+       }
        setAutoRelaySignals(true);
 }
 
@@ -155,3 +157,17 @@ void DBusAdaptop::pause() {
 void DBusAdaptop::playIfPaused() {
        QMetaObject::invokeMethod(parent(), "playIfPaused");
 }
+
+void DBusAdaptop::processBTConnect(QString stateName, QDBusVariant state) {
+       SomePlayer::Storage::Config config;
+       if (config.getValue("hw/hpautopause").toString() != "yes") {
+               return;
+       }
+       if (stateName == "State") {
+               if (state.variant().toString() == "disconnected") {
+                       pause();
+               } else if (state.variant().toString() == "connected") {
+                       QTimer::singleShot(1000, this, SLOT(playIfPaused()));
+               }
+       }
+}