From 53ca370f9259218317ef21a2c7c7289d15805807 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sat, 13 Aug 2022 16:30:13 +0200 Subject: [PATCH] Add advanced page ranges (list of ranges) --- harbour-seaprint.pro | 3 ++ ppm2pwg | 2 +- qml/components/RangeSetting.qml | 48 ++++++++++++++++++++++++-- qml/pages/PrinterPage.qml | 1 + src/harbour-seaprint.cpp | 5 ++- src/ippprinter.cpp | 23 ++++++------ src/rangelistchecker.cpp | 41 ++++++++++++++++++++++ src/rangelistchecker.h | 29 ++++++++++++++++ translations/harbour-seaprint-de.ts | 4 +++ translations/harbour-seaprint-es.ts | 4 +++ translations/harbour-seaprint-fr.ts | 4 +++ translations/harbour-seaprint-nl.ts | 4 +++ translations/harbour-seaprint-pl.ts | 4 +++ translations/harbour-seaprint-zh_CN.ts | 4 +++ translations/harbour-seaprint.ts | 4 +++ 15 files changed, 166 insertions(+), 14 deletions(-) create mode 100644 src/rangelistchecker.cpp create mode 100644 src/rangelistchecker.h diff --git a/harbour-seaprint.pro b/harbour-seaprint.pro index dd18274..b68ead2 100644 --- a/harbour-seaprint.pro +++ b/harbour-seaprint.pro @@ -34,6 +34,7 @@ DEFINES += PDF_CREATOR='\\"SeaPrint\ $$VERSION\\"' DEFINES += SEAPRINT_VERSION='\\"$$VERSION\\"' SOURCES += src/harbour-seaprint.cpp \ + src/rangelistchecker.cpp \ src/convertchecker.cpp \ src/curlrequester.cpp \ src/imageitem.cpp \ @@ -51,6 +52,7 @@ SOURCES += src/harbour-seaprint.cpp \ DISTFILES += qml/harbour-seaprint.qml \ qml/components/DependentOn.qml \ + qml/components/RangeListInputDialog.qml \ qml/cover/CoverPage.qml \ qml/components/*qml \ qml/pages/*.qml \ @@ -81,6 +83,7 @@ TRANSLATIONS += translations/harbour-seaprint-de.ts \ translations/harbour-seaprint-pl.ts HEADERS += \ + src/rangelistchecker.h \ src/convertchecker.h \ src/curlrequester.h \ src/imageitem.h \ diff --git a/ppm2pwg b/ppm2pwg index 89cfaa0..fafcd9d 160000 --- a/ppm2pwg +++ b/ppm2pwg @@ -1 +1 @@ -Subproject commit 89cfaa0b424310f54355ee2415d3bee9ed786255 +Subproject commit fafcd9d21d646ee633cae38265a7f899902c8e33 diff --git a/qml/components/RangeSetting.qml b/qml/components/RangeSetting.qml index 6e0bf1c..52b6dc0 100644 --- a/qml/components/RangeSetting.qml +++ b/qml/components/RangeSetting.qml @@ -5,6 +5,7 @@ Setting { property int high property int choice_low: 1 property int choice_high: 0 + property bool acceptRangeList: false property bool suppressChange: false @@ -41,7 +42,7 @@ Setting { } onChoiceChanged: { - if(choice == undefined) + if(choice == undefined || choice.constructor.name !== "Object") { suppressChange = true; low_slider.value = low_slider.minimumValue; @@ -50,7 +51,39 @@ Setting { } } - displayValue: choice == undefined ? qsTr("all") : ""+choice.low+" - "+choice.high + displayValue: prettify(choice) + + function prettify(choice) + { + if(choice == undefined) + { + return qsTr("all"); + } + else if(choice.constructor.name === "Object") + { + return (""+choice.low+" - "+choice.high) + } + else + { + var ret = ""; + for(var i = 0; i < choice.length; i++) + { + if(i!=0) + { + ret = ret+"," + } + if(choice[i].low == choice[i].high) + { + ret=ret+choice[i].low + } + else + { + ret=ret+choice[i].low+"-"+choice[i].high + } + } + return ret + } + } menu: ContextMenu { MenuItem { @@ -109,6 +142,17 @@ Setting { } + MenuItem { + visible: acceptRangeList + text: qsTr("Advanced") + onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("RangeListInputDialog.qml"), + {value: choice, title: prettyName}); + dialog.accepted.connect(function() { + choice = dialog.value; + }) + } + } + } diff --git a/qml/pages/PrinterPage.qml b/qml/pages/PrinterPage.qml index 9cb5765..f7caabe 100644 --- a/qml/pages/PrinterPage.qml +++ b/qml/pages/PrinterPage.qml @@ -120,6 +120,7 @@ Page { property var pdfpages: ConvertChecker.pdfPages(selectedFile) high: pdfpages == 0 ? 65535 : pdfpages + acceptRangeList: true } ChoiceSetting { tag: IppMsg.Integer diff --git a/src/harbour-seaprint.cpp b/src/harbour-seaprint.cpp index 6c0c4ef..e9b24e5 100644 --- a/src/harbour-seaprint.cpp +++ b/src/harbour-seaprint.cpp @@ -7,6 +7,7 @@ #include #include #include +#include Q_DECLARE_METATYPE(CURLcode) Q_DECLARE_METATYPE(Bytestream) @@ -41,7 +42,9 @@ int main(int argc, char *argv[]) qmlRegisterSingletonType("seaprint.ippdiscovery", 1, 0, "IppDiscovery", singletontype_provider); qmlRegisterSingletonType("seaprint.mimer", 1, 0, "Mimer", singletontype_provider); qmlRegisterSingletonType("seaprint.convertchecker", 1, 0, "ConvertChecker", singletontype_provider); - qmlRegisterSingletonType("seaprint.settings", 1, 0, "SeaPrintSettings", singletontype_provider); + qmlRegisterSingletonType("seaprint.settings", 1, 0, "SeaPrintSettings", singletontype_provider); + qmlRegisterSingletonType("seaprint.rangelistchecker", 1, 0, "RangeListChecker", singletontype_provider); + qmlRegisterType("seaprint.ippprinter", 1, 0, "IppPrinter"); qmlRegisterType("seaprint.imageitem", 1, 0, "ImageItem"); qmlRegisterUncreatableType("seaprint.ippmsg", 1, 0, "IppMsg", "Only used to supply an enum type"); diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index 76e9e51..81c4ced 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -721,21 +721,24 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename) Params.hwResW = PrinterResolutionRef.toObject()["x"].toInt(Params.hwResW); Params.hwResH = PrinterResolutionRef.toObject()["y"].toInt(Params.hwResH); - if(jobAttrs.contains("page-ranges")) + // Effected locally, unless it is Postscript which we cant't render + if(jobAttrs.contains("page-ranges") && mimeType != Mimer::Postscript) { - QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject(); - size_t fromPage = PageRanges["low"].toInt(); - size_t toPage = PageRanges["high"].toInt(); - if(fromPage != 0 || toPage != 0) + QJsonArray tmp; + QJsonValue pageRanges = getAttrOrDefault(jobAttrs, "page-ranges"); + if(pageRanges.isArray()) { - Params.pageRangeList = {{fromPage, toPage}}; + tmp = pageRanges.toArray(); } - - // Effected locally, unless it is Postscript which we cant't render - if(targetFormat != Mimer::Postscript) + else if(pageRanges.isObject()) { - jobAttrs.remove("page-ranges"); + tmp = {pageRanges.toObject()}; } + for(QJsonValueRef ref : tmp) + { + Params.pageRangeList.push_back({ref.toObject()["low"].toInt(), ref.toObject()["high"].toInt()}); + } + jobAttrs.remove("page-ranges"); } adjustRasterSettings(filename, mimeType, jobAttrs, Params); diff --git a/src/rangelistchecker.cpp b/src/rangelistchecker.cpp new file mode 100644 index 0000000..2674bfb --- /dev/null +++ b/src/rangelistchecker.cpp @@ -0,0 +1,41 @@ +#include "rangelistchecker.h" + +RangeListChecker::RangeListChecker() +{ + +} + +RangeListChecker::~RangeListChecker() +{ + +} + +RangeListChecker* RangeListChecker::m_Instance = 0; + +RangeListChecker* RangeListChecker::instance() +{ + static QMutex mutex; + if (!m_Instance) + { + mutex.lock(); + + if (!m_Instance) + m_Instance = new RangeListChecker; + + mutex.unlock(); + } + + return m_Instance; +} + +QJsonArray RangeListChecker::parse(QString str) const +{ + PrintParameters params; + params.setPageRange(str.toStdString()); + QJsonArray ret; + for(const std::pair& p : params.pageRangeList) + { + ret.append(QJsonObject {{"low", int(p.first)}, {"high", int(p.second)}}); + } + return ret; +} diff --git a/src/rangelistchecker.h b/src/rangelistchecker.h new file mode 100644 index 0000000..799d4f1 --- /dev/null +++ b/src/rangelistchecker.h @@ -0,0 +1,29 @@ +#ifndef RANGELISTCHECKER_H +#define RANGELISTCHECKER_H + +#include +#include +#include +#include + +#include "printparameters.h" + +class RangeListChecker : public QObject +{ + Q_OBJECT +public: + static RangeListChecker* instance(); + + Q_INVOKABLE QJsonArray parse(QString str) const; + +private: + static RangeListChecker* m_Instance; + + RangeListChecker(); + ~RangeListChecker(); + RangeListChecker(const RangeListChecker &); + RangeListChecker& operator=(const RangeListChecker &); + +}; + +#endif // RANGELISTCHECKER_H diff --git a/translations/harbour-seaprint-de.ts b/translations/harbour-seaprint-de.ts index 9c955a0..c435c86 100644 --- a/translations/harbour-seaprint-de.ts +++ b/translations/harbour-seaprint-de.ts @@ -531,6 +531,10 @@ auf diesem Drucker all Alle + + Advanced + + Setting diff --git a/translations/harbour-seaprint-es.ts b/translations/harbour-seaprint-es.ts index 80dc5b4..168d52c 100644 --- a/translations/harbour-seaprint-es.ts +++ b/translations/harbour-seaprint-es.ts @@ -530,6 +530,10 @@ all todos + + Advanced + + Setting diff --git a/translations/harbour-seaprint-fr.ts b/translations/harbour-seaprint-fr.ts index 860420f..2d8b781 100644 --- a/translations/harbour-seaprint-fr.ts +++ b/translations/harbour-seaprint-fr.ts @@ -531,6 +531,10 @@ sur cette imprimante all tout + + Advanced + + Setting diff --git a/translations/harbour-seaprint-nl.ts b/translations/harbour-seaprint-nl.ts index 74bd65c..6ded455 100644 --- a/translations/harbour-seaprint-nl.ts +++ b/translations/harbour-seaprint-nl.ts @@ -530,6 +530,10 @@ all alles + + Advanced + + Setting diff --git a/translations/harbour-seaprint-pl.ts b/translations/harbour-seaprint-pl.ts index ddfdce7..672ff29 100644 --- a/translations/harbour-seaprint-pl.ts +++ b/translations/harbour-seaprint-pl.ts @@ -530,6 +530,10 @@ all wszystkie + + Advanced + + Setting diff --git a/translations/harbour-seaprint-zh_CN.ts b/translations/harbour-seaprint-zh_CN.ts index dd1dbb3..b01724c 100644 --- a/translations/harbour-seaprint-zh_CN.ts +++ b/translations/harbour-seaprint-zh_CN.ts @@ -530,6 +530,10 @@ all 全部 + + Advanced + + Setting diff --git a/translations/harbour-seaprint.ts b/translations/harbour-seaprint.ts index ddd7d6a..4cdaabd 100644 --- a/translations/harbour-seaprint.ts +++ b/translations/harbour-seaprint.ts @@ -530,6 +530,10 @@ all + + Advanced + + Setting