fix: clean up execWithTask in Progress Dialog
This prevents weird problems, such as dialogs being non-modal when they should be! Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
79b0a16f7a
commit
58dc3e93d3
@ -108,10 +108,8 @@ void ModUpdateDialog::checkCandidates()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check for updates
|
// Check for updates
|
||||||
// FIXME: SOMEHOW THIS IS NOT MODAL???????
|
|
||||||
ProgressDialog progress_dialog(m_parent);
|
ProgressDialog progress_dialog(m_parent);
|
||||||
progress_dialog.setSkipButton(true, tr("Abort"));
|
progress_dialog.setSkipButton(true, tr("Abort"));
|
||||||
progress_dialog.setVisible(true);
|
|
||||||
progress_dialog.setWindowTitle(tr("Checking for updates..."));
|
progress_dialog.setWindowTitle(tr("Checking for updates..."));
|
||||||
auto ret = progress_dialog.execWithTask(&check_task);
|
auto ret = progress_dialog.execWithTask(&check_task);
|
||||||
|
|
||||||
|
@ -62,24 +62,24 @@ void ProgressDialog::updateSize()
|
|||||||
int ProgressDialog::execWithTask(Task* task)
|
int ProgressDialog::execWithTask(Task* task)
|
||||||
{
|
{
|
||||||
this->task = task;
|
this->task = task;
|
||||||
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 QDialog::DialogCode::Accepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDialog::DialogCode result;
|
||||||
if (handleImmediateResult(result)) {
|
if (handleImmediateResult(result)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect signals.
|
// Connect signals.
|
||||||
connect(task, SIGNAL(started()), SLOT(onTaskStarted()));
|
connect(task, &Task::started, this, &ProgressDialog::onTaskStarted);
|
||||||
connect(task, SIGNAL(failed(QString)), SLOT(onTaskFailed(QString)));
|
connect(task, &Task::failed, this, &ProgressDialog::onTaskFailed);
|
||||||
connect(task, SIGNAL(succeeded()), SLOT(onTaskSucceeded()));
|
connect(task, &Task::succeeded, this, &ProgressDialog::onTaskSucceeded);
|
||||||
connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString&)));
|
connect(task, &Task::status, this, &ProgressDialog::changeStatus);
|
||||||
connect(task, SIGNAL(stepStatus(QString)), SLOT(changeStatus(const QString&)));
|
connect(task, &Task::stepStatus, this, &ProgressDialog::changeStatus);
|
||||||
connect(task, SIGNAL(progress(qint64, qint64)), SLOT(changeProgress(qint64, qint64)));
|
connect(task, &Task::progress, this, &ProgressDialog::changeProgress);
|
||||||
|
|
||||||
connect(task, &Task::aborted, [this] { onTaskFailed(tr("Aborted by user")); });
|
connect(task, &Task::aborted, [this] { onTaskFailed(tr("Aborted by user")); });
|
||||||
|
|
||||||
@ -89,19 +89,15 @@ int ProgressDialog::execWithTask(Task* task)
|
|||||||
ui->globalProgressBar->setHidden(true);
|
ui->globalProgressBar->setHidden(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this didn't connect to an already running task, invoke start
|
// It's a good idea to start the task after we entered the dialog's event loop :^)
|
||||||
if (!task->isRunning()) {
|
if (!task->isRunning()) {
|
||||||
task->start();
|
QMetaObject::invokeMethod(task, &Task::start, Qt::QueuedConnection);
|
||||||
}
|
|
||||||
if (task->isRunning()) {
|
|
||||||
changeProgress(task->getProgress(), task->getTotalProgress());
|
|
||||||
changeStatus(task->getStatus());
|
|
||||||
return QDialog::exec();
|
|
||||||
} else if (handleImmediateResult(result)) {
|
|
||||||
return result;
|
|
||||||
} else {
|
} else {
|
||||||
return QDialog::Rejected;
|
changeStatus(task->getStatus());
|
||||||
|
changeProgress(task->getProgress(), task->getTotalProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return QDialog::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: only provide the unique_ptr overloads
|
// TODO: only provide the unique_ptr overloads
|
||||||
|
Loading…
Reference in New Issue
Block a user