harbour-seaprint/src/convertworker.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

#include "convertworker.h"
2020-05-01 21:54:33 +03:00
#include <sailfishapp.h>
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile)
{
2020-05-02 19:14:33 +03:00
QProcess* pdftoppm = new QProcess(this);
pdftoppm->setProgram("pdftoppm");
pdftoppm->setArguments({"-gray", "-rx", "300", "-ry", "300", filename});
QProcess* ppm2pwg = new QProcess(this);
2020-05-01 21:54:33 +03:00
QString Ppm2pwgPath = SailfishApp::pathTo("ppm2pwg").toString().remove("file://");
ppm2pwg->setProgram(Ppm2pwgPath);
QStringList env; // {"PREPEND_FILE="+tempfile->fileName()};
bool apple = false;
if(apple)
{
env.append("URF=true");
}
qDebug() << "Prepend file env done";
ppm2pwg->setEnvironment(env);
2020-05-02 19:14:33 +03:00
pdftoppm->setStandardOutputProcess(ppm2pwg);
ppm2pwg->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
2020-05-02 19:14:33 +03:00
connect(pdftoppm, SIGNAL(finished(int, QProcess::ExitStatus)), pdftoppm, SLOT(deleteLater()));
connect(ppm2pwg, SIGNAL(finished(int, QProcess::ExitStatus)), ppm2pwg, SLOT(deleteLater()));
qDebug() << "All connected";
2020-05-02 19:14:33 +03:00
pdftoppm->start();
ppm2pwg->start();
qDebug() << "Starting";
2020-05-02 19:14:33 +03:00
if(!pdftoppm->waitForStarted())
{
2020-05-02 19:14:33 +03:00
qDebug() << "pdftoppm died";
tempfile->deleteLater();
emit failed();
return;
}
if(!ppm2pwg->waitForStarted())
{
qDebug() << "ppm2pwg died";
tempfile->deleteLater();
emit failed();
return;
}
qDebug() << "All started";
ppm2pwg->waitForFinished();
qDebug() << "Finished";
emit done(request, tempfile);
qDebug() << "posted";
}