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 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'filewidget.cpp') 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); -- cgit v1.2.3-70-g09d2