2018-05-26 18:49:57 +00:00
|
|
|
|
|
|
|
#include "AsyncTaskDialog.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/AsyncTask.h"
|
2018-05-26 18:49:57 +00:00
|
|
|
|
|
|
|
#include "ui_AsyncTaskDialog.h"
|
|
|
|
|
2018-05-27 14:51:01 +00:00
|
|
|
|
2018-05-28 14:19:04 +00:00
|
|
|
AsyncTaskDialog::AsyncTaskDialog(AsyncTask::Ptr task, QWidget *parent)
|
2018-05-26 18:49:57 +00:00
|
|
|
: QDialog(parent),
|
2018-06-26 16:17:03 +00:00
|
|
|
ui(new Ui::AsyncTaskDialog),
|
|
|
|
task(task)
|
2018-05-26 18:49:57 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-05-27 14:51:01 +00:00
|
|
|
QString title = task->getTitle();
|
|
|
|
if (!title.isNull()) {
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:19:04 +00:00
|
|
|
connect(task.data(), &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
|
|
|
|
connect(task.data(), &AsyncTask::finished, this, [this]() {
|
2018-05-27 16:28:48 +00:00
|
|
|
close();
|
|
|
|
});
|
2018-05-26 18:49:57 +00:00
|
|
|
|
2018-05-27 19:57:37 +00:00
|
|
|
updateLog(task->getLog());
|
2018-05-27 14:51:01 +00:00
|
|
|
|
|
|
|
connect(&timer, SIGNAL(timeout()), this, SLOT(updateProgressTimer()));
|
|
|
|
timer.setInterval(1000);
|
|
|
|
timer.setSingleShot(false);
|
|
|
|
timer.start();
|
|
|
|
|
|
|
|
updateProgressTimer();
|
2018-05-26 18:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AsyncTaskDialog::~AsyncTaskDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-27 19:57:37 +00:00
|
|
|
void AsyncTaskDialog::updateLog(const QString &log)
|
2018-05-26 18:49:57 +00:00
|
|
|
{
|
2018-05-27 19:57:37 +00:00
|
|
|
ui->logTextEdit->setPlainText(log);
|
2018-05-26 18:49:57 +00:00
|
|
|
}
|
2018-05-27 14:51:01 +00:00
|
|
|
|
|
|
|
void AsyncTaskDialog::updateProgressTimer()
|
|
|
|
{
|
2018-07-07 10:32:51 +00:00
|
|
|
int secondsElapsed = (task->getElapsedTime() + 500) / 1000;
|
2018-05-27 14:51:01 +00:00
|
|
|
int minutesElapsed = secondsElapsed / 60;
|
|
|
|
int hoursElapsed = minutesElapsed / 60;
|
|
|
|
|
|
|
|
QString label = tr("Running for") + " ";
|
|
|
|
if (hoursElapsed) {
|
|
|
|
label += tr("%n hour", "%n hours", hoursElapsed);
|
|
|
|
label += " ";
|
|
|
|
}
|
|
|
|
if (minutesElapsed) {
|
|
|
|
label += tr("%n minute", "%n minutes", minutesElapsed % 60);
|
|
|
|
label += " ";
|
|
|
|
}
|
|
|
|
label += tr("%n seconds", "%n second", secondsElapsed % 60);
|
|
|
|
ui->timeLabel->setText(label);
|
|
|
|
}
|
2018-05-27 16:28:48 +00:00
|
|
|
|
|
|
|
void AsyncTaskDialog::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2018-05-28 14:19:04 +00:00
|
|
|
if (interruptOnClose) {
|
2018-05-27 16:28:48 +00:00
|
|
|
task->interrupt();
|
|
|
|
task->wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncTaskDialog::reject()
|
|
|
|
{
|
2018-05-28 14:19:04 +00:00
|
|
|
task->interrupt();
|
2018-05-27 16:28:48 +00:00
|
|
|
}
|