From a96627c5a93fa33e3cdd5573aab18480e3044dc1 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 4 Jan 2025 00:16:36 +0100 Subject: [PATCH] Playlist: Invalidate deleted songs in main thread Fixes #1625 --- src/playlist/playlist.cpp | 25 ++++--------------------- src/playlist/playlist.h | 7 ++++--- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index d5cee5725..9485c9690 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -1637,7 +1637,7 @@ void Playlist::ItemsLoaded() { // Should we gray out deleted songs asynchronously on startup? if (greyout) { - (void)QtConcurrent::run(&Playlist::InvalidateDeletedSongs, this); + InvalidateDeletedSongs(); } Q_EMIT PlaylistLoaded(); @@ -1921,18 +1921,6 @@ void Playlist::ReloadItems(const QList &rows) { } -void Playlist::ReloadItemsBlocking(const QList &rows) { - - for (const int row : rows) { - PlaylistItemPtr item = item_at(row); - const Song old_metadata = item->Metadata(); - item->Reload(); - QPersistentModelIndex idx = index(row, 0); - ItemReloadComplete(idx, old_metadata, false); - } - -} - void Playlist::Shuffle() { PlaylistItemPtrList new_items(items_); @@ -2312,8 +2300,8 @@ void Playlist::InvalidateDeletedSongs() { PlaylistItemPtr item = items_.value(row); const Song song = item->Metadata(); - if (song.url().isLocalFile()) { - bool exists = QFile::exists(song.url().toLocalFile()); + if (song.url().isValid() && song.url().isLocalFile()) { + const bool exists = QFile::exists(song.url().toLocalFile()); if (!exists && !item->HasForegroundColor(kInvalidSongPriority)) { // Gray out the song if it's not there @@ -2328,12 +2316,7 @@ void Playlist::InvalidateDeletedSongs() { } if (!invalidated_rows.isEmpty()) { - if (QThread::currentThread() == thread()) { - ReloadItems(invalidated_rows); - } - else { - ReloadItemsBlocking(invalidated_rows); - } + ReloadItems(invalidated_rows); } } diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index f4ac6cc52..11d8fe5ea 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -239,14 +239,12 @@ class Playlist : public QAbstractListModel { // song will be reloaded to even out the situation because obviously something has changed. // This returns true if this playlist had current item when the method was invoked. bool ApplyValidityOnCurrentSong(const QUrl &url, bool valid); - // Grays out and reloads all deleted songs in all playlists. Also, "ungreys" those songs which were once deleted but now got restored somehow. - void InvalidateDeletedSongs(); + // Removes from the playlist all local files that don't exist anymore. void RemoveDeletedSongs(); void StopAfter(const int row); void ReloadItems(const QList &rows); - void ReloadItemsBlocking(const QList &rows); void InformOfCurrentSongChange(const bool minor); // Just emits the dataChanged() signal so the mood column is repainted. @@ -354,6 +352,9 @@ class Playlist : public QAbstractListModel { void TurnOnDynamicPlaylist(PlaylistGeneratorPtr gen); void InsertDynamicItems(const int count); + // Grays out and reloads all deleted songs in all playlists. Also, "ungreys" those songs which were once deleted but now got restored somehow. + void InvalidateDeletedSongs(); + private Q_SLOTS: void TracksAboutToBeDequeued(const QModelIndex&, const int begin, const int end); void TracksDequeued();