diff options
-rw-r--r-- | logic/net/NetJob.cpp | 6 | ||||
-rw-r--r-- | logic/net/NetJob.h | 6 | ||||
-rw-r--r-- | logic/screenshots/ImgurUpload.cpp | 57 | ||||
-rw-r--r-- | logic/screenshots/ImgurUpload.h | 1 |
4 files changed, 37 insertions, 33 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(); + qCritical() << "Double finished ImgurUpload!"; + return; + } + QByteArray data = m_reply->readAll(); + m_reply.reset(); + QJsonParseError jsonError; + QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); + if (jsonError.error != QJsonParseError::NoError) + { + qDebug() << "imgur server did not reply with JSON" << jsonError.errorString(); + finished = true; 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); + emit failed(m_index_within_job); return; } - else + auto object = doc.object(); + if (!object.value("success").toBool()) { - qDebug() << m_reply->readAll(); + 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; }; |