Application: Allow to quit running instances by commandline

This commit is contained in:
Hannah von Reth 2019-11-28 11:57:51 +01:00 committed by Kevin Ottens
parent fa82a4aff3
commit dabf7aaebc
No known key found for this signature in database
GPG Key ID: 074BBBCB8DECC9E2
2 changed files with 13 additions and 0 deletions

View File

@ -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 <filename> : write log output to file <filename>.\n"
" --logdir <name> : 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")) {

View File

@ -123,6 +123,7 @@ private:
// options from command line:
bool _showLogWindow;
bool _quitInstance = false;
QString _logFile;
QString _logDir;
int _logExpire;