GH-849 Further NetJob related fixes

This commit is contained in:
Petr Mrázek 2015-04-26 13:47:14 +02:00
parent d5c79db12c
commit 84549ed807
11 changed files with 39 additions and 42 deletions

View File

@ -584,8 +584,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
if (!skin_dls.isEmpty()) if (!skin_dls.isEmpty())
{ {
auto job = new NetJob("Startup player skins download"); auto job = new NetJob("Startup player skins download");
connect(job, SIGNAL(succeeded()), SLOT(skinJobFinished())); connect(job, &NetJob::succeeded, this, &MainWindow::skinJobFinished);
connect(job, SIGNAL(failed()), SLOT(skinJobFinished())); connect(job, &NetJob::failed, this, &MainWindow::skinJobFinished);
for (auto action : skin_dls) for (auto action : skin_dls)
{ {
job->addNetAction(action); job->addNetAction(action);

View File

@ -165,9 +165,9 @@ void UpdateDialog::changelogLoaded()
ui->changelogBrowser->setHtml(html); ui->changelogBrowser->setHtml(html);
} }
void UpdateDialog::changelogFailed() void UpdateDialog::changelogFailed(QString reason)
{ {
ui->changelogBrowser->setHtml(tr("<p align=\"center\" <span style=\"font-size:22pt;\">Failed to fetch changelog...</span></p>")); ui->changelogBrowser->setHtml(tr("<p align=\"center\" <span style=\"font-size:22pt;\">Failed to fetch changelog... Error: %1</span></p>").arg(reason));
} }
void UpdateDialog::on_btnUpdateLater_clicked() void UpdateDialog::on_btnUpdateLater_clicked()

View File

@ -53,7 +53,7 @@ public slots:
void changelogLoaded(); void changelogLoaded();
/// Slot for when the chengelog fails to load... /// Slot for when the chengelog fails to load...
void changelogFailed(); void changelogFailed(QString reason);
private: private:
ByteArrayDownloadPtr changelogDownload; ByteArrayDownloadPtr changelogDownload;

View File

@ -116,9 +116,9 @@ void LegacyUpdate::fmllibsStart()
dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry)); dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry));
} }
connect(dljob, SIGNAL(succeeded()), SLOT(fmllibsFinished())); connect(dljob, &NetJob::succeeded, this, &LegacyUpdate::fmllibsFinished);
connect(dljob, SIGNAL(failed()), SLOT(fmllibsFailed())); connect(dljob, &NetJob::failed, this, &LegacyUpdate::fmllibsFailed);
connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); connect(dljob, &NetJob::progress, this, &LegacyUpdate::progress);
legacyDownloadJob.reset(dljob); legacyDownloadJob.reset(dljob);
legacyDownloadJob->start(); legacyDownloadJob->start();
} }
@ -154,9 +154,9 @@ void LegacyUpdate::fmllibsFinished()
lwjglStart(); lwjglStart();
} }
void LegacyUpdate::fmllibsFailed() void LegacyUpdate::fmllibsFailed(QString reason)
{ {
emitFailed("Game update failed: it was impossible to fetch the required FML libraries."); emitFailed(tr("Game update failed: it was impossible to fetch the required FML libraries. Reason: %1").arg(reason));
return; return;
} }
@ -201,9 +201,8 @@ void LegacyUpdate::lwjglStart()
QNetworkReply *rep = worker->get(req); QNetworkReply *rep = worker->get(req);
m_reply = std::shared_ptr<QNetworkReply>(rep); m_reply = std::shared_ptr<QNetworkReply>(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); connect(rep, &QNetworkReply::downloadProgress, this, &LegacyUpdate::progress);
connect(worker.get(), SIGNAL(finished(QNetworkReply *)), connect(worker.get(), &QNetworkAccessManager::finished, this, &LegacyUpdate::lwjglFinished);
SLOT(lwjglFinished(QNetworkReply *)));
} }
void LegacyUpdate::lwjglFinished(QNetworkReply *reply) void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
@ -240,8 +239,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
req.setRawHeader("Host", hostname.toLatin1()); req.setRawHeader("Host", hostname.toLatin1());
req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
QNetworkReply *rep = worker->get(req); QNetworkReply *rep = worker->get(req);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)), connect(rep, &QNetworkReply::downloadProgress, this, &LegacyUpdate::progress);
SIGNAL(progress(qint64, qint64)));
m_reply = std::shared_ptr<QNetworkReply>(rep); m_reply = std::shared_ptr<QNetworkReply>(rep);
return; return;
} }
@ -341,9 +339,9 @@ void LegacyUpdate::extractLwjgl()
doneFile.close(); doneFile.close();
} }
void LegacyUpdate::lwjglFailed() void LegacyUpdate::lwjglFailed(QString reason)
{ {
emitFailed("Bad stuff happened while trying to get the lwjgl libs..."); emitFailed(tr("Bad stuff happened while trying to get the lwjgl libs: %1").arg(reason));
} }
void LegacyUpdate::jarStart() void LegacyUpdate::jarStart()
@ -377,7 +375,7 @@ void LegacyUpdate::jarStart()
auto entry = metacache->resolveEntry("versions", localPath); auto entry = metacache->resolveEntry("versions", localPath);
dljob->addNetAction(CacheDownload::make(QUrl(urlstr), entry)); dljob->addNetAction(CacheDownload::make(QUrl(urlstr), entry));
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); connect(dljob, SIGNAL(failed(QString)), SLOT(jarFailed(QString)));
connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
legacyDownloadJob.reset(dljob); legacyDownloadJob.reset(dljob);
legacyDownloadJob->start(); legacyDownloadJob->start();
@ -389,10 +387,10 @@ void LegacyUpdate::jarFinished()
ModTheJar(); ModTheJar();
} }
void LegacyUpdate::jarFailed() void LegacyUpdate::jarFailed(QString reason)
{ {
// bad, bad // bad, bad
emitFailed("Failed to download the minecraft jar. Try again later."); emitFailed(tr("Failed to download the minecraft jar: %1.").arg(reason));
} }
void LegacyUpdate::ModTheJar() void LegacyUpdate::ModTheJar()

View File

@ -39,15 +39,15 @@ private
slots: slots:
void lwjglStart(); void lwjglStart();
void lwjglFinished(QNetworkReply *); void lwjglFinished(QNetworkReply *);
void lwjglFailed(); void lwjglFailed(QString reason);
void jarStart(); void jarStart();
void jarFinished(); void jarFinished();
void jarFailed(); void jarFailed(QString reason);
void fmllibsStart(); void fmllibsStart();
void fmllibsFinished(); void fmllibsFinished();
void fmllibsFailed(); void fmllibsFailed(QString reason);
void extractLwjgl(); void extractLwjgl();

View File

@ -64,7 +64,7 @@ void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
emit progress(current_progress, total_progress); emit progress(current_progress, total_progress);
} }
void NetJob::start() void NetJob::executeTask()
{ {
qDebug() << m_job_name.toLocal8Bit() << " started."; qDebug() << m_job_name.toLocal8Bit() << " started.";
m_running = true; m_running = true;
@ -86,12 +86,12 @@ void NetJob::startMoreParts()
if(!m_failed.size()) if(!m_failed.size())
{ {
qDebug() << m_job_name << "succeeded."; qDebug() << m_job_name << "succeeded.";
emit succeeded(); emitSucceeded();
} }
else else
{ {
qCritical() << m_job_name << "failed."; qCritical() << m_job_name << "failed.";
emit failed(tr("%1 failed").arg(m_job_name)); emitFailed(tr("Job '%1' failed to process:\n%2").arg(m_job_name).arg(getFailedFiles().join("\n")));
} }
} }
return; return;

View File

@ -21,17 +21,17 @@
#include "MD5EtagDownload.h" #include "MD5EtagDownload.h"
#include "CacheDownload.h" #include "CacheDownload.h"
#include "HttpMetaCache.h" #include "HttpMetaCache.h"
#include "tasks/ProgressProvider.h" #include "tasks/Task.h"
#include "QObjectPtr.h" #include "QObjectPtr.h"
class NetJob; class NetJob;
typedef QObjectPtr<NetJob> NetJobPtr; typedef QObjectPtr<NetJob> NetJobPtr;
class NetJob : public ProgressProvider class NetJob : public Task
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit NetJob(QString job_name) : ProgressProvider(), m_job_name(job_name) {} explicit NetJob(QString job_name) : Task(), m_job_name(job_name) {}
virtual ~NetJob() {} virtual ~NetJob() {}
template <typename T> bool addNetAction(T action) template <typename T> bool addNetAction(T action)
{ {
@ -87,7 +87,7 @@ private slots:
void startMoreParts(); void startMoreParts();
public slots: public slots:
virtual void start(); virtual void executeTask();
// FIXME: implement // FIXME: implement
virtual void abort() {}; virtual void abort() {};

View File

@ -159,11 +159,10 @@ void DownloadTask::fileDownloadFinished()
emitSucceeded(); emitSucceeded();
} }
void DownloadTask::fileDownloadFailed() void DownloadTask::fileDownloadFailed(QString reason)
{ {
// TODO: Give more info about the failure. qCritical() << "Failed to download update files:" << reason;
qCritical() << "Failed to download update files."; emitFailed(tr("Failed to download update files: %1").arg(reason));
emitFailed(tr("Failed to download update files."));
} }
void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total) void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total)

View File

@ -78,7 +78,7 @@ protected slots:
void vinfoDownloadFailed(); void vinfoDownloadFailed();
void fileDownloadFinished(); void fileDownloadFinished();
void fileDownloadFailed(); void fileDownloadFailed(QString reason);
void fileDownloadProgressChanged(qint64 current, qint64 total); void fileDownloadProgressChanged(qint64 current, qint64 total);
}; };

View File

@ -96,7 +96,7 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
job->addNetAction(ByteArrayDownload::make(indexUrl)); job->addNetAction(ByteArrayDownload::make(indexUrl));
connect(job, &NetJob::succeeded, [this, notifyNoUpdate]() connect(job, &NetJob::succeeded, [this, notifyNoUpdate]()
{ updateCheckFinished(notifyNoUpdate); }); { updateCheckFinished(notifyNoUpdate); });
connect(job, SIGNAL(failed()), SLOT(updateCheckFailed())); connect(job, &NetJob::failed, this, &UpdateChecker::updateCheckFailed);
indexJob.reset(job); indexJob.reset(job);
job->start(); job->start();
} }
@ -260,10 +260,10 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
emit channelListLoaded(); emit channelListLoaded();
} }
void UpdateChecker::chanListDownloadFailed() void UpdateChecker::chanListDownloadFailed(QString reason)
{ {
m_chanListLoading = false; m_chanListLoading = false;
qCritical() << "Failed to download channel list."; qCritical() << QString("Failed to download channel list: %1").arg(reason);
emit channelListLoaded(); emit channelListLoaded();
} }

View File

@ -70,7 +70,7 @@ private slots:
void updateCheckFailed(); void updateCheckFailed();
void chanListDownloadFinished(bool notifyNoUpdate); void chanListDownloadFinished(bool notifyNoUpdate);
void chanListDownloadFailed(); void chanListDownloadFailed(QString reason);
private: private:
friend class UpdateCheckerTest; friend class UpdateCheckerTest;