diff options
Diffstat (limited to 'jobs/basejob.cpp')
-rw-r--r-- | jobs/basejob.cpp | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index ea1a7158..240192d9 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -24,7 +24,7 @@ #include <QtNetwork/QNetworkRequest> #include <QtNetwork/QNetworkReply> #include <QtCore/QTimer> -#include <QtCore/QStringBuilder> +//#include <QtCore/QStringBuilder> #include <array> @@ -45,16 +45,15 @@ class BaseJob::Private public: // Using an idiom from clang-tidy: // http://clang.llvm.org/extra/clang-tidy/checks/modernize-pass-by-value.html - Private(const ConnectionData* c, HttpVerb v, - QString endpoint, QUrlQuery q, Data data, bool nt) - : connection(c), verb(v), apiEndpoint(std::move(endpoint)) + Private(HttpVerb v, QString endpoint, QUrlQuery q, Data data, bool nt) + : verb(v), apiEndpoint(std::move(endpoint)) , requestQuery(std::move(q)), requestData(std::move(data)) , needsToken(nt) { } void sendRequest(); - const ConnectionData* connection; + const ConnectionData* connection = nullptr; // Contents for the network request HttpVerb verb; @@ -80,16 +79,15 @@ inline QDebug operator<<(QDebug dbg, const BaseJob* j) return dbg << j->objectName(); } -BaseJob::BaseJob(const ConnectionData* connection, HttpVerb verb, - const QString& name, const QString& endpoint, +BaseJob::BaseJob(HttpVerb verb, const QString& name, const QString& endpoint, const Query& query, const Data& data, bool needsToken) - : d(new Private(connection, verb, endpoint, query, data, needsToken)) + : d(new Private(verb, endpoint, query, data, needsToken)) { setObjectName(name); d->timer.setSingleShot(true); connect (&d->timer, &QTimer::timeout, this, &BaseJob::timeout); d->retryTimer.setSingleShot(true); - connect (&d->retryTimer, &QTimer::timeout, this, &BaseJob::start); + connect (&d->retryTimer, &QTimer::timeout, this, &BaseJob::sendRequest); } BaseJob::~BaseJob() @@ -98,9 +96,14 @@ BaseJob::~BaseJob() qCDebug(d->logCat) << this << "destroyed"; } -const ConnectionData* BaseJob::connection() const +const QString& BaseJob::apiEndpoint() const { - return d->connection; + return d->apiEndpoint; +} + +void BaseJob::setApiEndpoint(const QString& apiEndpoint) +{ + d->apiEndpoint = apiEndpoint; } const QUrlQuery& BaseJob::query() const @@ -155,7 +158,18 @@ void BaseJob::Private::sendRequest() } } -void BaseJob::start() +void BaseJob::beforeStart(const ConnectionData* connData) +{ +} + +void BaseJob::start(const ConnectionData* connData) +{ + d->connection = connData; + beforeStart(connData); + sendRequest(); +} + +void BaseJob::sendRequest() { emit aboutToStart(); d->retryTimer.stop(); // In case we were counting down at the moment |