fix: various issues with ProgressDialog and SequentialTasks

- Fix aborting sequential tasks
- Fix displaying wrong number of tasks concluded
- Fix text cutting when the URL is too big
This commit is contained in:
flow 2022-05-01 11:08:00 -03:00 committed by flow
parent 8f2c485c92
commit 166f872712
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
4 changed files with 58 additions and 58 deletions

View File

@ -33,11 +33,17 @@ void SequentialTask::executeTask()
bool SequentialTask::abort() bool SequentialTask::abort()
{ {
bool succeeded = true; if(m_currentIndex == -1 || m_currentIndex >= m_queue.size()) {
for (auto& task : m_queue) { m_queue.clear();
if (!task->abort()) succeeded = false; return true;
} }
bool succeeded = m_queue[m_currentIndex]->abort();
m_queue.clear();
if(succeeded)
emitAborted();
return succeeded; return succeeded;
} }
@ -76,7 +82,7 @@ void SequentialTask::subTaskProgress(qint64 current, qint64 total)
setProgress(0, 100); setProgress(0, 100);
return; return;
} }
setProgress(m_currentIndex, m_queue.count()); setProgress(m_currentIndex + 1, m_queue.count());
m_stepProgress = current; m_stepProgress = current;
m_stepTotalProgress = total; m_stepTotalProgress = total;

View File

@ -16,8 +16,8 @@
#include "ProgressDialog.h" #include "ProgressDialog.h"
#include "ui_ProgressDialog.h" #include "ui_ProgressDialog.h"
#include <QKeyEvent>
#include <QDebug> #include <QDebug>
#include <QKeyEvent>
#include "tasks/Task.h" #include "tasks/Task.h"
@ -44,6 +44,7 @@ void ProgressDialog::on_skipButton_clicked(bool checked)
{ {
Q_UNUSED(checked); Q_UNUSED(checked);
task->abort(); task->abort();
QDialog::reject();
} }
ProgressDialog::~ProgressDialog() ProgressDialog::~ProgressDialog()
@ -63,14 +64,12 @@ int ProgressDialog::execWithTask(Task *task)
this->task = task; this->task = task;
QDialog::DialogCode result; QDialog::DialogCode result;
if(!task) if (!task) {
{
qDebug() << "Programmer error: progress dialog created with null task."; qDebug() << "Programmer error: progress dialog created with null task.";
return Accepted; return Accepted;
} }
if(handleImmediateResult(result)) if (handleImmediateResult(result)) {
{
return result; return result;
} }
@ -79,8 +78,11 @@ int ProgressDialog::execWithTask(Task *task)
connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString))); connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString)));
connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded())); connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded()));
connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString&))); connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString&)));
connect(task, SIGNAL(stepStatus(QString)), SLOT(changeStatus(const QString&)));
connect(task, SIGNAL(progress(qint64, qint64)), SLOT(changeProgress(qint64, qint64))); connect(task, SIGNAL(progress(qint64, qint64)), SLOT(changeProgress(qint64, qint64)));
connect(task, &Task::aborted, [this] { onTaskFailed(tr("Aborted by user")); });
m_is_multi_step = task->isMultiStep(); m_is_multi_step = task->isMultiStep();
if (!m_is_multi_step) { if (!m_is_multi_step) {
ui->globalStatusLabel->setHidden(true); ui->globalStatusLabel->setHidden(true);
@ -88,22 +90,16 @@ int ProgressDialog::execWithTask(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()); changeProgress(task->getProgress(), task->getTotalProgress());
changeStatus(task->getStatus()); changeStatus(task->getStatus());
return QDialog::exec(); return QDialog::exec();
} } else if (handleImmediateResult(result)) {
else if(handleImmediateResult(result))
{
return result; return result;
} } else {
else
{
return QDialog::Rejected; return QDialog::Rejected;
} }
} }
@ -122,14 +118,10 @@ int ProgressDialog::execWithTask(std::unique_ptr<Task> &task)
bool ProgressDialog::handleImmediateResult(QDialog::DialogCode& result) bool ProgressDialog::handleImmediateResult(QDialog::DialogCode& result)
{ {
if(task->isFinished()) if (task->isFinished()) {
{ if (task->wasSuccessful()) {
if(task->wasSuccessful())
{
result = QDialog::Accepted; result = QDialog::Accepted;
} } else {
else
{
result = QDialog::Rejected; result = QDialog::Rejected;
} }
return true; return true;
@ -142,9 +134,7 @@ Task *ProgressDialog::getTask()
return task; return task;
} }
void ProgressDialog::onTaskStarted() void ProgressDialog::onTaskStarted() {}
{
}
void ProgressDialog::onTaskFailed(QString failure) void ProgressDialog::onTaskFailed(QString failure)
{ {
@ -158,8 +148,9 @@ void ProgressDialog::onTaskSucceeded()
void ProgressDialog::changeStatus(const QString& status) void ProgressDialog::changeStatus(const QString& status)
{ {
ui->globalStatusLabel->setText(task->getStatus());
ui->statusLabel->setText(task->getStepStatus()); ui->statusLabel->setText(task->getStepStatus());
ui->globalStatusLabel->setText(status);
updateSize(); updateSize();
} }
@ -171,8 +162,7 @@ void ProgressDialog::changeProgress(qint64 current, qint64 total)
if (!m_is_multi_step) { if (!m_is_multi_step) {
ui->taskProgressBar->setMaximum(total); ui->taskProgressBar->setMaximum(total);
ui->taskProgressBar->setValue(current); ui->taskProgressBar->setValue(current);
} } else {
else{
ui->taskProgressBar->setMaximum(task->getStepProgress()); ui->taskProgressBar->setMaximum(task->getStepProgress());
ui->taskProgressBar->setValue(task->getStepTotalProgress()); ui->taskProgressBar->setValue(task->getStepTotalProgress());
} }
@ -180,15 +170,11 @@ void ProgressDialog::changeProgress(qint64 current, qint64 total)
void ProgressDialog::keyPressEvent(QKeyEvent* e) void ProgressDialog::keyPressEvent(QKeyEvent* e)
{ {
if(ui->skipButton->isVisible()) if (ui->skipButton->isVisible()) {
{ if (e->key() == Qt::Key_Escape) {
if (e->key() == Qt::Key_Escape)
{
on_skipButton_clicked(true); on_skipButton_clicked(true);
return; return;
} } else if (e->key() == Qt::Key_Tab) {
else if(e->key() == Qt::Key_Tab)
{
ui->skipButton->setFocusPolicy(Qt::StrongFocus); ui->skipButton->setFocusPolicy(Qt::StrongFocus);
ui->skipButton->setFocus(); ui->skipButton->setFocus();
ui->skipButton->setAutoDefault(true); ui->skipButton->setAutoDefault(true);
@ -201,12 +187,9 @@ void ProgressDialog::keyPressEvent(QKeyEvent *e)
void ProgressDialog::closeEvent(QCloseEvent* e) void ProgressDialog::closeEvent(QCloseEvent* e)
{ {
if (task && task->isRunning()) if (task && task->isRunning()) {
{
e->ignore(); e->ignore();
} } else {
else
{
QDialog::closeEvent(e); QDialog::closeEvent(e);
} }
} }

View File

@ -40,6 +40,12 @@
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="statusLabel"> <widget class="QLabel" name="statusLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Task Status...</string> <string>Task Status...</string>
</property> </property>

View File

@ -402,6 +402,10 @@ void ModFolderPage::on_actionInstall_mods_triggered()
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater(); tasks->deleteLater();
}); });
connect(tasks, &Task::aborted, [this, tasks]() {
CustomMessageBox::selectable(this, tr("Aborted"), tr("Download stopped by user."), QMessageBox::Information)->show();
tasks->deleteLater();
});
connect(tasks, &Task::succeeded, [this, tasks]() { connect(tasks, &Task::succeeded, [this, tasks]() {
QStringList warnings = tasks->warnings(); QStringList warnings = tasks->warnings();
if (warnings.count()) { CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show(); } if (warnings.count()) { CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show(); }
@ -411,6 +415,7 @@ void ModFolderPage::on_actionInstall_mods_triggered()
for (auto task : mdownload.getTasks()) { for (auto task : mdownload.getTasks()) {
tasks->addTask(task); tasks->addTask(task);
} }
ProgressDialog loadDialog(this); ProgressDialog loadDialog(this);
loadDialog.setSkipButton(true, tr("Abort")); loadDialog.setSkipButton(true, tr("Abort"));
loadDialog.execWithTask(tasks); loadDialog.execWithTask(tasks);