From c03f3395cdb892677aa1982e94a5fd7b5c857405 Mon Sep 17 00:00:00 2001 From: "Thomas (nezza-_-) Roth" Date: Mon, 11 Dec 2017 15:06:26 +0100 Subject: [PATCH] Fix #148: Show elapsed time of running analysis. (#207) * Fix #148: Show elapsed time of running analysis. * OptionsDialog: Add missing space after elapsed hours. * OptionsDialog: Hide elapsed label when showing the dialog. --- src/dialogs/OptionsDialog.cpp | 32 ++++++++++++++++++++++++++++++++ src/dialogs/OptionsDialog.h | 6 ++++++ src/dialogs/OptionsDialog.ui | 21 ++++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 52ace6fb..32d867c7 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -24,6 +24,7 @@ OptionsDialog::OptionsDialog(MainWindow *main): setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); ui->progressBar->setVisible(0); ui->statusLabel->setVisible(0); + ui->elapsedLabel->setVisible(0); QString logoFile = (palette().window().color().value() < 127) ? ":/img/cutter_white_plain.svg" : ":/img/cutter_plain.svg"; ui->logoSvgWidget->load(logoFile); @@ -131,6 +132,7 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) ui->statusLabel->setEnabled(1); ui->progressBar->setVisible(1); ui->statusLabel->setVisible(1); + ui->elapsedLabel->setVisible(1); ui->statusLabel->setText(tr("Starting analysis")); //ui->progressBar->setValue(5); @@ -139,12 +141,42 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) core->resetDefaultAsmOptions(); + // Timer for showing elapsed analysis time. + analTimer.setInterval(1000); + analTimer.setSingleShot(false); + analTimer.start(); + analElapsedTimer.start(); + + updateProgressTimer(); + connect(&analTimer, SIGNAL(timeout()), this, SLOT(updateProgressTimer())); + // Threads stuff // connect signal/slot connect(&analThread, &AnalThread::updateProgress, this, &OptionsDialog::updateProgress); analThread.start(main, level, advanced); } +void OptionsDialog::updateProgressTimer() +{ + int secondsElapsed = (analElapsedTimer.elapsed()+500)/1000; + int minutesElapsed = secondsElapsed / 60; + int hoursElapsed = minutesElapsed / 60; + + QString label = tr("Running since") + " "; + 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) { ui->statusLabel->setText(status); diff --git a/src/dialogs/OptionsDialog.h b/src/dialogs/OptionsDialog.h index 2d7e7922..119d10e7 100644 --- a/src/dialogs/OptionsDialog.h +++ b/src/dialogs/OptionsDialog.h @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include "cutter.h" #include "AnalThread.h" @@ -32,6 +34,8 @@ private slots: void on_archComboBox_currentIndexChanged(int index); void on_pdbSelectButton_clicked(); + void updateProgressTimer(); + void updatePDBLayout(); void anal_finished(); @@ -51,6 +55,8 @@ public: QString getSelectedCPU(); int getSelectedBits(); QString getSelectedOS(); + QTimer analTimer; + QElapsedTimer analElapsedTimer; void reject() override; }; diff --git a/src/dialogs/OptionsDialog.ui b/src/dialogs/OptionsDialog.ui index 5160b71d..e52866db 100644 --- a/src/dialogs/OptionsDialog.ui +++ b/src/dialogs/OptionsDialog.ui @@ -7,7 +7,7 @@ 0 0 598 - 460 + 524 @@ -900,6 +900,25 @@ 0 + + + + + 0 + 0 + + + + + 150 + 0 + + + + Timer label + + +