harbour-seaprint/qml/pages/utils.js

119 lines
3.2 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 mimetypes = [];
2019-12-01 22:27:00 +03:00
var supported = [];
if(has(formats, "application/pdf"))
{
mimetypes.push("application/pdf");
2019-12-01 22:27:00 +03:00
supported.push("PDF");
}
2020-02-17 22:06:39 +03:00
if(has(formats, "application/postscript"))
{
mimetypes.push("application/postscript");
supported.push("Postscript");
}
2019-12-01 22:27:00 +03:00
if(has(formats, "image/jpeg"))
{
mimetypes.push("image/jpeg");
2019-12-01 22:27:00 +03:00
supported.push("JPEG");
}
//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"] ? printer.attrs["printer-info"].value.split(";") : [];
for(var i in info)
{
if(info[i].split(":")[0] == "CMD")
{
if(!has(supported, "PDF") && has(info[i].split(":")[1].split(","), "PDF"))
{
mimetypes.push("application/pdf");
maybe.push("PDF");
}
2020-02-17 22:06:39 +03:00
if(!has(supported, "Postscript") && has(info[i].split(":")[1].split(","), "POSTSCRIPT"))
{
mimetypes.push("application/postscript");
maybe.push("Postscript");
}
break;
}
}
return {supported: supported.join(" "), maybe: maybe.join(" "), mimetypes: mimetypes};
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);
}