Change format support indicators to pictures

This commit is contained in:
Anton Thomasson 2021-03-06 15:43:01 +01:00
parent 43373d159e
commit 0010cd593a
2 changed files with 67 additions and 33 deletions

View file

@ -145,7 +145,8 @@ Page {
visible: Object.keys(printer.attrs).length !== 0 visible: Object.keys(printer.attrs).length !== 0
property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown") property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown")
property bool canPrint: Utils.supported_formats(printer, ConvertChecker, considerAdditionalFormatsSetting.value).mimetypes.indexOf(selectedFileType) != -1 property var supported_formats: Utils.supported_formats(printer, ConvertChecker, considerAdditionalFormatsSetting.value)
property bool canPrint: supported_formats.mimetypes.indexOf(selectedFileType) != -1
Connections { Connections {
target: printer target: printer
@ -254,16 +255,44 @@ Page {
spacing: Theme.paddingMedium spacing: Theme.paddingMedium
Label { Label {
id: format_unsupported_label id: format_unsupported_label
visible: format_label.text == "" visible: !supported_formats.pdf && !supported_formats.postscript && !supported_formats.office && !supported_formats.images
color: "red" color: "red"
font.pixelSize: Theme.fontSizeExtraSmall font.pixelSize: Theme.fontSizeExtraSmall
text: qsTr("No compatible formats supported") text: qsTr("No compatible formats supported")
} }
Label {
id: format_label HighlightImage {
color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.primaryColor : "red" height: Theme.itemSizeExtraSmall/2
font.pixelSize: Theme.fontSizeExtraSmall width: Theme.itemSizeExtraSmall/2
text: Utils.supported_formats(printer, ConvertChecker, considerAdditionalFormatsSetting.value).supported visible: supported_formats.pdf
highlightColor: "red"
highlighted: !(selectedFile == "" || canPrint)
source: "image://theme/icon-m-file-pdf"
}
HighlightImage {
height: Theme.itemSizeExtraSmall/2
width: Theme.itemSizeExtraSmall/2
visible: supported_formats.postscript
highlightColor: "red"
highlighted: !(selectedFile == "" || canPrint)
source: "image://theme/icon-m-file-other"
}
HighlightImage {
height: Theme.itemSizeExtraSmall/2
width: Theme.itemSizeExtraSmall/2
visible: supported_formats.office
highlightColor: "red"
highlighted: !(selectedFile == "" || canPrint)
source: "image://theme/icon-m-file-formatted"
}
HighlightImage {
height: Theme.itemSizeExtraSmall/2
width: Theme.itemSizeExtraSmall/2
visible: supported_formats.images
highlightColor: "red"
highlighted: !(selectedFile == "" || canPrint)
source: "image://theme/icon-m-file-image"
} }
} }

View file

@ -1,3 +1,5 @@
// TODO move to IppPrinter and/or Mimer when i figure out how to handle considerAdditionalFormats there
function supported_formats(printer, ConvertChecker, considerAdditionalFormats) function supported_formats(printer, ConvertChecker, considerAdditionalFormats)
{ {
var formats = printer.attrs["document-format-supported"].value; var formats = printer.attrs["document-format-supported"].value;
@ -9,37 +11,40 @@ function supported_formats(printer, ConvertChecker, considerAdditionalFormats)
var raster = (has(formats, Mimer.PWG) || has(formats, Mimer.URF)); var raster = (has(formats, Mimer.PWG) || has(formats, Mimer.URF));
var mimetypes = []; var mimetypes = [];
var supported = []; var pdf = false;
var postscript = false;
var office = false;
var images = false;
if(has(formats, Mimer.PDF) || if(has(formats, Mimer.PDF) ||
(ConvertChecker.pdf && ( has(formats, Mimer.Postscript) || raster ))) (ConvertChecker.pdf && ( has(formats, Mimer.Postscript) || raster )))
{ {
mimetypes.push(Mimer.PDF); pdf = true;
supported.push("PDF"); mimetypes.push(Mimer.PDF);
} }
if(has(formats, Mimer.Postscript)) if(has(formats, Mimer.Postscript))
{ {
mimetypes.push(Mimer.Postscript); postscript = true;
supported.push("Postscript"); mimetypes.push(Mimer.Postscript);
} }
if((ConvertChecker.pdf && ConvertChecker.calligra) && if((ConvertChecker.pdf && ConvertChecker.calligra) &&
( has(formats, Mimer.PDF) || has(formats, Mimer.Postscript) || raster )) ( has(formats, Mimer.PDF) || has(formats, Mimer.Postscript) || raster ))
{ {
mimetypes = mimetypes.concat(Mimer.OfficeFormats); office = true;
} mimetypes = mimetypes.concat(Mimer.OfficeFormats);
}
if (raster || has(formats, Mimer.JPEG) || has(formats, Mimer.PNG)) if (raster || has(formats, Mimer.JPEG) || has(formats, Mimer.PNG))
{ {
mimetypes.push(Mimer.JPEG); images = true;
supported.push("JPEG"); mimetypes.push(Mimer.JPEG);
mimetypes.push(Mimer.PNG); mimetypes.push(Mimer.PNG);
supported.push("PNG"); mimetypes.push(Mimer.TIFF);
mimetypes.push(Mimer.TIFF); mimetypes.push(Mimer.GIF);
mimetypes.push(Mimer.GIF); }
} return {pdf: pdf, postscript: postscript, office: office, images: images, mimetypes: mimetypes};
return {supported: supported.join(" "), mimetypes: mimetypes};
} }
function has(arrayish, what) function has(arrayish, what)