From e619d7a2802ed8e29b60918713c0327d9268c26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bara?= Date: Sun, 20 Mar 2011 16:07:24 +0000 Subject: [PATCH] fixing a bug where streams were removed from playlist during Clementine's startup --- src/core/player.cpp | 2 +- src/library/libraryplaylistitem.h | 2 +- src/playlist/playlist.cpp | 11 +++++++---- src/playlist/playlistitem.h | 3 +++ src/scripting/python/playlistitem.sip | 7 +++++-- src/ui/mainwindow.cpp | 8 +++++--- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/core/player.cpp b/src/core/player.cpp index af5d822be..8f60ea259 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -154,7 +154,7 @@ void Player::TrackEnded() { } if (current_item_ && current_item_->IsLocalLibraryItem() && - !playlists_->active()->has_scrobbled()) { + current_item_->Metadata().id() != -1 && !playlists_->active()->has_scrobbled()) { // The track finished before its scrobble point (30 seconds), so increment // the play count now. playlists_->library_backend()->IncrementPlayCountAsync( diff --git a/src/library/libraryplaylistitem.h b/src/library/libraryplaylistitem.h index 367f60cf9..1dbc49cc0 100644 --- a/src/library/libraryplaylistitem.h +++ b/src/library/libraryplaylistitem.h @@ -34,7 +34,7 @@ class LibraryPlaylistItem : public PlaylistItem { QUrl Url() const; - bool IsLocalLibraryItem() const { return song_.id() != -1; } + bool IsLocalLibraryItem() const { return true; } protected: QVariant DatabaseValue(DatabaseColumn column) const; diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index ef1ed4d24..022830de5 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -235,7 +235,8 @@ QVariant Playlist::data(const QModelIndex& index, int role) const { case Role_CanSetRating: return index.column() == Column_Rating && - items_[index.row()]->IsLocalLibraryItem(); + items_[index.row()]->IsLocalLibraryItem() && + items_[index.row()]->Metadata().id() != -1; case Qt::EditRole: case Qt::ToolTipRole: @@ -1130,11 +1131,13 @@ void Playlist::ItemsLoaded() { PlaylistItemList items = watcher->future().results(); - // backend returns empty elements for items which it couldn't + // backend returns empty elements for library items which it couldn't // match (because they got deleted); we don't need those QMutableListIterator it(items); while (it.hasNext()) { - if (it.next()->Metadata().filename().isEmpty()) { + PlaylistItemPtr item = it.next(); + + if (item->IsLocalLibraryItem() && item->Metadata().filename().isEmpty()) { it.remove(); } } @@ -1402,7 +1405,7 @@ void Playlist::RateSong(const QModelIndex& index, double rating) { if(has_item_at(row)) { PlaylistItemPtr item = item_at(row); - if (item && item->IsLocalLibraryItem()) { + if (item && item->IsLocalLibraryItem() && item->Metadata().id() != -1) { library_->UpdateSongRatingAsync(item->Metadata().id(), rating); } } diff --git a/src/playlist/playlistitem.h b/src/playlist/playlistitem.h index 867f3e3dd..c2486e057 100644 --- a/src/playlist/playlistitem.h +++ b/src/playlist/playlistitem.h @@ -130,6 +130,9 @@ class PlaylistItem : public boost::enable_shared_from_this { // Convenience function to find out whether this item is from the local // library, as opposed to a device, a file on disk, or a stream. + // Remember that even if this returns true, the library item might be + // invalid so you might want to check that it's id is not equal to -1 + // before actually using it. virtual bool IsLocalLibraryItem() const { return false; } protected: diff --git a/src/scripting/python/playlistitem.sip b/src/scripting/python/playlistitem.sip index 720436c69..27835c872 100644 --- a/src/scripting/python/playlistitem.sip +++ b/src/scripting/python/playlistitem.sip @@ -177,8 +177,11 @@ Returns true if L{SetTemporaryMetadata()} has been called. bool IsLocalLibraryItem() const; %Docstring IsLocalLibraryItem() -> bool -Convenience function to check whether this item is from the local library (the -list of songs appearing in the Library tab). +Convenience function to check whether this item is from the local +library, as opposed to a device, a file on disk or a stream. +Remember that even if this returns true, the library item might be +invalid so you might want to check that it's id is not equal to -1 +before actually using it. %End void SetBackgroundColor(short priority, const QColor& color); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 84cf5b205..e171c0ce5 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -847,7 +847,8 @@ void MainWindow::SongChanged(const Song& song) { void MainWindow::TrackSkipped(PlaylistItemPtr item) { // If it was a library item then we have to increment its skipped count in // the database. - if (item && item->IsLocalLibraryItem() && !playlists_->active()->has_scrobbled()) { + if (item && item->IsLocalLibraryItem() && + item->Metadata().id() != -1 && !playlists_->active()->has_scrobbled()) { Song song = item->Metadata(); const qint64 position = player_->engine()->position_nanosec(); const qint64 length = player_->engine()->length_nanosec(); @@ -989,7 +990,7 @@ void MainWindow::UpdateTrackPosition() { playlists_->active()->set_scrobbled(true); // Update the play count for the song if it's from the library - if (item->IsLocalLibraryItem()) { + if (item->IsLocalLibraryItem() && item->Metadata().id() != -1) { library_->backend()->IncrementPlayCountAsync(item->Metadata().id()); } } @@ -1191,7 +1192,8 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex& ui_->action_edit_value->setText(tr("Edit tag \"%1\"...").arg(column_name)); // Is it a library item? - if (playlists_->current()->item_at(source_index.row())->IsLocalLibraryItem()) { + PlaylistItemPtr item = playlists_->current()->item_at(source_index.row()); + if (item->IsLocalLibraryItem() && item->Metadata().id() != -1) { playlist_organise_->setVisible(editable); } else { playlist_copy_to_library_->setVisible(editable);