cutter/src/dialogs/RizinTaskDialog.cpp

73 lines
1.6 KiB
C++
Raw Normal View History

2020-12-16 09:51:53 +00:00
#include "RizinTaskDialog.h"
#include "common/RizinTask.h"
#include <QCloseEvent>
2020-12-16 09:51:53 +00:00
#include "ui_RizinTaskDialog.h"
2020-12-16 09:51:53 +00:00
RizinTaskDialog::RizinTaskDialog(RizinTask::Ptr task, QWidget *parent)
: QDialog(parent),
2020-12-16 09:51:53 +00:00
ui(new Ui::RizinTaskDialog),
task(task)
{
ui->setupUi(this);
2020-12-16 09:51:53 +00:00
connect(task.data(), &RizinTask::finished, this, [this]() {
close();
});
2020-12-16 09:51:53 +00:00
connect(&timer, &QTimer::timeout, this, &RizinTaskDialog::updateProgressTimer);
timer.setInterval(1000);
timer.setSingleShot(false);
timer.start();
elapsedTimer.start();
updateProgressTimer();
}
2020-12-16 09:51:53 +00:00
RizinTaskDialog::~RizinTaskDialog()
{
}
2020-12-16 09:51:53 +00:00
void RizinTaskDialog::updateProgressTimer()
{
int secondsElapsed = elapsedTimer.elapsed() / 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);
}
2020-12-16 09:51:53 +00:00
void RizinTaskDialog::setDesc(const QString &label)
{
ui->descLabel->setText(label);
}
2020-12-16 09:51:53 +00:00
void RizinTaskDialog::closeEvent(QCloseEvent *event)
{
if (breakOnClose) {
task->breakTask();
setDesc("Attempting to stop the task...");
event->ignore();
} else {
QWidget::closeEvent(event);
}
}
2020-12-16 09:51:53 +00:00
void RizinTaskDialog::reject()
{
task->breakTask();
setDesc("Attempting to stop the task...");
}