From 6fca8b1c3dd6f9fe413571d537c959c91cf177e3 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Fri, 17 Aug 2012 14:35:24 +0100 Subject: [PATCH] Fix some possible crashes when requesting MPRIS data during Clementine's startup --- src/core/mpris1.cpp | 42 +++++++++++++++++++++++------------------- src/core/mpris2.cpp | 4 ++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/core/mpris1.cpp b/src/core/mpris1.cpp index bf1141860..b2f63f8bf 100644 --- a/src/core/mpris1.cpp +++ b/src/core/mpris1.cpp @@ -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; } diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index 674e67e14..8146f74d5 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -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";