From dabf7aaebcb3b45fa56c7329bbf33afaff078c87 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 28 Nov 2019 11:57:51 +0100 Subject: [PATCH] Application: Allow to quit running instances by commandline --- src/gui/application.cpp | 12 ++++++++++++ src/gui/application.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 2e5cbbb2f..094899cda 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -72,6 +72,7 @@ namespace { "Options:\n" " --help, -h : show this help screen.\n" " --version, -v : show version information.\n" + " -q --quit : quit the running instance\n" " --logwindow, -l : open a window to show log output.\n" " --logfile : write log output to file .\n" " --logdir : write each sync log output in a new file\n" @@ -248,6 +249,11 @@ Application::Application(int &argc, char **argv) if (_helpOnly || _versionOnly) return; + if (_quitInstance) { + QTimer::singleShot(0, qApp, &QApplication::quit); + return; + } + if (isRunning()) return; @@ -536,6 +542,10 @@ void Application::slotParseMessage(const QString &msg, QObject *) if (_showLogWindow) { _gui->slotToggleLogBrowser(); // _showLogWindow is set in parseOptions. } + if (_quitInstance) { + qApp->quit(); + } + } else if (msg.startsWith(QLatin1String("MSG_SHOWMAINDIALOG"))) { qCInfo(lcApplication) << "Running for" << _startedAt.elapsed() / 1000.0 << "sec"; if (_startedAt.elapsed() < 10 * 1000) { @@ -560,6 +570,8 @@ void Application::parseOptions(const QStringList &options) if (option == QLatin1String("--help") || option == QLatin1String("-h")) { setHelp(); break; + } else if (option == QLatin1String("--quit") || option == QLatin1String("-q")) { + _quitInstance = true; } else if (option == QLatin1String("--logwindow") || option == QLatin1String("-l")) { _showLogWindow = true; } else if (option == QLatin1String("--logfile")) { diff --git a/src/gui/application.h b/src/gui/application.h index f6f84ee2d..b09eaa083 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -123,6 +123,7 @@ private: // options from command line: bool _showLogWindow; + bool _quitInstance = false; QString _logFile; QString _logDir; int _logExpire; -- 2.30.2