File indexing completed on 2024-05-12 05:14:44
0001 /* 0002 * editdlgtypes.h - dialogues to create or edit alarm or alarm template types 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2001-2022 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "editdlg.h" 0012 #include "preferences.h" 0013 #include "kalarmcalendar/alarmtext.h" 0014 #include "kalarmcalendar/kaevent.h" 0015 0016 using namespace KAlarmCal; 0017 0018 class QAbstractButton; 0019 class QGroupBox; 0020 class QComboBox; 0021 class EmailIdCombo; 0022 class CheckBox; 0023 class ComboBox; 0024 class FontColourButton; 0025 class ButtonGroup; 0026 class RadioButton; 0027 class Reminder; 0028 class SoundPicker; 0029 class SpecialActionsButton; 0030 class CommandEdit; 0031 class LineEdit; 0032 class TextEdit; 0033 class SoundWidget; 0034 class MessageWindow; 0035 class PickLogFileRadio; 0036 0037 class EditDisplayAlarmDlg : public EditAlarmDlg 0038 { 0039 Q_OBJECT 0040 public: 0041 explicit EditDisplayAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 0042 EditDisplayAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 0043 GetResourceType = RES_PROMPT, bool readOnly = false); 0044 0045 // Methods to initialise values in the New Alarm dialogue. 0046 // N.B. setTime() must be called first to set the date-only characteristic, 0047 // followed by setRecurrence(). 0048 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 0049 void setBgColour(const QColor&); 0050 void setFgColour(const QColor&); 0051 void setNotify(bool); 0052 void setConfirmAck(bool); 0053 void setAutoClose(bool); 0054 void setAudio(Preferences::SoundType, const QString& file = QString(), float volume = -1, int repeatPause = -1); 0055 void setReminder(int minutes, bool onceOnly); 0056 0057 Reminder* createReminder(QWidget* parent) override; 0058 static CheckBox* createConfirmAckCheckbox(QWidget* parent); 0059 0060 static QString i18n_lbl_DisplayMethod(); // text of 'Display method' label 0061 static QString i18n_combo_Window(); // text of 'Window' selection 0062 static QString i18n_combo_Notify(); // text of 'Notification' selection 0063 static QString i18n_chk_ConfirmAck(); // text of 'Confirm acknowledgement' checkbox 0064 0065 protected: 0066 QString type_caption() const override; 0067 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 0068 void type_initValues(const KAEvent&) override; 0069 void type_showOptions(bool more) override; 0070 void setReadOnly(bool readOnly) override; 0071 void saveState(const KAEvent*) override; 0072 bool type_stateChanged() const override; 0073 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 0074 KAEvent::Flags getAlarmFlags() const override; 0075 bool type_validate(bool trial) override { Q_UNUSED(trial); return true; } 0076 CheckBox* type_createConfirmAckCheckbox(QWidget* parent) override { mConfirmAck = createConfirmAckCheckbox(parent); return mConfirmAck; } 0077 bool checkText(QString& result, bool showErrorMessage = true) const override; 0078 0079 private Q_SLOTS: 0080 void slotAlarmTypeChanged(int index); 0081 void slotDisplayMethodChanged(int index); 0082 void slotPickFile(); 0083 void slotCmdScriptToggled(bool); 0084 void setColours(const QColor& fg, const QColor& bg); 0085 0086 private: 0087 0088 // Display alarm options 0089 ComboBox* mTypeCombo; 0090 QWidget* mDisplayMethodBox; 0091 ComboBox* mDisplayMethodCombo; 0092 QWidget* mFileBox; 0093 QWidget* mFilePadding; 0094 SoundPicker* mSoundPicker; 0095 CheckBox* mConfirmAck; 0096 FontColourButton* mFontColourButton; 0097 SpecialActionsButton* mSpecialActionsButton {nullptr}; 0098 KAEvent::EmailId mEmailId; // if email text, message's Akonadi item ID, else -1 0099 bool mReminderDeferral {false}; 0100 bool mReminderArchived {false}; 0101 // Text message alarm widgets 0102 TextEdit* mTextMessageEdit; // text message edit box 0103 // Text file alarm widgets 0104 LineEdit* mFileMessageEdit; // text file URL edit box 0105 QPushButton* mFileBrowseButton; // text file browse button 0106 QString mFileDefaultDir; // default directory for browse button 0107 // Command output alarm widgets 0108 CommandEdit* mCmdEdit; 0109 0110 // Initial state of all controls 0111 int mSavedType; // mTypeCombo index 0112 Preferences::SoundType mSavedSoundType; // mSoundPicker sound type 0113 int mSavedRepeatPause; // mSoundPicker repeat pause 0114 QUrl mSavedSoundFile; // mSoundPicker sound file 0115 float mSavedSoundVolume; // mSoundPicker volume 0116 float mSavedSoundFadeVolume; // mSoundPicker fade volume 0117 int mSavedSoundFadeSeconds; // mSoundPicker fade time 0118 bool mSavedCmdScript; // mCmdEdit->isScript() status 0119 int mSavedDisplayMethod; // mDisplayMethodCombo index 0120 bool mSavedConfirmAck; // mConfirmAck status 0121 QFont mSavedFont; // mFontColourButton font 0122 QColor mSavedBgColour; // mBgColourChoose selection 0123 QColor mSavedFgColour; // mFontColourButton foreground colour 0124 QString mSavedPreAction; // mSpecialActionsButton pre-alarm action 0125 QString mSavedPostAction; // mSpecialActionsButton post-alarm action 0126 int mSavedReminder; // mReminder value 0127 bool mSavedAutoClose; // mLateCancel->isAutoClose() value 0128 bool mSavedOnceOnly; // mReminder once-only status 0129 KAEvent::ExtraActionOptions mSavedPreActionOptions; // mSpecialActionsButton pre-alarm action options 0130 }; 0131 0132 0133 class EditCommandAlarmDlg : public EditAlarmDlg 0134 { 0135 Q_OBJECT 0136 public: 0137 explicit EditCommandAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 0138 EditCommandAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 0139 GetResourceType = RES_PROMPT, bool readOnly = false); 0140 0141 // Methods to initialise values in the New Alarm dialogue. 0142 // N.B. setTime() must be called first to set the date-only characteristic, 0143 // followed by setRecurrence(). 0144 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 0145 0146 static QString i18n_chk_EnterScript(); // text of 'Enter a script' checkbox 0147 static QString i18n_radio_ExecInTermWindow(); // text of 'Execute in terminal window' radio button 0148 static QString i18n_chk_ExecInTermWindow(); // text of 'Execute in terminal window' checkbox 0149 0150 protected: 0151 QString type_caption() const override; 0152 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 0153 void type_initValues(const KAEvent&) override; 0154 void type_showOptions(bool more) override; 0155 void setReadOnly(bool readOnly) override; 0156 void saveState(const KAEvent*) override; 0157 bool type_stateChanged() const override; 0158 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 0159 KAEvent::Flags getAlarmFlags() const override; 0160 bool type_validate(bool trial) override; 0161 void type_executedTry(const QString& text, void* obj) override; 0162 bool checkText(QString& result, bool showErrorMessage = true) const override; 0163 0164 private Q_SLOTS: 0165 void slotCmdScriptToggled(bool); 0166 0167 private: 0168 // Command alarm options 0169 CommandEdit* mCmdEdit; 0170 CheckBox* mCmdDontShowError; 0171 QGroupBox* mCmdOutputBox; 0172 ButtonGroup* mCmdOutputGroup; // what to do with command output 0173 RadioButton* mCmdExecInTerm; 0174 PickLogFileRadio* mCmdLogToFile; 0175 RadioButton* mCmdDiscardOutput; 0176 LineEdit* mCmdLogFileEdit; // log file URL edit box 0177 QWidget* mCmdPadding; 0178 0179 // Initial state of all controls 0180 bool mSavedCmdScript; // mCmdEdit->isScript() status 0181 bool mSavedCmdDontShowError; // mCmdDontShowError value 0182 QAbstractButton* mSavedCmdOutputRadio; // selected button in mCmdOutputGroup 0183 QString mSavedCmdLogFile; // mCmdLogFileEdit value 0184 }; 0185 0186 0187 class EditEmailAlarmDlg : public EditAlarmDlg 0188 { 0189 Q_OBJECT 0190 public: 0191 explicit EditEmailAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 0192 EditEmailAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 0193 GetResourceType = RES_PROMPT, bool readOnly = false); 0194 0195 // Methods to initialise values in the New Alarm dialogue. 0196 // N.B. setTime() must be called first to set the date-only characteristic, 0197 // followed by setRecurrence(). 0198 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 0199 void setEmailFields(uint fromID, const KCalendarCore::Person::List&, const QString& subject, 0200 const QStringList& attachments); 0201 void setBcc(bool); 0202 0203 static QString i18n_chk_CopyEmailToSelf(); // text of 'Copy email to self' checkbox 0204 0205 protected: 0206 QString type_caption() const override; 0207 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 0208 void type_initValues(const KAEvent&) override; 0209 void type_showOptions(bool) override {} 0210 void setReadOnly(bool readOnly) override; 0211 void saveState(const KAEvent*) override; 0212 bool type_stateChanged() const override; 0213 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 0214 KAEvent::Flags getAlarmFlags() const override; 0215 bool type_validate(bool trial) override; 0216 void type_aboutToTry() override; 0217 bool checkText(QString& result, bool showErrorMessage = true) const override; 0218 0219 private Q_SLOTS: 0220 void slotTrySuccess(); 0221 void openAddressBook(); 0222 void slotAddAttachment(); 0223 void slotRemoveAttachment(); 0224 0225 private: 0226 void attachmentEnable(); 0227 0228 // Email alarm options 0229 EmailIdCombo* mEmailFromList; 0230 LineEdit* mEmailToEdit; 0231 QPushButton* mEmailAddressButton {nullptr}; // email open address book button 0232 LineEdit* mEmailSubjectEdit; 0233 TextEdit* mEmailMessageEdit; // email body edit box 0234 QComboBox* mEmailAttachList; 0235 QPushButton* mEmailAddAttachButton; 0236 QPushButton* mEmailRemoveButton {nullptr}; 0237 CheckBox* mEmailBcc; 0238 QString mAttachDefaultDir; 0239 0240 KCalendarCore::Person::List mEmailAddresses; // list of addresses to send email to 0241 0242 QStringList mEmailAttachments; // list of email attachment file names 0243 0244 // Initial state of all controls 0245 QString mSavedEmailFrom; // mEmailFromList current value 0246 QString mSavedEmailTo; // mEmailToEdit value 0247 QString mSavedEmailSubject; // mEmailSubjectEdit value 0248 QStringList mSavedEmailAttach; // mEmailAttachList values 0249 bool mSavedEmailBcc; // mEmailBcc status 0250 }; 0251 0252 0253 class EditAudioAlarmDlg : public EditAlarmDlg 0254 { 0255 Q_OBJECT 0256 public: 0257 explicit EditAudioAlarmDlg(bool Template, QWidget* parent = nullptr, GetResourceType = RES_PROMPT); 0258 EditAudioAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 0259 GetResourceType = RES_PROMPT, bool readOnly = false); 0260 ~EditAudioAlarmDlg() override; 0261 0262 // Methods to initialise values in the New Alarm dialogue. 0263 // N.B. setTime() must be called first to set the date-only characteristic, 0264 // followed by setRecurrence(). 0265 void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) override; 0266 void setAudio(const QString& file, float volume = -1); 0267 0268 protected: 0269 QString type_caption() const override; 0270 void type_init(QWidget* parent, QVBoxLayout* frameLayout) override; 0271 void type_initValues(const KAEvent&) override; 0272 void type_showOptions(bool) override {} 0273 void setReadOnly(bool readOnly) override; 0274 void saveState(const KAEvent*) override; 0275 bool type_stateChanged() const override; 0276 void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) override; 0277 KAEvent::Flags getAlarmFlags() const override; 0278 bool type_validate(bool trial) override { Q_UNUSED(trial); return true; } 0279 void type_executedTry(const QString& text, void* obj) override; 0280 bool checkText(QString& result, bool showErrorMessage = true) const override; 0281 0282 protected Q_SLOTS: 0283 void slotTry() override; 0284 0285 private Q_SLOTS: 0286 void audioWinDestroyed() { slotAudioPlaying(false); } 0287 void slotAudioPlaying(bool playing); 0288 0289 private: 0290 MessageWindow* mMessageWindow {nullptr}; // MessageWindow controlling test audio playback 0291 0292 // Audio alarm options 0293 SoundWidget* mSoundConfig; 0294 QWidget* mPadding; // allow top-adjustment of controls 0295 0296 // Initial state of all controls 0297 QString mSavedFile; // sound file 0298 float mSavedVolume; // volume 0299 float mSavedFadeVolume; // fade volume 0300 int mSavedFadeSeconds; // fade time 0301 int mSavedRepeatPause; // sound file repeat pause 0302 }; 0303 0304 // vim: et sw=4: