Consider PDF support listed in printer-info

This commit is contained in:
Anton Thomasson 2020-02-16 14:01:19 +01:00
parent 8257eed03a
commit 86bfedf01a
2 changed files with 38 additions and 7 deletions

View file

@ -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
}
Row {
spacing: Theme.paddingMedium
Label {
id: format_label
color: canPrint ? Theme.primaryColor : "red"
font.pixelSize: Theme.fontSizeExtraSmall
text: Utils.supported_formats(printer)
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 {

View file

@ -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)