Add basic conversion heuristics
This commit is contained in:
parent
69fa9e52fb
commit
cd31098279
5 changed files with 55 additions and 11 deletions
|
@ -3,7 +3,7 @@ function supported_formats(printer)
|
|||
var formats = printer.attrs["document-format-supported"].value;
|
||||
var mimetypes = [];
|
||||
var supported = [];
|
||||
if(has(formats, "application/pdf"))
|
||||
if(has(formats, "application/pdf") || as(formats, "application/pwg-raster") || has(formats, "application/urf") )
|
||||
{
|
||||
mimetypes.push("application/pdf");
|
||||
supported.push("PDF");
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "convertworker.h"
|
||||
#include <sailfishapp.h>
|
||||
|
||||
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile)
|
||||
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename,
|
||||
bool apple, QTemporaryFile* tempfile)
|
||||
{
|
||||
|
||||
QProcess* pdftoppm = new QProcess(this);
|
||||
|
@ -14,7 +15,6 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
ppm2pwg->setProgram(Ppm2pwgPath);
|
||||
QStringList env; // {"PREPEND_FILE="+tempfile->fileName()};
|
||||
|
||||
bool apple = false;
|
||||
if(apple)
|
||||
{
|
||||
env.append("URF=true");
|
||||
|
|
|
@ -8,7 +8,8 @@ class ConvertWorker : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile);
|
||||
void convertPdf(QNetworkRequest request, QString filename,
|
||||
bool apple, QTemporaryFile* tempfile);
|
||||
//convertImage();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "ippprinter.h"
|
||||
#include <seaprint_version.h>
|
||||
#include "mimer.h"
|
||||
|
||||
IppPrinter::IppPrinter()
|
||||
{
|
||||
|
@ -260,9 +261,37 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
|||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint "SEAPRINT_VERSION);
|
||||
|
||||
// TODO: do this only conditionally, and to the raster suppoerted/preferred
|
||||
bool transcode = true;
|
||||
if(transcode)
|
||||
|
||||
Mimer* mimer = Mimer::instance();
|
||||
QString mimeType = mimer->get_type(filename);
|
||||
ConvertFrom from = NotConvertable;
|
||||
ConvertTarget target = NoConvert;
|
||||
|
||||
if(mimeType == "application/pdf")
|
||||
{
|
||||
from = Pdf;
|
||||
}
|
||||
else if (mimeType.contains("image")) {
|
||||
// from = Image; TODO: handle image conversions
|
||||
}
|
||||
|
||||
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
||||
|
||||
qDebug() << supportedMimeTypes << supportedMimeTypes.contains(mimeType);
|
||||
|
||||
if(from == Pdf)
|
||||
{
|
||||
if(supportedMimeTypes.contains("image/pwg-raster"))
|
||||
{
|
||||
target = PwgConvert;
|
||||
}
|
||||
else if (supportedMimeTypes.contains("image/urf"))
|
||||
{
|
||||
target = UrfConvert;
|
||||
}
|
||||
}
|
||||
|
||||
if(from == Pdf && target != NoConvert)
|
||||
{
|
||||
file.close();
|
||||
QTemporaryFile* tempfile = new QTemporaryFile();
|
||||
|
@ -271,10 +300,10 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
|||
qDebug() << tempfile->fileName();
|
||||
tempfile->close();
|
||||
|
||||
emit doConvertPdf(request, filename, tempfile);
|
||||
emit doConvertPdf(request, filename, target==UrfConvert, tempfile);
|
||||
}
|
||||
else {
|
||||
|
||||
else
|
||||
{
|
||||
QByteArray filedata = file.readAll();
|
||||
contents = contents.append(filedata);
|
||||
file.close();
|
||||
|
|
|
@ -28,6 +28,20 @@ public:
|
|||
Q_INVOKABLE bool getJobs();
|
||||
Q_INVOKABLE bool cancelJob(qint32 jobId);
|
||||
|
||||
enum ConvertTarget
|
||||
{
|
||||
NoConvert,
|
||||
PwgConvert,
|
||||
UrfConvert
|
||||
};
|
||||
|
||||
enum ConvertFrom
|
||||
{
|
||||
NotConvertable,
|
||||
Pdf,
|
||||
Image
|
||||
};
|
||||
|
||||
signals:
|
||||
void urlChanged();
|
||||
void attrsChanged();
|
||||
|
@ -37,7 +51,7 @@ signals:
|
|||
void jobFinished(bool status);
|
||||
void cancelStatus(bool status);
|
||||
|
||||
void doConvertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile);
|
||||
void doConvertPdf(QNetworkRequest request, QString filename, bool urf, QTemporaryFile* tempfile);
|
||||
|
||||
public slots:
|
||||
void print(QJsonObject attrs, QString file);
|
||||
|
|
Loading…
Reference in a new issue