mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 20:06:12 +00:00
Add AsyncTaskDialog
This commit is contained in:
parent
68e57f536f
commit
6dd71958e2
@ -47,7 +47,7 @@ void AnalTask::runTask()
|
||||
binLoadAddr = Core()->math(ui->entry_loadOffset->text());
|
||||
ut64 mapAddr = Core()->math(ui->entry_mapOffset->text()); // Where to map the file once loaded (-m)
|
||||
|
||||
emit updateProgress(tr("Loading binary..."));
|
||||
log(tr("Loading Binary...\n"));
|
||||
|
||||
// Set the CPU details (handle auto)
|
||||
Core()->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(),
|
||||
@ -106,7 +106,9 @@ void AnalTask::runTask()
|
||||
Core()->setConfig("prj.simple", true);
|
||||
|
||||
// Start analysis
|
||||
emit updateProgress(tr("Analysis in progress..."));
|
||||
log(tr("Analysis in progress...\n"));
|
||||
|
||||
Core()->analyze(this->level, this->advanced);
|
||||
emit updateProgress(tr("Analysis complete!"));
|
||||
|
||||
log(tr("Analysis complete!"));
|
||||
}
|
||||
|
@ -20,10 +20,9 @@ public:
|
||||
void interruptAndWait();
|
||||
|
||||
protected:
|
||||
void runTask();
|
||||
void runTask() override;
|
||||
|
||||
signals:
|
||||
void updateProgress(QString str);
|
||||
void openFileFailed();
|
||||
|
||||
private:
|
||||
|
@ -161,7 +161,8 @@ SOURCES += \
|
||||
utils/JsonModel.cpp \
|
||||
dialogs/VersionInfoDialog.cpp \
|
||||
widgets/ZignaturesWidget.cpp \
|
||||
utils/AsyncTask.cpp
|
||||
utils/AsyncTask.cpp \
|
||||
dialogs/AsyncTaskDialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
Cutter.h \
|
||||
@ -237,7 +238,8 @@ HEADERS += \
|
||||
utils/JsonModel.h \
|
||||
dialogs/VersionInfoDialog.h \
|
||||
widgets/ZignaturesWidget.h \
|
||||
utils/AsyncTask.h
|
||||
utils/AsyncTask.h \
|
||||
dialogs/AsyncTaskDialog.h
|
||||
|
||||
FORMS += \
|
||||
dialogs/AboutDialog.ui \
|
||||
@ -280,7 +282,8 @@ FORMS += \
|
||||
widgets/JupyterWidget.ui \
|
||||
dialogs/R2PluginsDialog.ui \
|
||||
dialogs/VersionInfoDialog.ui \
|
||||
widgets/ZignaturesWidget.ui
|
||||
widgets/ZignaturesWidget.ui \
|
||||
dialogs/AsyncTaskDialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc \
|
||||
|
26
src/dialogs/AsyncTaskDialog.cpp
Normal file
26
src/dialogs/AsyncTaskDialog.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
#include "AsyncTaskDialog.h"
|
||||
#include "utils/AsyncTask.h"
|
||||
|
||||
#include "ui_AsyncTaskDialog.h"
|
||||
|
||||
AsyncTaskDialog::AsyncTaskDialog(AsyncTask *task, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::AsyncTaskDialog),
|
||||
task(task)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(task, &AsyncTask::logChanged, this, &AsyncTaskDialog::updateLog);
|
||||
|
||||
updateLog();
|
||||
}
|
||||
|
||||
AsyncTaskDialog::~AsyncTaskDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void AsyncTaskDialog::updateLog()
|
||||
{
|
||||
ui->logTextEdit->setPlainText(task->getLog());
|
||||
}
|
30
src/dialogs/AsyncTaskDialog.h
Normal file
30
src/dialogs/AsyncTaskDialog.h
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
#ifndef ASYNCTASKDIALOG_H
|
||||
#define ASYNCTASKDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
namespace Ui {
|
||||
class AsyncTaskDialog;
|
||||
}
|
||||
|
||||
class AsyncTask;
|
||||
|
||||
class AsyncTaskDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AsyncTaskDialog(AsyncTask *task, QWidget *parent = nullptr);
|
||||
~AsyncTaskDialog();
|
||||
|
||||
private slots:
|
||||
void updateLog();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::AsyncTaskDialog> ui;
|
||||
AsyncTask *task;
|
||||
};
|
||||
|
||||
#endif //ASYNCTASKDIALOG_H
|
88
src/dialogs/AsyncTaskDialog.ui
Normal file
88
src/dialogs/AsyncTaskDialog.ui
Normal file
@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AsyncTaskDialog</class>
|
||||
<widget class="QDialog" name="AsyncTaskDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="timeLabel">
|
||||
<property name="text">
|
||||
<string>Time</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="maximum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="logTextEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AsyncTaskDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AsyncTaskDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -2,6 +2,7 @@
|
||||
#include "ui_OptionsDialog.h"
|
||||
#include "MainWindow.h"
|
||||
#include "dialogs/NewFileDialog.h"
|
||||
#include "dialogs/AsyncTaskDialog.h"
|
||||
#include "utils/Helpers.h"
|
||||
|
||||
#include <QSettings>
|
||||
@ -169,11 +170,12 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
|
||||
updateProgressTimer();
|
||||
connect(&analTimer, SIGNAL(timeout()), this, SLOT(updateProgressTimer()));
|
||||
|
||||
// Threads stuff, connect signal/slot
|
||||
connect(&analTask, &AnalTask::updateProgress, this, &OptionsDialog::updateProgress);
|
||||
connect(&analTask, &AnalTask::openFileFailed, main, &MainWindow::openNewFileFailed);
|
||||
analTask.setSettings(main, level, advanced);
|
||||
Core()->getAsyncTaskManager()->start(&analTask);
|
||||
|
||||
AsyncTaskDialog *taskDialog = new AsyncTaskDialog(&analTask, main);
|
||||
taskDialog->show();
|
||||
}
|
||||
|
||||
void OptionsDialog::updateProgressTimer()
|
||||
|
@ -44,12 +44,20 @@ void AsyncTask::run()
|
||||
{
|
||||
runningMutex.lock();
|
||||
running = true;
|
||||
logBuffer = "";
|
||||
emit logChanged(logBuffer);
|
||||
runTask();
|
||||
emit finished();
|
||||
running = false;
|
||||
runningMutex.unlock();
|
||||
}
|
||||
|
||||
void AsyncTask::log(QString s)
|
||||
{
|
||||
logBuffer += s;
|
||||
emit logChanged(logBuffer);
|
||||
}
|
||||
|
||||
AsyncTaskManager::AsyncTaskManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@ -26,17 +26,24 @@ public:
|
||||
bool isInterrupted() { return interrupted; }
|
||||
bool isRunning() { return running; }
|
||||
|
||||
const QString &getLog() { return logBuffer; }
|
||||
|
||||
protected:
|
||||
virtual void runTask() =0;
|
||||
|
||||
void log(QString s);
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
void logChanged(const QString &log);
|
||||
|
||||
private:
|
||||
bool running;
|
||||
bool interrupted;
|
||||
QMutex runningMutex;
|
||||
|
||||
QString logBuffer;
|
||||
|
||||
void prepareRun();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user