aboutsummaryrefslogtreecommitdiff
path: root/lib/jobs/basejob.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-29 16:38:10 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-29 16:47:05 +0900
commite58a03c84f89a5ec9091ca81ef040df659700ef2 (patch)
tree84797022d4b5cffea17cfc4da40beb630d5709a2 /lib/jobs/basejob.h
parenta677a3443fda9f77e893d448a55e8d0482d3d4b0 (diff)
downloadlibquotient-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/jobs/basejob.h')
-rw-r--r--lib/jobs/basejob.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/jobs/basejob.h b/lib/jobs/basejob.h
index 6c91a333..25f13472 100644
--- a/lib/jobs/basejob.h
+++ b/lib/jobs/basejob.h
@@ -43,6 +43,7 @@ namespace QMatrixClient
class BaseJob: public QObject
{
Q_OBJECT
+ Q_PROPERTY(QUrl requestUrl READ requestUrl CONSTANT)
Q_PROPERTY(int maxRetries READ maxRetries WRITE setMaxRetries)
public:
/* Just in case, the values are compatible with KJob
@@ -55,7 +56,7 @@ namespace QMatrixClient
, Abandoned = 50 //< A very brief period between abandoning and object deletion
, ErrorLevel = 100 //< Errors have codes starting from this
, NetworkError = 100
- , JsonParseError
+ , JsonParseError // TODO: Merge into IncorrectResponseError
, TimeoutError
, ContentAccessError
, NotFoundError
@@ -129,10 +130,15 @@ namespace QMatrixClient
const Query& query, Data&& data = {},
bool needsToken = true);
+ QUrl requestUrl() const;
+ bool isBackground() const;
+
Status status() const;
int error() const;
+ QString errorCaption() const;
virtual QString errorString() const;
- QByteArray errorDetails() const;
+ QByteArray errorRawData() const;
+ QUrl errorUrl() const;
int maxRetries() const;
void setMaxRetries(int newMaxRetries);
@@ -147,7 +153,8 @@ namespace QMatrixClient
}
public slots:
- void start(const ConnectionData* connData);
+ void start(const ConnectionData* connData,
+ bool inBackground = false);
/**
* Abandons the result of this job, arrived or unarrived.
@@ -302,7 +309,7 @@ namespace QMatrixClient
void timeout();
private slots:
- void sendRequest();
+ void sendRequest(bool inBackground);
void checkReply();
void gotReply();