From 1abbdfb76880b3045f6ccf9e3662764ee22d1b9e Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Thu, 30 Jul 2020 22:21:14 +0200 Subject: [PATCH] Add progress to pdf conversions --- src/convertworker.cpp | 23 ++++++++++++++++++++++- src/convertworker.h | 1 + src/ippprinter.cpp | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/convertworker.cpp b/src/convertworker.cpp index 895d1dc..0ff34f9 100644 --- a/src/convertworker.cpp +++ b/src/convertworker.cpp @@ -225,8 +225,29 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo } qDebug() << "All started"; + bool ppm2pwgSuccess = false; - if(!ppm2pwg->waitForFinished(10000+5000*pages)) + for(size_t i = 0; i < (5*pages+10); i++) + { + if(ppm2pwg->waitForFinished(1000)) + { + ppm2pwgSuccess = true; + break; + } + else + { + QList ppm2pwgOutput = ppm2pwg->readAllStandardError().split('\n'); + for(QList::iterator it = ppm2pwgOutput.begin(); it != ppm2pwgOutput.end(); it++) + { + if(it->startsWith("Page")) + { + QList ppm2pwgTokens = it->split(' '); + emit progress(ppm2pwgTokens.last().toInt(), pages); + } + } + } + } + if(!ppm2pwgSuccess) { qDebug() << "ppm2pwg failed"; tempfile->deleteLater(); diff --git a/src/convertworker.h b/src/convertworker.h index cf466a9..c86a2a7 100644 --- a/src/convertworker.h +++ b/src/convertworker.h @@ -18,6 +18,7 @@ public slots: signals: void done(QNetworkRequest request, QTemporaryFile* data); + void progress(qint64 done, qint64 pages); void failed(QString message); }; diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index f4c8967..24d3501 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -33,6 +33,7 @@ IppPrinter::IppPrinter() connect(this, &IppPrinter::doConvertPdf, _worker, &ConvertWorker::convertPdf); connect(this, &IppPrinter::doConvertImage, _worker, &ConvertWorker::convertImage); connect(_worker, &ConvertWorker::done, this, &IppPrinter::convertDone); + connect(_worker, &ConvertWorker::progress, this, &IppPrinter::setProgress); connect(_worker, &ConvertWorker::failed, this, &IppPrinter::convertFailed); _workerThread.start();