Add page range support
This commit is contained in:
parent
eb58606250
commit
e1d34a4d1d
13 changed files with 221 additions and 36 deletions
|
@ -3,25 +3,103 @@ import Sailfish.Silica 1.0
|
|||
|
||||
Setting {
|
||||
|
||||
//TODO
|
||||
|
||||
property int low
|
||||
property int high
|
||||
property int choice_low
|
||||
property int choice_high
|
||||
property int choice_low: 1
|
||||
property int choice_high: 0
|
||||
|
||||
|
||||
function update_choice() {
|
||||
choice = new Object({low: choice_low, high: choice_high});
|
||||
}
|
||||
|
||||
onChoice_highChanged: {
|
||||
if(choice_high < choice_low)
|
||||
{
|
||||
low_slider.value = choice_high > 0 ? choice_high : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
update_choice()
|
||||
}
|
||||
}
|
||||
onChoice_lowChanged: {
|
||||
if(choice_low > choice_high)
|
||||
{
|
||||
high_slider.value = choice_low
|
||||
}
|
||||
else
|
||||
{
|
||||
update_choice()
|
||||
}
|
||||
}
|
||||
|
||||
ValueButton {
|
||||
enabled: valid
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
label: prettyName
|
||||
value: choice ? choice : default_choice
|
||||
value: choice_high==0 ? qsTr("all") : ""+choice_low+" - "+choice_high
|
||||
onClicked: parent.clicked()
|
||||
}
|
||||
|
||||
property var menu: ContextMenu {
|
||||
id: menu
|
||||
enabled: valid
|
||||
|
||||
MenuItem {
|
||||
Slider
|
||||
{
|
||||
id: low_slider
|
||||
minimumValue: 1
|
||||
maximumValue: high
|
||||
width: parent.width
|
||||
stepSize: 1
|
||||
value: choice_low
|
||||
onValueChanged:
|
||||
{
|
||||
choice_low = value;
|
||||
}
|
||||
}
|
||||
IconButton
|
||||
{
|
||||
anchors.right: parent.right
|
||||
icon.source: "image://theme/icon-s-edit"
|
||||
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("IntegerInputDialog.qml"),
|
||||
{value: choice, title: prettyName,
|
||||
min: 1, max: high});
|
||||
dialog.accepted.connect(function() {
|
||||
choice_low = dialog.value;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
Slider
|
||||
{
|
||||
id: high_slider
|
||||
minimumValue: 0
|
||||
maximumValue: high
|
||||
width: parent.width
|
||||
stepSize: 1
|
||||
value: choice_high
|
||||
onValueChanged:
|
||||
{
|
||||
choice_high = value;
|
||||
}
|
||||
}
|
||||
IconButton
|
||||
{
|
||||
anchors.right: parent.right
|
||||
icon.source: "image://theme/icon-s-edit"
|
||||
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("IntegerInputDialog.qml"),
|
||||
{value: choice, title: prettyName,
|
||||
min: 1, max: high});
|
||||
dialog.accepted.connect(function() {
|
||||
choice_high = dialog.value;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import QtQuick 2.0
|
|||
import Sailfish.Silica 1.0
|
||||
import seaprint.mimer 1.0
|
||||
import seaprint.ippmsg 1.0
|
||||
import seaprint.convertchecker 1.0
|
||||
import "utils.js" as Utils
|
||||
|
||||
Page {
|
||||
|
@ -39,7 +40,7 @@ Page {
|
|||
ListElement {name: "sides"; prettyName: qsTr("Sides"); tag: IppMsg.Enum}
|
||||
ListElement {name: "media"; prettyName: qsTr("Print media"); tag: IppMsg.Keyword}
|
||||
ListElement {name: "copies"; prettyName: qsTr("Copies"); tag: IppMsg.Integer}
|
||||
// ListElement {name: "page-ranges"; prettyName: qsTr("Page range"); tag: IppMsg.IntegerRange}
|
||||
ListElement {name: "page-ranges"; prettyName: qsTr("Page range"); tag: IppMsg.IntegerRange}
|
||||
ListElement {name: "print-color-mode"; prettyName: qsTr("Color mode"); tag: IppMsg.Enum}
|
||||
// ListElement {name: "orientation-requested"; prettyName: qsTr("Orientation"); tag: IppMsg.Enum}
|
||||
ListElement {name: "print-quality"; prettyName: qsTr("Quality"); tag: IppMsg.Enum}
|
||||
|
@ -111,11 +112,14 @@ Page {
|
|||
})
|
||||
break
|
||||
case IppMsg.IntegerRange:
|
||||
var valid = printer.attrs.hasOwnProperty(name+"-supported") &&
|
||||
name=="page-ranges" && Mimer.get_type(selectedFile) == "application/pdf";
|
||||
loader.setSource("../components/RangeSetting.qml",
|
||||
{name: name,
|
||||
prettyName: prettyName,
|
||||
tag: tag,
|
||||
valid: false //TODO printer.attrs.hasOwnProperty(name+"-supported"),
|
||||
valid: valid,
|
||||
high: name=="page-ranges" ? ConvertChecker.pdfPages(selectedFile) : 0
|
||||
})
|
||||
break
|
||||
case IppMsg.Resolution:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "convertchecker.h"
|
||||
#include <QProcess>
|
||||
#include <QtDebug>
|
||||
|
||||
ConvertChecker::ConvertChecker()
|
||||
{
|
||||
|
@ -38,3 +39,36 @@ ConvertChecker* ConvertChecker::instance()
|
|||
|
||||
return m_Instance;
|
||||
}
|
||||
|
||||
quint32 ConvertChecker::pdfPages(QString filename)
|
||||
{
|
||||
quint32 pages = 0;
|
||||
if(!_pdf)
|
||||
{
|
||||
return pages;
|
||||
}
|
||||
|
||||
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<QByteArray> pdfInfoOutputLines = pdfInfoOutput.split('\n');
|
||||
for(QList<QByteArray>::iterator it = pdfInfoOutputLines.begin(); it != pdfInfoOutputLines.end(); it++)
|
||||
{
|
||||
if(it->startsWith("Pages"))
|
||||
{
|
||||
QList<QByteArray> pagesTokens = it->split(' ');
|
||||
pages = pagesTokens.last().toInt();
|
||||
}
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ public:
|
|||
static ConvertChecker* instance();
|
||||
Q_PROPERTY(bool pdf MEMBER _pdf)
|
||||
|
||||
Q_INVOKABLE quint32 pdfPages(QString pdf);
|
||||
|
||||
signals:
|
||||
protected:
|
||||
private:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "convertworker.h"
|
||||
#include <sailfishapp.h>
|
||||
#include "papersizes.h"
|
||||
#include "convertchecker.h"
|
||||
#include <QImage>
|
||||
#include <QMatrix>
|
||||
#include <QPainter>
|
||||
|
@ -44,34 +45,20 @@ void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize,
|
|||
|
||||
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble)
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh)
|
||||
{
|
||||
|
||||
QProcess* pdfinfo = new QProcess(this);
|
||||
pdfinfo->setProgram("pdfinfo");
|
||||
pdfinfo->setArguments({filename});
|
||||
pdfinfo->start();
|
||||
|
||||
if(!pdfinfo->waitForStarted() || !pdfinfo->waitForFinished())
|
||||
quint32 pages = ConvertChecker::instance()->pdfPages(filename);
|
||||
if (!pages)
|
||||
{
|
||||
qDebug() << "pdfinfo died";
|
||||
pdfinfo->deleteLater();
|
||||
qDebug() << "pdfinfo returned 0 pages";
|
||||
tempfile->deleteLater();
|
||||
emit failed(tr("Failed to get info about PDF file"));
|
||||
return;
|
||||
}
|
||||
QByteArray pdfInfoOutput = pdfinfo->readAllStandardOutput();
|
||||
pdfinfo->deleteLater();
|
||||
qDebug() << pdfInfoOutput;
|
||||
QList<QByteArray> pdfInfoOutputLines = pdfInfoOutput.split('\n');
|
||||
quint32 pages = 0;
|
||||
for(QList<QByteArray>::iterator it = pdfInfoOutputLines.begin(); it != pdfInfoOutputLines.end(); it++)
|
||||
|
||||
if(PageRangeHigh==0)
|
||||
{
|
||||
if(it->startsWith("Pages"))
|
||||
{
|
||||
QList<QByteArray> pagesTokens = it->split(' ');
|
||||
pages = pagesTokens.last().toInt();
|
||||
}
|
||||
PageRangeHigh=pages;
|
||||
}
|
||||
|
||||
bool urf = false;
|
||||
|
@ -132,11 +119,17 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
{
|
||||
QProcess* pdftops = new QProcess(this);
|
||||
pdftops->setProgram("pdftops");
|
||||
QStringList PdfToPsArgs = {"-paper", ShortPaperSize, filename, "-"};
|
||||
QStringList PdfToPsArgs;
|
||||
if(TwoSided)
|
||||
{
|
||||
PdfToPsArgs.prepend("-duplex");
|
||||
PdfToPsArgs.append("-duplex");
|
||||
}
|
||||
if(PageRangeLow != 0)
|
||||
{
|
||||
PdfToPsArgs << QStringList {"-f", QString::number(PageRangeLow), "-l", QString::number(PageRangeHigh)};
|
||||
}
|
||||
PdfToPsArgs << QStringList {"-paper", ShortPaperSize, filename, "-"};
|
||||
|
||||
pdftops->setArguments(PdfToPsArgs);
|
||||
|
||||
pdftops->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
|
||||
|
@ -169,7 +162,13 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
|
||||
QProcess* pdftocairo = new QProcess(this);
|
||||
pdftocairo->setProgram("pdftocairo");
|
||||
pdftocairo->setArguments({"-pdf", "-paper", ShortPaperSize, filename, "-"});
|
||||
QStringList PdfToCairoArgs;
|
||||
if(PageRangeLow != 0)
|
||||
{
|
||||
PdfToCairoArgs << QStringList {"-f", QString::number(PageRangeLow), "-l", QString::number(PageRangeHigh)};
|
||||
}
|
||||
PdfToCairoArgs << QStringList {"-pdf", "-paper", ShortPaperSize, filename, "-"};
|
||||
pdftocairo->setArguments(PdfToCairoArgs);
|
||||
|
||||
QProcess* pdftoppm = new QProcess(this);
|
||||
pdftoppm->setProgram("pdftoppm");
|
||||
|
|
|
@ -10,7 +10,8 @@ class ConvertWorker : public QObject
|
|||
public slots:
|
||||
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh);
|
||||
|
||||
void convertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
|
|
|
@ -432,6 +432,17 @@ void IppPrinter::print(QJsonObject attrs, QString filename,
|
|||
{
|
||||
attrs.remove("sides");
|
||||
}
|
||||
quint32 PageRangeLow = 0;
|
||||
quint32 PageRangeHigh = 0;
|
||||
if(mimeType == "application/pdf" && documentFormat != "application/pdf")
|
||||
{
|
||||
if(attrs.contains("page-ranges"))
|
||||
{
|
||||
QJsonObject PageRanges = getAttrOrDefault(attrs, "page-ranges").toObject();
|
||||
PageRangeLow = PageRanges["low"].toInt();
|
||||
PageRangeHigh = PageRanges["high"].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Final op attributes:" << o;
|
||||
qDebug() << "Final job attributes:" << attrs;
|
||||
|
@ -476,7 +487,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename,
|
|||
}
|
||||
|
||||
emit doConvertPdf(request, filename, tempfile, documentFormat, Colors, Quality,
|
||||
PaperSize, HwResX, HwResY, TwoSided, Tumble);
|
||||
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh);
|
||||
}
|
||||
else if (mimeType.contains("image"))
|
||||
{
|
||||
|
|
|
@ -42,7 +42,8 @@ signals:
|
|||
|
||||
void doConvertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh);
|
||||
|
||||
void doConvertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
|
|
|
@ -349,6 +349,17 @@
|
|||
<source>Zero margins</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Page range</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>RangeSetting</name>
|
||||
<message>
|
||||
<source>all</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsPage</name>
|
||||
|
|
|
@ -349,6 +349,17 @@
|
|||
<source>Zero margins</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Page range</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>RangeSetting</name>
|
||||
<message>
|
||||
<source>all</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsPage</name>
|
||||
|
|
|
@ -349,6 +349,17 @@
|
|||
<source>Zero margins</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Page range</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>RangeSetting</name>
|
||||
<message>
|
||||
<source>all</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsPage</name>
|
||||
|
|
|
@ -349,6 +349,17 @@
|
|||
<source>Zero margins</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Page range</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>RangeSetting</name>
|
||||
<message>
|
||||
<source>all</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsPage</name>
|
||||
|
|
|
@ -349,6 +349,17 @@
|
|||
<source>Zero margins</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Page range</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>RangeSetting</name>
|
||||
<message>
|
||||
<source>all</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsPage</name>
|
||||
|
|
Loading…
Reference in a new issue