diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index ed6db4916..d047d4198 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -134,13 +134,19 @@ void Mpris2::EngineStateChanged(Engine::State newState) { } EmitNotification("PlaybackStatus", PlaybackStatus(newState)); + if (newState == Engine::Playing) + EmitNotification("CanSeek", CanSeek(newState)); } 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"); @@ -171,11 +177,17 @@ 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); } - // ------------------Root Interface--------------- // +// ------------------Root Interface--------------- // bool Mpris2::CanQuit() const { return true; } @@ -326,7 +338,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) { @@ -397,11 +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 { + return mpris1_->player() ? mpris1_->player()->GetCaps(state) & CAN_SEEK + : true; } bool Mpris2::CanControl() const { return true; } 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: 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.