Fix marking CUE songs available

This commit is contained in:
Jonas Kvinge 2021-06-05 02:50:20 +02:00
parent a4a20ec220
commit a883508eca
3 changed files with 14 additions and 6 deletions

View File

@ -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()) {

View File

@ -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;

View File

@ -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 {