From 0cc682c629a4e471495114584bb85be9c73b40ee Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 7 Mar 2014 16:15:38 +0100 Subject: [PATCH] Fix a few paste upload bugs Fixes https://www.pivotaltracker.com/story/show/66994990 --- logic/net/PasteUpload.cpp | 11 +++++------ logic/net/PasteUpload.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/logic/net/PasteUpload.cpp b/logic/net/PasteUpload.cpp index fa54d084..402eb400 100644 --- a/logic/net/PasteUpload.cpp +++ b/logic/net/PasteUpload.cpp @@ -25,7 +25,7 @@ void PasteUpload::executeTask() m_reply = std::shared_ptr(rep); connect(rep, &QNetworkReply::downloadProgress, [&](qint64 value, qint64 max) - { setProgress(value / max * 100); }); + { setProgress(value / qMax((qint64)1, max) * 100); }); connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); @@ -52,10 +52,9 @@ void PasteUpload::downloadFinished() emitFailed(jsonError.errorString()); return; } - QString error; - if (!parseResult(doc, &error)) + if (!parseResult(doc)) { - emitFailed(error); + emitFailed(tr("paste.ee returned an error. Please consult the logs for more information")); return; } } @@ -69,13 +68,13 @@ void PasteUpload::downloadFinished() emitSucceeded(); } -bool PasteUpload::parseResult(QJsonDocument doc, QString *parseError) +bool PasteUpload::parseResult(QJsonDocument doc) { auto object = doc.object(); auto status = object.value("status").toString("error"); if (status == "error") { - parseError = new QString(object.value("error").toString()); + QLOG_ERROR() << "paste.ee reported error:" << QString(object.value("error").toString()); return false; } // FIXME: not the place for GUI things. diff --git a/logic/net/PasteUpload.h b/logic/net/PasteUpload.h index 917a0016..83876c17 100644 --- a/logic/net/PasteUpload.h +++ b/logic/net/PasteUpload.h @@ -14,7 +14,7 @@ protected: virtual void executeTask(); private: - bool parseResult(QJsonDocument doc, QString *parseError); + bool parseResult(QJsonDocument doc); QString m_text; QString m_error; QWidget *m_window;