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
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 {
target: printer
@ -254,16 +255,44 @@ Page {
spacing: Theme.paddingMedium
Label {
id: format_unsupported_label
visible: format_label.text == ""
visible: !supported_formats.pdf && !supported_formats.postscript && !supported_formats.office && !supported_formats.images
color: "red"
font.pixelSize: Theme.fontSizeExtraSmall
text: qsTr("No compatible formats supported")
}
Label {
id: format_label
color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.primaryColor : "red"
font.pixelSize: Theme.fontSizeExtraSmall
text: Utils.supported_formats(printer, ConvertChecker, considerAdditionalFormatsSetting.value).supported
HighlightImage {
height: Theme.itemSizeExtraSmall/2
width: Theme.itemSizeExtraSmall/2
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)
{
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 mimetypes = [];
var supported = [];
var pdf = false;
var postscript = false;
var office = false;
var images = false;
if(has(formats, Mimer.PDF) ||
(ConvertChecker.pdf && ( has(formats, Mimer.Postscript) || raster )))
{
mimetypes.push(Mimer.PDF);
supported.push("PDF");
}
if(has(formats, Mimer.Postscript))
{
mimetypes.push(Mimer.Postscript);
supported.push("Postscript");
}
{
pdf = true;
mimetypes.push(Mimer.PDF);
}
if(has(formats, Mimer.Postscript))
{
postscript = true;
mimetypes.push(Mimer.Postscript);
}
if((ConvertChecker.pdf && ConvertChecker.calligra) &&
( has(formats, Mimer.PDF) || has(formats, Mimer.Postscript) || raster ))
{
mimetypes = mimetypes.concat(Mimer.OfficeFormats);
}
if((ConvertChecker.pdf && ConvertChecker.calligra) &&
( has(formats, Mimer.PDF) || has(formats, Mimer.Postscript) || raster ))
{
office = true;
mimetypes = mimetypes.concat(Mimer.OfficeFormats);
}
if (raster || has(formats, Mimer.JPEG) || has(formats, Mimer.PNG))
{
mimetypes.push(Mimer.JPEG);
supported.push("JPEG");
mimetypes.push(Mimer.PNG);
supported.push("PNG");
mimetypes.push(Mimer.TIFF);
mimetypes.push(Mimer.GIF);
if (raster || has(formats, Mimer.JPEG) || has(formats, Mimer.PNG))
{
images = true;
mimetypes.push(Mimer.JPEG);
mimetypes.push(Mimer.PNG);
mimetypes.push(Mimer.TIFF);
mimetypes.push(Mimer.GIF);
}
}
return {supported: supported.join(" "), mimetypes: mimetypes};
return {pdf: pdf, postscript: postscript, office: office, images: images, mimetypes: mimetypes};
}
function has(arrayish, what)