aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp19
-rw-r--r--jobs/basejob.h16
2 files changed, 30 insertions, 5 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 519e1517..cfdf8a28 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -42,12 +42,23 @@ class BaseJob::Private
BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken)
: d(new Private(connection, type, needsToken))
{
+ // Work around KJob inability to separate success and failure signals
+ connect(this, &BaseJob::result, [this]() {
+ if (error() == NoError)
+ emit success(this);
+ else
+ emit failure(this);
+ });
}
BaseJob::~BaseJob()
{
if( d->reply )
+ {
+ if( d->reply->isRunning() )
+ d->reply->abort();
d->reply->deleteLater();
+ }
delete d;
}
@@ -108,6 +119,9 @@ void BaseJob::fail(int errorCode, QString errorString)
{
setError( errorCode );
setErrorText( errorString );
+ if( d->reply->isRunning() )
+ d->reply->abort();
+ qWarning() << this << "failed:" << errorString;
emitResult();
}
@@ -125,7 +139,7 @@ void BaseJob::gotReply()
{
if( d->reply->error() != QNetworkReply::NoError )
{
- qDebug() << "NetworkError!!!" << d->reply->error();
+ qDebug() << "NetworkError:" << d->reply->error();
fail( NetworkError, d->reply->errorString() );
return;
}
@@ -142,8 +156,7 @@ void BaseJob::gotReply()
void BaseJob::timeout()
{
qDebug() << "Timeout!";
- if( d->reply->isRunning() )
- d->reply->abort();
+ fail( TimeoutError, "The job has timed out" );
}
void BaseJob::sslErrors(const QList<QSslError>& errors)
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 95cf4232..f1ad66d1 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -45,8 +45,20 @@ namespace QMatrixClient
void start() override;
- enum ErrorCode { NetworkError = KJob::UserDefinedError, JsonParseError, UserDefinedError };
-
+ enum ErrorCode { NetworkError = KJob::UserDefinedError,
+ JsonParseError, TimeoutError, UserDefinedError };
+
+ signals:
+ /**
+ * Emitted together with KJob::result() but only if there's no error.
+ */
+ void success(BaseJob*);
+ /**
+ * Emitted together with KJob::result() if there's an error.
+ * Same as result(), this won't be emitted in case of kill(Quietly).
+ */
+ void failure(BaseJob*);
+
protected:
ConnectionData* connection() const;