NOISSUE eliminate ProgressProvider

This commit is contained in:
Petr Mrázek 2015-04-26 23:04:50 +02:00
parent 84549ed807
commit f8650e3965
32 changed files with 80 additions and 123 deletions

View File

@ -44,11 +44,11 @@ void LoginDialog::accept()
// Setup the login task and start it
m_account = MojangAccount::createFromUsername(ui->userTextBox->text());
m_loginTask = m_account->login(nullptr, ui->passTextBox->text());
connect(m_loginTask.get(), &ProgressProvider::failed, this, &LoginDialog::onTaskFailed);
connect(m_loginTask.get(), &ProgressProvider::succeeded, this,
connect(m_loginTask.get(), &Task::failed, this, &LoginDialog::onTaskFailed);
connect(m_loginTask.get(), &Task::succeeded, this,
&LoginDialog::onTaskSucceeded);
connect(m_loginTask.get(), &ProgressProvider::status, this, &LoginDialog::onTaskStatus);
connect(m_loginTask.get(), &ProgressProvider::progress, this, &LoginDialog::onTaskProgress);
connect(m_loginTask.get(), &Task::status, this, &LoginDialog::onTaskStatus);
connect(m_loginTask.get(), &Task::progress, this, &LoginDialog::onTaskProgress);
m_loginTask->start();
}

View File

@ -54,7 +54,7 @@ void ProgressDialog::updateSize()
resize(QSize(480, minimumSizeHint().height()));
}
int ProgressDialog::exec(ProgressProvider *task)
int ProgressDialog::exec(Task *task)
{
this->task = task;
@ -74,7 +74,7 @@ int ProgressDialog::exec(ProgressProvider *task)
return QDialog::Accepted;
}
ProgressProvider *ProgressDialog::getTask()
Task *ProgressDialog::getTask()
{
return task;
}

View File

@ -17,7 +17,7 @@
#include <QDialog>
class ProgressProvider;
class Task;
namespace Ui
{
@ -34,11 +34,11 @@ public:
void updateSize();
int exec(ProgressProvider *task);
int exec(Task *task);
void setSkipButton(bool present, QString label = QString());
ProgressProvider *getTask();
Task *getTask();
public
slots:
@ -49,7 +49,7 @@ slots:
void changeStatus(const QString &status);
void changeProgress(qint64 current, qint64 total);
private
slots:
void on_skipButton_clicked(bool checked);
@ -61,5 +61,5 @@ protected:
private:
Ui::ProgressDialog *ui;
ProgressProvider *task;
Task *task;
};

View File

@ -17,7 +17,6 @@
#include <QWidget>
#include "net/NetJob.h"
#include "java/JavaChecker.h"
#include "BaseInstance.h"
#include "BasePage.h"

View File

@ -18,7 +18,6 @@
#include <QWidget>
#include "minecraft/OneSixInstance.h"
#include "net/NetJob.h"
#include "pages/BasePage.h"
#include <MultiMC.h>

View File

@ -18,7 +18,6 @@
#include <QWidget>
#include "BaseInstance.h"
#include "net/NetJob.h"
#include "BaseProcess.h"
#include "BasePage.h"
#include <MultiMC.h>

View File

@ -18,7 +18,6 @@
#include <QWidget>
#include "minecraft/OneSixInstance.h"
#include "net/NetJob.h"
#include "BasePage.h"
#include <MultiMC.h>

View File

@ -18,7 +18,6 @@
#include <QWidget>
#include "BaseInstance.h"
#include "net/NetJob.h"
#include "BasePage.h"
#include <MultiMC.h>

View File

@ -18,7 +18,6 @@
#include <QWidget>
#include "minecraft/OneSixInstance.h"
#include "net/NetJob.h"
#include "BasePage.h"
namespace Ui
@ -72,7 +71,6 @@ private:
Ui::VersionPage *ui;
std::shared_ptr<MinecraftProfile> m_version;
OneSixInstance *m_inst;
NetJobPtr forgeJob;
public
slots:

View File

@ -21,7 +21,7 @@ class OneSixInstance;
class QDir;
class QString;
class QObject;
class ProgressProvider;
class Task;
struct BaseVersion;
typedef std::shared_ptr<BaseVersion> BaseVersionPtr;
@ -35,7 +35,7 @@ public:
virtual bool add(OneSixInstance *to);
virtual bool remove(OneSixInstance *from);
virtual ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
virtual Task *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
protected:
virtual QString id() const = 0;

View File

@ -177,7 +177,6 @@ SET(LOGIC_SOURCES
icons/IconList.cpp
# Tasks
tasks/ProgressProvider.h
tasks/Task.h
tasks/Task.cpp
tasks/ThreadTask.h

View File

@ -384,8 +384,8 @@ protected:
{ setProgress(100 * current / qMax((qint64)1, total)); });
connect(fjob, &NetJob::status, [this](const QString & msg)
{ setStatus(msg); });
connect(fjob, &NetJob::failed, [this]()
{ emitFailed(tr("Failure to download forge")); });
connect(fjob, &NetJob::failed, [this](QString reason)
{ emitFailed(tr("Failure to download forge:\n%1").arg(reason)); });
connect(fjob, &NetJob::succeeded, installFunction);
fjob->start();
}
@ -428,7 +428,7 @@ private:
BaseVersionPtr m_version;
};
ProgressProvider *ForgeInstaller::createInstallTask(OneSixInstance *instance,
Task *ForgeInstaller::createInstallTask(OneSixInstance *instance,
BaseVersionPtr version, QObject *parent)
{
if (!version)

View File

@ -30,7 +30,7 @@ class ForgeInstaller : public BaseInstaller
public:
ForgeInstaller();
virtual ~ForgeInstaller(){}
virtual ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
virtual Task *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
virtual QString id() const override { return "net.minecraftforge"; }
protected:

View File

@ -33,7 +33,7 @@ void JavaCheckerJob::partFinished(JavaCheckResult result)
}
}
void JavaCheckerJob::start()
void JavaCheckerJob::executeTask()
{
qDebug() << m_job_name.toLocal8Bit() << " started.";
m_running = true;

View File

@ -18,16 +18,16 @@
#include <QtNetwork>
#include <QLabel>
#include "JavaChecker.h"
#include "tasks/ProgressProvider.h"
#include "tasks/Task.h"
class JavaCheckerJob;
typedef std::shared_ptr<JavaCheckerJob> JavaCheckerJobPtr;
class JavaCheckerJob : public ProgressProvider
class JavaCheckerJob : public Task
{
Q_OBJECT
public:
explicit JavaCheckerJob(QString job_name) : ProgressProvider(), m_job_name(job_name) {};
explicit JavaCheckerJob(QString job_name) : Task(), m_job_name(job_name) {};
bool addJavaCheckerAction(JavaCheckerPtr base)
{
@ -66,17 +66,17 @@ public:
signals:
void started();
void progress(int current, int total);
void finished(QList<JavaCheckResult>);
public
slots:
virtual void start();
// FIXME: implement
public slots:
virtual void abort() {};
private
slots:
private slots:
void partFinished(JavaCheckResult result);
protected:
virtual void executeTask() override;
private:
QString m_job_name;
QList<JavaCheckerPtr> javacheckers;

View File

@ -178,7 +178,7 @@ void JavaListLoadTask::executeTask()
m_job = std::shared_ptr<JavaCheckerJob>(new JavaCheckerJob("Java detection"));
connect(m_job.get(), SIGNAL(finished(QList<JavaCheckResult>)), this, SLOT(javaCheckerFinished(QList<JavaCheckResult>)));
connect(m_job.get(), SIGNAL(progress(int, int)), this, SLOT(checkerProgress(int, int)));
connect(m_job.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(checkerProgress(qint64, qint64)));
qDebug() << "Probing the following Java paths: ";
int id = 0;
@ -197,7 +197,7 @@ void JavaListLoadTask::executeTask()
m_job->start();
}
void JavaListLoadTask::checkerProgress(int current, int total)
void JavaListLoadTask::checkerProgress(qint64 current, qint64 total)
{
float progress = (current * 100.0) / total;
this->setProgress((int) progress);

View File

@ -87,7 +87,7 @@ public:
virtual void executeTask();
public slots:
void javaCheckerFinished(QList<JavaCheckResult> results);
void checkerProgress(int current, int total);
void checkerProgress(qint64 current, qint64 total);
protected:
std::shared_ptr<JavaCheckerJob> m_job;

View File

@ -136,7 +136,7 @@ private:
BaseVersionPtr m_version;
};
ProgressProvider *LiteLoaderInstaller::createInstallTask(OneSixInstance *instance,
Task *LiteLoaderInstaller::createInstallTask(OneSixInstance *instance,
BaseVersionPtr version,
QObject *parent)
{

View File

@ -30,7 +30,7 @@ public:
bool add(OneSixInstance *to) override;
virtual QString id() const override { return "com.mumfrey.liteloader"; }
ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
Task *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
private:
LiteLoaderVersionPtr m_version;

View File

@ -72,7 +72,7 @@ void OneSixUpdate::executeTask()
return;
}
connect(versionUpdateTask.get(), SIGNAL(succeeded()), SLOT(jarlibStart()));
connect(versionUpdateTask.get(), SIGNAL(failed(QString)), SLOT(versionUpdateFailed(QString)));
connect(versionUpdateTask.get(), &NetJob::failed, this, &OneSixUpdate::versionUpdateFailed);
connect(versionUpdateTask.get(), SIGNAL(progress(qint64, qint64)),
SIGNAL(progress(qint64, qint64)));
setStatus(tr("Getting the version files from Mojang..."));
@ -100,7 +100,7 @@ void OneSixUpdate::assetIndexStart()
jarlibDownloadJob.reset(job);
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetIndexFinished()));
connect(jarlibDownloadJob.get(), SIGNAL(failed()), SLOT(assetIndexFailed()));
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::assetIndexFailed);
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)),
SIGNAL(progress(qint64, qint64)));
@ -146,7 +146,7 @@ void OneSixUpdate::assetIndexFinished()
job->addNetAction(dl);
jarlibDownloadJob.reset(job);
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetsFinished()));
connect(jarlibDownloadJob.get(), SIGNAL(failed()), SLOT(assetsFailed()));
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::assetsFailed);
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)),
SIGNAL(progress(qint64, qint64)));
jarlibDownloadJob->start();
@ -155,9 +155,9 @@ void OneSixUpdate::assetIndexFinished()
assetsFinished();
}
void OneSixUpdate::assetIndexFailed()
void OneSixUpdate::assetIndexFailed(QString reason)
{
emitFailed(tr("Failed to download the assets index!"));
emitFailed(tr("Failed to download the assets index:\n%1").arg(reason));
}
void OneSixUpdate::assetsFinished()
@ -165,9 +165,9 @@ void OneSixUpdate::assetsFinished()
emitSucceeded();
}
void OneSixUpdate::assetsFailed()
void OneSixUpdate::assetsFailed(QString reason)
{
emitFailed(tr("Failed to download assets!"));
emitFailed(tr("Failed to download assets:\n%1").arg(reason));
}
void OneSixUpdate::jarlibStart()
@ -280,7 +280,7 @@ void OneSixUpdate::jarlibStart()
}
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(jarlibFinished()));
connect(jarlibDownloadJob.get(), SIGNAL(failed()), SLOT(jarlibFailed()));
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::jarlibFailed);
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)),
SIGNAL(progress(qint64, qint64)));
@ -336,12 +336,12 @@ void OneSixUpdate::jarlibFinished()
}
}
void OneSixUpdate::jarlibFailed()
void OneSixUpdate::jarlibFailed(QString reason)
{
QStringList failed = jarlibDownloadJob->getFailedFiles();
QString failed_all = failed.join("\n");
emitFailed(
tr("Failed to download the following files:\n%1\n\nPlease try again.").arg(failed_all));
tr("Failed to download the following files:\n%1\n\nReason:%2\nPlease try again.").arg(failed_all, reason));
}
void OneSixUpdate::fmllibsStart()
@ -400,7 +400,7 @@ void OneSixUpdate::fmllibsStart()
}
connect(dljob, SIGNAL(succeeded()), SLOT(fmllibsFinished()));
connect(dljob, SIGNAL(failed()), SLOT(fmllibsFailed()));
connect(dljob, &NetJob::failed, this, &OneSixUpdate::fmllibsFailed);
connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
legacyDownloadJob.reset(dljob);
legacyDownloadJob->start();
@ -437,9 +437,9 @@ void OneSixUpdate::fmllibsFinished()
assetIndexStart();
}
void OneSixUpdate::fmllibsFailed()
void OneSixUpdate::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.\nReason:\n%1").arg(reason));
return;
}

View File

@ -40,18 +40,18 @@ slots:
void jarlibStart();
void jarlibFinished();
void jarlibFailed();
void jarlibFailed(QString reason);
void fmllibsStart();
void fmllibsFinished();
void fmllibsFailed();
void fmllibsFailed(QString reason);
void assetIndexStart();
void assetIndexFinished();
void assetIndexFailed();
void assetIndexFailed(QString reason);
void assetsFinished();
void assetsFailed();
void assetsFailed(QString reason);
private:
NetJobPtr jarlibDownloadJob;

View File

@ -33,7 +33,7 @@ void NewsChecker::reloadNews()
qDebug() << "Ignored request to reload news. Currently reloading already.";
return;
}
qDebug() << "Reloading news.";
NetJob* job = new NetJob("News RSS Feed");
@ -95,10 +95,10 @@ void NewsChecker::rssDownloadFinished()
succeed();
}
void NewsChecker::rssDownloadFailed()
void NewsChecker::rssDownloadFailed(QString reason)
{
// Set an error message and fail.
fail("Failed to load news RSS feed.");
fail(tr("Failed to load news RSS feed:\n%1").arg(reason));
}

View File

@ -31,7 +31,7 @@ public:
* Constructs a news reader to read from the given RSS feed URL.
*/
NewsChecker(const QString& feedUrl);
/*!
* Returns the error message for the last time the news was loaded.
* Empty string if the last load was successful.
@ -42,7 +42,7 @@ public:
* Returns true if the news has been loaded successfully.
*/
bool isNewsLoaded() const;
//! True if the news is currently loading. If true, reloadNews() will do nothing.
bool isLoadingNews() const;
@ -70,7 +70,7 @@ signals:
protected slots:
void rssDownloadFinished();
void rssDownloadFailed();
void rssDownloadFailed(QString reason);
protected:
//! The URL for the RSS feed to fetch.
@ -91,7 +91,7 @@ protected:
*/
QString m_lastLoadError;
/*!
* Emits newsLoaded() and sets m_lastLoadError to empty string.
*/

View File

@ -104,9 +104,9 @@ void StatusChecker::statusDownloadFinished()
succeed();
}
void StatusChecker::statusDownloadFailed()
void StatusChecker::statusDownloadFailed(QString reason)
{
fail("Failed to load status JSON.");
fail(tr("Failed to load status JSON:\n%1").arg(reason));
}

View File

@ -44,7 +44,7 @@ signals:
protected slots:
void statusDownloadFinished();
void statusDownloadFailed();
void statusDownloadFailed(QString reason);
protected:
QMap<QString, QString> m_prevEntries;

View File

@ -1,41 +0,0 @@
/* Copyright 2013-2015 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QObject>
class ProgressProvider : public QObject
{
Q_OBJECT
protected:
explicit ProgressProvider(QObject *parent = 0) : QObject(parent)
{
}
signals:
void started();
void progress(qint64 current, qint64 total);
void succeeded();
void failed(QString reason);
void status(QString status);
public:
virtual ~ProgressProvider() {}
virtual bool isRunning() const = 0;
public
slots:
virtual void start() = 0;
virtual void abort() = 0;
};

View File

@ -4,7 +4,7 @@ SequentialTask::SequentialTask(QObject *parent) : Task(parent), m_currentIndex(-
{
}
void SequentialTask::addTask(std::shared_ptr<ProgressProvider> task)
void SequentialTask::addTask(std::shared_ptr<Task> task)
{
m_queue.append(task);
}
@ -19,7 +19,7 @@ void SequentialTask::startNext()
{
if (m_currentIndex != -1)
{
std::shared_ptr<ProgressProvider> previous = m_queue[m_currentIndex];
std::shared_ptr<Task> previous = m_queue[m_currentIndex];
disconnect(previous.get(), 0, this, 0);
}
m_currentIndex++;
@ -28,7 +28,7 @@ void SequentialTask::startNext()
emitSucceeded();
return;
}
std::shared_ptr<ProgressProvider> next = m_queue[m_currentIndex];
std::shared_ptr<Task> next = m_queue[m_currentIndex];
connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString)));
connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString)));
connect(next.get(), SIGNAL(progress(qint64, qint64)), this, SLOT(subTaskProgress(qint64, qint64)));

View File

@ -11,7 +11,7 @@ class SequentialTask : public Task
public:
explicit SequentialTask(QObject *parent = 0);
void addTask(std::shared_ptr<ProgressProvider> task);
void addTask(std::shared_ptr<Task> task);
protected:
void executeTask();
@ -24,6 +24,6 @@ slots:
void subTaskProgress(qint64 current, qint64 total);
private:
QQueue<std::shared_ptr<ProgressProvider> > m_queue;
QQueue<std::shared_ptr<Task> > m_queue;
int m_currentIndex;
};

View File

@ -16,7 +16,7 @@
#include "Task.h"
#include <QDebug>
Task::Task(QObject *parent) : ProgressProvider(parent)
Task::Task(QObject *parent) : QObject(parent)
{
}

View File

@ -17,9 +17,8 @@
#include <QObject>
#include <QString>
#include "ProgressProvider.h"
class Task : public ProgressProvider
class Task : public QObject
{
Q_OBJECT
public:
@ -40,6 +39,13 @@ public:
*/
virtual QString failReason() const;
signals:
void started();
void progress(qint64 current, qint64 total);
void succeeded();
void failed(QString reason);
void status(QString status);
public
slots:
virtual void start();

View File

@ -39,15 +39,15 @@ void TranslationDownloader::indexRecieved()
connect(m_dl_job.get(), &NetJob::failed, this, &TranslationDownloader::dlFailed);
m_dl_job->start();
}
void TranslationDownloader::dlFailed()
void TranslationDownloader::dlFailed(QString reason)
{
qCritical() << "Translations Download Failed!";
qCritical() << "Translations Download Failed:" << reason;
}
void TranslationDownloader::dlGood()
{
qDebug() << "Got translations!";
}
void TranslationDownloader::indexFailed()
void TranslationDownloader::indexFailed(QString reason)
{
qCritical() << "Translations Index Download Failed!";
qCritical() << "Translations Index Download Failed:" << reason;
}

View File

@ -20,8 +20,8 @@ public:
private slots:
void indexRecieved();
void indexFailed();
void dlFailed();
void indexFailed(QString reason);
void dlFailed(QString reason);
void dlGood();
private: