Processing BT audio disconnecting
[someplayer] / src / dbusadaptor.cpp
index 83c1d5a..a6264f0 100644 (file)
@@ -43,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);
 }
 
@@ -154,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()));
+               }
+       }
+}