From 7f3d33ab7e02ab34efb2e0db9a7a912c66de7eef Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 3 Jan 2018 12:14:37 +0100 Subject: Check Present attribute on cached data Well, we cannot cache the Present attribute, because it can change without our knowledge, when a movie file has been archived in the meantime. Leave it in CachedFileData for now, but check it when we found a cache entry. While working on this, I realized that the Origin attribute is pretty much useless, at least in its current form. countMd5() already checks the origin table, and everything else was guesswork on the filename. Also, it was an extra, quite expensive SQL-Query for every video file, so remove it. --- filewidget.cpp | 28 +++++----------------------- filewidget.h | 4 +--- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/filewidget.cpp b/filewidget.cpp index b637e4c..92956cf 100644 --- a/filewidget.cpp +++ b/filewidget.cpp @@ -133,8 +133,6 @@ void FileWidget::setupGui(){ mQOrigin.prepare("SELECT COUNT(*) FROM files_origin WHERE cmd5sum = :md5"); mQFiles = QSqlQuery(mDb); mQFiles.prepare("SELECT COUNT(*) FROM files WHERE cmd5sum = :md5"); - mQSimilar = QSqlQuery(mDb); - mQSimilar.prepare("SELECT ifiles_id, tfilename FROM files WHERE tfilename ~ :fn AND files.ifiles_id NOT IN (SELECT ifiles_id FROM files_origin WHERE ifiles_id = files.ifiles_id)"); mFileDisplay = new FileDisplay(this); mOrignDlg = new OriginDialog(this); @@ -298,14 +296,6 @@ void FileWidget::gatherData(){ int haveFile = md5Count(md5); if(haveFile){ fd->attr = Present; - }else{ - QString complFn = fi.completeBaseName(); - bool hasOrig = haveOrigin(complFn); - if(hasOrig){ - fd->attr = Origin; - }else{ - fd->attr = NotPresent; - } } QJsonDocument jDoc = Helper::ffpmegData(fi.absoluteFilePath()); QJsonObject jObj = jDoc.object(); @@ -344,6 +334,11 @@ void FileWidget::gatherData(){ if(insert){ mFileCache.insert(fi.absoluteFilePath(), fd); } + }else{ + int haveFile = md5Count(fd->md5Sum); + if(haveFile){ + fd->attr = Present; + } } root->appendRow(constructRow(fd)); } @@ -373,16 +368,6 @@ int FileWidget::md5Count(const QString &md5) { return retval; } -bool FileWidget::haveOrigin(const QString filename){ - bool retval = false; - mQSimilar.bindValue(":fn", filename); - mQSimilar.exec(); - while(mQSimilar.next()){ - retval = true; - } - return retval; -} - void FileWidget::readHeaderData(){ QSettings s; QByteArray headers = s.value("video/fileheaders").toByteArray(); @@ -471,9 +456,6 @@ QList FileWidget::constructRow(CachedFileData *fd) const{ if(attr == Present){ fData[IconColumn]->setIcon(QIcon(":/huge_bra.png")); fData[NameColumn]->setForeground(greenBrush); - }else if(attr == Origin){ - fData[IconColumn]->setIcon(QIcon(":/butt_plug.png")); - fData[NameColumn]->setForeground(blueBrush); }else if(attr == NotPresent){ fData[IconColumn]->setIcon(QIcon(":/chastity_belt.png")); fData[NameColumn]->setForeground(redBrush); diff --git a/filewidget.h b/filewidget.h index 0d66d9d..131f187 100644 --- a/filewidget.h +++ b/filewidget.h @@ -30,7 +30,7 @@ class QStandardItem; class FileWidget : public QWidget { Q_OBJECT public: - enum FileAttrs { NotPresent = 0, Present = 1, NoVideo = 2, ParentDir = 3, Directory = 4, Origin = 5 }; + enum FileAttrs { NotPresent = 0, Present = 1, NoVideo = 2, ParentDir = 3, Directory = 4 }; enum CustomRoles { AttrsRole = Qt::UserRole + 1, FullPathRole = Qt::UserRole + 2, DurationRole = Qt::UserRole + 3, MD5SumRole = Qt::UserRole + 4, SecondsRole = Qt::UserRole + 5, SizeRole = Qt::UserRole + 6 }; enum { ColumnCount = 7 }; enum Columns { IconColumn = 0, NameColumn = 1, CopiedColumn = 2, MimeColumn = 3, DurationColumn = 4, SizeColumn = 5, Md5Column = 6 }; @@ -83,7 +83,6 @@ class FileWidget : public QWidget { void createActions(); void fileData(const QString &fullPath, const QString &md5); int md5Count(const QString &md5); - bool haveOrigin(const QString filename); void readHeaderData(); void writeHeaderData(); void readSettings(); @@ -103,7 +102,6 @@ class FileWidget : public QWidget { QSqlDatabase mDb; QSqlQuery mQOrigin; QSqlQuery mQFiles; - QSqlQuery mQSimilar; QMimeData *mMimeData; QAction *mSelDirA; QAction *mRefreshA; -- cgit v1.2.3-70-g09d2