mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-24 05:45:27 +00:00
Interrupt AsyncTask from AsyncTaskDialog
This commit is contained in:
parent
3e8b76138c
commit
f09d32bd3d
@ -18,7 +18,10 @@ AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
|
connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
|
||||||
connect(task, &AsyncTask::finished, this, &QWidget::close);
|
connect(task, &AsyncTask::finished, this, [this]() {
|
||||||
|
this->task = nullptr;
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
|
||||||
updateLog();
|
updateLog();
|
||||||
|
|
||||||
@ -41,6 +44,10 @@ void AsyncTaskDialog::updateLog()
|
|||||||
|
|
||||||
void AsyncTaskDialog::updateProgressTimer()
|
void AsyncTaskDialog::updateProgressTimer()
|
||||||
{
|
{
|
||||||
|
if(!task) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int secondsElapsed = (task->getTimer().elapsed() + 500) / 1000;
|
int secondsElapsed = (task->getTimer().elapsed() + 500) / 1000;
|
||||||
int minutesElapsed = secondsElapsed / 60;
|
int minutesElapsed = secondsElapsed / 60;
|
||||||
int hoursElapsed = minutesElapsed / 60;
|
int hoursElapsed = minutesElapsed / 60;
|
||||||
@ -57,3 +64,20 @@ void AsyncTaskDialog::updateProgressTimer()
|
|||||||
label += tr("%n seconds", "%n second", secondsElapsed % 60);
|
label += tr("%n seconds", "%n second", secondsElapsed % 60);
|
||||||
ui->timeLabel->setText(label);
|
ui->timeLabel->setText(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AsyncTaskDialog::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
if (interruptOnClose && task) {
|
||||||
|
task->interrupt();
|
||||||
|
task->wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget::closeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncTaskDialog::reject()
|
||||||
|
{
|
||||||
|
if (task) {
|
||||||
|
task->interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,14 +21,22 @@ public:
|
|||||||
AsyncTaskDialog(AsyncTask *task, QWidget *parent = nullptr);
|
AsyncTaskDialog(AsyncTask *task, QWidget *parent = nullptr);
|
||||||
~AsyncTaskDialog();
|
~AsyncTaskDialog();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void reject() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateLog();
|
void updateLog();
|
||||||
void updateProgressTimer();
|
void updateProgressTimer();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::AsyncTaskDialog> ui;
|
std::unique_ptr<Ui::AsyncTaskDialog> ui;
|
||||||
AsyncTask *task;
|
AsyncTask *task;
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
|
||||||
|
bool interruptOnClose;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ASYNCTASKDIALOG_H
|
#endif //ASYNCTASKDIALOG_H
|
||||||
|
Loading…
Reference in New Issue
Block a user