1 /*
2  *  commandoptions.h  -  extract command line options
3  *  Program:  kalarm
4  *  SPDX-FileCopyrightText: 2001-2020 David Jarvie <djarvie@kde.org>
5  *
6  *  SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #pragma once
10 
11 #include "editdlg.h"
12 #include "eventid.h"
13 
14 #include <KAlarmCal/KAEvent>
15 #include <KAlarmCal/KARecurrence>
16 #include <KAlarmCal/KADateTime>
17 
18 #include <QColor>
19 #include <QStringList>
20 class QCommandLineParser;
21 class QCommandLineOption;
22 
23 using namespace KAlarmCal;
24 
25 class CommandOptions
26 {
27 public:
28     enum Command
29     {
30         CMD_ERROR,        // error in command line options
31         NONE,             // no command
32         TRAY,             // --tray
33         TRIGGER_EVENT,    // --triggerEvent
34         CANCEL_EVENT,     // --cancelEvent
35         EDIT,             // --edit
36         EDIT_NEW_PRESET,  // --edit-new-preset
37         EDIT_NEW,         // --edit-new-display, --edit-new-command, --edit-new-email
38         NEW,              // --file, --exec-display, --exec, --mail, message
39         LIST              // --list
40     };
41     QStringList setOptions(QCommandLineParser*, const QStringList& args);
firstInstance()42     static CommandOptions* firstInstance()        { return mFirstInstance; }
43     CommandOptions();
44     void                parse();
45     void                process();
command()46     Command             command() const           { return mCommand; }
commandName()47     QString             commandName() const       { return optionName(mCommandOpt); }
eventId()48     QString             eventId() const           { return mEventId; }
resourceId()49     QString             resourceId() const        { return mResourceId; }
name()50     QString             name() const              { return mName; }
editType()51     EditAlarmDlg::Type  editType() const          { return mEditType; }
editAction()52     KAEvent::SubAction  editAction() const        { return mEditAction; }
text()53     QString             text() const              { return mText; }
alarmTime()54     KADateTime          alarmTime() const         { return mAlarmTime; }
recurrence()55     KARecurrence*       recurrence() const        { return mRecurrence; }
subRepeatCount()56     int                 subRepeatCount() const    { return mRepeatCount; }
subRepeatInterval()57     KCalendarCore::Duration  subRepeatInterval() const { return mRepeatInterval; }
lateCancel()58     int                 lateCancel() const        { return mLateCancel; }
bgColour()59     QColor              bgColour() const          { return mBgColour; }
fgColour()60     QColor              fgColour() const          { return mFgColour; }
reminderMinutes()61     int                 reminderMinutes() const   { return mReminderMinutes; }
audioFile()62     QString             audioFile() const         { return mAudioFile; }
audioVolume()63     float               audioVolume() const       { return mAudioVolume; }
addressees()64     KCalendarCore::Person::List addressees() const     { return mAddressees; }
attachments()65     QStringList         attachments() const       { return mAttachments; }
subject()66     QString             subject() const           { return mSubject; }
fromID()67     uint                fromID() const            { return mFromID; }
flags()68     KAEvent::Flags      flags() const             { return mFlags; }
disableAll()69     bool                disableAll() const        { return mDisableAll; }
outputText()70     QString             outputText() const        { return mError; }
71 #ifndef NDEBUG
simulationTime()72     KADateTime          simulationTime() const    { return mSimulationTime; }
73 #endif
74     static void         printError(const QString& errmsg);
75 
76 private:
77     enum Option
78     {
79         ACK_CONFIRM,
80         ATTACH,
81         AUTO_CLOSE,
82         BCC,
83         BEEP,
84         COLOUR,
85         COLOURFG,
86         OptCANCEL_EVENT,
87         DISABLE,
88         DISABLE_ALL,
89         EXEC,
90         EXEC_DISPLAY,
91         OptEDIT,
92         EDIT_NEW_DISPLAY,
93         EDIT_NEW_COMMAND,
94         EDIT_NEW_EMAIL,
95         EDIT_NEW_AUDIO,
96         OptEDIT_NEW_PRESET,
97         FILE,
98         FROM_ID,
99         INTERVAL,
100         KORGANIZER,
101         LATE_CANCEL,
102         OptLIST,
103         LOGIN,
104         MAIL,
105         NAME,
106         NOTIFY,
107         PLAY,
108         PLAY_REPEAT,
109         RECURRENCE,
110         REMINDER,
111         REMINDER_ONCE,
112         REPEAT,
113         SPEAK,
114         SUBJECT,
115 #ifndef NDEBUG
116         TEST_SET_TIME,
117 #endif
118         TIME,
119         OptTRAY,
120         OptTRIGGER_EVENT,
121         UNTIL,
122         VOLUME,
123         Num_Options,       // number of Option values
124         Opt_Message        // special value representing "message"
125     };
126 
127     bool        checkCommand(Option, Command, EditAlarmDlg::Type = EditAlarmDlg::NO_TYPE);
128     void        setError(const QString& error);
129     void        setErrorRequires(Option opt, Option opt2, Option opt3 = Num_Options);
130     void        setErrorParameter(Option);
131     void        setErrorIncompatible(Option opt1, Option opt2);
checkEditType(EditAlarmDlg::Type type,Option opt)132     void        checkEditType(EditAlarmDlg::Type type, Option opt)
133                               { checkEditType(type, EditAlarmDlg::NO_TYPE, opt); }
134     void        checkEditType(EditAlarmDlg::Type, EditAlarmDlg::Type, Option);
135     QString     arg(int n);
136     QString     optionName(Option, bool shortName = false) const;
137 
138     static CommandOptions* mFirstInstance;       // the first instance
139     QCommandLineParser* mParser {nullptr};
140     QVector<QCommandLineOption*> mOptions;       // all possible command line options
141     QStringList         mNonExecArguments;       // arguments except for --exec or --exec-display parameters
142     QStringList         mExecArguments;          // arguments for --exec or --exec-display
143     QString             mError;                  // error message
144     Command             mCommand {NONE};         // the selected command
145     Option              mCommandOpt;             // option for the selected command
146     QString             mEventId;                // TRIGGER_EVENT, CANCEL_EVENT, EDIT: event ID
147     QString             mResourceId;             // TRIGGER_EVENT, CANCEL_EVENT, EDIT: optional resource ID
148     QString             mName;                   // NEW, EDIT_NEW_PRESET: alarm/template name
149     EditAlarmDlg::Type  mEditType;               // NEW, EDIT_NEW_*: alarm edit type
150     KAEvent::SubAction  mEditAction;             // NEW: alarm edit sub-type
151     bool                mEditActionSet {false};  // NEW: mEditAction is valid
152     QString             mText;                   // NEW: alarm text
153     KADateTime          mAlarmTime;              // NEW: alarm time
154     KARecurrence*       mRecurrence {nullptr};   // NEW: recurrence
155     int                 mRepeatCount {0};        // NEW: sub-repetition count
156     KCalendarCore::Duration mRepeatInterval {0}; // NEW: sub-repetition interval
157     int                 mLateCancel {0};         // NEW: late-cancellation interval
158     QColor              mBgColour;               // NEW: background colour
159     QColor              mFgColour;               // NEW: foreground colour
160     int                 mReminderMinutes {0};    // NEW: reminder period
161     QString             mAudioFile;              // NEW: audio file path
162     float               mAudioVolume {-1.0f};    // NEW: audio file volume
163     KCalendarCore::Person::List mAddressees;     // NEW: email addressees
164     QStringList         mAttachments;            // NEW: email attachment file names
165     QString             mSubject;                // NEW: email subject
166     uint                mFromID {0};             // NEW: email sender ID
167     KAEvent::Flags      mFlags;                  // NEW: event flags
168     bool                mDisableAll {false};     // disable all alarm monitoring
169 #ifndef NDEBUG
170     KADateTime          mSimulationTime;         // system time to be simulated, or invalid if none
171 #endif
172 };
173 
174 
175 // vim: et sw=4:
176