Added dialog to show infinite progress-bar while running script (#1145)

* Added dialog to show infinite progress-bar while running script

* Replaced loadScript with cmdTask for thread safe execution.
This commit is contained in:
Gaurav Kumar Ghildiyal 2019-01-28 19:07:20 +05:30 committed by Itay Cohen
parent 8c6db6e3bb
commit 57231192f4
4 changed files with 84 additions and 7 deletions

View File

@ -225,7 +225,8 @@ SOURCES += \
common/QtResImporter.cpp \ common/QtResImporter.cpp \
common/CutterSeekable.cpp \ common/CutterSeekable.cpp \
common/RefreshDeferrer.cpp \ common/RefreshDeferrer.cpp \
dialogs/WelcomeDialog.cpp dialogs/WelcomeDialog.cpp \
RunScriptTask.cpp
HEADERS += \ HEADERS += \
@ -333,7 +334,8 @@ HEADERS += \
common/QtResImporter.h \ common/QtResImporter.h \
common/CutterSeekable.h \ common/CutterSeekable.h \
common/RefreshDeferrer.h \ common/RefreshDeferrer.h \
dialogs/WelcomeDialog.h dialogs/WelcomeDialog.h \
RunScriptTask.h
FORMS += \ FORMS += \
dialogs/AboutDialog.ui \ dialogs/AboutDialog.ui \

View File

@ -51,6 +51,7 @@
#include "dialogs/RenameDialog.h" #include "dialogs/RenameDialog.h"
#include "dialogs/preferences/PreferencesDialog.h" #include "dialogs/preferences/PreferencesDialog.h"
#include "dialogs/OpenFileDialog.h" #include "dialogs/OpenFileDialog.h"
#include "dialogs/AsyncTaskDialog.h"
// Widgets Headers // Widgets Headers
#include "widgets/DisassemblerGraphView.h" #include "widgets/DisassemblerGraphView.h"
@ -86,6 +87,8 @@
#include "widgets/BreakpointWidget.h" #include "widgets/BreakpointWidget.h"
#include "widgets/RegisterRefsWidget.h" #include "widgets/RegisterRefsWidget.h"
#include "RunScriptTask.h"
// Graphics // Graphics
#include <QGraphicsEllipseItem> #include <QGraphicsEllipseItem>
#include <QGraphicsScene> #include <QGraphicsScene>
@ -446,8 +449,8 @@ void MainWindow::setFilename(const QString &fn)
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME, QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME,
tr("Do you really want to exit?\nSave your project before closing!"), tr("Do you really want to exit?\nSave your project before closing!"),
(QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel)); (QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel));
if (ret == QMessageBox::Cancel) { if (ret == QMessageBox::Cancel) {
event->ignore(); event->ignore();
return; return;
@ -810,7 +813,18 @@ void MainWindow::on_actionRun_Script_triggered()
const QString &fileName = QDir::toNativeSeparators(dialog.getOpenFileName(this, tr("Select radare2 script"))); const QString &fileName = QDir::toNativeSeparators(dialog.getOpenFileName(this, tr("Select radare2 script")));
if (fileName.isEmpty()) // Cancel was pressed if (fileName.isEmpty()) // Cancel was pressed
return; return;
core->loadScript(fileName);
RunScriptTask *runScriptTask = new RunScriptTask();
runScriptTask->setFileName(fileName);
AsyncTask::Ptr runScriptTaskPtr(runScriptTask);
AsyncTaskDialog *taskDialog = new AsyncTaskDialog(runScriptTaskPtr, this);
taskDialog->setInterruptOnClose(true);
taskDialog->setAttribute(Qt::WA_DeleteOnClose);
taskDialog->show();
Core()->getAsyncTaskManager()->start(runScriptTaskPtr);
} }
/** /**
@ -840,8 +854,8 @@ void MainWindow::on_actionReset_settings_triggered()
{ {
QMessageBox::StandardButton ret = QMessageBox::StandardButton ret =
(QMessageBox::StandardButton)QMessageBox::question(this, APPNAME, (QMessageBox::StandardButton)QMessageBox::question(this, APPNAME,
tr("Do you really want to clear all settings?"), tr("Do you really want to clear all settings?"),
QMessageBox::Ok | QMessageBox::Cancel); QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok) { if (ret == QMessageBox::Ok) {
Config()->resetAll(); Config()->resetAll();
} }

29
src/RunScriptTask.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "Cutter.h"
#include "RunScriptTask.h"
#include "MainWindow.h"
RunScriptTask::RunScriptTask() :
AsyncTask()
{
}
RunScriptTask::~RunScriptTask()
{
}
void RunScriptTask::interrupt()
{
AsyncTask::interrupt();
r_cons_singleton()->context->breaked = true;
}
void RunScriptTask::runTask()
{
if (!this->fileName.isNull()) {
log(tr("Executing script..."));
Core()->cmdTask(". " + this->fileName);
if (isInterrupted()) {
return;
}
}
}

32
src/RunScriptTask.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef RUNSCRIPTTHREAD_H
#define RUNSCRIPTTHREAD_H
#include "common/AsyncTask.h"
#include "Cutter.h"
class RunScriptTask : public AsyncTask
{
Q_OBJECT
public:
explicit RunScriptTask();
~RunScriptTask();
QString getTitle() override {
return tr("Run Script");
}
void setFileName(const QString &fileName) {
this->fileName = fileName;
}
void interrupt() override;
protected:
void runTask() override;
private:
QString fileName;
};
#endif // RUNSCRIPTTHREAD_H