From c973c446e39533088a95826b8457e6f18aa0d054 Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Thu, 10 Mar 2016 21:07:34 +0000 Subject: [PATCH 1/6] mpris2: add support for CanGoNext, CanGoPrevious, CanSeek --- src/core/mpris2.cpp | 14 ++++++++++++++ src/core/mpris2.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index ed6db4916..63801b8e0 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -171,6 +171,12 @@ void Mpris2::EmitNotification(const QString& name) { value = Volume(); else if (name == "Position") value = Position(); + else if (name == "CanGoNext") + value = CanGoNext(); + else if (name == "CanGoPrevious") + value = CanGoPrevious(); + else if (name == "CanSeek") + value = CanSeek(); if (value.isValid()) EmitNotification(name, value); } @@ -404,6 +410,14 @@ bool Mpris2::CanSeek() const { } } +bool Mpris2::CanSeek(Engine::State state) const { + if (mpris1_->player()) { + return mpris1_->player()->GetCaps(state) & CAN_SEEK; + } else { + return true; + } +} + bool Mpris2::CanControl() const { return true; } void Mpris2::Next() { diff --git a/src/core/mpris2.h b/src/core/mpris2.h index 48ae27c2b..5c3bfdb11 100644 --- a/src/core/mpris2.h +++ b/src/core/mpris2.h @@ -217,6 +217,8 @@ class Mpris2 : public QObject { QString current_track_id() const; + bool CanSeek(Engine::State state) const; + QString DesktopEntryAbsolutePath() const; private: From 3cf6cdb9255005ff7475d400d1313e6aa8f637e2 Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Thu, 10 Mar 2016 21:14:31 +0000 Subject: [PATCH 2/6] mpris2: more notifications in CurrentSongChanged Emit CanGoNext, CanGoPrevious, CanSeek notifications in CurrentSongChanged --- src/core/mpris2.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index 63801b8e0..8cec66bdc 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -332,7 +332,12 @@ QString Mpris2::current_track_id() const { // We send Metadata change notification as soon as the process of // changing song starts... -void Mpris2::CurrentSongChanged(const Song& song) { ArtLoaded(song, ""); } +void Mpris2::CurrentSongChanged(const Song& song) { + ArtLoaded(song, ""); + EmitNotification("CanGoNext", CanGoNext()); + EmitNotification("CanGoPrevious", CanGoPrevious()); + EmitNotification("CanSeek", CanSeek()); +} // ... and we add the cover information later, when it's available. void Mpris2::ArtLoaded(const Song& song, const QString& art_uri) { From 5f14e887a71f4fa1d44d5ea2626bb8a05a2235bc Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Thu, 10 Mar 2016 21:19:08 +0000 Subject: [PATCH 3/6] mpris2: more notifications in RepeatModeChanged Emit CanGoNext, CanGoPrevious notifications in RepeatModeChanged --- src/core/mpris2.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index 8cec66bdc..4b182c51b 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -140,7 +140,11 @@ void Mpris2::VolumeChanged() { EmitNotification("Volume"); } void Mpris2::ShuffleModeChanged() { EmitNotification("Shuffle"); } -void Mpris2::RepeatModeChanged() { EmitNotification("LoopStatus"); } +void Mpris2::RepeatModeChanged() { + EmitNotification("LoopStatus"); + EmitNotification("CanGoNext", CanGoNext()); + EmitNotification("CanGoPrevious", CanGoPrevious()); +} void Mpris2::EmitNotification(const QString& name, const QVariant& val) { EmitNotification(name, val, "org.mpris.MediaPlayer2.Player"); From 5b066991abc517d219aba92b46fee4c495221635 Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Thu, 10 Mar 2016 21:20:53 +0000 Subject: [PATCH 4/6] playlist: call InformOfCurrentSongChange only after updating the virtual index Calling InformOfCurrentSongChange before updating the virtual index results in sending the CanGoNext and CanGoPrevious notifications with the wrong values. --- src/playlist/playlist.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index 42b68ebef..c653a5528 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -633,10 +633,6 @@ void Playlist::set_current_row(int i, bool is_stopping) { old_current_item_index.row(), ColumnCount - 1)); } - if (current_item_index_.isValid() && !is_stopping) { - InformOfCurrentSongChange(); - } - // Update the virtual index if (i == -1) { current_virtual_index_ = -1; @@ -655,6 +651,10 @@ void Playlist::set_current_row(int i, bool is_stopping) { current_virtual_index_ = i; } + if (current_item_index_.isValid() && !is_stopping) { + InformOfCurrentSongChange(); + } + // The structure of a dynamic playlist is as follows: // history - active song - future // We have to ensure that this invariant is maintained. From 91c144478be6b2beb8223652bc0c365bf8fbf232 Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Thu, 10 Mar 2016 21:29:09 +0000 Subject: [PATCH 5/6] mpris2: emit CanSeek notification in EngineStateChanged When the engine status is Playing must emit the notification CanSeek --- src/core/mpris2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index 4b182c51b..38b279226 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -134,6 +134,8 @@ void Mpris2::EngineStateChanged(Engine::State newState) { } EmitNotification("PlaybackStatus", PlaybackStatus(newState)); + if (newState == Engine::Playing) + EmitNotification("CanSeek", CanSeek(newState)); } void Mpris2::VolumeChanged() { EmitNotification("Volume"); } From 3dd55e1c8627fc42a57918c72c5a22419313f7b1 Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Tue, 29 Mar 2016 21:17:11 -0700 Subject: [PATCH 6/6] mpris2: fix format Minor code refactoring: - Use ternary operator in Mpri2::CanSeek - Run make format --- src/core/mpris2.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index 38b279226..d047d4198 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -187,7 +187,7 @@ void Mpris2::EmitNotification(const QString& name) { if (value.isValid()) EmitNotification(name, value); } - // ------------------Root Interface--------------- // +// ------------------Root Interface--------------- // bool Mpris2::CanQuit() const { return true; } @@ -414,19 +414,12 @@ bool Mpris2::CanPause() const { } bool Mpris2::CanSeek() const { - if (mpris1_->player()) { - return mpris1_->player()->GetCaps() & CAN_SEEK; - } else { - return true; - } + return mpris1_->player() ? mpris1_->player()->GetCaps() & CAN_SEEK : true; } bool Mpris2::CanSeek(Engine::State state) const { - if (mpris1_->player()) { - return mpris1_->player()->GetCaps(state) & CAN_SEEK; - } else { - return true; - } + return mpris1_->player() ? mpris1_->player()->GetCaps(state) & CAN_SEEK + : true; } bool Mpris2::CanControl() const { return true; }