diff --git a/src/library/libraryplaylistitem.cpp b/src/library/libraryplaylistitem.cpp index c91ba6500..e166114a4 100644 --- a/src/library/libraryplaylistitem.cpp +++ b/src/library/libraryplaylistitem.cpp @@ -17,7 +17,6 @@ #include "libraryplaylistitem.h" -#include #include LibraryPlaylistItem::LibraryPlaylistItem(const QString& type) diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index 12b511d61..b290ad1c1 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -1123,14 +1123,27 @@ void Playlist::ItemsLoaded() { watcher->deleteLater(); PlaylistItemList items = watcher->future().results(); + + // backend returns empty elements for 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()) { + it.remove(); + } + } + is_loading_ = true; InsertItems(items, 0); is_loading_ = false; PlaylistBackend::Playlist p = backend_->GetPlaylist(id_); - last_played_item_index_ = - p.last_played == -1 ? QModelIndex() : index(p.last_played); + // the newly loaded list of items might be shorter than it was before so + // look out for a bad last_played index + last_played_item_index_ = p.last_played == -1 || p.last_played >= rowCount() + ? QModelIndex() + : index(p.last_played); if (!p.dynamic_type.isEmpty()) { GeneratorPtr gen = Generator::Create(p.dynamic_type); @@ -1361,9 +1374,11 @@ void Playlist::RemoveItemsNotInQueue() { void Playlist::ReloadItems(const QList& rows) { foreach (int row, rows) { - item_at(row)->Reload(); + PlaylistItemPtr item = item_at(row); + + item->Reload(); InformOfCurrentSongChange(index(row, 0), index(row, ColumnCount-1), - item_at(row)->Metadata()); + item->Metadata()); } } diff --git a/src/playlist/playlistbackend.h b/src/playlist/playlistbackend.h index 39098792d..ae3cd0e3b 100644 --- a/src/playlist/playlistbackend.h +++ b/src/playlist/playlistbackend.h @@ -53,13 +53,14 @@ class PlaylistBackend : public QObject { PlaylistList GetAllPlaylists(); Playlist GetPlaylist(int id); PlaylistItemFuture GetPlaylistItems(int playlist); - void SavePlaylistAsync(int playlist, const PlaylistItemList& items, - int last_played, smart_playlists::GeneratorPtr dynamic); + void SetPlaylistOrder(const QList& ids); int CreatePlaylist(const QString& name); - void RemovePlaylist(int id); + void SavePlaylistAsync(int playlist, const PlaylistItemList& items, + int last_played, smart_playlists::GeneratorPtr dynamic); void RenamePlaylist(int id, const QString& new_name); + void RemovePlaylist(int id); void SetLibrary(LibraryBackend* library); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index b6fab59ce..e1876f514 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -342,7 +342,8 @@ void PlaylistManager::SongChangeRequestProcessed(const QUrl& url, bool valid) { Song current_song = current->Metadata(); // if validity has changed, reload the item - if(current_song.url() == url && current_song.filetype() != Song::Type_Stream && + if(current_song.filetype() != Song::Type_Stream && + current_song.filename() == url.toLocalFile() && current_song.is_valid() != QFile::exists(current_song.filename())) { playlist->ReloadItems(QList() << playlist->current_row()); }