aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General/library/library.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/General/library/library.cpp')
-rw-r--r--src/plugins/General/library/library.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/plugins/General/library/library.cpp b/src/plugins/General/library/library.cpp
index 5b10b600c..14ff9ac7a 100644
--- a/src/plugins/General/library/library.cpp
+++ b/src/plugins/General/library/library.cpp
@@ -123,6 +123,8 @@ bool Library::createTables()
if(!ok)
qWarning("Library: unable to create table, error: %s", qPrintable(query.lastError().text()));
+ removeInvalid();
+
return ok;
}
@@ -133,8 +135,9 @@ void Library::addTrack(TrackInfo *track, const QString &filePath)
return;
QSqlQuery query(db);
- query.prepare("INSERT INTO track_library VALUES("
- "NULL, :timestamp, "
+ query.prepare("INSERT OR REPLACE INTO track_library VALUES("
+ "(SELECT ID FROM track_library WHERE URL = :url), "
+ ":timestamp, "
":title, :artist, :albumartist, :album, :comment, :genre, :composer, "
":year, :track, :discnumber, :duration, "
":audioinfo, :url, :filepath)");
@@ -218,6 +221,9 @@ bool Library::scanDirectories(const QStringList &paths)
return false;
}
+ removeInvalid();
+ qDebug("Library: directory scan finished");
+
return true;
}
@@ -279,6 +285,44 @@ void Library::addDirectory(const QString &s)
}
}
+void Library::removeInvalid()
+{
+ QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME);
+ if(!db.isOpen())
+ return;
+
+ QSqlQuery query(db);
+ if(!query.exec("SELECT FilePath FROM track_library"))
+ {
+ qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
+ return;
+ }
+
+ QString previousPath;
+
+ while (query.next())
+ {
+ QString path = query.value(0).toString();
+ if(previousPath == path)
+ continue;
+
+ previousPath = path;
+
+ if(!QFile::exists(path))
+ {
+ qDebug("Library: removing '%s' from library", qPrintable(path));
+ QSqlQuery rmQuery(db);
+ rmQuery.prepare("DELETE FROM track_library WHERE FilePath = :filepath");
+ rmQuery.bindValue(":filepath", path);
+ if(!rmQuery.exec())
+ {
+ qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
+ return;
+ }
+ }
+ }
+}
+
bool Library::checkFile(const QFileInfo &info)
{
QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME);