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"
|
#include "ui_AsyncTaskDialog.h"
|
||||||
|
|
||||||
|
|
||||||
AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent)
|
AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent)
|
||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
ui(new Ui::AsyncTaskDialog),
|
ui(new Ui::AsyncTaskDialog),
|
||||||
@ -11,9 +12,21 @@ AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
QString title = task->getTitle();
|
||||||
|
if (!title.isNull()) {
|
||||||
|
setWindowTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
|
connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
|
||||||
|
|
||||||
updateLog();
|
updateLog();
|
||||||
|
|
||||||
|
connect(&timer, SIGNAL(timeout()), this, SLOT(updateProgressTimer()));
|
||||||
|
timer.setInterval(1000);
|
||||||
|
timer.setSingleShot(false);
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
updateProgressTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncTaskDialog::~AsyncTaskDialog()
|
AsyncTaskDialog::~AsyncTaskDialog()
|
||||||
@ -24,3 +37,22 @@ void AsyncTaskDialog::updateLog()
|
|||||||
{
|
{
|
||||||
ui->logTextEdit->setPlainText(task->getLog());
|
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
|
#ifndef ASYNCTASKDIALOG_H
|
||||||
#define ASYNCTASKDIALOG_H
|
#define ASYNCTASKDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class AsyncTaskDialog;
|
class AsyncTaskDialog;
|
||||||
}
|
}
|
||||||
@ -21,10 +23,12 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateLog();
|
void updateLog();
|
||||||
|
void updateProgressTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::AsyncTaskDialog> ui;
|
std::unique_ptr<Ui::AsyncTaskDialog> ui;
|
||||||
AsyncTask *task;
|
AsyncTask *task;
|
||||||
|
QTimer timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ASYNCTASKDIALOG_H
|
#endif //ASYNCTASKDIALOG_H
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Cutter</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
|
@ -161,15 +161,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
|
|||||||
|
|
||||||
main->initUI();
|
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);
|
connect(&analTask, &AnalTask::openFileFailed, main, &MainWindow::openNewFileFailed);
|
||||||
analTask.setSettings(main, level, advanced);
|
analTask.setSettings(main, level, advanced);
|
||||||
Core()->getAsyncTaskManager()->start(&analTask);
|
Core()->getAsyncTaskManager()->start(&analTask);
|
||||||
@ -178,24 +169,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
|
|||||||
taskDialog->show();
|
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)
|
void OptionsDialog::updateProgress(const QString &status)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ class OptionsDialog : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit OptionsDialog(MainWindow *main);
|
explicit OptionsDialog(MainWindow *main);
|
||||||
~OptionsDialog();
|
~OptionsDialog();
|
||||||
RAnalFunction functionAt(ut64 addr);
|
|
||||||
QStringList asm_plugins;
|
QStringList asm_plugins;
|
||||||
|
|
||||||
void setupAndStartAnalysis(int level, QList<QString> advanced);
|
void setupAndStartAnalysis(int level, QList<QString> advanced);
|
||||||
@ -35,8 +35,6 @@ private slots:
|
|||||||
void on_pdbSelectButton_clicked();
|
void on_pdbSelectButton_clicked();
|
||||||
void on_scriptSelectButton_clicked();
|
void on_scriptSelectButton_clicked();
|
||||||
|
|
||||||
void updateProgressTimer();
|
|
||||||
|
|
||||||
void updatePDBLayout();
|
void updatePDBLayout();
|
||||||
void updateScriptLayout();
|
void updateScriptLayout();
|
||||||
|
|
||||||
@ -68,8 +66,7 @@ public:
|
|||||||
int getSelectedBBSize();
|
int getSelectedBBSize();
|
||||||
Endianness getSelectedEndianness();
|
Endianness getSelectedEndianness();
|
||||||
QString getSelectedOS();
|
QString getSelectedOS();
|
||||||
QTimer analTimer;
|
|
||||||
QElapsedTimer analElapsedTimer;
|
|
||||||
void reject() override;
|
void reject() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ void AsyncTask::prepareRun()
|
|||||||
{
|
{
|
||||||
interrupted = false;
|
interrupted = false;
|
||||||
wait();
|
wait();
|
||||||
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncTask::run()
|
void AsyncTask::run()
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
class AsyncTaskManager;
|
class AsyncTaskManager;
|
||||||
|
|
||||||
@ -27,6 +28,9 @@ public:
|
|||||||
bool isRunning() { return running; }
|
bool isRunning() { return running; }
|
||||||
|
|
||||||
const QString &getLog() { return logBuffer; }
|
const QString &getLog() { return logBuffer; }
|
||||||
|
const QElapsedTimer &getTimer() { return timer; }
|
||||||
|
|
||||||
|
virtual QString getTitle() { return QString(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void runTask() =0;
|
virtual void runTask() =0;
|
||||||
@ -42,6 +46,7 @@ private:
|
|||||||
bool interrupted;
|
bool interrupted;
|
||||||
QMutex runningMutex;
|
QMutex runningMutex;
|
||||||
|
|
||||||
|
QElapsedTimer timer;
|
||||||
QString logBuffer;
|
QString logBuffer;
|
||||||
|
|
||||||
void prepareRun();
|
void prepareRun();
|
||||||
|
Loading…
Reference in New Issue
Block a user