harbour-seaprint/qml/pages/utils.js

94 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-12-01 22:27:00 +03:00
function supported_formats(printer)
{
var formats = printer.attrs["document-format-supported"].value;
var supported = [];
if(has(formats, "application/pdf"))
{
supported.push("PDF");
}
if(has(formats, "image/jpeg"))
{
supported.push("JPEG");
}
2019-12-08 15:55:56 +03:00
if(supported.length == 0)
{
2020-01-04 21:58:47 +03:00
supported.push(qsTr("No relevant formats supported"))
2019-12-08 15:55:56 +03:00
}
2020-01-03 14:45:51 +03:00
return supported.join(" ");
2019-12-01 22:27:00 +03:00
}
function has(arrayish, what)
{
for(var i in arrayish)
{
if(arrayish[i] == what)
return true
}
return false
}
2020-01-03 15:37:51 +03:00
function ippName(name, value)
{
switch(name) {
case "job-state":
switch(value) {
case 3:
return qsTr("pending");
case 4:
return qsTr("pending-held");
case 5:
return qsTr("processing");
case 6:
return qsTr("processing-stopped");
case 7:
return qsTr("canceled");
case 8:
return qsTr("aborted");
case 9:
return qsTr("completed");
default:
return qsTr("unknown state ")+value
}
case "print-quality":
switch(value) {
case 3:
return qsTr("draft");
case 4:
return qsTr("normal");
case 5:
return qsTr("high");
default:
return qsTr("unknown quality ")+value
}
case "orientation-requested":
switch(value) {
case 3:
return qsTr("portrait");
case 4:
return qsTr("landscape");
case 5:
return qsTr("reverse landscape");
case 6:
return qsTr("reverse portrait");
default:
return qsTr("unknown orientation ")+value
}
case "printer-resolution":
var units = "";
if(value.units==3) {
units=qsTr("dpi");
} else if (units==4){
units=qsTr("dots/cm")
}
return ""+value.x+"x"+value.y+units;
}
return value;
}
function endsWith(ending, string)
{
return string.lastIndexOf(ending) == (string.length - ending.length);
}