mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 12:02:48 +01:00
Remove all existing magnatune songs before reloading the database
This commit is contained in:
parent
575d44144c
commit
a5102a2b27
@ -145,8 +145,9 @@ void LibraryBackend::RemoveDirectory(const Directory& dir) {
|
||||
SongList LibraryBackend::FindSongsInDirectory(int id) {
|
||||
QSqlDatabase db(db_->Connect());
|
||||
|
||||
QSqlQuery q("SELECT ROWID, " + Song::kColumnSpec +
|
||||
" FROM songs WHERE directory = :directory", db);
|
||||
QSqlQuery q(QString("SELECT ROWID, " + Song::kColumnSpec +
|
||||
" FROM %1 WHERE directory = :directory")
|
||||
.arg(songs_table_), db);
|
||||
q.bindValue(":directory", id);
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q.lastError())) return SongList();
|
||||
|
@ -126,6 +126,7 @@ void MagnatuneService::ReloadDatabaseFinished() {
|
||||
|
||||
root_->ClearNotify();
|
||||
|
||||
// The XML file is compressed
|
||||
QtIOCompressor gzip(reply);
|
||||
gzip.setStreamFormat(QtIOCompressor::GzipFormat);
|
||||
if (!gzip.open(QIODevice::ReadOnly)) {
|
||||
@ -133,8 +134,13 @@ void MagnatuneService::ReloadDatabaseFinished() {
|
||||
return;
|
||||
}
|
||||
|
||||
SongList songs;
|
||||
// Remove all existing songs in the database
|
||||
// FindSongsByDirectory isn't the nicest way to do it, but it's easy
|
||||
SongList songs = library_backend_->FindSongsInDirectory(0);
|
||||
library_backend_->DeleteSongs(songs);
|
||||
songs.clear();
|
||||
|
||||
// Parse the XML we got from Magnatune
|
||||
QXmlStreamReader reader(&gzip);
|
||||
while (!reader.atEnd()) {
|
||||
reader.readNext();
|
||||
@ -145,6 +151,7 @@ void MagnatuneService::ReloadDatabaseFinished() {
|
||||
}
|
||||
}
|
||||
|
||||
// Add the songs to the database
|
||||
library_backend_->AddOrUpdateSongs(songs);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user