summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/ConsoleWindow.cpp9
-rw-r--r--application/ConsoleWindow.h1
-rw-r--r--application/dialogs/ProgressDialog.cpp37
-rw-r--r--application/dialogs/ProgressDialog.h3
-rw-r--r--logic/CMakeLists.txt4
-rw-r--r--logic/forge/ForgeInstaller.cpp6
-rw-r--r--logic/forge/ForgeMirrors.cpp2
-rw-r--r--logic/forge/ForgeXzDownload.cpp2
-rw-r--r--logic/java/JavaCheckerJob.h2
-rw-r--r--logic/java/JavaVersionList.cpp8
-rw-r--r--logic/java/JavaVersionList.h1
-rw-r--r--logic/launch/LaunchStep.cpp1
-rw-r--r--logic/launch/LaunchStep.h1
-rw-r--r--logic/launch/LaunchTask.cpp6
-rw-r--r--logic/launch/LaunchTask.h5
-rw-r--r--logic/launch/steps/LaunchMinecraft.cpp (renamed from logic/launch/steps/LaunchCommand.cpp)18
-rw-r--r--logic/launch/steps/LaunchMinecraft.h (renamed from logic/launch/steps/LaunchCommand.h)4
-rw-r--r--logic/launch/steps/Update.cpp11
-rw-r--r--logic/launch/steps/Update.h1
-rw-r--r--logic/minecraft/LegacyInstance.cpp4
-rw-r--r--logic/minecraft/LegacyUpdate.cpp3
-rw-r--r--logic/minecraft/OneSixInstance.cpp4
-rw-r--r--logic/net/ByteArrayDownload.cpp2
-rw-r--r--logic/net/CacheDownload.cpp2
-rw-r--r--logic/net/MD5EtagDownload.cpp2
-rw-r--r--logic/net/NetAction.h2
-rw-r--r--logic/net/NetJob.cpp4
-rw-r--r--logic/net/NetJob.h4
-rw-r--r--logic/net/PasteUpload.cpp6
-rw-r--r--logic/screenshots/ImgurAlbumCreation.cpp2
-rw-r--r--logic/screenshots/ImgurUpload.cpp2
-rw-r--r--logic/tasks/SequentialTask.cpp8
-rw-r--r--logic/tasks/Task.cpp19
-rw-r--r--logic/tasks/Task.h26
-rw-r--r--logic/updater/DownloadTask.cpp2
35 files changed, 151 insertions, 63 deletions
diff --git a/application/ConsoleWindow.cpp b/application/ConsoleWindow.cpp
index 9dc5874d..8f3f20bd 100644
--- a/application/ConsoleWindow.cpp
+++ b/application/ConsoleWindow.cpp
@@ -131,6 +131,7 @@ ConsoleWindow::ConsoleWindow(std::shared_ptr<LaunchTask> proc, QWidget *parent)
// Set up signal connections
connect(m_proc.get(), &LaunchTask::succeeded, this, &ConsoleWindow::onSucceeded);
connect(m_proc.get(), &LaunchTask::failed, this, &ConsoleWindow::onFailed);
+ connect(m_proc.get(), &LaunchTask::requestProgress, this, &ConsoleWindow::onProgressRequested);
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()
{
diff --git a/application/ConsoleWindow.h b/application/ConsoleWindow.h
index f9e4c89e..ac5a6fd1 100644
--- a/application/ConsoleWindow.h
+++ b/application/ConsoleWindow.h
@@ -46,6 +46,7 @@ slots:
void onSucceeded();
void onFailed(QString reason);
+ void onProgressRequested(Task *task);
// FIXME: add handlers for the other MinecraftLauncher signals (pre/post launch command
// failures)
diff --git a/application/dialogs/ProgressDialog.cpp b/application/dialogs/ProgressDialog.cpp
index 9a437d7a..939c5870 100644
--- a/application/dialogs/ProgressDialog.cpp
+++ b/application/dialogs/ProgressDialog.cpp
@@ -57,6 +57,12 @@ void ProgressDialog::updateSize()
int ProgressDialog::exec(Task *task)
{
this->task = task;
+ QDialog::DialogCode result;
+
+ if(handleImmediateResult(result))
+ {
+ return result;
+ }
// Connect signals.
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(!task->isRunning())
+ {
task->start();
+ }
if(task->isRunning())
+ {
+ changeProgress(task->getProgress(), task->getTotalProgress());
+ changeStatus(task->getStatus());
return QDialog::exec();
+ }
+ else if(handleImmediateResult(result))
+ {
+ return result;
+ }
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()
diff --git a/application/dialogs/ProgressDialog.h b/application/dialogs/ProgressDialog.h
index fb80d0ce..44cbbe88 100644
--- a/application/dialogs/ProgressDialog.h
+++ b/application/dialogs/ProgressDialog.h
@@ -59,6 +59,9 @@ protected:
virtual void closeEvent(QCloseEvent *e);
private:
+ bool handleImmediateResult(QDialog::DialogCode &result);
+
+private:
Ui::ProgressDialog *ui;
Task *task;
diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt
index 7afc0213..fe445c05 100644
--- a/logic/CMakeLists.txt
+++ b/logic/CMakeLists.txt
@@ -95,8 +95,8 @@ set(LOGIC_SOURCES
# Game launch logic
launch/steps/CheckJava.cpp
launch/steps/CheckJava.h
- launch/steps/LaunchCommand.cpp
- launch/steps/LaunchCommand.h
+ launch/steps/LaunchMinecraft.cpp
+ launch/steps/LaunchMinecraft.h
launch/steps/ModMinecraftJar.cpp
launch/steps/ModMinecraftJar.h
launch/steps/PostLaunchCommand.cpp
diff --git a/logic/forge/ForgeInstaller.cpp b/logic/forge/ForgeInstaller.cpp
index 32ce5788..60dce822 100644
--- a/logic/forge/ForgeInstaller.cpp
+++ b/logic/forge/ForgeInstaller.cpp
@@ -381,10 +381,8 @@ protected:
{
NetJob *fjob = new NetJob("Forge download");
fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry));
- connect(fjob, &NetJob::progress, [this](qint64 current, qint64 total)
- { setProgress(100 * current / qMax((qint64)1, total)); });
- connect(fjob, &NetJob::status, [this](const QString & msg)
- { setStatus(msg); });
+ connect(fjob, &NetJob::progress, this, &Task::setProgress);
+ connect(fjob, &NetJob::status, this, &Task::setStatus);
connect(fjob, &NetJob::failed, [this](QString reason)
{ emitFailed(tr("Failure to download Forge:\n%1").arg(reason)); });
connect(fjob, &NetJob::succeeded, installFunction);
diff --git a/logic/forge/ForgeMirrors.cpp b/logic/forge/ForgeMirrors.cpp
index 0dea0826..a2fc2c62 100644
--- a/logic/forge/ForgeMirrors.cpp
+++ b/logic/forge/ForgeMirrors.cpp
@@ -110,7 +110,7 @@ void ForgeMirrors::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_total_progress = bytesTotal;
m_progress = bytesReceived;
- emit progress(m_index_within_job, bytesReceived, bytesTotal);
+ emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}
void ForgeMirrors::downloadReadyRead()
diff --git a/logic/forge/ForgeXzDownload.cpp b/logic/forge/ForgeXzDownload.cpp
index 712deb33..56320ced 100644
--- a/logic/forge/ForgeXzDownload.cpp
+++ b/logic/forge/ForgeXzDownload.cpp
@@ -83,7 +83,7 @@ void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_total_progress = bytesTotal;
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)
diff --git a/logic/java/JavaCheckerJob.h b/logic/java/JavaCheckerJob.h
index 4e2038ca..23003a03 100644
--- a/logic/java/JavaCheckerJob.h
+++ b/logic/java/JavaCheckerJob.h
@@ -36,7 +36,7 @@ public:
// if this is already running, the action needs to be started right away!
if (isRunning())
{
- emit progress(current_progress, total_progress);
+ setProgress(current_progress, total_progress);
connect(base.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
base->performCheck();
diff --git a/logic/java/JavaVersionList.cpp b/logic/java/JavaVersionList.cpp
index 52f2e62f..a463ca6c 100644
--- a/logic/java/JavaVersionList.cpp
+++ b/logic/java/JavaVersionList.cpp
@@ -162,7 +162,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(qint64,qint64)), this, SLOT(checkerProgress(qint64, qint64)));
+ connect(m_job.get(), &Task::progress, this, &Task::setProgress);
qDebug() << "Probing the following Java paths: ";
int id = 0;
@@ -181,12 +181,6 @@ void JavaListLoadTask::executeTask()
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)
{
QList<JavaVersionPtr> candidates;
diff --git a/logic/java/JavaVersionList.h b/logic/java/JavaVersionList.h
index f0176673..d78f9e7c 100644
--- a/logic/java/JavaVersionList.h
+++ b/logic/java/JavaVersionList.h
@@ -89,7 +89,6 @@ public:
virtual void executeTask();
public slots:
void javaCheckerFinished(QList<JavaCheckResult> results);
- void checkerProgress(qint64 current, qint64 total);
protected:
std::shared_ptr<JavaCheckerJob> m_job;
diff --git a/logic/launch/LaunchStep.cpp b/logic/launch/LaunchStep.cpp
index 9799d767..3078043b 100644
--- a/logic/launch/LaunchStep.cpp
+++ b/logic/launch/LaunchStep.cpp
@@ -23,4 +23,5 @@ void LaunchStep::bind(LaunchTask *parent)
connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine);
connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines);
connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished);
+ connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested);
}
diff --git a/logic/launch/LaunchStep.h b/logic/launch/LaunchStep.h
index 9b9631cb..ea472c0d 100644
--- a/logic/launch/LaunchStep.h
+++ b/logic/launch/LaunchStep.h
@@ -38,6 +38,7 @@ signals:
void logLines(QStringList lines, MessageLevel::Enum level);
void logLine(QString line, MessageLevel::Enum level);
void readyForLaunch();
+ void progressReportingRequest();
public slots:
virtual void proceed() {};
diff --git a/logic/launch/LaunchTask.cpp b/logic/launch/LaunchTask.cpp
index 66502020..1defeba3 100644
--- a/logic/launch/LaunchTask.cpp
+++ b/logic/launch/LaunchTask.cpp
@@ -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)
{
m_censorFilter = filter;
diff --git a/logic/launch/LaunchTask.h b/logic/launch/LaunchTask.h
index 24139ea8..bd0485c8 100644
--- a/logic/launch/LaunchTask.h
+++ b/logic/launch/LaunchTask.h
@@ -92,6 +92,10 @@ signals:
*/
void readyForLaunch();
+ void requestProgress(Task *task);
+
+ void requestLogging();
+
/**
* @brief emitted when we want to log something
* @param text the text to log
@@ -104,6 +108,7 @@ public slots:
void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC);
void onReadyForLaunch();
void onStepFinished();
+ void onProgressReportingRequested();
protected: /* data */
InstancePtr m_instance;
diff --git a/logic/launch/steps/LaunchCommand.cpp b/logic/launch/steps/LaunchMinecraft.cpp
index 2cbb3785..f01a584d 100644
--- a/logic/launch/steps/LaunchCommand.cpp
+++ b/logic/launch/steps/LaunchMinecraft.cpp
@@ -13,18 +13,18 @@
* limitations under the License.
*/
-#include "LaunchCommand.h"
+#include "LaunchMinecraft.h"
#include <launch/LaunchTask.h>
#include <minecraft/OneSixInstance.h>
#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::stateChanged, this, &LaunchCommand::on_state);
+ connect(&m_process, &LoggedProcess::log, this, &LaunchMinecraft::logLines);
+ connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchMinecraft::on_state);
}
-void LaunchCommand::executeTask()
+void LaunchMinecraft::executeTask()
{
auto instance = m_parent->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)
{
@@ -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);
}
-void LaunchCommand::proceed()
+void LaunchMinecraft::proceed()
{
if(mayProceed)
{
@@ -118,7 +118,7 @@ void LaunchCommand::proceed()
}
}
-bool LaunchCommand::abort()
+bool LaunchMinecraft::abort()
{
if(mayProceed)
{
diff --git a/logic/launch/steps/LaunchCommand.h b/logic/launch/steps/LaunchMinecraft.h
index 4a631054..808ec33b 100644
--- a/logic/launch/steps/LaunchCommand.h
+++ b/logic/launch/steps/LaunchMinecraft.h
@@ -18,11 +18,11 @@
#include <launch/LaunchStep.h>
#include <launch/LoggedProcess.h>
-class LaunchCommand: public LaunchStep
+class LaunchMinecraft: public LaunchStep
{
Q_OBJECT
public:
- explicit LaunchCommand(LaunchTask *parent);
+ explicit LaunchMinecraft(LaunchTask *parent);
virtual void executeTask();
virtual bool abort();
virtual void proceed();
diff --git a/logic/launch/steps/Update.cpp b/logic/launch/steps/Update.cpp
index 069b4f41..4901f001 100644
--- a/logic/launch/steps/Update.cpp
+++ b/logic/launch/steps/Update.cpp
@@ -22,12 +22,19 @@ void Update::executeTask()
if(m_updateTask)
{
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;
}
emitSucceeded();
}
+void Update::proceed()
+{
+ m_updateTask->start();
+}
+
void Update::updateFinished()
{
if(m_updateTask->successful())
@@ -40,4 +47,4 @@ void Update::updateFinished()
emit logLine(reason, MessageLevel::Fatal);
emitFailed(reason);
}
-} \ No newline at end of file
+}
diff --git a/logic/launch/steps/Update.h b/logic/launch/steps/Update.h
index 3ad07264..14928253 100644
--- a/logic/launch/steps/Update.h
+++ b/logic/launch/steps/Update.h
@@ -32,6 +32,7 @@ public:
{
return false;
}
+ virtual void proceed();
private slots:
void updateFinished();
diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp
index 4648ce59..ed0b1001 100644
--- a/logic/minecraft/LegacyInstance.cpp
+++ b/logic/minecraft/LegacyInstance.cpp
@@ -25,7 +25,7 @@
#include "minecraft/LegacyUpdate.h"
#include "icons/IconList.h"
#include "launch/LaunchTask.h"
-#include <launch/steps/LaunchCommand.h>
+#include <launch/steps/LaunchMinecraft.h>
#include <launch/steps/PostLaunchCommand.h>
#include <launch/steps/ModMinecraftJar.h>
#include <launch/steps/Update.h>
@@ -156,7 +156,7 @@ std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr sess
}
// actually launch the game
{
- auto step = std::make_shared<LaunchCommand>(pptr);
+ auto step = std::make_shared<LaunchMinecraft>(pptr);
step->setWorkingDirectory(minecraftRoot());
step->setLaunchScript(launchScript);
process->appendStep(step);
diff --git a/logic/minecraft/LegacyUpdate.cpp b/logic/minecraft/LegacyUpdate.cpp
index e136deec..c48984c4 100644
--- a/logic/minecraft/LegacyUpdate.cpp
+++ b/logic/minecraft/LegacyUpdate.cpp
@@ -24,7 +24,8 @@
#include "net/URLConstants.h"
#include "MMCZip.h"
-#include "minecraft/LegacyUpdate.h"
+#include "LegacyUpdate.h"
+
#include "minecraft/LwjglVersionList.h"
#include "minecraft/MinecraftVersionList.h"
#include "minecraft/ModList.h"
diff --git a/logic/minecraft/OneSixInstance.cpp b/logic/minecraft/OneSixInstance.cpp
index 5e2f5c64..3b2ff750 100644
--- a/logic/minecraft/OneSixInstance.cpp
+++ b/logic/minecraft/OneSixInstance.cpp
@@ -25,7 +25,7 @@
#include "launch/LaunchTask.h"
#include <launch/steps/PreLaunchCommand.h>
#include <launch/steps/Update.h>
-#include <launch/steps/LaunchCommand.h>
+#include <launch/steps/LaunchMinecraft.h>
#include <launch/steps/PostLaunchCommand.h>
#include <launch/steps/TextPrint.h>
#include <launch/steps/ModMinecraftJar.h>
@@ -263,7 +263,7 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
}
// actually launch the game
{
- auto step = std::make_shared<LaunchCommand>(pptr);
+ auto step = std::make_shared<LaunchMinecraft>(pptr);
step->setWorkingDirectory(minecraftRoot());
step->setLaunchScript(launchScript);
process->appendStep(step);
diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp
index 151487f0..21990eeb 100644
--- a/logic/net/ByteArrayDownload.cpp
+++ b/logic/net/ByteArrayDownload.cpp
@@ -44,7 +44,7 @@ void ByteArrayDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal
{
m_total_progress = bytesTotal;
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)
diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp
index a4fac6ef..b125a3d9 100644
--- a/logic/net/CacheDownload.cpp
+++ b/logic/net/CacheDownload.cpp
@@ -90,7 +90,7 @@ void CacheDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_total_progress = bytesTotal;
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)
diff --git a/logic/net/MD5EtagDownload.cpp b/logic/net/MD5EtagDownload.cpp
index 651ab602..7593c87e 100644
--- a/logic/net/MD5EtagDownload.cpp
+++ b/logic/net/MD5EtagDownload.cpp
@@ -99,7 +99,7 @@ void MD5EtagDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_total_progress = bytesTotal;
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)
diff --git a/logic/net/NetAction.h b/logic/net/NetAction.h
index 7c5bd5de..85eac8e3 100644
--- a/logic/net/NetAction.h
+++ b/logic/net/NetAction.h
@@ -81,7 +81,7 @@ public:
signals:
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 failed(int index);
diff --git a/logic/net/NetJob.cpp b/logic/net/NetJob.cpp
index 40d2d1c9..52307e2a 100644
--- a/logic/net/NetJob.cpp
+++ b/logic/net/NetJob.cpp
@@ -61,7 +61,7 @@ void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
total_progress -= slot.total_progress;
slot.total_progress = bytesTotal;
total_progress += slot.total_progress;
- emit progress(current_progress, total_progress);
+ setProgress(current_progress, total_progress);
}
void NetJob::executeTask()
@@ -107,7 +107,7 @@ void NetJob::startMoreParts()
// connect signals :D
connect(part.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(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)));
part->start();
}
diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h
index 4ac6d769..9e4656c7 100644
--- a/logic/net/NetJob.h
+++ b/logic/net/NetJob.h
@@ -49,10 +49,10 @@ public:
// if this is already running, the action needs to be started right away!
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(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)));
base->start();
}
diff --git a/logic/net/PasteUpload.cpp b/logic/net/PasteUpload.cpp
index b780194f..cfbc561d 100644
--- a/logic/net/PasteUpload.cpp
+++ b/logic/net/PasteUpload.cpp
@@ -30,10 +30,8 @@ void PasteUpload::executeTask()
m_reply = std::shared_ptr<QNetworkReply>(rep);
setStatus(tr("Uploading to paste.ee"));
- connect(rep, &QNetworkReply::downloadProgress, [&](qint64 value, qint64 max)
- { setProgress(value / qMax((qint64)1, max) * 100); });
- connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this,
- SLOT(downloadError(QNetworkReply::NetworkError)));
+ connect(rep, &QNetworkReply::downloadProgress, this, &Task::setProgress);
+ connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
}
diff --git a/logic/screenshots/ImgurAlbumCreation.cpp b/logic/screenshots/ImgurAlbumCreation.cpp
index f332c220..e009ef4d 100644
--- a/logic/screenshots/ImgurAlbumCreation.cpp
+++ b/logic/screenshots/ImgurAlbumCreation.cpp
@@ -86,5 +86,5 @@ void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTota
{
m_total_progress = bytesTotal;
m_progress = bytesReceived;
- emit progress(m_index_within_job, bytesReceived, bytesTotal);
+ emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}
diff --git a/logic/screenshots/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp
index abb695b3..48e0ec18 100644
--- a/logic/screenshots/ImgurUpload.cpp
+++ b/logic/screenshots/ImgurUpload.cpp
@@ -110,5 +110,5 @@ void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_total_progress = bytesTotal;
m_progress = bytesReceived;
- emit progress(m_index_within_job, bytesReceived, bytesTotal);
+ emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}
diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp
index f744d273..ac0e7820 100644
--- a/logic/tasks/SequentialTask.cpp
+++ b/logic/tasks/SequentialTask.cpp
@@ -48,12 +48,8 @@ void SequentialTask::subTaskProgress(qint64 current, qint64 total)
{
if(total == 0)
{
- setProgress(0);
+ setProgress(0, 100);
return;
}
- auto dcurrent = (double) current;
- 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);
+ setProgress(current, total);
}
diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp
index eaeff4c2..3c4e3188 100644
--- a/logic/tasks/Task.cpp
+++ b/logic/tasks/Task.cpp
@@ -23,12 +23,18 @@ Task::Task(QObject *parent) : QObject(parent)
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()
@@ -41,6 +47,7 @@ void Task::start()
void Task::emitFailed(QString reason)
{
m_running = false;
+ m_finished = true;
m_succeeded = false;
m_failReason = reason;
qCritical() << "Task failed: " << reason;
@@ -52,6 +59,7 @@ void Task::emitSucceeded()
{
if (!m_running) { return; } // Don't succeed twice.
m_running = false;
+ m_finished = true;
m_succeeded = true;
qDebug() << "Task succeeded";
emit succeeded();
@@ -63,6 +71,11 @@ bool Task::isRunning() const
return m_running;
}
+bool Task::isFinished() const
+{
+ return m_finished;
+}
+
bool Task::successful() const
{
return m_succeeded;
diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h
index 9362348a..04899c69 100644
--- a/logic/tasks/Task.h
+++ b/logic/tasks/Task.h
@@ -27,6 +27,8 @@ public:
virtual bool isRunning() const;
+ virtual bool isFinished() const;
+
/*!
* True if this task was successful.
* If the task failed or is still running, returns false.
@@ -41,6 +43,21 @@ public:
virtual bool canAbort() const { return false; }
+ QString getStatus()
+ {
+ return m_status;
+ }
+
+ qint64 getProgress()
+ {
+ return m_progress;
+ }
+
+ qint64 getTotalProgress()
+ {
+ return m_progressTotal;
+ }
+
signals:
void started();
void progress(qint64 current, qint64 total);
@@ -61,14 +78,17 @@ protected slots:
virtual void emitSucceeded();
virtual void emitFailed(QString reason);
-protected
-slots:
+public slots:
void setStatus(const QString &status);
- void setProgress(int progress);
+ void setProgress(qint64 current, qint64 total);
protected:
bool m_running = false;
+ bool m_finished = false;
bool m_succeeded = false;
QString m_failReason = "";
+ QString m_status;
+ int m_progress = 0;
+ int m_progressTotal = 100;
};
diff --git a/logic/updater/DownloadTask.cpp b/logic/updater/DownloadTask.cpp
index 76741748..1bbb0edf 100644
--- a/logic/updater/DownloadTask.cpp
+++ b/logic/updater/DownloadTask.cpp
@@ -154,7 +154,7 @@ void DownloadTask::fileDownloadFailed(QString reason)
void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total)
{
- setProgress((int)(((float)current / (float)total) * 100));
+ setProgress(current, total);
}
QString DownloadTask::updateFilesDir()