From 8cad5d9ae9bb1840c6d11ca3d1d4e1c067ca3d01 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Tue, 16 Nov 2021 19:55:13 +0100 Subject: [PATCH] Prototype for future ConvertChecker --- src/convertchecker.cpp | 52 ++++++++++-------------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/src/convertchecker.cpp b/src/convertchecker.cpp index ab974bd..e5094ae 100644 --- a/src/convertchecker.cpp +++ b/src/convertchecker.cpp @@ -1,3 +1,8 @@ +#include +#include + +#include + #include "convertchecker.h" #include #include @@ -5,26 +10,14 @@ ConvertChecker::ConvertChecker() { - _pdf = false; + _pdf = true; _calligra = false; - QProcess pdftoppm(this); - pdftoppm.setProgram("pdftoppm"); - pdftoppm.setArguments({"-h"}); - pdftoppm.start(); QProcess calligraconverter(this); calligraconverter.setProgram("calligraconverter"); calligraconverter.setArguments({"-h"}); calligraconverter.start(); - if(pdftoppm.waitForFinished(2000)) - { - if(pdftoppm.exitStatus() == QProcess::NormalExit && pdftoppm.exitCode() == 0) - { - _pdf = true; - } - } - if(calligraconverter.waitForFinished(2000)) { if(calligraconverter.exitStatus() == QProcess::NormalExit && calligraconverter.exitCode() == 0) @@ -58,33 +51,12 @@ ConvertChecker* ConvertChecker::instance() quint32 ConvertChecker::pdfPages(QString filename) { - quint32 pages = 0; - if(!_pdf || (Mimer::instance()->get_type(filename) != Mimer::PDF)) - { // pdfinfo is a bit slow to return on some non-PDFs - return pages; - } + std::string url("file://"); + url.append(filename.toStdString()); + GError* error = nullptr; + PopplerDocument* doc = poppler_document_new_from_file(url.c_str(), nullptr, &error); + quint32 pages = poppler_document_get_n_pages(doc); + g_object_unref(doc); - QProcess* pdfinfo = new QProcess(this); - pdfinfo->setProgram("pdfinfo"); - pdfinfo->setArguments({filename}); - pdfinfo->start(); - - if(!pdfinfo->waitForStarted(1000) || !pdfinfo->waitForFinished(1000)) - { - pdfinfo->deleteLater(); - return pages; - } - QByteArray pdfInfoOutput = pdfinfo->readAllStandardOutput(); - pdfinfo->deleteLater(); - qDebug() << pdfInfoOutput; - QList pdfInfoOutputLines = pdfInfoOutput.split('\n'); - for(QList::iterator it = pdfInfoOutputLines.begin(); it != pdfInfoOutputLines.end(); it++) - { - if(it->startsWith("Pages")) - { - QList pagesTokens = it->split(' '); - pages = pagesTokens.last().toInt(); - } - } return pages; }