cutter/src/dialogs/AsyncTaskDialog.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

2018-05-26 18:49:57 +00:00
#include "AsyncTaskDialog.h"
#include "utils/AsyncTask.h"
#include "ui_AsyncTaskDialog.h"
2018-05-27 14:51:01 +00:00
2018-05-26 18:49:57 +00:00
AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent)
: QDialog(parent),
ui(new Ui::AsyncTaskDialog),
task(task)
{
ui->setupUi(this);
2018-05-27 14:51:01 +00:00
QString title = task->getTitle();
if (!title.isNull()) {
setWindowTitle(title);
}
2018-05-26 18:49:57 +00:00
connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
updateLog();
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()
{
}
void AsyncTaskDialog::updateLog()
{
ui->logTextEdit->setPlainText(task->getLog());
}
2018-05-27 14:51:01 +00:00
void AsyncTaskDialog::updateProgressTimer()
{
int secondsElapsed = (task->getTimer().elapsed() + 500) / 1000;
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);
}