2020-05-01 16:02:29 +03:00
|
|
|
#include "convertworker.h"
|
2020-05-01 21:54:33 +03:00
|
|
|
#include <sailfishapp.h>
|
2020-05-01 16:02:29 +03:00
|
|
|
|
2020-05-03 15:13:44 +03:00
|
|
|
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename,
|
2020-05-05 21:36:01 +03:00
|
|
|
bool apple, quint32 HwResX, quint32 HwResY, QTemporaryFile* tempfile)
|
2020-05-01 16:02:29 +03:00
|
|
|
{
|
|
|
|
|
2020-05-05 21:36:01 +03:00
|
|
|
QString HwResX_s = QString::number(HwResX);
|
|
|
|
QString HwResY_s = QString::number(HwResY);
|
|
|
|
|
2020-05-02 19:14:33 +03:00
|
|
|
QProcess* pdftoppm = new QProcess(this);
|
|
|
|
pdftoppm->setProgram("pdftoppm");
|
2020-05-05 21:36:01 +03:00
|
|
|
pdftoppm->setArguments({"-gray", "-rx", HwResX_s, "-ry", HwResY_s, filename});
|
2020-05-01 16:02:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
QProcess* ppm2pwg = new QProcess(this);
|
2020-05-06 21:46:41 +03:00
|
|
|
// Yo dawg, I heard you like programs...
|
2020-05-05 21:07:21 +03:00
|
|
|
ppm2pwg->setProgram("harbour-seaprint");
|
|
|
|
ppm2pwg->setArguments({"ppm2pwg"});
|
2020-05-05 21:36:01 +03:00
|
|
|
QStringList env = {"HWRES_X="+HwResX_s, "HWRES_Y="+HwResY_s};
|
2020-05-01 16:02:29 +03:00
|
|
|
|
|
|
|
if(apple)
|
|
|
|
{
|
|
|
|
env.append("URF=true");
|
|
|
|
}
|
|
|
|
|
|
|
|
ppm2pwg->setEnvironment(env);
|
|
|
|
|
2020-05-02 19:14:33 +03:00
|
|
|
pdftoppm->setStandardOutputProcess(ppm2pwg);
|
2020-05-01 16:02:29 +03:00
|
|
|
ppm2pwg->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
|
|
|
|
|
2020-05-02 19:14:33 +03:00
|
|
|
connect(pdftoppm, SIGNAL(finished(int, QProcess::ExitStatus)), pdftoppm, SLOT(deleteLater()));
|
2020-05-01 16:02:29 +03:00
|
|
|
connect(ppm2pwg, SIGNAL(finished(int, QProcess::ExitStatus)), ppm2pwg, SLOT(deleteLater()));
|
|
|
|
|
|
|
|
qDebug() << "All connected";
|
|
|
|
|
|
|
|
|
2020-05-02 19:14:33 +03:00
|
|
|
pdftoppm->start();
|
2020-05-01 16:02:29 +03:00
|
|
|
ppm2pwg->start();
|
|
|
|
|
|
|
|
qDebug() << "Starting";
|
|
|
|
|
|
|
|
|
2020-05-02 19:14:33 +03:00
|
|
|
if(!pdftoppm->waitForStarted())
|
2020-05-01 16:02:29 +03:00
|
|
|
{
|
2020-05-02 19:14:33 +03:00
|
|
|
qDebug() << "pdftoppm died";
|
2020-05-01 16:02:29 +03:00
|
|
|
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";
|
|
|
|
}
|