Commit 681e0892 authored by David Jarvie's avatar David Jarvie
Browse files

If KAlarm already running, don't exit if a new activation has command line errors

If an error (e.g. unknown option) occurred parsing a KAlarm command
line while another KAlarm instance was already running, the running
instance was terminated. This fix lets the running instance continue.
parent 943c9615
Pipeline #111231 passed with stage
in 1 minute and 41 seconds
......@@ -5,6 +5,7 @@ KAlarm Change Log
* Ensure KAlarm command line actions are performed if KAlarm is already running [KDE Bug 446749]
* Don't disable alarms after KAlarm command line action while KAlarm is already running [KDE Bug 446749]
* Fix resource ID numbers not working in command line & DBUS commands.
* If KAlarm is already running, don't exit if a new activation has unknown command line options.
=== Version 3.3.3 (KDE Applications 21.12) --- 7 November 2021 ===
* Show numbers in localised form.
......
/*
* commandoptions.cpp - extract command line options
* Program: kalarm
* SPDX-FileCopyrightText: 2001-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2001-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -237,7 +237,17 @@ QStringList CommandOptions::setOptions(QCommandLineParser* parser, const QString
void CommandOptions::parse()
{
mParser->process(mNonExecArguments);
// First check for parse errors (unknown option, missing argument).
// Simply calling mParser->process() would exit the program if an error is found,
// which isn't the correct action if another KAlarm instance is running.
if (!mParser->parse(mNonExecArguments))
{
qCWarning(KALARM_LOG) << "CommandOptions::parse:" << mParser->errorText();
mError.clear();
setError(mParser->errorText());
}
else
mParser->process(mNonExecArguments);
}
void CommandOptions::process()
......
......@@ -428,10 +428,13 @@ int KAlarmApp::activateInstance(const QStringList& args, const QString& workingD
Q_EMIT setExitValue(1);
if (outputText)
{
// Instance was activated from main().
*outputText = options->outputText();
delete options;
return 1;
}
// Instance was activated by DBus.
std::cerr << qPrintable(options->outputText()) << std::endl;;
mReadOnly = true; // don't need write access to calendars
exitCode = 1;
break;
......@@ -1056,7 +1059,7 @@ void KAlarmApp::processQueue()
if (commandLine)
{
const QString errmsg = xi18nc("@info:shell", "Cannot create alarm: No default calendar is defined");
std::cerr << errmsg.toLocal8Bit().data() << std::endl;
std::cerr << qPrintable(errmsg) << std::endl;
}
ok = false;
}
......@@ -1084,7 +1087,7 @@ void KAlarmApp::processQueue()
{
const QStringList alarms = scheduledAlarmList();
for (const QString& alarm : alarms)
std::cout << alarm.toUtf8().constData() << std::endl;
std::cout << qUtf8Printable(alarm) << std::endl;
break;
}
default:
......
......@@ -59,10 +59,13 @@ int main(int argc, char* argv[])
int exitCode = app->activateInstance(args, QDir::currentPath(), &outputText);
if (exitCode >= 0)
{
if (exitCode > 0)
std::cout << qPrintable(outputText) << std::endl;
else
std::cerr << qPrintable(outputText) << std::endl;
if (!outputText.isEmpty())
{
if (exitCode > 0)
std::cerr << qPrintable(outputText) << std::endl;
else
std::cout << qPrintable(outputText) << std::endl;
}
exit(exitCode);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment