From 231e7df644045ae59da1c8f52387814b59602240 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sat, 6 Jun 2020 17:20:30 +0200 Subject: [PATCH] Expose IPP type enums to QML --- qml/pages/PrinterPage.qml | 33 +++++++++++++++++---------------- src/harbour-seaprint.cpp | 1 + src/ippmsg.h | 7 +++++-- src/ippprinter.h | 2 -- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/qml/pages/PrinterPage.qml b/qml/pages/PrinterPage.qml index 9f0b925..a907033 100644 --- a/qml/pages/PrinterPage.qml +++ b/qml/pages/PrinterPage.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 import seaprint.mimer 1.0 +import seaprint.ippmsg 1.0 import "utils.js" as Utils import Nemo.Configuration 1.0 @@ -55,16 +56,16 @@ Page { ListModel { id:mod - ListElement {name: "sides"; prettyName: qsTr("Sides"); tag: 0x23} - ListElement {name: "media"; prettyName: qsTr("Print media"); tag: 0x44} - ListElement {name: "copies"; prettyName: qsTr("Copies"); tag: 0x21} -// ListElement {name: "page-ranges"; prettyName: qsTr("Page range"); tag: 0x33} - ListElement {name: "print-color-mode"; prettyName: qsTr("Color mode"); tag: 0x23} -// ListElement {name: "orientation-requested"; prettyName: qsTr("Orientation"); tag: 0x23} - ListElement {name: "print-quality"; prettyName: qsTr("Quality"); tag: 0x23} - ListElement {name: "printer-resolution"; prettyName: qsTr("Resolution"); tag: 0x32} - ListElement {name: "document-format"; prettyName: qsTr("Transfer format"); tag: 0x49} - ListElement {name: "media-source"; prettyName: qsTr("Media source"); tag: 0x44} + 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: "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} + ListElement {name: "printer-resolution"; prettyName: qsTr("Resolution"); tag: IppMsg.Resolution} + ListElement {name: "document-format"; prettyName: qsTr("Transfer format"); tag: IppMsg.MimeMediaType} + ListElement {name: "media-source"; prettyName: qsTr("Media source"); tag: IppMsg.Keyword} } SilicaListView { @@ -96,7 +97,7 @@ Page { Component.onCompleted: { switch(tag) { - case 0x21: + case IppMsg.Integer: loader.setSource("../components/IntegerSetting.qml", {name: name, prettyName: prettyName, @@ -107,7 +108,7 @@ Page { default_choice: printer.attrs[name+"-default"].value }) break - case 0x33: + case IppMsg.IntegerRange: loader.setSource("../components/RangeSetting.qml", {name: name, prettyName: prettyName, @@ -115,10 +116,10 @@ Page { valid: false //TODO printer.attrs.hasOwnProperty(name+"-supported"), }) break - case 0x32: - case 0x23: - case 0x44: - case 0x49: + case IppMsg.Resolution: + case IppMsg.Enum: + case IppMsg.Keyword: + case IppMsg.MimeMediaType: loader.setSource("../components/ChoiceSetting.qml", {name: name, prettyName: prettyName, diff --git a/src/harbour-seaprint.cpp b/src/harbour-seaprint.cpp index 5b2252c..468de25 100644 --- a/src/harbour-seaprint.cpp +++ b/src/harbour-seaprint.cpp @@ -37,6 +37,7 @@ int main(int argc, char *argv[]) qmlRegisterSingletonType("seaprint.mimer", 1, 0, "Mimer", singletontype_provider); qmlRegisterSingletonType("seaprint.convertchecker", 1, 0, "ConvertChecker", singletontype_provider); qmlRegisterType("seaprint.ippprinter", 1, 0, "IppPrinter"); + qmlRegisterUncreatableType("seaprint.ippmsg", 1, 0, "IppMsg", "Only used to supply an enum type"); QQuickView* view = SailfishApp::createView(); diff --git a/src/ippmsg.h b/src/ippmsg.h index 6b31af9..9cba800 100644 --- a/src/ippmsg.h +++ b/src/ippmsg.h @@ -4,6 +4,7 @@ #include "bytestream.h" #include +#include #include #include #include @@ -12,6 +13,7 @@ class IppMsg { + Q_GADGET public: enum IppTag : quint8 { @@ -39,6 +41,7 @@ public: NaturalLanguage = 0x48, MimeMediaType = 0x49 }; + Q_ENUMS(IppTag) enum Operation : quint16 { PrintJob = 0x0002, @@ -59,8 +62,8 @@ public: PurgeJobs = 0x0012 }; - IppMsg(); - IppMsg(QNetworkReply* resp); + explicit IppMsg(); + explicit IppMsg(QNetworkReply* resp); IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs = QJsonObject()); IppMsg(const IppMsg& other) = default; ~IppMsg(); diff --git a/src/ippprinter.h b/src/ippprinter.h index 7a8ea5a..7ee6c57 100644 --- a/src/ippprinter.h +++ b/src/ippprinter.h @@ -31,8 +31,6 @@ public: Q_INVOKABLE bool getJobs(); Q_INVOKABLE bool cancelJob(qint32 jobId); - bool hasPrinterDeviceIdCmd(QString cmd); - signals: void urlChanged(); void attrsChanged();