1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Fix some possible crashes when requesting MPRIS data during Clementine's startup

This commit is contained in:
David Sansome 2012-08-17 14:35:24 +01:00
parent 0b97b8c74b
commit 6fca8b1c3d
2 changed files with 27 additions and 19 deletions

View File

@ -197,14 +197,16 @@ DBusStatus Mpris1Player::GetStatus(Engine::State state) const {
break;
}
PlaylistManagerInterface* playlists_ = app_->playlist_manager();
PlaylistSequence::RepeatMode repeat_mode = playlists_->sequence()->repeat_mode();
status.random = playlists_->sequence()->shuffle_mode() == PlaylistSequence::Shuffle_Off ? 0 : 1;
status.repeat = repeat_mode == PlaylistSequence::Repeat_Track ? 1 : 0;
status.repeat_playlist = (repeat_mode == PlaylistSequence::Repeat_Album ||
repeat_mode == PlaylistSequence::Repeat_Playlist ||
repeat_mode == PlaylistSequence::Repeat_Track) ? 1 : 0;
if (app_->playlist_manager()->sequence()) {
PlaylistManagerInterface* playlists_ = app_->playlist_manager();
PlaylistSequence::RepeatMode repeat_mode = playlists_->sequence()->repeat_mode();
status.random = playlists_->sequence()->shuffle_mode() == PlaylistSequence::Shuffle_Off ? 0 : 1;
status.repeat = repeat_mode == PlaylistSequence::Repeat_Track ? 1 : 0;
status.repeat_playlist = (repeat_mode == PlaylistSequence::Repeat_Album ||
repeat_mode == PlaylistSequence::Repeat_Playlist ||
repeat_mode == PlaylistSequence::Repeat_Track) ? 1 : 0;
}
return status;
}
@ -238,10 +240,19 @@ int Mpris1Player::GetCaps(Engine::State state) const {
PlaylistItemPtr current_item = app_->player()->GetCurrentItem();
PlaylistManagerInterface* playlists = app_->playlist_manager();
// play is disabled when playlist is empty or when last.fm stream is already playing
if (playlists->active()->rowCount() != 0
&& !(state == Engine::Playing && (app_->player()->GetCurrentItem()->options() & PlaylistItem::LastFMControls))) {
caps |= CAN_PLAY;
if (playlists->active()) {
// play is disabled when playlist is empty or when last.fm stream is already playing
if (playlists->active() && playlists->active()->rowCount() != 0
&& !(state == Engine::Playing && (app_->player()->GetCurrentItem()->options() & PlaylistItem::LastFMControls))) {
caps |= CAN_PLAY;
}
if (playlists->active()->next_row() != -1) {
caps |= CAN_GO_NEXT;
}
if (playlists->active()->previous_row() != -1) {
caps |= CAN_GO_PREV;
}
}
if (current_item) {
@ -254,13 +265,6 @@ int Mpris1Player::GetCaps(Engine::State state) const {
}
}
if (playlists->active()->next_row() != -1) {
caps |= CAN_GO_NEXT;
}
if (playlists->active()->previous_row() != -1) {
caps |= CAN_GO_PREV;
}
return caps;
}

View File

@ -234,6 +234,10 @@ QString Mpris2::PlaybackStatus(Engine::State state) const {
}
QString Mpris2::LoopStatus() const {
if (!app_->playlist_manager()->sequence()) {
return "None";
}
switch (app_->playlist_manager()->sequence()->repeat_mode()) {
case PlaylistSequence::Repeat_Album:
case PlaylistSequence::Repeat_Playlist: return "Playlist";