GH-1053 add back update progress dialog

This commit is contained in:
Petr Mrázek 2015-07-26 17:55:29 +02:00
parent 6310f6569c
commit d8caab515a
35 changed files with 151 additions and 63 deletions

View File

@ -131,6 +131,7 @@ ConsoleWindow::ConsoleWindow(std::shared_ptr<LaunchTask> proc, QWidget *parent)
// Set up signal connections // Set up signal connections
connect(m_proc.get(), &LaunchTask::succeeded, this, &ConsoleWindow::onSucceeded); connect(m_proc.get(), &LaunchTask::succeeded, this, &ConsoleWindow::onSucceeded);
connect(m_proc.get(), &LaunchTask::failed, this, &ConsoleWindow::onFailed); connect(m_proc.get(), &LaunchTask::failed, this, &ConsoleWindow::onFailed);
connect(m_proc.get(), &LaunchTask::requestProgress, this, &ConsoleWindow::onProgressRequested);
setMayClose(false); setMayClose(false);
@ -247,6 +248,14 @@ void ConsoleWindow::onFailed(QString reason)
} }
} }
void ConsoleWindow::onProgressRequested(Task* task)
{
ProgressDialog progDialog(this);
m_proc->proceed();
progDialog.exec(task);
}
ConsoleWindow::~ConsoleWindow() ConsoleWindow::~ConsoleWindow()
{ {

View File

@ -46,6 +46,7 @@ slots:
void onSucceeded(); void onSucceeded();
void onFailed(QString reason); void onFailed(QString reason);
void onProgressRequested(Task *task);
// FIXME: add handlers for the other MinecraftLauncher signals (pre/post launch command // FIXME: add handlers for the other MinecraftLauncher signals (pre/post launch command
// failures) // failures)

View File

@ -57,6 +57,12 @@ void ProgressDialog::updateSize()
int ProgressDialog::exec(Task *task) int ProgressDialog::exec(Task *task)
{ {
this->task = task; this->task = task;
QDialog::DialogCode result;
if(handleImmediateResult(result))
{
return result;
}
// Connect signals. // Connect signals.
connect(task, SIGNAL(started()), SLOT(onTaskStarted())); connect(task, SIGNAL(started()), SLOT(onTaskStarted()));
@ -67,11 +73,40 @@ int ProgressDialog::exec(Task *task)
// if this didn't connect to an already running task, invoke start // if this didn't connect to an already running task, invoke start
if(!task->isRunning()) if(!task->isRunning())
{
task->start(); task->start();
}
if(task->isRunning()) if(task->isRunning())
{
changeProgress(task->getProgress(), task->getTotalProgress());
changeStatus(task->getStatus());
return QDialog::exec(); return QDialog::exec();
}
else if(handleImmediateResult(result))
{
return result;
}
else else
return QDialog::Accepted; {
return QDialog::Rejected;
}
}
bool ProgressDialog::handleImmediateResult(QDialog::DialogCode &result)
{
if(task->isFinished())
{
if(task->successful())
{
result = QDialog::Accepted;
}
else
{
result = QDialog::Rejected;
}
return true;
}
return false;
} }
Task *ProgressDialog::getTask() Task *ProgressDialog::getTask()

View File

@ -58,6 +58,9 @@ protected:
virtual void keyPressEvent(QKeyEvent *e); virtual void keyPressEvent(QKeyEvent *e);
virtual void closeEvent(QCloseEvent *e); virtual void closeEvent(QCloseEvent *e);
private:
bool handleImmediateResult(QDialog::DialogCode &result);
private: private:
Ui::ProgressDialog *ui; Ui::ProgressDialog *ui;

View File

@ -95,8 +95,8 @@ set(LOGIC_SOURCES
# Game launch logic # Game launch logic
launch/steps/CheckJava.cpp launch/steps/CheckJava.cpp
launch/steps/CheckJava.h launch/steps/CheckJava.h
launch/steps/LaunchCommand.cpp launch/steps/LaunchMinecraft.cpp
launch/steps/LaunchCommand.h launch/steps/LaunchMinecraft.h
launch/steps/ModMinecraftJar.cpp launch/steps/ModMinecraftJar.cpp
launch/steps/ModMinecraftJar.h launch/steps/ModMinecraftJar.h
launch/steps/PostLaunchCommand.cpp launch/steps/PostLaunchCommand.cpp

View File

@ -381,10 +381,8 @@ protected:
{ {
NetJob *fjob = new NetJob("Forge download"); NetJob *fjob = new NetJob("Forge download");
fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry)); fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry));
connect(fjob, &NetJob::progress, [this](qint64 current, qint64 total) connect(fjob, &NetJob::progress, this, &Task::setProgress);
{ setProgress(100 * current / qMax((qint64)1, total)); }); connect(fjob, &NetJob::status, this, &Task::setStatus);
connect(fjob, &NetJob::status, [this](const QString & msg)
{ setStatus(msg); });
connect(fjob, &NetJob::failed, [this](QString reason) connect(fjob, &NetJob::failed, [this](QString reason)
{ emitFailed(tr("Failure to download Forge:\n%1").arg(reason)); }); { emitFailed(tr("Failure to download Forge:\n%1").arg(reason)); });
connect(fjob, &NetJob::succeeded, installFunction); connect(fjob, &NetJob::succeeded, installFunction);

View File

@ -110,7 +110,7 @@ void ForgeMirrors::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }
void ForgeMirrors::downloadReadyRead() void ForgeMirrors::downloadReadyRead()

View File

@ -83,7 +83,7 @@ void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }
void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)

View File

@ -36,7 +36,7 @@ public:
// if this is already running, the action needs to be started right away! // if this is already running, the action needs to be started right away!
if (isRunning()) if (isRunning())
{ {
emit progress(current_progress, total_progress); setProgress(current_progress, total_progress);
connect(base.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult))); connect(base.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
base->performCheck(); base->performCheck();

View File

@ -162,7 +162,7 @@ void JavaListLoadTask::executeTask()
m_job = std::shared_ptr<JavaCheckerJob>(new JavaCheckerJob("Java detection")); 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(finished(QList<JavaCheckResult>)), this, SLOT(javaCheckerFinished(QList<JavaCheckResult>)));
connect(m_job.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(checkerProgress(qint64, qint64))); connect(m_job.get(), &Task::progress, this, &Task::setProgress);
qDebug() << "Probing the following Java paths: "; qDebug() << "Probing the following Java paths: ";
int id = 0; int id = 0;
@ -181,12 +181,6 @@ void JavaListLoadTask::executeTask()
m_job->start(); m_job->start();
} }
void JavaListLoadTask::checkerProgress(qint64 current, qint64 total)
{
float progress = (current * 100.0) / total;
this->setProgress((int) progress);
}
void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results) void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results)
{ {
QList<JavaVersionPtr> candidates; QList<JavaVersionPtr> candidates;

View File

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

View File

@ -23,4 +23,5 @@ void LaunchStep::bind(LaunchTask *parent)
connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine); connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines); connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished); connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished);
connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested);
} }

View File

@ -38,6 +38,7 @@ signals:
void logLines(QStringList lines, MessageLevel::Enum level); void logLines(QStringList lines, MessageLevel::Enum level);
void logLine(QString line, MessageLevel::Enum level); void logLine(QString line, MessageLevel::Enum level);
void readyForLaunch(); void readyForLaunch();
void progressReportingRequest();
public slots: public slots:
virtual void proceed() {}; virtual void proceed() {};

View File

@ -103,6 +103,12 @@ void LaunchTask::onStepFinished()
} }
} }
void LaunchTask::onProgressReportingRequested()
{
state = LaunchTask::Waiting;
emit requestProgress(m_steps[currentStep].get());
}
void LaunchTask::setCensorFilter(QMap<QString, QString> filter) void LaunchTask::setCensorFilter(QMap<QString, QString> filter)
{ {
m_censorFilter = filter; m_censorFilter = filter;

View File

@ -92,6 +92,10 @@ signals:
*/ */
void readyForLaunch(); void readyForLaunch();
void requestProgress(Task *task);
void requestLogging();
/** /**
* @brief emitted when we want to log something * @brief emitted when we want to log something
* @param text the text to log * @param text the text to log
@ -104,6 +108,7 @@ public slots:
void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC); void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
void onReadyForLaunch(); void onReadyForLaunch();
void onStepFinished(); void onStepFinished();
void onProgressReportingRequested();
protected: /* data */ protected: /* data */
InstancePtr m_instance; InstancePtr m_instance;

View File

@ -13,18 +13,18 @@
* limitations under the License. * limitations under the License.
*/ */
#include "LaunchCommand.h" #include "LaunchMinecraft.h"
#include <launch/LaunchTask.h> #include <launch/LaunchTask.h>
#include <minecraft/OneSixInstance.h> #include <minecraft/OneSixInstance.h>
#include <QStandardPaths> #include <QStandardPaths>
LaunchCommand::LaunchCommand(LaunchTask *parent) : LaunchStep(parent) LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent)
{ {
connect(&m_process, &LoggedProcess::log, this, &LaunchCommand::logLines); connect(&m_process, &LoggedProcess::log, this, &LaunchMinecraft::logLines);
connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchCommand::on_state); connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchMinecraft::on_state);
} }
void LaunchCommand::executeTask() void LaunchMinecraft::executeTask()
{ {
auto instance = m_parent->instance(); auto instance = m_parent->instance();
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance); std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
@ -58,7 +58,7 @@ void LaunchCommand::executeTask()
} }
} }
void LaunchCommand::on_state(LoggedProcess::State state) void LaunchMinecraft::on_state(LoggedProcess::State state)
{ {
switch(state) switch(state)
{ {
@ -103,12 +103,12 @@ void LaunchCommand::on_state(LoggedProcess::State state)
} }
} }
void LaunchCommand::setWorkingDirectory(const QString &wd) void LaunchMinecraft::setWorkingDirectory(const QString &wd)
{ {
m_process.setWorkingDirectory(wd); m_process.setWorkingDirectory(wd);
} }
void LaunchCommand::proceed() void LaunchMinecraft::proceed()
{ {
if(mayProceed) if(mayProceed)
{ {
@ -118,7 +118,7 @@ void LaunchCommand::proceed()
} }
} }
bool LaunchCommand::abort() bool LaunchMinecraft::abort()
{ {
if(mayProceed) if(mayProceed)
{ {

View File

@ -18,11 +18,11 @@
#include <launch/LaunchStep.h> #include <launch/LaunchStep.h>
#include <launch/LoggedProcess.h> #include <launch/LoggedProcess.h>
class LaunchCommand: public LaunchStep class LaunchMinecraft: public LaunchStep
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit LaunchCommand(LaunchTask *parent); explicit LaunchMinecraft(LaunchTask *parent);
virtual void executeTask(); virtual void executeTask();
virtual bool abort(); virtual bool abort();
virtual void proceed(); virtual void proceed();

View File

@ -22,12 +22,19 @@ void Update::executeTask()
if(m_updateTask) if(m_updateTask)
{ {
connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished())); connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished()));
m_updateTask->start(); connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress);
connect(m_updateTask.get(), &Task::status, this, &Task::setStatus);
emit progressReportingRequest();
return; return;
} }
emitSucceeded(); emitSucceeded();
} }
void Update::proceed()
{
m_updateTask->start();
}
void Update::updateFinished() void Update::updateFinished()
{ {
if(m_updateTask->successful()) if(m_updateTask->successful())
@ -40,4 +47,4 @@ void Update::updateFinished()
emit logLine(reason, MessageLevel::Fatal); emit logLine(reason, MessageLevel::Fatal);
emitFailed(reason); emitFailed(reason);
} }
} }

View File

@ -32,6 +32,7 @@ public:
{ {
return false; return false;
} }
virtual void proceed();
private slots: private slots:
void updateFinished(); void updateFinished();

View File

@ -25,7 +25,7 @@
#include "minecraft/LegacyUpdate.h" #include "minecraft/LegacyUpdate.h"
#include "icons/IconList.h" #include "icons/IconList.h"
#include "launch/LaunchTask.h" #include "launch/LaunchTask.h"
#include <launch/steps/LaunchCommand.h> #include <launch/steps/LaunchMinecraft.h>
#include <launch/steps/PostLaunchCommand.h> #include <launch/steps/PostLaunchCommand.h>
#include <launch/steps/ModMinecraftJar.h> #include <launch/steps/ModMinecraftJar.h>
#include <launch/steps/Update.h> #include <launch/steps/Update.h>
@ -156,7 +156,7 @@ std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr sess
} }
// actually launch the game // actually launch the game
{ {
auto step = std::make_shared<LaunchCommand>(pptr); auto step = std::make_shared<LaunchMinecraft>(pptr);
step->setWorkingDirectory(minecraftRoot()); step->setWorkingDirectory(minecraftRoot());
step->setLaunchScript(launchScript); step->setLaunchScript(launchScript);
process->appendStep(step); process->appendStep(step);

View File

@ -24,7 +24,8 @@
#include "net/URLConstants.h" #include "net/URLConstants.h"
#include "MMCZip.h" #include "MMCZip.h"
#include "minecraft/LegacyUpdate.h" #include "LegacyUpdate.h"
#include "minecraft/LwjglVersionList.h" #include "minecraft/LwjglVersionList.h"
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
#include "minecraft/ModList.h" #include "minecraft/ModList.h"

View File

@ -25,7 +25,7 @@
#include "launch/LaunchTask.h" #include "launch/LaunchTask.h"
#include <launch/steps/PreLaunchCommand.h> #include <launch/steps/PreLaunchCommand.h>
#include <launch/steps/Update.h> #include <launch/steps/Update.h>
#include <launch/steps/LaunchCommand.h> #include <launch/steps/LaunchMinecraft.h>
#include <launch/steps/PostLaunchCommand.h> #include <launch/steps/PostLaunchCommand.h>
#include <launch/steps/TextPrint.h> #include <launch/steps/TextPrint.h>
#include <launch/steps/ModMinecraftJar.h> #include <launch/steps/ModMinecraftJar.h>
@ -263,7 +263,7 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
} }
// actually launch the game // actually launch the game
{ {
auto step = std::make_shared<LaunchCommand>(pptr); auto step = std::make_shared<LaunchMinecraft>(pptr);
step->setWorkingDirectory(minecraftRoot()); step->setWorkingDirectory(minecraftRoot());
step->setLaunchScript(launchScript); step->setLaunchScript(launchScript);
process->appendStep(step); process->appendStep(step);

View File

@ -44,7 +44,7 @@ void ByteArrayDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }
void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error) void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error)

View File

@ -90,7 +90,7 @@ void CacheDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }
void CacheDownload::downloadError(QNetworkReply::NetworkError error) void CacheDownload::downloadError(QNetworkReply::NetworkError error)

View File

@ -99,7 +99,7 @@ void MD5EtagDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }
void MD5EtagDownload::downloadError(QNetworkReply::NetworkError error) void MD5EtagDownload::downloadError(QNetworkReply::NetworkError error)

View File

@ -81,7 +81,7 @@ public:
signals: signals:
void started(int index); void started(int index);
void progress(int index, qint64 current, qint64 total); void netActionProgress(int index, qint64 current, qint64 total);
void succeeded(int index); void succeeded(int index);
void failed(int index); void failed(int index);

View File

@ -61,7 +61,7 @@ void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
total_progress -= slot.total_progress; total_progress -= slot.total_progress;
slot.total_progress = bytesTotal; slot.total_progress = bytesTotal;
total_progress += slot.total_progress; total_progress += slot.total_progress;
emit progress(current_progress, total_progress); setProgress(current_progress, total_progress);
} }
void NetJob::executeTask() void NetJob::executeTask()
@ -107,7 +107,7 @@ void NetJob::startMoreParts()
// connect signals :D // connect signals :D
connect(part.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); connect(part.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
connect(part.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); connect(part.get(), SIGNAL(failed(int)), SLOT(partFailed(int)));
connect(part.get(), SIGNAL(progress(int, qint64, qint64)), connect(part.get(), SIGNAL(netActionProgress(int, qint64, qint64)),
SLOT(partProgress(int, qint64, qint64))); SLOT(partProgress(int, qint64, qint64)));
part->start(); part->start();
} }

View File

@ -49,10 +49,10 @@ public:
// if this is already running, the action needs to be started right away! // if this is already running, the action needs to be started right away!
if (isRunning()) if (isRunning())
{ {
emit progress(current_progress, total_progress); setProgress(current_progress, total_progress);
connect(base.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); connect(base.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
connect(base.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); connect(base.get(), SIGNAL(failed(int)), SLOT(partFailed(int)));
connect(base.get(), SIGNAL(progress(int, qint64, qint64)), connect(base.get(), SIGNAL(netActionProgress(int, qint64, qint64)),
SLOT(partProgress(int, qint64, qint64))); SLOT(partProgress(int, qint64, qint64)));
base->start(); base->start();
} }

View File

@ -30,10 +30,8 @@ void PasteUpload::executeTask()
m_reply = std::shared_ptr<QNetworkReply>(rep); m_reply = std::shared_ptr<QNetworkReply>(rep);
setStatus(tr("Uploading to paste.ee")); setStatus(tr("Uploading to paste.ee"));
connect(rep, &QNetworkReply::downloadProgress, [&](qint64 value, qint64 max) connect(rep, &QNetworkReply::downloadProgress, this, &Task::setProgress);
{ setProgress(value / qMax((qint64)1, max) * 100); }); connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this,
SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
} }

View File

@ -86,5 +86,5 @@ void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTota
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }

View File

@ -110,5 +110,5 @@ void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
m_total_progress = bytesTotal; m_total_progress = bytesTotal;
m_progress = bytesReceived; m_progress = bytesReceived;
emit progress(m_index_within_job, bytesReceived, bytesTotal); emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
} }

View File

@ -48,12 +48,8 @@ void SequentialTask::subTaskProgress(qint64 current, qint64 total)
{ {
if(total == 0) if(total == 0)
{ {
setProgress(0); setProgress(0, 100);
return; return;
} }
auto dcurrent = (double) current; setProgress(current, total);
auto dtotal = (double) total;
auto partial = ((dcurrent / dtotal) * 100.0f)/* / double(m_queue.size())*/;
// auto bigpartial = double(m_currentIndex) * 100.0f / double(m_queue.size());
setProgress(partial);
} }

View File

@ -23,12 +23,18 @@ Task::Task(QObject *parent) : QObject(parent)
void Task::setStatus(const QString &new_status) void Task::setStatus(const QString &new_status)
{ {
emit status(new_status); if(m_status != new_status)
{
m_status = new_status;
emit status(m_status);
}
} }
void Task::setProgress(int new_progress) void Task::setProgress(qint64 current, qint64 total)
{ {
emit progress(new_progress, 100); m_progress = current;
m_progressTotal = total;
emit progress(m_progress, m_progressTotal);
} }
void Task::start() void Task::start()
@ -41,6 +47,7 @@ void Task::start()
void Task::emitFailed(QString reason) void Task::emitFailed(QString reason)
{ {
m_running = false; m_running = false;
m_finished = true;
m_succeeded = false; m_succeeded = false;
m_failReason = reason; m_failReason = reason;
qCritical() << "Task failed: " << reason; qCritical() << "Task failed: " << reason;
@ -52,6 +59,7 @@ void Task::emitSucceeded()
{ {
if (!m_running) { return; } // Don't succeed twice. if (!m_running) { return; } // Don't succeed twice.
m_running = false; m_running = false;
m_finished = true;
m_succeeded = true; m_succeeded = true;
qDebug() << "Task succeeded"; qDebug() << "Task succeeded";
emit succeeded(); emit succeeded();
@ -63,6 +71,11 @@ bool Task::isRunning() const
return m_running; return m_running;
} }
bool Task::isFinished() const
{
return m_finished;
}
bool Task::successful() const bool Task::successful() const
{ {
return m_succeeded; return m_succeeded;

View File

@ -27,6 +27,8 @@ public:
virtual bool isRunning() const; virtual bool isRunning() const;
virtual bool isFinished() const;
/*! /*!
* True if this task was successful. * True if this task was successful.
* If the task failed or is still running, returns false. * If the task failed or is still running, returns false.
@ -41,6 +43,21 @@ public:
virtual bool canAbort() const { return false; } virtual bool canAbort() const { return false; }
QString getStatus()
{
return m_status;
}
qint64 getProgress()
{
return m_progress;
}
qint64 getTotalProgress()
{
return m_progressTotal;
}
signals: signals:
void started(); void started();
void progress(qint64 current, qint64 total); void progress(qint64 current, qint64 total);
@ -61,14 +78,17 @@ protected slots:
virtual void emitSucceeded(); virtual void emitSucceeded();
virtual void emitFailed(QString reason); virtual void emitFailed(QString reason);
protected public slots:
slots:
void setStatus(const QString &status); void setStatus(const QString &status);
void setProgress(int progress); void setProgress(qint64 current, qint64 total);
protected: protected:
bool m_running = false; bool m_running = false;
bool m_finished = false;
bool m_succeeded = false; bool m_succeeded = false;
QString m_failReason = ""; QString m_failReason = "";
QString m_status;
int m_progress = 0;
int m_progressTotal = 100;
}; };

View File

@ -154,7 +154,7 @@ void DownloadTask::fileDownloadFailed(QString reason)
void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total) void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total)
{ {
setProgress((int)(((float)current / (float)total) * 100)); setProgress(current, total);
} }
QString DownloadTask::updateFilesDir() QString DownloadTask::updateFilesDir()