diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-29 16:38:10 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-29 16:47:05 +0900 |
commit | e58a03c84f89a5ec9091ca81ef040df659700ef2 (patch) | |
tree | 84797022d4b5cffea17cfc4da40beb630d5709a2 /lib/connection.cpp | |
parent | a677a3443fda9f77e893d448a55e8d0482d3d4b0 (diff) | |
download | libquotient-e58a03c84f89a5ec9091ca81ef040df659700ef2.tar.gz libquotient-e58a03c84f89a5ec9091ca81ef040df659700ef2.zip |
BaseJob: "background" switch; more extensive error reporting
Running a request in background, aside from some tweaks on the network
layer (see QNetworkRequest::BackgroundRequestAttribute), allows to
distinguish jobs not immediately caused by user interaction (such as
fetching thumbnails). This can be used to show or not show certain
notifications in UI of clients.
Error reporting has been extended with more methods:
errorCaption() - a human-readable phrase calculated from the status
code; intended to be shown as a dialog caption and in similar
situations.
errorRawData() - former errorDetails(), returns the raw response from
the server.
errorUrl() - returns a URL that may be useful with the error (e.g. for
the upcoming "consent not given" error, this will have the policy URL).
Connection::resultFailed() - a new signal emitted when _any_
BaseJob::failure() is emitted (enables centralised error handling
across all network requests in clients).
As a part of matching changes in Connection, callApi has an overload
that allows to specify the policy; a custom enum instead of bool has
been chosen for the parameter type, to avoid clashes with (arbitrary)
types of job parameters.
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 84557224..572ac76b 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -196,7 +196,7 @@ void Connection::doConnectToServer(const QString& user, const QString& password, }); connect(loginJob, &BaseJob::failure, this, [this, loginJob] { - emit loginError(loginJob->errorString(), loginJob->errorDetails()); + emit loginError(loginJob->errorString(), loginJob->errorRawData()); }); } @@ -263,7 +263,7 @@ void Connection::sync(int timeout) // Raw string: http://en.cppreference.com/w/cpp/language/string_literal const QString filter { R"({"room": { "timeline": { "limit": 100 } } })" }; auto job = d->syncJob = - callApi<SyncJob>(d->data->lastEvent(), filter, timeout); + callApi<SyncJob>(InBackground, d->data->lastEvent(), filter, timeout); connect( job, &SyncJob::success, this, [this, job] { onSyncSuccess(job->takeData()); d->syncJob = nullptr; @@ -272,15 +272,19 @@ void Connection::sync(int timeout) connect( job, &SyncJob::retryScheduled, this, [this,job] (int retriesTaken, int nextInMilliseconds) { - emit networkError(job->errorString(), job->errorDetails(), + emit networkError(job->errorString(), job->errorRawData(), retriesTaken, nextInMilliseconds); }); connect( job, &SyncJob::failure, this, [this, job] { d->syncJob = nullptr; if (job->error() == BaseJob::ContentAccessError) - emit loginError(job->errorString(), job->errorDetails()); + { + qCWarning(SYNCJOB) + << "Sync job failed with ContentAccessError - login expired?"; + emit loginError(job->errorString(), job->errorRawData()); + } else - emit syncError(job->errorString(), job->errorDetails()); + emit syncError(job->errorString(), job->errorRawData()); }); } @@ -386,22 +390,24 @@ inline auto splitMediaId(const QString& mediaId) return idParts; } -MediaThumbnailJob* Connection::getThumbnail(const QString& mediaId, QSize requestedSize) const +MediaThumbnailJob* Connection::getThumbnail(const QString& mediaId, + QSize requestedSize, RunningPolicy policy) const { auto idParts = splitMediaId(mediaId); - return callApi<MediaThumbnailJob>(idParts.front(), idParts.back(), - requestedSize); + return callApi<MediaThumbnailJob>(policy, + idParts.front(), idParts.back(), requestedSize); } -MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, QSize requestedSize) const +MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, + QSize requestedSize, RunningPolicy policy) const { - return getThumbnail(url.authority() + url.path(), requestedSize); + return getThumbnail(url.authority() + url.path(), requestedSize, policy); } -MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, int requestedWidth, - int requestedHeight) const +MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, + int requestedWidth, int requestedHeight, RunningPolicy policy) const { - return getThumbnail(url, QSize(requestedWidth, requestedHeight)); + return getThumbnail(url, QSize(requestedWidth, requestedHeight), policy); } UploadContentJob* Connection::uploadContent(QIODevice* contentSource, |