From 587fe92f7a37ad0661c18152c746ee7df1b848f7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 20 Jun 2022 18:45:47 +0200 Subject: Add --auto option to start immediately and quit when done --- src/main.cpp | 10 ++++++++-- src/speedcheck.cpp | 9 ++++++++- src/speedcheck.h | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index d5b71fb..5d9a396 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,11 +5,17 @@ int main(int argc, char **argv) { QApplication app(argc, argv); - if (argc != 2) { + bool autoStart = false; + if (argc < 2) { QMessageBox::critical(NULL, "Error", "Need one argument: file name"); return 1; } - SpeedCheck main(QString::fromLocal8Bit(argv[1])); + if (argc >= 3 && strcmp(argv[1], "--auto") == 0) { + autoStart = true; + argc--; + argv++; + } + SpeedCheck main(QString::fromLocal8Bit(argv[1]), autoStart); main.show(); app.exec(); return 0; diff --git a/src/speedcheck.cpp b/src/speedcheck.cpp index aa02d47..428be75 100644 --- a/src/speedcheck.cpp +++ b/src/speedcheck.cpp @@ -10,7 +10,7 @@ #include #include -SpeedCheck::SpeedCheck(QString fileName) +SpeedCheck::SpeedCheck(QString fileName, bool autoStart) : _ui(new Ui::MainWindow), _thread(NULL), _doQuit(false), @@ -21,6 +21,12 @@ SpeedCheck::SpeedCheck(QString fileName) connect(_ui->btnQuit, SIGNAL(clicked(bool)), this, SLOT(quitClicked(bool))); _timer.setInterval(200); connect(&_timer, SIGNAL(timeout()), this, SLOT(updateTimer())); + if (autoStart) { + _doQuit = true; + QTimer::singleShot(1, [this]() { + this->startClicked(true); + }); + } } SpeedCheck::~SpeedCheck() @@ -70,6 +76,7 @@ void SpeedCheck::testFinished() _thread = NULL; if (_doQuit) { QCoreApplication::instance()->quit(); + return; } _ui->btnStart->setEnabled(true); } diff --git a/src/speedcheck.h b/src/speedcheck.h index fd54605..c89e3f1 100644 --- a/src/speedcheck.h +++ b/src/speedcheck.h @@ -14,7 +14,7 @@ class SpeedCheck : public QMainWindow { Q_OBJECT public: - SpeedCheck(QString fileName); + SpeedCheck(QString fileName, bool autoStart); virtual ~SpeedCheck(); private slots: @@ -27,7 +27,7 @@ private slots: private: Ui::MainWindow *_ui; CopyThread *_thread; - volatile bool _doQuit; + bool _doQuit; QString _fileName; QTimer _timer; }; -- cgit v1.2.3-55-g7522