Simplify mime type handling
This commit is contained in:
parent
fee3d0a5eb
commit
f586efd500
2 changed files with 4 additions and 22 deletions
|
@ -12,6 +12,7 @@ Page {
|
|||
allowedOrientations: Orientation.All
|
||||
|
||||
property string selectedFile: ""
|
||||
property string selectedFileType
|
||||
|
||||
IppDiscovery {
|
||||
id: discovery
|
||||
|
@ -88,7 +89,7 @@ Page {
|
|||
visible: false
|
||||
|
||||
property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown")
|
||||
property bool canPrint: Utils.can_print(printer, selectedFile)
|
||||
property bool canPrint: printer.attrs["document-format-supported"].value.indexOf(selectedFileType) != -1
|
||||
|
||||
Connections {
|
||||
target: printer
|
||||
|
@ -226,6 +227,7 @@ Page {
|
|||
|
||||
onSelectedContentPropertiesChanged: {
|
||||
page.selectedFile = selectedContentProperties.filePath
|
||||
page.selectedFileType = selectedContentProperties.mimeType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,14 @@
|
|||
function supported_formats(printer)
|
||||
{
|
||||
return _formats(printer).supported;
|
||||
}
|
||||
|
||||
function format_filters(printer)
|
||||
{
|
||||
return _formats(printer).filters;
|
||||
}
|
||||
|
||||
function _formats(printer)
|
||||
{
|
||||
var formats = printer.attrs["document-format-supported"].value;
|
||||
var supported = [];
|
||||
var filters = [];
|
||||
if(has(formats, "application/pdf"))
|
||||
{
|
||||
supported.push("PDF");
|
||||
filters.push("*.pdf");
|
||||
}
|
||||
if(has(formats, "image/jpeg"))
|
||||
{
|
||||
supported.push("JPEG");
|
||||
filters.push("*.jpg");
|
||||
filters.push("*.jpeg");
|
||||
}
|
||||
|
||||
if(supported.length == 0)
|
||||
|
@ -30,7 +16,7 @@ function _formats(printer)
|
|||
supported.push("No relevant formats supported")
|
||||
}
|
||||
|
||||
return {supported: supported.join(" "), filters: filters};
|
||||
return supported.join(" ");
|
||||
}
|
||||
|
||||
function has(arrayish, what)
|
||||
|
@ -42,9 +28,3 @@ function has(arrayish, what)
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function can_print(printer, fileName)
|
||||
{
|
||||
// Move to ippprinter?
|
||||
return format_filters(printer).indexOf("*."+fileName.split('.').pop()) != -1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue