Confirmation dialogs for dangerous actions
[someplayer] / src / dbusadaptor.cpp
index 64a9d91..ac341e0 100644 (file)
@@ -26,6 +26,7 @@
 #include <QtCore/QStringList>
 #include <QtCore/QVariant>
 #include <QDebug>
+#include "config.h"
 
 /*
  * Implementation of adaptor class DBusAdaptop
@@ -103,14 +104,36 @@ void DBusAdaptop::processBTSignal(QString event, QString state) {
        if (msec > _DBUS_ACTION_TIMEOUT_) {
                if (event == "ButtonPressed") {
                        if (state == "next-song") {
-                               QMetaObject::invokeMethod(parent(), "next");
+                               next();
                        } else if (state == "previous-song") {
-                               QMetaObject::invokeMethod(parent(), "prev");
+                               prev();
                        } else if (state == "play-cd" || state == "pause-cd") {
-                               QMetaObject::invokeMethod(parent(), "toggle");
+                               toggle();
+                       } else if (state == "connection") {
+                               SomePlayer::Storage::Config config;
+                               if (config.getValue("hw/hpautopause").toString() != "yes") {
+                                       return;
+                               }
+                               bool present = QDBusInterface ("org.freedesktop.Hal",
+                                                              "/org/freedesktop/Hal/devices/platform_headphone",
+                                                              "org.freedesktop.Hal.Device",
+                                                              QDBusConnection::systemBus()).call ("GetProperty", "button.state.value").arguments().at(0).toBool();
+                               if (!present) {
+                                       pause();
+                               } else {
+                                       QTimer::singleShot(1000, this, SLOT(playIfPaused()));
+                               }
+
                        }
                }
        }
        _time = t;
 }
 
+void DBusAdaptop::pause() {
+       QMetaObject::invokeMethod(parent(), "pause");
+}
+
+void DBusAdaptop::playIfPaused() {
+       QMetaObject::invokeMethod(parent(), "playIfPaused");
+}