1 /* 2 * editdlgtypes.h - dialogues to create or edit alarm or alarm template types 3 * Program: kalarm 4 * SPDX-FileCopyrightText: 2001-2021 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 "preferences.h" 13 14 #include <KAlarmCal/AlarmText> 15 #include <KAlarmCal/KAEvent> 16 17 using namespace KAlarmCal; 18 19 class QAbstractButton; 20 class QGroupBox; 21 class QComboBox; 22 class EmailIdCombo; 23 class CheckBox; 24 class ComboBox; 25 class FontColourButton; 26 class ButtonGroup; 27 class RadioButton; 28 class Reminder; 29 class SoundPicker; 30 class SpecialActionsButton; 31 class CommandEdit; 32 class LineEdit; 33 class TextEdit; 34 class SoundWidget; 35 class MessageWindow; 36 class PickLogFileRadio; 37 38 class EditDisplayAlarmDlg : public EditAlarmDlg 39 { 40 Q_OBJECT 41 public: 42 explicit EditDisplayAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 43 EditDisplayAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 44 GetResourceType = RES_PROMPT, bool readOnly = false); 45 46 // Methods to initialise values in the New Alarm dialogue. 47 // N.B. setTime() must be called first to set the date-only characteristic, 48 // followed by setRecurrence(). 49 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 50 void setBgColour(const QColor&); 51 void setFgColour(const QColor&); 52 void setNotify(bool); 53 void setConfirmAck(bool); 54 void setAutoClose(bool); 55 void setAudio(Preferences::SoundType, const QString& file = QString(), float volume = -1, int repeatPause = -1); 56 void setReminder(int minutes, bool onceOnly); 57 58 Reminder* createReminder(QWidget* parent) override; 59 static CheckBox* createConfirmAckCheckbox(QWidget* parent); 60 61 static QString i18n_lbl_DisplayMethod(); // text of 'Display method' label 62 static QString i18n_combo_Window(); // text of 'Window' selection 63 static QString i18n_combo_Notify(); // text of 'Notification' selection 64 static QString i18n_chk_ConfirmAck(); // text of 'Confirm acknowledgement' checkbox 65 66 protected: 67 QString type_caption() const override; 68 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 69 void type_initValues(const KAEvent&) override; 70 void type_showOptions(bool more) override; 71 void setReadOnly(bool readOnly) override; 72 void saveState(const KAEvent*) override; 73 bool type_stateChanged() const override; 74 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 75 KAEvent::Flags getAlarmFlags() const override; type_validate(bool trial)76 bool type_validate(bool trial) override { Q_UNUSED(trial); return true; } type_createConfirmAckCheckbox(QWidget * parent)77 CheckBox* type_createConfirmAckCheckbox(QWidget* parent) override { mConfirmAck = createConfirmAckCheckbox(parent); return mConfirmAck; } 78 bool checkText(QString& result, bool showErrorMessage = true) const override; 79 80 private Q_SLOTS: 81 void slotAlarmTypeChanged(int index); 82 void slotDisplayMethodChanged(int index); 83 void slotPickFile(); 84 void slotCmdScriptToggled(bool); 85 void setColours(const QColor& fg, const QColor& bg); 86 87 private: 88 89 // Display alarm options 90 ComboBox* mTypeCombo; 91 QWidget* mDisplayMethodBox; 92 ComboBox* mDisplayMethodCombo; 93 QWidget* mFileBox; 94 QWidget* mFilePadding; 95 SoundPicker* mSoundPicker; 96 CheckBox* mConfirmAck; 97 FontColourButton* mFontColourButton; 98 SpecialActionsButton* mSpecialActionsButton {nullptr}; 99 Akonadi::Item::Id mAkonadiItemId; // if email text, message's Akonadi item ID, else -1 100 bool mReminderDeferral {false}; 101 bool mReminderArchived {false}; 102 // Text message alarm widgets 103 TextEdit* mTextMessageEdit; // text message edit box 104 // Text file alarm widgets 105 LineEdit* mFileMessageEdit; // text file URL edit box 106 QPushButton* mFileBrowseButton; // text file browse button 107 QString mFileDefaultDir; // default directory for browse button 108 // Command output alarm widgets 109 CommandEdit* mCmdEdit; 110 111 // Initial state of all controls 112 int mSavedType; // mTypeCombo index 113 Preferences::SoundType mSavedSoundType; // mSoundPicker sound type 114 bool mSavedSound; // mSoundPicker sound status 115 int mSavedRepeatPause; // mSoundPicker repeat pause 116 QUrl mSavedSoundFile; // mSoundPicker sound file 117 float mSavedSoundVolume; // mSoundPicker volume 118 float mSavedSoundFadeVolume; // mSoundPicker fade volume 119 int mSavedSoundFadeSeconds; // mSoundPicker fade time 120 bool mSavedCmdScript; // mCmdEdit->isScript() status 121 int mSavedDisplayMethod; // mDisplayMethodCombo index 122 bool mSavedConfirmAck; // mConfirmAck status 123 QFont mSavedFont; // mFontColourButton font 124 QColor mSavedBgColour; // mBgColourChoose selection 125 QColor mSavedFgColour; // mFontColourButton foreground colour 126 QString mSavedPreAction; // mSpecialActionsButton pre-alarm action 127 QString mSavedPostAction; // mSpecialActionsButton post-alarm action 128 int mSavedReminder; // mReminder value 129 bool mSavedAutoClose; // mLateCancel->isAutoClose() value 130 bool mSavedOnceOnly; // mReminder once-only status 131 KAEvent::ExtraActionOptions mSavedPreActionOptions; // mSpecialActionsButton pre-alarm action options 132 }; 133 134 135 class EditCommandAlarmDlg : public EditAlarmDlg 136 { 137 Q_OBJECT 138 public: 139 explicit EditCommandAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 140 EditCommandAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 141 GetResourceType = RES_PROMPT, bool readOnly = false); 142 143 // Methods to initialise values in the New Alarm dialogue. 144 // N.B. setTime() must be called first to set the date-only characteristic, 145 // followed by setRecurrence(). 146 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 147 148 static QString i18n_chk_EnterScript(); // text of 'Enter a script' checkbox 149 static QString i18n_radio_ExecInTermWindow(); // text of 'Execute in terminal window' radio button 150 static QString i18n_chk_ExecInTermWindow(); // text of 'Execute in terminal window' checkbox 151 152 protected: 153 QString type_caption() const override; 154 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 155 void type_initValues(const KAEvent&) override; 156 void type_showOptions(bool more) override; 157 void setReadOnly(bool readOnly) override; 158 void saveState(const KAEvent*) override; 159 bool type_stateChanged() const override; 160 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 161 KAEvent::Flags getAlarmFlags() const override; 162 bool type_validate(bool trial) override; 163 void type_executedTry(const QString& text, void* obj) override; 164 bool checkText(QString& result, bool showErrorMessage = true) const override; 165 166 private Q_SLOTS: 167 void slotCmdScriptToggled(bool); 168 169 private: 170 // Command alarm options 171 CommandEdit* mCmdEdit; 172 CheckBox* mCmdDontShowError; 173 QGroupBox* mCmdOutputBox; 174 ButtonGroup* mCmdOutputGroup; // what to do with command output 175 RadioButton* mCmdExecInTerm; 176 PickLogFileRadio* mCmdLogToFile; 177 RadioButton* mCmdDiscardOutput; 178 LineEdit* mCmdLogFileEdit; // log file URL edit box 179 QWidget* mCmdPadding; 180 181 // Initial state of all controls 182 bool mSavedCmdScript; // mCmdEdit->isScript() status 183 bool mSavedCmdDontShowError; // mCmdDontShowError value 184 QAbstractButton* mSavedCmdOutputRadio; // selected button in mCmdOutputGroup 185 QString mSavedCmdLogFile; // mCmdLogFileEdit value 186 }; 187 188 189 class EditEmailAlarmDlg : public EditAlarmDlg 190 { 191 Q_OBJECT 192 public: 193 explicit EditEmailAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 194 EditEmailAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 195 GetResourceType = RES_PROMPT, bool readOnly = false); 196 197 // Methods to initialise values in the New Alarm dialogue. 198 // N.B. setTime() must be called first to set the date-only characteristic, 199 // followed by setRecurrence(). 200 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 201 void setEmailFields(uint fromID, const KCalendarCore::Person::List&, const QString& subject, 202 const QStringList& attachments); 203 void setBcc(bool); 204 205 static QString i18n_chk_CopyEmailToSelf(); // text of 'Copy email to self' checkbox 206 207 protected: 208 QString type_caption() const override; 209 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 210 void type_initValues(const KAEvent&) override; type_showOptions(bool)211 void type_showOptions(bool) override {} 212 void setReadOnly(bool readOnly) override; 213 void saveState(const KAEvent*) override; 214 bool type_stateChanged() const override; 215 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 216 KAEvent::Flags getAlarmFlags() const override; 217 bool type_validate(bool trial) override; 218 void type_aboutToTry() override; 219 bool checkText(QString& result, bool showErrorMessage = true) const override; 220 221 private Q_SLOTS: 222 void slotTrySuccess(); 223 void openAddressBook(); 224 void slotAddAttachment(); 225 void slotRemoveAttachment(); 226 227 private: 228 void attachmentEnable(); 229 230 // Email alarm options 231 EmailIdCombo* mEmailFromList; 232 LineEdit* mEmailToEdit; 233 QPushButton* mEmailAddressButton; // email open address book button 234 LineEdit* mEmailSubjectEdit; 235 TextEdit* mEmailMessageEdit; // email body edit box 236 QComboBox* mEmailAttachList; 237 QPushButton* mEmailAddAttachButton; 238 QPushButton* mEmailRemoveButton {nullptr}; 239 CheckBox* mEmailBcc; 240 QString mAttachDefaultDir; 241 242 KCalendarCore::Person::List mEmailAddresses; // list of addresses to send email to 243 244 QStringList mEmailAttachments; // list of email attachment file names 245 246 // Initial state of all controls 247 QString mSavedEmailFrom; // mEmailFromList current value 248 QString mSavedEmailTo; // mEmailToEdit value 249 QString mSavedEmailSubject; // mEmailSubjectEdit value 250 QStringList mSavedEmailAttach; // mEmailAttachList values 251 bool mSavedEmailBcc; // mEmailBcc status 252 }; 253 254 255 class EditAudioAlarmDlg : public EditAlarmDlg 256 { 257 Q_OBJECT 258 public: 259 explicit EditAudioAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 260 EditAudioAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 261 GetResourceType = RES_PROMPT, bool readOnly = false); 262 263 // Methods to initialise values in the New Alarm dialogue. 264 // N.B. setTime() must be called first to set the date-only characteristic, 265 // followed by setRecurrence(). 266 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 267 void setAudio(const QString& file, float volume = -1); 268 269 protected: 270 QString type_caption() const override; 271 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 272 void type_initValues(const KAEvent&) override; type_showOptions(bool)273 void type_showOptions(bool) override {} 274 void setReadOnly(bool readOnly) override; 275 void saveState(const KAEvent*) override; 276 bool type_stateChanged() const override; 277 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 278 KAEvent::Flags getAlarmFlags() const override; type_validate(bool trial)279 bool type_validate(bool trial) override { Q_UNUSED(trial); return true; } 280 void type_executedTry(const QString& text, void* obj) override; 281 bool checkText(QString& result, bool showErrorMessage = true) const override; 282 283 protected Q_SLOTS: 284 void slotTry() override; 285 286 private Q_SLOTS: audioWinDestroyed()287 void audioWinDestroyed() { slotAudioPlaying(false); } 288 void slotAudioPlaying(bool playing); 289 290 private: 291 MessageWindow* mMessageWindow {nullptr}; // MessageWindow controlling test audio playback 292 293 // Audio alarm options 294 SoundWidget* mSoundConfig; 295 QWidget* mPadding; // allow top-adjustment of controls 296 297 // Initial state of all controls 298 QString mSavedFile; // sound file 299 float mSavedVolume; // volume 300 float mSavedFadeVolume; // fade volume 301 int mSavedFadeSeconds; // fade time 302 int mSavedRepeatPause; // sound file repeat pause 303 }; 304 305 306 // vim: et sw=4: 307