GH-849 Fix failure signals not getting delivered from NetJob properly

This commit is contained in:
Petr Mrázek 2015-04-05 16:06:15 +02:00
parent f623dc54ef
commit d5c79db12c
4 changed files with 38 additions and 34 deletions

View File

@ -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;

View File

@ -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

View File

@ -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)
{
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() << jsonError.errorString();
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() << doc.toJson();
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;
}
else
{
qDebug() << m_reply->readAll();
m_reply.reset();
emit failed(m_index_within_job);
return;
}
}
void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{

View File

@ -27,4 +27,5 @@ slots:
private:
ScreenshotPtr m_shot;
bool finished = true;
};