Make additional formats a printer property
...and add them to format choices ...and consider them properly supported, for now
This commit is contained in:
parent
ed218e5278
commit
8571b7fb5c
5 changed files with 44 additions and 51 deletions
|
@ -107,6 +107,7 @@ Page {
|
|||
Connections {
|
||||
target: printer
|
||||
onAttrsChanged: {
|
||||
console.log(printer.url, Object.keys(printer.attrs))
|
||||
if(Object.keys(printer.attrs).length === 0) {
|
||||
delegate.visible = false
|
||||
}
|
||||
|
@ -209,7 +210,7 @@ Page {
|
|||
spacing: Theme.paddingMedium
|
||||
Label {
|
||||
id: format_unsupported_label
|
||||
visible: format_label.text == "" && maybe_format_label.text == ""
|
||||
visible: format_label.text == ""
|
||||
color: "red"
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
text: qsTr("No compatible formats supported")
|
||||
|
@ -220,13 +221,6 @@ Page {
|
|||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
text: Utils.supported_formats(printer, ConvertChecker).supported
|
||||
}
|
||||
Label {
|
||||
id: maybe_format_label
|
||||
color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.secondaryColor : "red"
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
font.italic: true
|
||||
text: Utils.supported_formats(printer, ConvertChecker).maybe
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -109,7 +109,8 @@ Page {
|
|||
prettyName: prettyName,
|
||||
tag: tag,
|
||||
valid: printer.attrs.hasOwnProperty(name+"-supported"),
|
||||
choices: printer.attrs[name+"-supported"].value,
|
||||
choices: name == "document-format" ? printer.attrs[name+"-supported"].value.concat(printer.additionalDocumentFormats)
|
||||
: printer.attrs[name+"-supported"].value,
|
||||
default_choice: printer.attrs[name+"-default"].value,
|
||||
mime_type: Mimer.get_type(selectedFile)
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
function supported_formats(printer, ConvertChecker)
|
||||
{
|
||||
var formats = printer.attrs["document-format-supported"].value;
|
||||
var formats = printer.attrs["document-format-supported"].value+printer.additionalDocumentFormats;
|
||||
var mimetypes = [];
|
||||
var supported = [];
|
||||
if(has(formats, "application/pdf") || (ConvertChecker.pdf && ( has(formats, "image/pwg-raster") || has(formats, "image/urf"))) )
|
||||
|
@ -21,29 +21,8 @@ function supported_formats(printer, ConvertChecker)
|
|||
mimetypes.push("image/png");
|
||||
supported.push("PNG");
|
||||
}
|
||||
//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");
|
||||
}
|
||||
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};
|
||||
return {supported: supported.join(" "), mimetypes: mimetypes};
|
||||
}
|
||||
|
||||
function has(arrayish, what)
|
||||
|
|
|
@ -95,6 +95,10 @@ void IppPrinter::refresh() {
|
|||
_attrs = QJsonObject();
|
||||
emit attrsChanged();
|
||||
|
||||
_additionalDocumentFormats = QStringList();
|
||||
emit additionalDocumentFormatsChanged();
|
||||
|
||||
|
||||
QNetworkRequest request;
|
||||
|
||||
request.setUrl(httpUrl());
|
||||
|
@ -128,6 +132,31 @@ void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
|
|||
qDebug() << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
if(_attrs.contains("printer-device-id"))
|
||||
{
|
||||
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
||||
QStringList printerDeviceId = _attrs["printer-device-id"].toObject()["value"].toString().split(";");
|
||||
for (QStringList::iterator it = printerDeviceId.begin(); it != printerDeviceId.end(); it++)
|
||||
{
|
||||
QStringList kv = it->split(":");
|
||||
if(kv.length()==2 && kv[0]=="CMD")
|
||||
{
|
||||
QStringList cmds = kv[1].split(",");
|
||||
if(cmds.contains("PDF") && !supportedMimeTypes.contains("application/pdf"))
|
||||
{
|
||||
_additionalDocumentFormats.append("application/pdf");
|
||||
}
|
||||
if(cmds.contains("POSTSCRIPT") && !supportedMimeTypes.contains("application/postscript"))
|
||||
{
|
||||
_additionalDocumentFormats.append("application/postscript");
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug() << "additionalDocumentFormats" << _additionalDocumentFormats;
|
||||
emit additionalDocumentFormatsChanged();
|
||||
}
|
||||
|
||||
emit attrsChanged();
|
||||
}
|
||||
|
||||
|
@ -235,21 +264,6 @@ void IppPrinter::convertFailed(QString message)
|
|||
emit jobFinished(false);
|
||||
}
|
||||
|
||||
|
||||
bool IppPrinter::hasPrinterDeviceIdCmd(QString cmd)
|
||||
{
|
||||
QStringList printerDeviceId = _attrs["printer-device-id"].toObject()["value"].toString().split(";");
|
||||
for (QStringList::iterator it = printerDeviceId.begin(); it != printerDeviceId.end(); it++)
|
||||
{
|
||||
QStringList kv = it->split(":");
|
||||
if(kv.length()==2 && kv[0]=="CMD")
|
||||
{
|
||||
return kv[1].split(",").contains("PDF");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: make alwaysConvert force ratser format
|
||||
void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert)
|
||||
{
|
||||
|
@ -302,13 +316,13 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert)
|
|||
QString mimeType = mimer->get_type(filename);
|
||||
|
||||
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
||||
for(QStringList::iterator it = _additionalDocumentFormats.begin(); it != _additionalDocumentFormats.end(); it++)
|
||||
{
|
||||
supportedMimeTypes.append(*it);
|
||||
}
|
||||
|
||||
qDebug() << supportedMimeTypes << supportedMimeTypes.contains(mimeType);
|
||||
|
||||
bool supportsPdf = supportedMimeTypes.contains("application/pdf") || hasPrinterDeviceIdCmd("PDF");
|
||||
|
||||
qDebug() << "supportsPdf" << supportsPdf;
|
||||
|
||||
QJsonValue PrinterResolutionRef = getAttrOrDefault(attrs, "printer-resolution");
|
||||
quint32 HwResX = PrinterResolutionRef.toObject()["x"].toInt();
|
||||
quint32 HwResY = PrinterResolutionRef.toObject()["y"].toInt();
|
||||
|
|
|
@ -13,6 +13,7 @@ class IppPrinter : public QObject
|
|||
Q_PROPERTY(QJsonObject attrs MEMBER _attrs NOTIFY attrsChanged)
|
||||
Q_PROPERTY(QJsonObject jobAttrs MEMBER _jobAttrs NOTIFY jobAttrsChanged)
|
||||
Q_PROPERTY(QJsonArray jobs MEMBER _jobs NOTIFY jobsChanged)
|
||||
Q_PROPERTY(QStringList additionalDocumentFormats MEMBER _additionalDocumentFormats NOTIFY additionalDocumentFormatsChanged)
|
||||
Q_PROPERTY(QString busyMessage MEMBER _busyMessage NOTIFY busyMessageChanged)
|
||||
Q_PROPERTY(QString progress MEMBER _progress NOTIFY progressChanged)
|
||||
|
||||
|
@ -49,6 +50,7 @@ signals:
|
|||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY);
|
||||
|
||||
void additionalDocumentFormatsChanged();
|
||||
void busyMessageChanged();
|
||||
void progressChanged();
|
||||
|
||||
|
@ -86,6 +88,9 @@ private:
|
|||
QJsonObject _attrs;
|
||||
QJsonObject _jobAttrs;
|
||||
QJsonArray _jobs;
|
||||
|
||||
QStringList _additionalDocumentFormats;
|
||||
|
||||
QString _busyMessage;
|
||||
QString _progress;
|
||||
|
||||
|
|
Loading…
Reference in a new issue