From d5c79db12c326bd0175cd2990764948a536abbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 5 Apr 2015 16:06:15 +0200 Subject: [PATCH] GH-849 Fix failure signals not getting delivered from NetJob properly --- logic/net/NetJob.cpp | 6 ++-- logic/net/NetJob.h | 6 ---- logic/screenshots/ImgurUpload.cpp | 59 ++++++++++++++++++------------- logic/screenshots/ImgurUpload.h | 1 + 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/logic/net/NetJob.cpp b/logic/net/NetJob.cpp index 5a50b876..b5503daf 100644 --- a/logic/net/NetJob.cpp +++ b/logic/net/NetJob.cpp @@ -85,13 +85,13 @@ void NetJob::startMoreParts() { if(!m_failed.size()) { - qDebug() << m_job_name.toLocal8Bit() << "succeeded."; + qDebug() << m_job_name << "succeeded."; emit succeeded(); } else { - qCritical() << m_job_name.toLocal8Bit() << "failed."; - emit failed(); + qCritical() << m_job_name << "failed."; + emit failed(tr("%1 failed").arg(m_job_name)); } } return; diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h index 7f7b418c..912a74b3 100644 --- a/logic/net/NetJob.h +++ b/logic/net/NetJob.h @@ -86,12 +86,6 @@ public: private slots: void startMoreParts(); -signals: - void started(); - void progress(qint64 current, qint64 total); - void succeeded(); - void failed(); - public slots: virtual void start(); // FIXME: implement diff --git a/logic/screenshots/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp index 053156b9..abb695b3 100644 --- a/logic/screenshots/ImgurUpload.cpp +++ b/logic/screenshots/ImgurUpload.cpp @@ -20,6 +20,7 @@ ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot) void ImgurUpload::start() { + finished = false; m_status = Job_InProgress; QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); @@ -59,43 +60,51 @@ void ImgurUpload::start() } void ImgurUpload::downloadError(QNetworkReply::NetworkError error) { - qDebug() << m_reply->errorString(); + qCritical() << "ImgurUpload failed with error" << m_reply->errorString() << "Server reply:\n" << m_reply->readAll(); + if(finished) + { + qCritical() << "Double finished ImgurUpload!"; + return; + } m_status = Job_Failed; + finished = true; + m_reply.reset(); + emit failed(m_index_within_job); } void ImgurUpload::downloadFinished() { - if (m_status != Job_Failed) + if(finished) { - QByteArray data = m_reply->readAll(); - m_reply.reset(); - QJsonParseError jsonError; - QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - qDebug() << jsonError.errorString(); - emit failed(m_index_within_job); - return; - } - auto object = doc.object(); - if (!object.value("success").toBool()) - { - qDebug() << doc.toJson(); - emit failed(m_index_within_job); - return; - } - m_shot->m_imgurId = object.value("data").toObject().value("id").toString(); - m_shot->m_url = object.value("data").toObject().value("link").toString(); - m_status = Job_Finished; - emit succeeded(m_index_within_job); + qCritical() << "Double finished ImgurUpload!"; return; } - else + QByteArray data = m_reply->readAll(); + m_reply.reset(); + QJsonParseError jsonError; + QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); + if (jsonError.error != QJsonParseError::NoError) { - qDebug() << m_reply->readAll(); + qDebug() << "imgur server did not reply with JSON" << jsonError.errorString(); + finished = true; m_reply.reset(); emit failed(m_index_within_job); return; } + auto object = doc.object(); + if (!object.value("success").toBool()) + { + qDebug() << "Screenshot upload not successful:" << doc.toJson(); + finished = true; + m_reply.reset(); + emit failed(m_index_within_job); + return; + } + m_shot->m_imgurId = object.value("data").toObject().value("id").toString(); + m_shot->m_url = object.value("data").toObject().value("link").toString(); + m_status = Job_Finished; + finished = true; + emit succeeded(m_index_within_job); + return; } void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { diff --git a/logic/screenshots/ImgurUpload.h b/logic/screenshots/ImgurUpload.h index f569ac3e..f6f4c3a1 100644 --- a/logic/screenshots/ImgurUpload.h +++ b/logic/screenshots/ImgurUpload.h @@ -27,4 +27,5 @@ slots: private: ScreenshotPtr m_shot; + bool finished = true; };