From 3bf175c871cac7d6b60d8263196262ea5ffcda74 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 20 Apr 2017 20:26:12 -0700 Subject: dbus: monitor for udisks media removal events This makes assumptions that there is only one media device allowed at a time. Bug-AGL: SPEC-527 Change-Id: Ide3d760f147551945cc14b7f6b66bd025634a17b Signed-off-by: Matt Ranostay --- app/MediaPlayer.qml | 7 +++++++ app/dbus.cpp | 17 ++++++++++++++++- app/dbus.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml index 9019a3f..a937bc6 100644 --- a/app/MediaPlayer.qml +++ b/app/MediaPlayer.qml @@ -46,6 +46,13 @@ ApplicationWindow { Connections { target: dbus + onStopPlayback: { + player.stop() + playlist.clear() + playlistmodel.setSource(playlist) + playlistview.visible = false + } + onProcessPlaylistUpdate: { playlist.clear() playlist.addItems(mediaFiles) diff --git a/app/dbus.cpp b/app/dbus.cpp index 0deb4ee..3c298a0 100644 --- a/app/dbus.cpp +++ b/app/dbus.cpp @@ -28,11 +28,26 @@ DbusService::DbusService(QObject *parent) : QObject(parent) bool DbusService::enableLMS() { QDBusConnection session_bus = QDBusConnection::sessionBus(); + QDBusConnection system_bus = QDBusConnection::systemBus(); + bool ret; if (!session_bus.isConnected()) return false; - return session_bus.connect(QString("org.lightmediascanner"), QString("/org/lightmediascanner/Scanner1"), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(lmsUpdate(QString,QVariantMap,QStringList))); + if (!system_bus.isConnected()) + return false; + + ret = session_bus.connect(QString("org.lightmediascanner"), QString("/org/lightmediascanner/Scanner1"), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(lmsUpdate(QString,QVariantMap,QStringList))); + if (!ret) + return false; + + /* Only subscribe to DeviceRemoved events, since we need lms scan to complete on insert */ + return system_bus.connect(QString("org.freedesktop.UDisks"), QString("/org/freedesktop/UDisks"), "org.freedesktop.UDisks", "DeviceRemoved", this, SLOT(mediaRemoved(QDBusObjectPath))); +} + +void DbusService::mediaRemoved(const QDBusObjectPath&) +{ + emit stopPlayback(); } #if defined(HAVE_LIGHTMEDIASCANNER) diff --git a/app/dbus.h b/app/dbus.h index b2cfeb4..2dd6e34 100644 --- a/app/dbus.h +++ b/app/dbus.h @@ -54,11 +54,13 @@ signals: void processPlaylistShow(); void displayBluetoothMetadata(const QString& avrcp_artist, const QString& avrcp_title, const int avrcp_duration); + void stopPlayback(); void updatePosition(const int current_position); void updatePlayerStatus(const QString status); private slots: void lmsUpdate(const QString&, const QVariantMap&, const QStringList&); + void mediaRemoved(const QDBusObjectPath&); void newBluetoothDevice(const QDBusObjectPath&, const QVariantMap&); void removeBluetoothDevice(const QDBusObjectPath&, const QStringList&); void processBluetoothEvent(const QString&, const QVariantMap&, const QStringList&); -- cgit 1.2.3-korg