From ad0f92ba1e7be203d099b47a45f92ff8d9599339 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Tue, 17 Dec 2019 20:18:57 +0100 Subject: [PATCH] Improve job flow --- qml/pages/PrinterPage.qml | 12 ++++++++++-- src/ippprinter.cpp | 9 ++++++++- src/ippprinter.h | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/qml/pages/PrinterPage.qml b/qml/pages/PrinterPage.qml index ca25f3d..ca10c11 100644 --- a/qml/pages/PrinterPage.qml +++ b/qml/pages/PrinterPage.qml @@ -14,8 +14,16 @@ Page { Connections { target: printer - onJobAttrsChanged: { - notifier.notify(printer.jobAttrs["job-state-message"].value) + onJobAttrsFinished: { + var msg = printer.jobAttrs["job-state-message"] && printer.jobAttrs["job-state-message"].value != "" + ? printer.jobAttrs["job-state-message"].value : qsTr("Unknown") + if(status == true) { + notifier.notify(qsTr("Print success: ") + msg) + pageStack.pop() //or replace? + } + else { + notifier.notify(qsTr("Print failed: ") + msg) + } } } diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index 246cc03..9738e1c 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -83,19 +83,26 @@ void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply) void IppPrinter::printRequestFinished(QNetworkReply *reply) { + _jobAttrs = QJsonObject(); + bool status = false; if(reply->error() == QNetworkReply::NoError) { try { IppMsg resp(reply); qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getJobAttrs(); _jobAttrs = resp.getJobAttrs()[0].toObject(); - emit jobAttrsChanged(); + status = resp.getStatus() <= 0xff; } catch(std::exception e) { qDebug() << e.what(); } } + else { + _jobAttrs.insert("job-state-message", QJsonObject {{"tag", IppMsg::TextWithoutLanguage}, {"value", "Network error"}}); + } + emit jobAttrsChanged(); + emit jobAttrsFinished(status); } void IppPrinter::getJobsRequestFinished(QNetworkReply *reply) diff --git a/src/ippprinter.h b/src/ippprinter.h index 0f32321..53723f9 100644 --- a/src/ippprinter.h +++ b/src/ippprinter.h @@ -32,6 +32,8 @@ signals: void jobAttrsChanged(); void jobsChanged(); + void jobAttrsFinished(bool status); + public slots: void onUrlChanged(); void getPrinterAttributesFinished(QNetworkReply* reply);