mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Add Timer to AsyncTask
This commit is contained in:
parent
6dd71958e2
commit
896925736f
@ -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);
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
#ifndef ASYNCTASKDIALOG_H
|
||||
#define ASYNCTASKDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ui {
|
||||
class AsyncTaskDialog;
|
||||
}
|
||||
@ -21,10 +23,12 @@ public:
|
||||
|
||||
private slots:
|
||||
void updateLog();
|
||||
void updateProgressTimer();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::AsyncTaskDialog> ui;
|
||||
AsyncTask *task;
|
||||
QTimer timer;
|
||||
};
|
||||
|
||||
#endif //ASYNCTASKDIALOG_H
|
||||
|
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>Cutter</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
|
@ -161,15 +161,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> 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<QString> 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)
|
||||
{
|
||||
|
@ -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<QString> 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;
|
||||
};
|
||||
|
||||
|
@ -38,6 +38,7 @@ void AsyncTask::prepareRun()
|
||||
{
|
||||
interrupted = false;
|
||||
wait();
|
||||
timer.start();
|
||||
}
|
||||
|
||||
void AsyncTask::run()
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QRunnable>
|
||||
#include <QThreadPool>
|
||||
#include <QMutex>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user