diff --git a/src/dialogs/AsyncTaskDialog.cpp b/src/dialogs/AsyncTaskDialog.cpp index d26c6bda..4fdc9390 100644 --- a/src/dialogs/AsyncTaskDialog.cpp +++ b/src/dialogs/AsyncTaskDialog.cpp @@ -4,6 +4,7 @@ #include "ui_AsyncTaskDialog.h" + AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent) : QDialog(parent), ui(new Ui::AsyncTaskDialog), @@ -11,9 +12,21 @@ AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent) { ui->setupUi(this); + QString title = task->getTitle(); + if (!title.isNull()) { + setWindowTitle(title); + } + connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog); updateLog(); + + connect(&timer, SIGNAL(timeout()), this, SLOT(updateProgressTimer())); + timer.setInterval(1000); + timer.setSingleShot(false); + timer.start(); + + updateProgressTimer(); } AsyncTaskDialog::~AsyncTaskDialog() @@ -24,3 +37,22 @@ void AsyncTaskDialog::updateLog() { ui->logTextEdit->setPlainText(task->getLog()); } + +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); +} diff --git a/src/dialogs/AsyncTaskDialog.h b/src/dialogs/AsyncTaskDialog.h index ebc2488d..4d0fd5e4 100644 --- a/src/dialogs/AsyncTaskDialog.h +++ b/src/dialogs/AsyncTaskDialog.h @@ -2,9 +2,11 @@ #ifndef ASYNCTASKDIALOG_H #define ASYNCTASKDIALOG_H -#include #include +#include +#include + namespace Ui { class AsyncTaskDialog; } @@ -21,10 +23,12 @@ public: private slots: void updateLog(); + void updateProgressTimer(); private: std::unique_ptr ui; AsyncTask *task; + QTimer timer; }; #endif //ASYNCTASKDIALOG_H diff --git a/src/dialogs/AsyncTaskDialog.ui b/src/dialogs/AsyncTaskDialog.ui index 64d37b6e..0dc213c9 100644 --- a/src/dialogs/AsyncTaskDialog.ui +++ b/src/dialogs/AsyncTaskDialog.ui @@ -11,7 +11,7 @@ - Dialog + Cutter diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 907cfedc..9bbf3a2f 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -161,15 +161,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) main->initUI(); - // Timer for showing elapsed analysis time. - analTimer.setInterval(1000); - analTimer.setSingleShot(false); - analTimer.start(); - analElapsedTimer.start(); - - updateProgressTimer(); - connect(&analTimer, SIGNAL(timeout()), this, SLOT(updateProgressTimer())); - connect(&analTask, &AnalTask::openFileFailed, main, &MainWindow::openNewFileFailed); analTask.setSettings(main, level, advanced); Core()->getAsyncTaskManager()->start(&analTask); @@ -178,24 +169,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) taskDialog->show(); } -void OptionsDialog::updateProgressTimer() -{ - int secondsElapsed = (analElapsedTimer.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->elapsedLabel->setText(label); -} void OptionsDialog::updateProgress(const QString &status) { diff --git a/src/dialogs/OptionsDialog.h b/src/dialogs/OptionsDialog.h index 2b87aaf3..cc8c8589 100644 --- a/src/dialogs/OptionsDialog.h +++ b/src/dialogs/OptionsDialog.h @@ -19,7 +19,7 @@ class OptionsDialog : public QDialog public: explicit OptionsDialog(MainWindow *main); ~OptionsDialog(); - RAnalFunction functionAt(ut64 addr); + QStringList asm_plugins; void setupAndStartAnalysis(int level, QList advanced); @@ -35,8 +35,6 @@ private slots: void on_pdbSelectButton_clicked(); void on_scriptSelectButton_clicked(); - void updateProgressTimer(); - void updatePDBLayout(); void updateScriptLayout(); @@ -68,8 +66,7 @@ public: int getSelectedBBSize(); Endianness getSelectedEndianness(); QString getSelectedOS(); - QTimer analTimer; - QElapsedTimer analElapsedTimer; + void reject() override; }; diff --git a/src/utils/AsyncTask.cpp b/src/utils/AsyncTask.cpp index d0ae6068..922bf808 100644 --- a/src/utils/AsyncTask.cpp +++ b/src/utils/AsyncTask.cpp @@ -38,6 +38,7 @@ void AsyncTask::prepareRun() { interrupted = false; wait(); + timer.start(); } void AsyncTask::run() diff --git a/src/utils/AsyncTask.h b/src/utils/AsyncTask.h index 6a4c6708..e81ebc5e 100644 --- a/src/utils/AsyncTask.h +++ b/src/utils/AsyncTask.h @@ -5,6 +5,7 @@ #include #include #include +#include class AsyncTaskManager; @@ -27,6 +28,9 @@ public: bool isRunning() { return running; } const QString &getLog() { return logBuffer; } + const QElapsedTimer &getTimer() { return timer; } + + virtual QString getTitle() { return QString(); } protected: virtual void runTask() =0; @@ -42,6 +46,7 @@ private: bool interrupted; QMutex runningMutex; + QElapsedTimer timer; QString logBuffer; void prepareRun();