From a883508eca7faf3453ebb70433dc1543ddd25b65 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 5 Jun 2021 02:50:20 +0200 Subject: [PATCH] Fix marking CUE songs available --- src/collection/collectionbackend.cpp | 5 +++-- src/collection/collectionbackend.h | 4 ++-- src/collection/collectionwatcher.cpp | 11 +++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/collection/collectionbackend.cpp b/src/collection/collectionbackend.cpp index 3809656ac..e7da72b27 100644 --- a/src/collection/collectionbackend.cpp +++ b/src/collection/collectionbackend.cpp @@ -838,18 +838,19 @@ Song CollectionBackend::GetSongByUrl(const QUrl &url, const qint64 beginning) { } -SongList CollectionBackend::GetSongsByUrl(const QUrl &url) { +SongList CollectionBackend::GetSongsByUrl(const QUrl &url, const bool unavailable) { QMutexLocker l(db_->Mutex()); QSqlDatabase db(db_->Connect()); QSqlQuery q(db); - q.prepare(QString("SELECT ROWID, " + Song::kColumnSpec + " FROM %1 WHERE (url = :url1 OR url = :url2 OR url = :url3 OR url = :url4) AND unavailable = 0").arg(songs_table_)); + q.prepare(QString("SELECT ROWID, " + Song::kColumnSpec + " FROM %1 WHERE (url = :url1 OR url = :url2 OR url = :url3 OR url = :url4) AND unavailable = :unavailable").arg(songs_table_)); q.bindValue(":url1", url); q.bindValue(":url2", url.toString()); q.bindValue(":url3", url.toString(QUrl::FullyEncoded)); q.bindValue(":url4", url.toEncoded()); + q.bindValue(":unavailable", (unavailable ? 1 : 0)); SongList songs; if (q.exec()) { diff --git a/src/collection/collectionbackend.h b/src/collection/collectionbackend.h index 4dcf20622..8316ef79f 100644 --- a/src/collection/collectionbackend.h +++ b/src/collection/collectionbackend.h @@ -107,7 +107,7 @@ class CollectionBackendInterface : public QObject { virtual Song GetSongById(const int id) = 0; // Returns all sections of a song with the given filename. If there's just one section the resulting list will have it's size equal to 1. - virtual SongList GetSongsByUrl(const QUrl &url) = 0; + virtual SongList GetSongsByUrl(const QUrl &url, const bool unavailable = false) = 0; // Returns a section of a song with the given filename and beginning. If the section is not present in collection, returns invalid song. // Using default beginning value is suitable when searching for single-section songs. virtual Song GetSongByUrl(const QUrl &url, const qint64 beginning = 0) = 0; @@ -170,7 +170,7 @@ class CollectionBackend : public CollectionBackendInterface { SongList GetSongsById(const QStringList &ids); SongList GetSongsByForeignId(const QStringList &ids, const QString &table, const QString &column); - SongList GetSongsByUrl(const QUrl &url) override; + SongList GetSongsByUrl(const QUrl &url, const bool unavailable = false) override; Song GetSongByUrl(const QUrl &url, qint64 beginning = 0) override; void AddDirectory(const QString &path) override; diff --git a/src/collection/collectionwatcher.cpp b/src/collection/collectionwatcher.cpp index 8f55938cb..ab3526f9d 100644 --- a/src/collection/collectionwatcher.cpp +++ b/src/collection/collectionwatcher.cpp @@ -470,8 +470,15 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory } } - // nothing has changed - mark the song available without re-scanning - if (matching_song.is_unavailable()) t->readded_songs << matching_song; + // Nothing has changed - mark the song available without re-scanning + if (matching_song.is_unavailable()) { + if (matching_song.has_cue()) { + t->readded_songs << backend_->GetSongsByUrl(QUrl::fromLocalFile(file), true); + } + else { + t->readded_songs << matching_song; + } + } } else {