Wait till pdfworker finishes before new search, cancel running
Este cometimento está contido em:
ascendente
e8ef4be571
cometimento
53cf73cc8d
3
TODO
3
TODO
@ -25,5 +25,6 @@ type:file
|
||||
endswith:
|
||||
startswith:
|
||||
mtime:
|
||||
|
||||
tag:
|
||||
page:
|
||||
SearchWorker::setFilters()
|
||||
|
@ -121,7 +121,10 @@ void MainWindow::makePdfPreview()
|
||||
{
|
||||
if(!pdfWorkerThread.isRunning())
|
||||
pdfWorkerThread.start();
|
||||
qDeleteAll(ui->scrollAreaWidgetContents->children());
|
||||
|
||||
pdfWorker->cancelAndWait();
|
||||
QCoreApplication::processEvents(); //Process not processed images
|
||||
qDeleteAll(ui->scrollAreaWidgetContents->children());
|
||||
|
||||
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
|
||||
emit startPdfPreviewGeneration(this->pdfSearchResults, 0.75);
|
||||
|
@ -15,15 +15,25 @@ Poppler::Document * PdfWorker::document(QString path)
|
||||
return this->documentcache.value(path);
|
||||
|
||||
Poppler::Document *result = Poppler::Document::load(path);
|
||||
if(result == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
result->setRenderHint(Poppler::Document::TextAntialiasing);
|
||||
this->documentcache.insert(path, result);
|
||||
return result;
|
||||
}
|
||||
void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor)
|
||||
{
|
||||
this->cancelCurrent = false;
|
||||
this->generating = true;
|
||||
for(SearchResult &sr : paths)
|
||||
{
|
||||
Poppler::Document *doc = document(sr.path);
|
||||
if(doc == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
qDebug() << sr.path;
|
||||
if(doc->isLocked())
|
||||
{
|
||||
@ -39,6 +49,27 @@ void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor
|
||||
preview.previewImage = image;
|
||||
preview.documentPath = sr.path;
|
||||
emit previewReady(preview);
|
||||
if(this->cancelCurrent.load())
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
isFreeMutex.lock();
|
||||
isFree.wakeOne();
|
||||
isFreeMutex.unlock();
|
||||
generating = false;
|
||||
emit previewsFinished();
|
||||
}
|
||||
|
||||
void PdfWorker::cancelAndWait()
|
||||
{
|
||||
if(this->generating.load())
|
||||
{
|
||||
this->cancelCurrent = true;
|
||||
|
||||
isFreeMutex.lock();
|
||||
isFree.wait(&isFreeMutex);
|
||||
isFreeMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
#include <QHash>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <poppler-qt5.h>
|
||||
#include "pdfpreview.h"
|
||||
#include "searchresult.h"
|
||||
@ -13,8 +16,13 @@ class PdfWorker : public QObject
|
||||
private:
|
||||
QHash<QString, Poppler::Document *> documentcache;
|
||||
Poppler::Document *document(QString path);
|
||||
std::atomic<bool> cancelCurrent { false } ;
|
||||
std::atomic<bool> generating { false };
|
||||
QMutex isFreeMutex;
|
||||
QWaitCondition isFree;
|
||||
public:
|
||||
PdfWorker();
|
||||
void cancelAndWait();
|
||||
public slots:
|
||||
void generatePreviews(QVector<SearchResult> paths, double scalefactor);
|
||||
signals:
|
||||
|
@ -20,6 +20,13 @@ SearchWorker::SearchWorker(const QString &dbpath)
|
||||
queryContent->prepare("SELECT file.path, content.page, file.mtime FROM file INNER JOIN content ON file.id = content.fileid INNER JOIN content_fts ON content.id = content_fts.ROWID WHERE content_fts.content MATCH ? ORDER By file.mtime DESC, content.page ASC");
|
||||
}
|
||||
|
||||
|
||||
QString normalize(QString str)
|
||||
{
|
||||
str = str.replace(" ", " AND ");
|
||||
str = str.replace("|", " OR ");
|
||||
return str;
|
||||
}
|
||||
void SearchWorker::searchForFile(const QString &query)
|
||||
{
|
||||
QVector<SearchResult> results;
|
||||
|
Carregando…
Criar uma nova questão referindo esta
Bloquear um utilizador