From 8b3ffad51311c9e2e2695f7fbf2098938c87bdcc Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sun, 7 Jun 2020 14:54:15 +0200 Subject: [PATCH] Add setting to (not) consider additional formats --- qml/harbour-seaprint.qml | 7 +++++++ qml/pages/FirstPage.qml | 6 ++---- qml/pages/PrinterPage.qml | 11 +++++++++-- qml/pages/utils.js | 9 +++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/qml/harbour-seaprint.qml b/qml/harbour-seaprint.qml index e54f043..6e3acb9 100644 --- a/qml/harbour-seaprint.qml +++ b/qml/harbour-seaprint.qml @@ -103,5 +103,12 @@ ApplicationWindow key: "/apps/harbour-seaprint/settings/remove-redundant-raster-attributes" defaultValue: true } + + ConfigurationValue + { + id: considerAdditionalFormatsSetting + key: "/apps/harbour-seaprint/settings/consider-additional-formats" + defaultValue: true + } } diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index bc8f1d8..a631a3a 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -115,7 +115,7 @@ Page { visible: false property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown") - property bool canPrint: Utils.supported_formats(printer, ConvertChecker).mimetypes.indexOf(selectedFileType) != -1 + property bool canPrint: Utils.supported_formats(printer, ConvertChecker, considerAdditionalFormatsSetting.value).mimetypes.indexOf(selectedFileType) != -1 Connections { target: printer @@ -152,8 +152,6 @@ Page { property int debugCount: 0 onClicked: { - console.log(Utils.supported_formats(printer, ConvertChecker).mimetypes, selectedFileType, - Utils.supported_formats(printer, ConvertChecker).mimetypes.indexOf(selectedFileType) != -1) if(++debugCount == 5) { @@ -231,7 +229,7 @@ Page { id: format_label color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.primaryColor : "red" font.pixelSize: Theme.fontSizeExtraSmall - text: Utils.supported_formats(printer, ConvertChecker).supported + text: Utils.supported_formats(printer, ConvertChecker, considerAdditionalFormatsSetting.value).supported } } diff --git a/qml/pages/PrinterPage.qml b/qml/pages/PrinterPage.qml index 53cc9a9..60dd87c 100644 --- a/qml/pages/PrinterPage.qml +++ b/qml/pages/PrinterPage.qml @@ -118,8 +118,7 @@ Page { prettyName: prettyName, tag: tag, valid: printer.attrs.hasOwnProperty(name+"-supported"), - choices: name == "document-format" ? printer.attrs[name+"-supported"].value.concat(printer.additionalDocumentFormats) - : printer.attrs[name+"-supported"].value, + choices: maybeSupplementChoices(name, printer.attrs[name+"-supported"].value), default_choice: printer.attrs[name+"-default"].value, mime_type: Mimer.get_type(selectedFile) }) @@ -127,6 +126,14 @@ Page { } } + function maybeSupplementChoices(name, choices) + { + if(name == "document-format" && considerAdditionalFormatsSetting.value) + { + return choices.concat(printer.additionalDocumentFormats) + } + return choices + } } VerticalScrollDecorator {} diff --git a/qml/pages/utils.js b/qml/pages/utils.js index 257171f..97e4b7a 100644 --- a/qml/pages/utils.js +++ b/qml/pages/utils.js @@ -1,6 +1,11 @@ -function supported_formats(printer, ConvertChecker) +function supported_formats(printer, ConvertChecker, considerAdditionalFormats) { - var formats = printer.attrs["document-format-supported"].value+printer.additionalDocumentFormats; + var formats = printer.attrs["document-format-supported"].value; + if(considerAdditionalFormats) + { + formats=formats+printer.additionalDocumentFormats; + } + var mimetypes = []; var supported = []; if(has(formats, "application/pdf") ||