Merge pull request #5292 from printesoi/fix-mpris-signals

Fix mpris dbus notifications
This commit is contained in:
John Maguire 2016-03-30 15:36:04 +01:00
commit 9c33369fcc
3 changed files with 32 additions and 12 deletions

View File

@ -134,13 +134,19 @@ void Mpris2::EngineStateChanged(Engine::State newState) {
} }
EmitNotification("PlaybackStatus", PlaybackStatus(newState)); EmitNotification("PlaybackStatus", PlaybackStatus(newState));
if (newState == Engine::Playing)
EmitNotification("CanSeek", CanSeek(newState));
} }
void Mpris2::VolumeChanged() { EmitNotification("Volume"); } void Mpris2::VolumeChanged() { EmitNotification("Volume"); }
void Mpris2::ShuffleModeChanged() { EmitNotification("Shuffle"); } 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) { void Mpris2::EmitNotification(const QString& name, const QVariant& val) {
EmitNotification(name, val, "org.mpris.MediaPlayer2.Player"); EmitNotification(name, val, "org.mpris.MediaPlayer2.Player");
@ -171,11 +177,17 @@ void Mpris2::EmitNotification(const QString& name) {
value = Volume(); value = Volume();
else if (name == "Position") else if (name == "Position")
value = 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); if (value.isValid()) EmitNotification(name, value);
} }
// ------------------Root Interface--------------- // // ------------------Root Interface--------------- //
bool Mpris2::CanQuit() const { return true; } 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 // We send Metadata change notification as soon as the process of
// changing song starts... // 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. // ... and we add the cover information later, when it's available.
void Mpris2::ArtLoaded(const Song& song, const QString& art_uri) { void Mpris2::ArtLoaded(const Song& song, const QString& art_uri) {
@ -397,11 +414,12 @@ bool Mpris2::CanPause() const {
} }
bool Mpris2::CanSeek() const { bool Mpris2::CanSeek() const {
if (mpris1_->player()) { return mpris1_->player() ? mpris1_->player()->GetCaps() & CAN_SEEK : true;
return mpris1_->player()->GetCaps() & CAN_SEEK; }
} else {
return true; bool Mpris2::CanSeek(Engine::State state) const {
} return mpris1_->player() ? mpris1_->player()->GetCaps(state) & CAN_SEEK
: true;
} }
bool Mpris2::CanControl() const { return true; } bool Mpris2::CanControl() const { return true; }

View File

@ -217,6 +217,8 @@ class Mpris2 : public QObject {
QString current_track_id() const; QString current_track_id() const;
bool CanSeek(Engine::State state) const;
QString DesktopEntryAbsolutePath() const; QString DesktopEntryAbsolutePath() const;
private: private:

View File

@ -633,10 +633,6 @@ void Playlist::set_current_row(int i, bool is_stopping) {
old_current_item_index.row(), ColumnCount - 1)); old_current_item_index.row(), ColumnCount - 1));
} }
if (current_item_index_.isValid() && !is_stopping) {
InformOfCurrentSongChange();
}
// Update the virtual index // Update the virtual index
if (i == -1) { if (i == -1) {
current_virtual_index_ = -1; current_virtual_index_ = -1;
@ -655,6 +651,10 @@ void Playlist::set_current_row(int i, bool is_stopping) {
current_virtual_index_ = i; current_virtual_index_ = i;
} }
if (current_item_index_.isValid() && !is_stopping) {
InformOfCurrentSongChange();
}
// The structure of a dynamic playlist is as follows: // The structure of a dynamic playlist is as follows:
// history - active song - future // history - active song - future
// We have to ensure that this invariant is maintained. // We have to ensure that this invariant is maintained.