From 8f8000753142cabb2bc82a1cb1ae72a12bda8842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sat, 1 Apr 2017 13:20:13 +0200 Subject: [PATCH] Command Line Argument for Filename --- src/main.cpp | 30 ++++++++++++++++++++++++++++-- src/mainwindow.cpp | 2 +- src/newfiledialog.cpp | 15 +++++---------- src/newfiledialog.h | 4 ++-- src/optionsdialog.cpp | 9 ++++++++- src/optionsdialog.h | 6 ++++-- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5da5d03c..9326715f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,17 @@ + #include "mainwindow.h" #include "newfiledialog.h" +#include "optionsdialog.h" + #include +#include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); + a.setApplicationName("Iaito"); a.setApplicationVersion(APP_VERSION); // Set QString codec to UTF-8 @@ -16,6 +21,16 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); #endif + + QCommandLineParser cmdParser; + cmdParser.setApplicationDescription("A Qt and C++ GUI for radare2 reverse engineering framework"); + cmdParser.addHelpOption(); + cmdParser.addVersionOption(); + cmdParser.addPositionalArgument("filename", QCoreApplication::translate("main", "Filename to open.")); + cmdParser.process(a); + + QStringList args = cmdParser.positionalArguments(); + // Check r2 version QString r2version = r_core_version(); QString localVersion = "" R2_GITTAP; @@ -31,7 +46,18 @@ int main(int argc, char *argv[]) return 1; } - NewFileDialog n; - n.show(); + if(args.empty()) + { + NewFileDialog *n = new NewFileDialog(); + n->setAttribute(Qt::WA_DeleteOnClose); + n->exec(); + } + else // filename specified as positional argument + { + OptionsDialog *o = new OptionsDialog(args[0]); + o->setAttribute(Qt::WA_DeleteOnClose); + o->exec(); + } + return a.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 870df4b6..4be0d5f6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -100,7 +100,7 @@ MainWindow::MainWindow(QWidget *parent) : backButton->setIcon(QIcon(":/new/prefix1/img/icons/arrow_left.png")); //backButton->setPopupMode(QToolButton::DelayedPopup); ui->mainToolBar->insertWidget(ui->actionForward, backButton); - connect(backButton, SIGNAL(clicked()), this, SLOT(on_backButton_clicked())); + //connect(backButton, SIGNAL(clicked()), this, SLOT(on_backButton_clicked())); // Sepparator between undo/redo and goto lineEdit QWidget* spacer3 = new QWidget(); diff --git a/src/newfiledialog.cpp b/src/newfiledialog.cpp index 39cab6ae..18c9e980 100644 --- a/src/newfiledialog.cpp +++ b/src/newfiledialog.cpp @@ -8,6 +8,8 @@ #include #include +const int NewFileDialog::MaxRecentFiles; + static QColor getColorFor(QString str, int pos) { QList Colors; Colors << QColor(29, 188, 156); // Turquoise @@ -25,7 +27,7 @@ static QIcon getIconFor(QString str, int pos) { // Add to the icon list int w = 64; int h = 64; - + QPixmap pixmap(w,h); pixmap.fill(Qt::transparent); @@ -79,11 +81,6 @@ NewFileDialog::NewFileDialog(QWidget *parent) : ui->createButton->hide(); } -QString NewFileDialog::strippedName(const QString &fullFileName) -{ - return QFileInfo(fullFileName).fileName(); -} - NewFileDialog::~NewFileDialog() { delete ui; @@ -100,8 +97,7 @@ void NewFileDialog::on_loadFileButton_clicked() } else { // Close dialog and open OptionsDialog close(); - OptionsDialog* o = new OptionsDialog(nullptr); - o->setFilename (fname, this->strippedName(fname)); + OptionsDialog* o = new OptionsDialog(fname); o->exec(); } } @@ -145,8 +141,7 @@ void NewFileDialog::on_recentsList_itemDoubleClicked(QListWidgetItem *item) QString sitem = data.toString(); // Close dialog and open OptionsDialog close(); - OptionsDialog* o = new OptionsDialog(nullptr); - o->setFilename (sitem, this->strippedName(sitem)); + OptionsDialog* o = new OptionsDialog(sitem); o->exec(); } diff --git a/src/newfiledialog.h b/src/newfiledialog.h index 9ec27d77..5ad3af59 100644 --- a/src/newfiledialog.h +++ b/src/newfiledialog.h @@ -36,8 +36,8 @@ private slots: private: Ui::NewFileDialog *ui; - QString strippedName(const QString &fullFileName); - enum { MaxRecentFiles = 5 }; + + static const int MaxRecentFiles = 5; }; #endif // NEWFILEDIALOG_H diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index 69b1ff2b..b6446f42 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -6,7 +6,7 @@ #include #include -OptionsDialog::OptionsDialog(QWidget *parent): +OptionsDialog::OptionsDialog(QString filename, QWidget *parent): QDialog(parent), ui(new Ui::OptionsDialog), analThread(this) @@ -42,6 +42,8 @@ OptionsDialog::OptionsDialog(QWidget *parent): //this->layout()->setSizeConstraint(QLayout::SetFixedSize); connect(&analThread, SIGNAL(finished()), this, SLOT(anal_finished())); + + setFilename(filename); } OptionsDialog::~OptionsDialog() @@ -57,6 +59,11 @@ void OptionsDialog::setFilename(QString fn, QString shortfn) { this->core->tryFile (fn, 1); } +void OptionsDialog::setFilename(QString fn) +{ + setFilename(fn, QFileInfo(fn).fileName()); +} + void OptionsDialog::on_closeButton_clicked() { close(); diff --git a/src/optionsdialog.h b/src/optionsdialog.h index 2cda8b23..f86b313e 100644 --- a/src/optionsdialog.h +++ b/src/optionsdialog.h @@ -19,9 +19,8 @@ class OptionsDialog : public QDialog public: QRCore *core; - explicit OptionsDialog(QWidget *parent = 0); + explicit OptionsDialog(QString filename, QWidget *parent = 0); ~OptionsDialog(); - void setFilename(QString fn, QString shortfn); RAnalFunction functionAt(ut64 addr); QStringList asm_plugins; @@ -45,6 +44,9 @@ private: Ui::OptionsDialog *ui; AnalThread analThread; MainWindow *w; + + void setFilename(QString fn, QString shortfn); + void setFilename(QString fn); }; #endif // OPTIONSDIALOG_H