aboutsummaryrefslogtreecommitdiff
path: root/jobs/basejob.cpp
diff options
context:
space:
mode:
authorFelix Rohrbach <fxrh@gmx.de>2016-05-08 18:59:11 +0200
committerFelix Rohrbach <fxrh@gmx.de>2016-05-08 18:59:11 +0200
commit1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca (patch)
treefa0f4aded71f27974c9922bd587ba78774ade46c /jobs/basejob.cpp
parentfc95edb7a63bcacb02418c55e15a1aa21ac080cd (diff)
parent5a0e6080a6245aa2c68f254d7105f19629a5a654 (diff)
downloadlibquotient-1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca.tar.gz
libquotient-1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca.zip
Merge pull request #5 from KitsuneRal/basejob-improvement
Basejob improvement
Diffstat (limited to 'jobs/basejob.cpp')
-rw-r--r--jobs/basejob.cpp19
1 files changed, 16 insertions, 3 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)