From baca58ea5c271333038ad13466eeb7acc50ecdde Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 28 May 2018 11:00:39 +0900 Subject: BaseJob: support status tracking The newly introduced statusChanged() signal allows clients to be notified about the job state transitions. --- lib/jobs/basejob.cpp | 6 +++++- lib/jobs/basejob.h | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 8d11cc83..9a5460d4 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -505,14 +505,18 @@ QByteArray BaseJob::errorDetails() const void BaseJob::setStatus(Status s) { + if (d->status == s) + return; + + s.message.replace(d->connection->accessToken(), "(REDACTED)"); if (!s.good()) qCWarning(d->logCat) << this << "status" << s; d->status = std::move(s); + emit statusChanged(d->status); } void BaseJob::setStatus(int code, QString message) { - message.replace(d->connection->accessToken(), "(REDACTED)"); setStatus({ code, std::move(message) }); } diff --git a/lib/jobs/basejob.h b/lib/jobs/basejob.h index eec09506..6c91a333 100644 --- a/lib/jobs/basejob.h +++ b/lib/jobs/basejob.h @@ -107,6 +107,15 @@ namespace QMatrixClient << s.code << ": " << s.message; } + bool operator==(const Status& other) const + { + return code == other.code && message == other.message; + } + bool operator!=(const Status& other) const + { + return !operator==(other); + } + int code; QString message; }; @@ -156,6 +165,9 @@ namespace QMatrixClient /** The job has sent a network request */ void started(); + /** The job has changed its status */ + void statusChanged(Status newStatus); + /** * The previous network request has failed; the next attempt will * be done in the specified time -- cgit v1.2.3