1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-01-29 16:49:27 +01:00

Playlist: Invalidate deleted songs in main thread

Fixes #1625
This commit is contained in:
Jonas Kvinge 2025-01-04 00:16:36 +01:00
parent a13fc31f83
commit a96627c5a9
2 changed files with 8 additions and 24 deletions

View File

@ -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<int> &rows) {
}
void Playlist::ReloadItemsBlocking(const QList<int> &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);
}
}

View File

@ -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<int> &rows);
void ReloadItemsBlocking(const QList<int> &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();