From 86bfedf01a1e33a48f3bab73afc099bdadbcf861 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sun, 16 Feb 2020 14:01:19 +0100 Subject: [PATCH] Consider PDF support listed in printer-info --- qml/pages/FirstPage.qml | 23 +++++++++++++++++------ qml/pages/utils.js | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 24cfadf..295988a 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -108,7 +108,7 @@ Page { visible: false property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown") - property bool canPrint: printer.attrs["document-format-supported"].value.indexOf(selectedFileType) != -1 + property bool canPrint: Utils.supported_formats(printer).mimetypes.indexOf(selectedFileType) != -1 Connections { target: printer @@ -208,12 +208,23 @@ Page { text: printer.url } - Label { - id: format_label - color: canPrint ? Theme.primaryColor : "red" - font.pixelSize: Theme.fontSizeExtraSmall - text: Utils.supported_formats(printer) + Row { + spacing: Theme.paddingMedium + Label { + id: format_label + color: canPrint ? Theme.primaryColor : "red" + font.pixelSize: Theme.fontSizeExtraSmall + text: Utils.supported_formats(printer).supported + } + Label { + id: maybe_format_label + color: canPrint ? Theme.secondaryColor : "red" + font.pixelSize: Theme.fontSizeExtraSmall + font.italic: true + text: Utils.supported_formats(printer).maybe + } } + } RemorseItem { diff --git a/qml/pages/utils.js b/qml/pages/utils.js index 2567562..92393cd 100644 --- a/qml/pages/utils.js +++ b/qml/pages/utils.js @@ -1,13 +1,16 @@ function supported_formats(printer) { var formats = printer.attrs["document-format-supported"].value; + var mimetypes = []; var supported = []; if(has(formats, "application/pdf")) { + mimetypes.push("application/pdf"); supported.push("PDF"); } if(has(formats, "image/jpeg")) { + mimetypes.push("image/jpeg"); supported.push("JPEG"); } @@ -16,7 +19,24 @@ function supported_formats(printer) supported.push(qsTr("No compatible formats supported")) } - return supported.join(" "); + + //var info = "MFG:Hewlett-Packard;CMD:PJL,BIDI-ECP,PJL,POSTSCRIPT,PDF,PCLXL,PCL;MDL:HP LaserJet P3010 Series;CLS:PRINTER;DES:Hewlett-Packard ".split(";"); + var maybe = [] + var info = printer.attrs["printer-info"].value.split(";"); + for(var i in info) + { + if(info[i].split(":")[0] == "CMD") + { + if(has(info[i].split(":")[1].split(","), "PDF")) + { + mimetypes.push("application/pdf"); + maybe.push("PDF"); + } + break; + } + } + + return {supported: supported.join(" "), maybe: maybe.join(" "), mimetypes: mimetypes}; } function has(arrayish, what)