From e6b7e5e0fccef756398982bd51137bb433df7f4a Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 21 Mar 2015 07:10:32 +0100 Subject: Fixed and beefed up "Move to archive" It crashed when used on directories, because naturally md5sum was empty. So recurse through directories, collect files and check if we have a DB- Entry. If so, move the files back to archive. If not, skip them. --- archivemodel.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'archivemodel.cpp') diff --git a/archivemodel.cpp b/archivemodel.cpp index 695dd09..d1580de 100644 --- a/archivemodel.cpp +++ b/archivemodel.cpp @@ -1001,6 +1001,33 @@ void ArchiveFilesModel::updateSeriesPartForFile(const QString &md5sum, int newSe q.exec(); } +bool ArchiveFilesModel::hasFile(const QString &md5){ + if(md5.isEmpty()){ + return false; + } + QSqlDatabase db = QSqlDatabase::database("treedb"); + QSqlQuery fileQ(db); + fileQ.prepare("SELECT COUNT(*) FROM files WHERE cmd5sum = :md5"); + fileQ.bindValue(":md5", md5); + bool retval = false; + fileQ.exec(); + while(fileQ.next()){ + if(fileQ.value(0).toInt() == 1){ + retval = true; + } + } + return retval; +} + +bool ArchiveFilesModel::setDvdNo(const QString &md5, int dvdno){ + QSqlDatabase db = QSqlDatabase::database("treedb"); + QSqlQuery dvdNoQ(db); + dvdNoQ.prepare("UPDATE files SET idvd = :dvdno WHERE cmd5sum = :md5"); + dvdNoQ.bindValue(":dvdno", dvdno); + dvdNoQ.bindValue(":md5", md5); + return dvdNoQ.exec(); +} + void ArchiveFilesModel::refresh(){ populate(mSeriesPartIds); } -- cgit v1.2.3-70-g09d2