diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-12 22:04:28 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-14 00:18:59 +0900 |
commit | b3ad6aa8fe62f461c99ae7728482bd9958e38909 (patch) | |
tree | 36a529fca07f31dd1687ff0a7f6a21458ee9c511 | |
parent | 290ddb17189cf4c3a476b72eef13df1d26e8ede0 (diff) | |
download | libquotient-b3ad6aa8fe62f461c99ae7728482bd9958e38909.tar.gz libquotient-b3ad6aa8fe62f461c99ae7728482bd9958e38909.zip |
BaseJob: afterStart(), beforeAbandon(), up/downloadProgress()
To support the upcoming DownloadFileJob
-rw-r--r-- | jobs/basejob.cpp | 17 | ||||
-rw-r--r-- | jobs/basejob.h | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index 0a81ad5c..720ac560 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -217,15 +217,21 @@ void BaseJob::Private::sendRequest() } } -void BaseJob::beforeStart(const ConnectionData* connData) -{ -} +void BaseJob::beforeStart(const ConnectionData*) +{ } + +void BaseJob::afterStart(const ConnectionData*, QNetworkReply*) +{ } + +void BaseJob::beforeAbandon(QNetworkReply*) +{ } void BaseJob::start(const ConnectionData* connData) { d->connection = connData; beforeStart(connData); sendRequest(); + afterStart(connData, d->reply.data()); } void BaseJob::sendRequest() @@ -239,6 +245,10 @@ void BaseJob::sendRequest() connect( d->reply.data(), &QNetworkReply::finished, this, &BaseJob::gotReply ); if (d->reply->isRunning()) { + connect( d->reply.data(), &QNetworkReply::uploadProgress, + this, &BaseJob::uploadProgress); + connect( d->reply.data(), &QNetworkReply::downloadProgress, + this, &BaseJob::downloadProgress); d->timer.start(getCurrentTimeout()); qCDebug(d->logCat) << this << "request has been sent"; emit started(); @@ -431,6 +441,7 @@ void BaseJob::setStatus(int code, QString message) void BaseJob::abandon() { + beforeAbandon(d->reply.data()); this->disconnect(); if (d->reply) d->reply->disconnect(this); diff --git a/jobs/basejob.h b/jobs/basejob.h index 6648dc1b..e9e108c6 100644 --- a/jobs/basejob.h +++ b/jobs/basejob.h @@ -192,6 +192,9 @@ namespace QMatrixClient */ void failure(BaseJob*); + void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + void uploadProgress(qint64 bytesSent, qint64 bytesTotal); + protected: using headers_t = QHash<QByteArray, QByteArray>; @@ -210,6 +213,9 @@ namespace QMatrixClient void setExpectedContentTypes(const QByteArrayList& contentTypes); virtual void beforeStart(const ConnectionData* connData); + virtual void afterStart(const ConnectionData* connData, + QNetworkReply* reply); + virtual void beforeAbandon(QNetworkReply*); /** * Used by gotReply() to check the received reply for general |