From f56507c7adc008e504335cbb05439beac14230b3 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sun, 15 Dec 2019 11:24:36 +0100 Subject: [PATCH] Fix visibility of missing/lost printers --- qml/pages/FirstPage.qml | 17 +++++++++++++++-- src/ippprinter.cpp | 4 ++-- translations/harbour-seaprint-de.ts | 4 ++++ translations/harbour-seaprint.ts | 4 ++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index cfc308b..526dca4 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -73,11 +73,24 @@ Page { delegate: ListItem { id: delegate 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) + Connections { + target: printer + onAttrsChanged: { + if(Object.keys(printer.attrs).length === 0) { + delegate.visible = false + } + else { + delegate.visible = true + } + } + } + onClicked: { if(!canPrint) return; diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index 8245b88..246cc03 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -65,20 +65,20 @@ void IppPrinter::onUrlChanged() void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply) { qDebug() << reply->error() << reply->errorString() << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString(); + _attrs = QJsonObject(); if(reply->error() == QNetworkReply::NoError) { try { IppMsg resp(reply); qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs(); _attrs = resp.getPrinterAttrs(); - emit attrsChanged(); } catch(std::exception e) { qDebug() << e.what(); } } - + emit attrsChanged(); } void IppPrinter::printRequestFinished(QNetworkReply *reply) diff --git a/translations/harbour-seaprint-de.ts b/translations/harbour-seaprint-de.ts index c438ca4..8da74a3 100644 --- a/translations/harbour-seaprint-de.ts +++ b/translations/harbour-seaprint-de.ts @@ -108,6 +108,10 @@ Remove printer + + Unknown + + JobsPage diff --git a/translations/harbour-seaprint.ts b/translations/harbour-seaprint.ts index c438ca4..8da74a3 100644 --- a/translations/harbour-seaprint.ts +++ b/translations/harbour-seaprint.ts @@ -108,6 +108,10 @@ Remove printer + + Unknown + + JobsPage