Commit d9031c53 authored by David Jarvie's avatar David Jarvie
Browse files

Fix bugs when command generating text for a display alarm fails

1) Don't display the alarm window; only display an error message.
2) Don't redisplay the alarm on every restart.
parent 22a51f06
Pipeline #33629 passed with stage
in 11 minutes
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.15.2")
set(PIM_VERSION ${PIM_VERSION})
set(RELEASE_SERVICE_VERSION "20.08.2")
set(KALARM_VERSION "3.0.1")
set(KALARM_VERSION "3.0.2")
project(kalarm VERSION ${KALARM_VERSION})
......
KAlarm Change Log
=== Version 3.0.2 (KDE Applications 20.08.2) --- 9 September 2020 ===
+ If command generating text for display alarm fails, only display error message,
not the display alarm, and don't redisplay the alarm on every restart.
=== Version 3.0.1 (KDE Applications 20.08.1) --- 24 August 2020 ===
+ Fix inability to create alarms from templates, or load templates in edit dialogue [KDE Bug 425751]
+ Don't show spurious error message when deleting alarm template [KDE Bug 425751]
......
......@@ -2284,7 +2284,7 @@ void KAlarmApp::emailSent(KAMail::JobData& data, const QStringList& errmsgs, boo
* To connect to the output ready signals of the process, specify a slot to be
* called by supplying 'receiver' and 'slot' parameters.
*/
ShellProcess* KAlarmApp::execCommandAlarm(const KAEvent& event, const KAAlarm& alarm, const QObject* receiver, const char* slot)
ShellProcess* KAlarmApp::execCommandAlarm(const KAEvent& event, const KAAlarm& alarm, QObject* receiver, const char* slotOutput, const char* methodExited)
{
// doShellCommand() will error if the user is not authorised to run
// shell commands.
......@@ -2301,12 +2301,12 @@ ShellProcess* KAlarmApp::execCommandAlarm(const KAEvent& event, const KAAlarm& a
setEventCommandError(event, KAEvent::CMD_ERROR);
return nullptr;
}
return doShellCommand(tmpfile, event, &alarm, (flags | ProcData::TEMP_FILE), receiver, slot);
return doShellCommand(tmpfile, event, &alarm, (flags | ProcData::TEMP_FILE), receiver, slotOutput, methodExited);
}
else
{
qCDebug(KALARM_LOG) << "KAlarmApp::execCommandAlarm:" << command;
return doShellCommand(command, event, &alarm, flags, receiver, slot);
return doShellCommand(command, event, &alarm, flags, receiver, slotOutput, methodExited);
}
}
......@@ -2317,13 +2317,15 @@ ShellProcess* KAlarmApp::execCommandAlarm(const KAEvent& event, const KAAlarm& a
* derived from the remaining bits in 'flags'.
* 'flags' must contain the bit PRE_ACTION or POST_ACTION if and only if it is
* a pre- or post-alarm action respectively.
* To connect to the exited signal of the process, specify the name of a method
* to be called by supplying 'receiver' and 'methodExited' parameters.
* To connect to the output ready signals of the process, specify a slot to be
* called by supplying 'receiver' and 'slot' parameters.
*
* Note that if shell access is not authorised, the attempt to run the command
* will be errored.
*/
ShellProcess* KAlarmApp::doShellCommand(const QString& command, const KAEvent& event, const KAAlarm* alarm, int flags, const QObject* receiver, const char* slot)
ShellProcess* KAlarmApp::doShellCommand(const QString& command, const KAEvent& event, const KAAlarm* alarm, int flags, QObject* receiver, const char* slotOutput, const char* methodExited)
{
qCDebug(KALARM_LOG) << "KAlarmApp::doShellCommand:" << command << "," << event.id();
QIODevice::OpenMode mode = QIODevice::WriteOnly;
......@@ -2357,10 +2359,10 @@ ShellProcess* KAlarmApp::doShellCommand(const QString& command, const KAEvent& e
proc->setEnv(QStringLiteral("KALARM_UID"), event.id(), true);
proc->setOutputChannelMode(KProcess::MergedChannels); // combine stdout & stderr
connect(proc, &ShellProcess::shellExited, this, &KAlarmApp::slotCommandExited);
if ((flags & ProcData::DISP_OUTPUT) && receiver && slot)
if ((flags & ProcData::DISP_OUTPUT) && receiver && slotOutput)
{
connect(proc, SIGNAL(receivedStdout(ShellProcess*)), receiver, slot);
connect(proc, SIGNAL(receivedStderr(ShellProcess*)), receiver, slot);
connect(proc, SIGNAL(receivedStdout(ShellProcess*)), receiver, slotOutput);
connect(proc, SIGNAL(receivedStderr(ShellProcess*)), receiver, slotOutput);
}
if (mode == QIODevice::ReadWrite && !event.logFile().isEmpty())
{
......@@ -2388,6 +2390,11 @@ ShellProcess* KAlarmApp::doShellCommand(const QString& command, const KAEvent& e
pd->tempFiles += command;
if (!tmpXtermFile.isEmpty())
pd->tempFiles += tmpXtermFile;
if (receiver && methodExited)
{
pd->exitReceiver = receiver;
pd->exitMethod = methodExited;
}
mCommandProcesses.append(pd);
if (proc->start(mode))
return proc;
......@@ -2551,6 +2558,8 @@ void KAlarmApp::slotCommandExited(ShellProcess* proc)
if (executeAlarm)
execAlarm(*pd->event, *pd->alarm, pd->reschedule(), pd->allowDefer(), true);
mCommandProcesses.removeAt(i);
if (pd->exitReceiver && !pd->exitMethod.isEmpty())
QMetaObject::invokeMethod(pd->exitReceiver, pd->exitMethod.constData(), Qt::DirectConnection, Q_ARG(ShellProcess::Status, status));
delete pd;
break;
}
......
......@@ -79,7 +79,10 @@ class KAlarmApp : public QApplication
bool editNewAlarm(MainWindow* = nullptr);
void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
ShellProcess* execCommandAlarm(const KAEvent&, const KAAlarm&, const QObject* receiver = nullptr, const char* slot = nullptr);
ShellProcess* execCommandAlarm(const KAEvent&, const KAAlarm&,
QObject* receiver = nullptr,
const char* slotOutput = nullptr,
const char* methodExited = nullptr);
void alarmCompleted(const KAEvent&);
void rescheduleAlarm(KAEvent& e, const KAAlarm& a) { rescheduleAlarm(e, a, true); }
void purgeAll() { purge(0); }
......@@ -174,6 +177,8 @@ class KAlarmApp : public QApplication
ShellProcess* process;
KAEvent* event;
KAAlarm* alarm;
QObject* exitReceiver {nullptr};
QByteArray exitMethod;
QPointer<QWidget> messageBoxParent;
QStringList tempFiles;
int flags;
......@@ -209,7 +214,9 @@ class KAlarmApp : public QApplication
bool cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
bool cancelReminderAndDeferral(KAEvent&);
ShellProcess* doShellCommand(const QString& command, const KAEvent&, const KAAlarm*,
int flags = 0, const QObject* receiver = nullptr, const char* slot = nullptr);
int flags = 0, QObject* receiver = nullptr,
const char* slotOutput = nullptr,
const char* methodExited = nullptr);
QString composeXTermCommand(const QString& command, const KAEvent&, const KAAlarm*,
int flags, QString& tempScriptFile) const;
QString createTempScriptFile(const QString& command, bool insertShell, const KAEvent&, const KAAlarm&) const;
......
......@@ -37,7 +37,6 @@
#include "lib/file.h"
#include "lib/messagebox.h"
#include "lib/pushbutton.h"
#include "lib/shellprocess.h"
#include "lib/synchtimer.h"
#include "kalarm_debug.h"
......@@ -518,7 +517,7 @@ void MessageWin::initView()
mCommandText->setCurrentFont(mFont);
topLayout->addWidget(mCommandText);
mCommandText->setWhatsThis(i18nc("@info:whatsthis", "The output of the alarm's command"));
theApp()->execCommandAlarm(mEvent, mEvent.alarm(mAlarmType), this, SLOT(readProcessOutput(ShellProcess*)));
theApp()->execCommandAlarm(mEvent, mEvent.alarm(mAlarmType), this, SLOT(readProcessOutput(ShellProcess*)), "commandCompleted");
break;
}
case KAEvent::EMAIL:
......@@ -906,6 +905,30 @@ void MessageWin::readProcessOutput(ShellProcess* proc)
}
}
/******************************************************************************
* Called when the command which is providing the text for this display has
* completed. Check whether the command succeeded, even partially.
*/
void MessageWin::commandCompleted(ShellProcess::Status status)
{
switch (status)
{
case ShellProcess::SUCCESS:
case ShellProcess::DIED:
break;
case ShellProcess::UNAUTHORISED:
case ShellProcess::NOT_FOUND:
case ShellProcess::START_FAIL:
case ShellProcess::INACTIVE:
default:
// The command failed completely. KAlarmApp will output an error
// message, so delete the empty window.
close();
break;
}
}
/******************************************************************************
* Save settings to the session managed config file, for restoration
* when the program is restored.
......
......@@ -27,6 +27,7 @@
#include "mainwindowbase.h"
#include "resources/resource.h"
#include "lib/autoqpointer.h"
#include "lib/shellprocess.h"
#include <KAlarmCal/KAEvent>
......@@ -46,7 +47,6 @@ class QLabel;
class QTemporaryFile;
class DeferAlarmDlg;
class EditAlarmDlg;
class ShellProcess;
class AudioThread;
using namespace KAlarmCal;
......@@ -118,6 +118,7 @@ class MessageWin : public MainWindowBase
void setRemainingTextMinute();
void frameDrawn();
void readProcessOutput(ShellProcess*);
void commandCompleted(ShellProcess::Status);
private:
MessageWin(const KAEvent*, const DateTime& alarmDateTime, const QStringList& errmsgs,
......
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