Fix visibility of missing/lost printers

This commit is contained in:
Anton Thomasson 2019-12-15 11:24:36 +01:00
parent cf8f4a6680
commit f56507c7ad
4 changed files with 25 additions and 4 deletions

View file

@ -73,11 +73,24 @@ Page {
delegate: ListItem { delegate: ListItem {
id: delegate id: delegate
contentItem.height: visible ? Math.max(column.implicitHeight, Theme.itemSizeLarge+2*Theme.paddingMedium) : 0 contentItem.height: visible ? Math.max(column.implicitHeight, Theme.itemSizeLarge+2*Theme.paddingMedium) : 0
visible: printer.attrs["printer-name"] ? true : false
property string name: printer.attrs["printer-name"].value visible: false
property string name: printer.attrs["printer-name"] ? printer.attrs["printer-name"].value : qsTr("Unknown")
property bool canPrint: Utils.can_print(printer, selectedFile) property bool canPrint: Utils.can_print(printer, selectedFile)
Connections {
target: printer
onAttrsChanged: {
if(Object.keys(printer.attrs).length === 0) {
delegate.visible = false
}
else {
delegate.visible = true
}
}
}
onClicked: { onClicked: {
if(!canPrint) if(!canPrint)
return; return;

View file

@ -65,20 +65,20 @@ void IppPrinter::onUrlChanged()
void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply) void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
{ {
qDebug() << reply->error() << reply->errorString() << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString(); qDebug() << reply->error() << reply->errorString() << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
_attrs = QJsonObject();
if(reply->error() == QNetworkReply::NoError) if(reply->error() == QNetworkReply::NoError)
{ {
try { try {
IppMsg resp(reply); IppMsg resp(reply);
qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs(); qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs();
_attrs = resp.getPrinterAttrs(); _attrs = resp.getPrinterAttrs();
emit attrsChanged();
} }
catch(std::exception e) catch(std::exception e)
{ {
qDebug() << e.what(); qDebug() << e.what();
} }
} }
emit attrsChanged();
} }
void IppPrinter::printRequestFinished(QNetworkReply *reply) void IppPrinter::printRequestFinished(QNetworkReply *reply)

View file

@ -108,6 +108,10 @@
<source>Remove printer</source> <source>Remove printer</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>

View file

@ -108,6 +108,10 @@
<source>Remove printer</source> <source>Remove printer</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>