Commit 7dcd0e7a authored by David Jarvie's avatar David Jarvie

Provide notification option on command line and via D-Bus

parent 4c70f22f
Pipeline #35458 passed with stage
in 33 minutes and 49 seconds
KAlarm Change Log
=== Version 3.1.0 (KDE Applications 20.12) --- 21 September 2020 ===
=== Version 3.1.0 (KDE Applications 20.12) --- 24 September 2020 ===
+ Add option to show alarm message as a notification instead of in a window [KDE Bug 345922]
=== Version 3.0.2 (KDE Applications 20.08.2) --- 16 September 2020 ===
......
......@@ -139,6 +139,9 @@ QStringList CommandOptions::setOptions(QCommandLineParser* parser, const QString
= new QCommandLineOption(QStringList{QStringLiteral("m"), QStringLiteral("mail")},
i18n("Send an email to the given address (repeat as needed)"),
QStringLiteral("address"));
mOptions[NOTIFY]
= new QCommandLineOption(QStringList{QStringLiteral("n"), QStringLiteral("notify")},
i18n("Display alarm message as a notification"));
mOptions[PLAY]
= new QCommandLineOption(QStringList{QStringLiteral("p"), QStringLiteral("play")},
i18n("Audio file to play once"),
......@@ -389,6 +392,7 @@ void CommandOptions::process()
checkEditType(EditAlarmDlg::DISPLAY, REMINDER_ONCE);
checkEditType(EditAlarmDlg::DISPLAY, ACK_CONFIRM);
checkEditType(EditAlarmDlg::DISPLAY, AUTO_CLOSE);
checkEditType(EditAlarmDlg::DISPLAY, NOTIFY);
checkEditType(EditAlarmDlg::EMAIL, SUBJECT);
checkEditType(EditAlarmDlg::EMAIL, FROM_ID);
checkEditType(EditAlarmDlg::EMAIL, ATTACH);
......@@ -584,6 +588,20 @@ void CommandOptions::process()
else if (mParser->isSet(*mOptions.at(AUTO_CLOSE)))
setErrorRequires(AUTO_CLOSE, LATE_CANCEL);
if (mParser->isSet(*mOptions.at(NOTIFY)))
{
if (mParser->isSet(*mOptions.at(COLOUR)))
setErrorIncompatible(NOTIFY, COLOUR);
if (mParser->isSet(*mOptions.at(COLOURFG)))
setErrorIncompatible(NOTIFY, COLOURFG);
if (mParser->isSet(*mOptions.at(ACK_CONFIRM)))
setErrorIncompatible(NOTIFY, ACK_CONFIRM);
if (mParser->isSet(*mOptions.at(PLAY)))
setErrorIncompatible(NOTIFY, PLAY);
if (mParser->isSet(*mOptions.at(AUTO_CLOSE)))
setErrorIncompatible(NOTIFY, AUTO_CLOSE);
}
if (mParser->isSet(*mOptions.at(ACK_CONFIRM)))
mFlags |= KAEvent::CONFIRM_ACK;
if (mParser->isSet(*mOptions.at(AUTO_CLOSE)))
......@@ -592,6 +610,8 @@ void CommandOptions::process()
mFlags |= KAEvent::BEEP;
if (mParser->isSet(*mOptions.at(SPEAK)))
mFlags |= KAEvent::SPEAK;
if (mParser->isSet(*mOptions.at(NOTIFY)))
mFlags |= KAEvent::NOTIFY;
if (mParser->isSet(*mOptions.at(KORGANIZER)))
mFlags |= KAEvent::COPY_KORGANIZER;
if (mParser->isSet(*mOptions.at(DISABLE)))
......@@ -647,6 +667,8 @@ void CommandOptions::process()
errors << optionName(REMINDER_ONCE);
if (mParser->isSet(*mOptions.at(SPEAK)))
errors << optionName(SPEAK);
if (mParser->isSet(*mOptions.at(NOTIFY)))
errors << optionName(NOTIFY);
if (mParser->isSet(*mOptions.at(SUBJECT)))
errors << optionName(SUBJECT);
if (mParser->isSet(*mOptions.at(TIME)))
......
......@@ -25,148 +25,149 @@ using namespace KAlarmCal;
class CommandOptions
{
public:
enum Command
{
CMD_ERROR, // error in command line options
NONE, // no command
TRAY, // --tray
TRIGGER_EVENT, // --triggerEvent
CANCEL_EVENT, // --cancelEvent
EDIT, // --edit
EDIT_NEW_PRESET, // --edit-new-preset
EDIT_NEW, // --edit-new-display, --edit-new-command, --edit-new-email
NEW, // --file, --exec-display, --exec, --mail, message
LIST // --list
};
QStringList setOptions(QCommandLineParser*, const QStringList& args);
static CommandOptions* firstInstance() { return mFirstInstance; }
CommandOptions();
void parse();
void process();
Command command() const { return mCommand; }
QString commandName() const { return optionName(mCommandOpt); }
QString eventId() const { return mEventId; }
QString resourceId() const { return mResourceId; }
QString templateName() const { return mTemplateName; }
EditAlarmDlg::Type editType() const { return mEditType; }
KAEvent::SubAction editAction() const { return mEditAction; }
QString text() const { return mText; }
KADateTime alarmTime() const { return mAlarmTime; }
KARecurrence* recurrence() const { return mRecurrence; }
int subRepeatCount() const { return mRepeatCount; }
KCalendarCore::Duration subRepeatInterval() const { return mRepeatInterval; }
int lateCancel() const { return mLateCancel; }
QColor bgColour() const { return mBgColour; }
QColor fgColour() const { return mFgColour; }
int reminderMinutes() const { return mReminderMinutes; }
QString audioFile() const { return mAudioFile; }
float audioVolume() const { return mAudioVolume; }
KCalendarCore::Person::List addressees() const { return mAddressees; }
QStringList attachments() const { return mAttachments; }
QString subject() const { return mSubject; }
uint fromID() const { return mFromID; }
KAEvent::Flags flags() const { return mFlags; }
bool disableAll() const { return mDisableAll; }
QString outputText() const { return mError; }
public:
enum Command
{
CMD_ERROR, // error in command line options
NONE, // no command
TRAY, // --tray
TRIGGER_EVENT, // --triggerEvent
CANCEL_EVENT, // --cancelEvent
EDIT, // --edit
EDIT_NEW_PRESET, // --edit-new-preset
EDIT_NEW, // --edit-new-display, --edit-new-command, --edit-new-email
NEW, // --file, --exec-display, --exec, --mail, message
LIST // --list
};
QStringList setOptions(QCommandLineParser*, const QStringList& args);
static CommandOptions* firstInstance() { return mFirstInstance; }
CommandOptions();
void parse();
void process();
Command command() const { return mCommand; }
QString commandName() const { return optionName(mCommandOpt); }
QString eventId() const { return mEventId; }
QString resourceId() const { return mResourceId; }
QString templateName() const { return mTemplateName; }
EditAlarmDlg::Type editType() const { return mEditType; }
KAEvent::SubAction editAction() const { return mEditAction; }
QString text() const { return mText; }
KADateTime alarmTime() const { return mAlarmTime; }
KARecurrence* recurrence() const { return mRecurrence; }
int subRepeatCount() const { return mRepeatCount; }
KCalendarCore::Duration subRepeatInterval() const { return mRepeatInterval; }
int lateCancel() const { return mLateCancel; }
QColor bgColour() const { return mBgColour; }
QColor fgColour() const { return mFgColour; }
int reminderMinutes() const { return mReminderMinutes; }
QString audioFile() const { return mAudioFile; }
float audioVolume() const { return mAudioVolume; }
KCalendarCore::Person::List addressees() const { return mAddressees; }
QStringList attachments() const { return mAttachments; }
QString subject() const { return mSubject; }
uint fromID() const { return mFromID; }
KAEvent::Flags flags() const { return mFlags; }
bool disableAll() const { return mDisableAll; }
QString outputText() const { return mError; }
#ifndef NDEBUG
KADateTime simulationTime() const { return mSimulationTime; }
KADateTime simulationTime() const { return mSimulationTime; }
#endif
static void printError(const QString& errmsg);
static void printError(const QString& errmsg);
private:
enum Option
{
ACK_CONFIRM,
ATTACH,
AUTO_CLOSE,
BCC,
BEEP,
COLOUR,
COLOURFG,
OptCANCEL_EVENT,
DISABLE,
DISABLE_ALL,
EXEC,
EXEC_DISPLAY,
OptEDIT,
EDIT_NEW_DISPLAY,
EDIT_NEW_COMMAND,
EDIT_NEW_EMAIL,
EDIT_NEW_AUDIO,
OptEDIT_NEW_PRESET,
FILE,
FROM_ID,
INTERVAL,
KORGANIZER,
LATE_CANCEL,
OptLIST,
LOGIN,
MAIL,
PLAY,
PLAY_REPEAT,
RECURRENCE,
REMINDER,
REMINDER_ONCE,
REPEAT,
SPEAK,
SUBJECT,
private:
enum Option
{
ACK_CONFIRM,
ATTACH,
AUTO_CLOSE,
BCC,
BEEP,
COLOUR,
COLOURFG,
OptCANCEL_EVENT,
DISABLE,
DISABLE_ALL,
EXEC,
EXEC_DISPLAY,
OptEDIT,
EDIT_NEW_DISPLAY,
EDIT_NEW_COMMAND,
EDIT_NEW_EMAIL,
EDIT_NEW_AUDIO,
OptEDIT_NEW_PRESET,
FILE,
FROM_ID,
INTERVAL,
KORGANIZER,
LATE_CANCEL,
OptLIST,
LOGIN,
MAIL,
NOTIFY,
PLAY,
PLAY_REPEAT,
RECURRENCE,
REMINDER,
REMINDER_ONCE,
REPEAT,
SPEAK,
SUBJECT,
#ifndef NDEBUG
TEST_SET_TIME,
TEST_SET_TIME,
#endif
TIME,
OptTRAY,
OptTRIGGER_EVENT,
UNTIL,
VOLUME,
Num_Options, // number of Option values
Opt_Message // special value representing "message"
};
TIME,
OptTRAY,
OptTRIGGER_EVENT,
UNTIL,
VOLUME,
Num_Options, // number of Option values
Opt_Message // special value representing "message"
};
bool checkCommand(Option, Command, EditAlarmDlg::Type = EditAlarmDlg::NO_TYPE);
void setError(const QString& error);
void setErrorRequires(Option opt, Option opt2, Option opt3 = Num_Options);
void setErrorParameter(Option);
void setErrorIncompatible(Option opt1, Option opt2);
void checkEditType(EditAlarmDlg::Type type, Option opt)
{ checkEditType(type, EditAlarmDlg::NO_TYPE, opt); }
void checkEditType(EditAlarmDlg::Type, EditAlarmDlg::Type, Option);
QString arg(int n);
QString optionName(Option, bool shortName = false) const;
bool checkCommand(Option, Command, EditAlarmDlg::Type = EditAlarmDlg::NO_TYPE);
void setError(const QString& error);
void setErrorRequires(Option opt, Option opt2, Option opt3 = Num_Options);
void setErrorParameter(Option);
void setErrorIncompatible(Option opt1, Option opt2);
void checkEditType(EditAlarmDlg::Type type, Option opt)
{ checkEditType(type, EditAlarmDlg::NO_TYPE, opt); }
void checkEditType(EditAlarmDlg::Type, EditAlarmDlg::Type, Option);
QString arg(int n);
QString optionName(Option, bool shortName = false) const;
static CommandOptions* mFirstInstance; // the first instance
QCommandLineParser* mParser {nullptr};
QVector<QCommandLineOption*> mOptions; // all possible command line options
QStringList mNonExecArguments; // arguments except for --exec or --exec-display parameters
QStringList mExecArguments; // arguments for --exec or --exec-display
QString mError; // error message
Command mCommand {NONE}; // the selected command
Option mCommandOpt; // option for the selected command
QString mEventId; // TRIGGER_EVENT, CANCEL_EVENT, EDIT: event ID
QString mResourceId; // TRIGGER_EVENT, CANCEL_EVENT, EDIT: optional resource ID
QString mTemplateName; // EDIT_NEW_PRESET: template name
EditAlarmDlg::Type mEditType; // NEW, EDIT_NEW_*: alarm edit type
KAEvent::SubAction mEditAction; // NEW: alarm edit sub-type
bool mEditActionSet {false}; // NEW: mEditAction is valid
QString mText; // NEW: alarm text
KADateTime mAlarmTime; // NEW: alarm time
KARecurrence* mRecurrence {nullptr}; // NEW: recurrence
int mRepeatCount {0}; // NEW: sub-repetition count
KCalendarCore::Duration mRepeatInterval {0}; // NEW: sub-repetition interval
int mLateCancel {0}; // NEW: late-cancellation interval
QColor mBgColour; // NEW: background colour
QColor mFgColour; // NEW: foreground colour
int mReminderMinutes {0}; // NEW: reminder period
QString mAudioFile; // NEW: audio file path
float mAudioVolume {-1.0f}; // NEW: audio file volume
KCalendarCore::Person::List mAddressees; // NEW: email addressees
QStringList mAttachments; // NEW: email attachment file names
QString mSubject; // NEW: email subject
uint mFromID {0}; // NEW: email sender ID
KAEvent::Flags mFlags; // NEW: event flags
bool mDisableAll {false}; // disable all alarm monitoring
static CommandOptions* mFirstInstance; // the first instance
QCommandLineParser* mParser {nullptr};
QVector<QCommandLineOption*> mOptions; // all possible command line options
QStringList mNonExecArguments; // arguments except for --exec or --exec-display parameters
QStringList mExecArguments; // arguments for --exec or --exec-display
QString mError; // error message
Command mCommand {NONE}; // the selected command
Option mCommandOpt; // option for the selected command
QString mEventId; // TRIGGER_EVENT, CANCEL_EVENT, EDIT: event ID
QString mResourceId; // TRIGGER_EVENT, CANCEL_EVENT, EDIT: optional resource ID
QString mTemplateName; // EDIT_NEW_PRESET: template name
EditAlarmDlg::Type mEditType; // NEW, EDIT_NEW_*: alarm edit type
KAEvent::SubAction mEditAction; // NEW: alarm edit sub-type
bool mEditActionSet {false}; // NEW: mEditAction is valid
QString mText; // NEW: alarm text
KADateTime mAlarmTime; // NEW: alarm time
KARecurrence* mRecurrence {nullptr}; // NEW: recurrence
int mRepeatCount {0}; // NEW: sub-repetition count
KCalendarCore::Duration mRepeatInterval {0}; // NEW: sub-repetition interval
int mLateCancel {0}; // NEW: late-cancellation interval
QColor mBgColour; // NEW: background colour
QColor mFgColour; // NEW: foreground colour
int mReminderMinutes {0}; // NEW: reminder period
QString mAudioFile; // NEW: audio file path
float mAudioVolume {-1.0f}; // NEW: audio file volume
KCalendarCore::Person::List mAddressees; // NEW: email addressees
QStringList mAttachments; // NEW: email attachment file names
QString mSubject; // NEW: email subject
uint mFromID {0}; // NEW: email sender ID
KAEvent::Flags mFlags; // NEW: event flags
bool mDisableAll {false}; // disable all alarm monitoring
#ifndef NDEBUG
KADateTime mSimulationTime; // system time to be simulated, or invalid if none
KADateTime mSimulationTime; // system time to be simulated, or invalid if none
#endif
};
......
......@@ -488,6 +488,7 @@ KAEvent::Flags DBusHandler::convertStartFlags(const KADateTime& start, unsigned
if (flags & EXCL_HOLIDAYS) kaEventFlags |= KAEvent::EXCL_HOLIDAYS;
if (flags & WORK_TIME_ONLY) kaEventFlags |= KAEvent::WORK_TIME_ONLY;
if (flags & DISABLED) kaEventFlags |= KAEvent::DISABLED;
if (flags & NOTIFY) kaEventFlags |= KAEvent::NOTIFY;
if (start.isDateOnly()) kaEventFlags |= KAEvent::ANY_TIME;
return kaEventFlags;
}
......
......@@ -469,6 +469,10 @@ void EditDisplayAlarmDlg::setFgColour(const QColor& colour)
mFontColourButton->setFgColour(colour);
setColours(colour, mFontColourButton->bgColour());
}
void EditDisplayAlarmDlg::setNotify(bool notify)
{
mDisplayMethodCombo->setCurrentIndex(notify ? dNOTIFY : dWINDOW);
}
void EditDisplayAlarmDlg::setConfirmAck(bool confirm)
{
mConfirmAck->setChecked(confirm);
......
......@@ -50,6 +50,7 @@ public:
void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override;
void setBgColour(const QColor&);
void setFgColour(const QColor&);
void setNotify(bool);
void setConfirmAck(bool);
void setAutoClose(bool);
void setAudio(Preferences::SoundType, const QString& file = QString(), float volume = -1, int repeatPause = -1);
......
......@@ -499,6 +499,8 @@ int KAlarmApp::activateInstance(const QStringList& args, const QString& workingD
}
if (options->reminderMinutes())
dlg->setReminder(options->reminderMinutes(), (options->flags() & KAEvent::REMINDER_ONCE));
if (options->flags() & KAEvent::NOTIFY)
dlg->setNotify(true);
if (options->flags() & KAEvent::CONFIRM_ACK)
dlg->setConfirmAck(true);
if (options->flags() & KAEvent::AUTO_CLOSE)
......
/*
* kalarmiface.h - D-Bus interface to KAlarm
* Program: kalarm
* SPDX-FileCopyrightText: 2004-2009 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2004-2020 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -17,68 +17,47 @@
class KAlarmIface
{
public:
/** Bit values for the @p flags parameter of "scheduleXxxx()" D-Bus calls.
* The bit values may be OR'ed together.
* @li REPEAT_AT_LOGIN - repeat the alarm at every login.
* @li BEEP - sound an audible beep when the alarm is displayed.
* @li SPEAK - speak the alarm message when it is displayed.
* @li REPEAT_SOUND - repeat the sound file while the alarm is displayed.
* @li CONFIRM_ACK - closing the alarm message window requires a confirmation prompt.
* @li AUTO_CLOSE - auto-close the alarm window after the late-cancel period.
* @li DISPLAY_COMMAND - display command output in the alarm window.
* @li SCRIPT - the command to execute is a script, not a shell command line.
* @li EXEC_IN_XTERM - execute the command alarm in a terminal window.
* @li EMAIL_BCC - send a blind copy the email to the user.
* @li SHOW_IN_KORG - show the alarm as an event in KOrganizer
* @li EXCL_HOLIDAYS - do not trigger the alarm on holidays
* @li WORK_TIME_ONLY - do not trigger the alarm outside working hours (or on holidays)
* @li DISABLED - set the alarm status to disabled.
*/
enum Flags
{
REPEAT_AT_LOGIN = 0x01, // repeat alarm at every login
BEEP = 0x02, // sound audible beep when alarm is displayed
REPEAT_SOUND = 0x08, // repeat sound file while alarm is displayed
CONFIRM_ACK = 0x04, // closing the alarm message window requires confirmation prompt
AUTO_CLOSE = 0x10, // auto-close alarm window after late-cancel period
EMAIL_BCC = 0x20, // blind copy the email to the user
DISABLED = 0x40, // alarm is currently disabled
SCRIPT = 0x80, // command is a script, not a shell command line
EXEC_IN_XTERM = 0x100, // execute command alarm in terminal window
SPEAK = 0x200, // speak the alarm message when it is displayed
SHOW_IN_KORG = 0x400, // show the alarm as an event in KOrganizer
DISPLAY_COMMAND = 0x800, // display command output in alarm window
EXCL_HOLIDAYS = 0x1000, // don't trigger alarm on holidays
WORK_TIME_ONLY = 0x2000 // trigger only during working hours
};
/** Values for the @p repeatType parameter of "scheduleXxxx()" D-Bus calls.
* @li MINUTELY - the repeat interval is measured in minutes.
* @li DAILY - the repeat interval is measured in days.
* @li WEEKLY - the repeat interval is measured in weeks.
* @li MONTHLY - the repeat interval is measured in months.
* @li YEARLY - the repeat interval is measured in years.
*/
enum RecurType
{
MINUTELY = 1, // the repeat interval is measured in minutes
DAILY = 2, // the repeat interval is measured in days
WEEKLY = 3, // the repeat interval is measured in weeks
MONTHLY = 4, // the repeat interval is measured in months
YEARLY = 5 // the repeat interval is measured in years
};
/** Values for the @p type parameter of "editNew()" D-Bus call.
* @li DISPLAY - create a display alarm.
* @li COMMAND - create a command alarm.
* @li EMAIL - create an email alarm.
*/
enum AlarmType
{
DISPLAY = 1, // display alarm
COMMAND = 2, // command alarm
EMAIL = 3, // email alarm
AUDIO = 4 // audio alarm
};
public:
/** Bit values for the @p flags parameter of "scheduleXxxx()" D-Bus calls.
* The bit values may be OR'ed together.
*/
enum Flags
{
REPEAT_AT_LOGIN = 0x01, //!< repeat the alarm at every login
BEEP = 0x02, //!< sound an audible beep when the alarm is displayed
REPEAT_SOUND = 0x08, //!< repeat the sound file while the alarm is displayed
CONFIRM_ACK = 0x04, //!< closing the alarm message window requires a confirmation prompt
AUTO_CLOSE = 0x10, //!< auto-close the alarm window after the late-cancel period
EMAIL_BCC = 0x20, //!< send a blind copy of the email to the user
DISABLED = 0x40, //!< set the alarm status to disabled
SCRIPT = 0x80, //!< the command to execute is a script, not a shell command line
EXEC_IN_XTERM = 0x100, //!< execute the command alarm in a terminal window
SPEAK = 0x200, //!< speak the alarm message when it is displayed
SHOW_IN_KORG = 0x400, //!< show the alarm as an event in KOrganizer
DISPLAY_COMMAND = 0x800, //!< display command output in the alarm window
EXCL_HOLIDAYS = 0x1000, //!< don't trigger the alarm on holidays
WORK_TIME_ONLY = 0x2000, //!< do not trigger the alarm outside working hours (or on holidays)
NOTIFY = 0x4000 //!< display the alarm message as a notification
};
/** Values for the @p repeatType parameter of "scheduleXxxx()" D-Bus calls. */
enum RecurType
{
MINUTELY = 1, //!< the repeat interval is measured in minutes
DAILY = 2, //!< the repeat interval is measured in days
WEEKLY = 3, //!< the repeat interval is measured in weeks
MONTHLY = 4, //!< the repeat interval is measured in months
YEARLY = 5 //!< the repeat interval is measured in years
};
/** Values for the @p type parameter of "editNew()" D-Bus call. */
enum AlarmType
{
DISPLAY = 1, //!< create a display alarm
COMMAND = 2, //!< create a command alarm
EMAIL = 3, //!< create an email alarm
AUDIO = 4 //!< create an audio alarm
};
};
#endif // KALARMIFACE_H
......
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