File indexing completed on 2024-05-12 05:14:42
0001 /* 0002 * editdlg.h - dialog to create or modify an alarm or alarm template 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2001-2023 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "resources/resource.h" 0012 #include "kalarmcalendar/alarmtext.h" 0013 #include "kalarmcalendar/datetime.h" 0014 #include "kalarmcalendar/kaevent.h" 0015 0016 #include <QDialog> 0017 #include <QTime> 0018 0019 class QLabel; 0020 class QShowEvent; 0021 class QResizeEvent; 0022 class QAbstractButton; 0023 class QGroupBox; 0024 class QFrame; 0025 class QVBoxLayout; 0026 class QLineEdit; 0027 class QTabWidget; 0028 class ButtonGroup; 0029 class TimeEdit; 0030 class RadioButton; 0031 class CheckBox; 0032 class LateCancelSelector; 0033 class AlarmTimeWidget; 0034 class RecurrenceEdit; 0035 class Reminder; 0036 class StackedScrollGroup; 0037 class TimeSpinBox; 0038 class QDialogButtonBox; 0039 0040 using namespace KAlarmCal; 0041 0042 0043 class EditAlarmDlg : public QDialog 0044 { 0045 Q_OBJECT 0046 public: 0047 enum Type { NO_TYPE, DISPLAY, COMMAND, EMAIL, AUDIO }; 0048 enum GetResourceType { 0049 RES_PROMPT, // prompt for resource 0050 RES_USE_EVENT_ID, // use resource containing event, or prompt if not found 0051 RES_IGNORE // don't get resource 0052 }; 0053 0054 static EditAlarmDlg* create(bool Template, Type, QWidget* parent = nullptr, 0055 GetResourceType = RES_PROMPT); 0056 static EditAlarmDlg* create(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 0057 GetResourceType = RES_PROMPT, bool readOnly = false); 0058 ~EditAlarmDlg() override; 0059 bool getEvent(KAEvent&, Resource&); 0060 0061 // Methods to initialise values in the New Alarm dialogue. 0062 void setName(const QString&); 0063 0064 /** Set the start date/time for the alarm. 0065 * N.B. setTime() must be called first to set the date-only characteristic, 0066 * followed by setRecurrence() if applicable. 0067 */ 0068 void setTime(const DateTime&); // must be called first to set date-only value 0069 0070 /** Return the start date/time for the alarm. */ 0071 KADateTime time() const; 0072 0073 void setRecurrence(const KARecurrence&, const KCalendarCore::Duration& subRepeatInterval, int subRepeatCount); 0074 void setRepeatAtLogin(); 0075 virtual void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) = 0; 0076 void setLateCancel(int minutes); 0077 void setWakeFromSuspend(bool); 0078 void setShowInKOrganizer(bool); 0079 0080 QSize sizeHint() const override { return minimumSizeHint(); } 0081 0082 static int instanceCount(); 0083 static QString i18n_chk_ShowInKOrganizer(); // text of 'Show in KOrganizer' checkbox 0084 0085 protected: 0086 EditAlarmDlg(bool Template, KAEvent::SubAction, QWidget* parent = nullptr, 0087 GetResourceType = RES_PROMPT); 0088 EditAlarmDlg(bool Template, const KAEvent&, bool newAlarm, QWidget* parent = nullptr, 0089 GetResourceType = RES_PROMPT, bool readOnly = false); 0090 void init(const KAEvent& event); 0091 void resizeEvent(QResizeEvent*) override; 0092 void showEvent(QShowEvent*) override; 0093 void closeEvent(QCloseEvent*) override; 0094 bool eventFilter(QObject*, QEvent*) override; 0095 virtual QString type_caption() const = 0; 0096 virtual void type_init(QWidget* parent, QVBoxLayout* frameLayout) = 0; 0097 virtual void type_initValues(const KAEvent&) = 0; 0098 virtual void type_showOptions(bool more) = 0; 0099 virtual void setReadOnly(bool readOnly) = 0; 0100 virtual void saveState(const KAEvent*) = 0; 0101 virtual bool type_stateChanged() const = 0; 0102 virtual void type_setEvent(KAEvent&, const KADateTime&, const QString& name, const QString& text, int lateCancel, bool trial) = 0; 0103 virtual KAEvent::Flags getAlarmFlags() const; 0104 virtual bool type_validate(bool trial) = 0; 0105 virtual void type_aboutToTry() {} 0106 virtual void type_executedTry(const QString& text, void* obj) { Q_UNUSED(text); Q_UNUSED(obj); } 0107 virtual Reminder* createReminder(QWidget* parent) { Q_UNUSED(parent); return nullptr; } 0108 virtual CheckBox* type_createConfirmAckCheckbox(QWidget* parent) { Q_UNUSED(parent); return nullptr; } 0109 virtual bool checkText(QString& result, bool showErrorMessage = true) const = 0; 0110 0111 void showMainPage(); 0112 bool isTemplate() const { return mTemplate; } 0113 bool isNewAlarm() const { return mNewAlarm; } 0114 bool dateOnly() const; 0115 bool isTimedRecurrence() const; 0116 bool showingMore() const { return mShowingMore; } 0117 Reminder* reminder() const { return mReminder; } 0118 LateCancelSelector* lateCancel() const { return mLateCancel; } 0119 0120 protected Q_SLOTS: 0121 virtual void slotTry(); 0122 virtual void slotHelp(); // Load Template 0123 virtual void slotDefault(); // More/Less Options 0124 void slotButtonClicked(QAbstractButton*); 0125 void contentsChanged(); 0126 0127 private Q_SLOTS: 0128 void slotRecurTypeChange(int repeatType); 0129 void slotRecurFrequencyChange(); 0130 void slotEditDeferral(); 0131 void slotShowMainPage(); 0132 void slotShowRecurrenceEdit(); 0133 void slotAnyTimeToggled(bool anyTime); 0134 void slotTemplateTimeType(QAbstractButton*); 0135 void slotSetSubRepetition(); 0136 void slotResize(); 0137 void focusFixTimer(); 0138 0139 private: 0140 void init(const KAEvent& event, GetResourceType getResource); 0141 void initValues(const KAEvent&); 0142 void setEvent(KAEvent&, const QString& text, bool trial); 0143 bool validate(); 0144 virtual bool stateChanged() const; 0145 void showOptions(bool more); 0146 void setWakeFromSuspendEnabledStatus(); 0147 0148 protected: 0149 KAEvent::SubAction mAlarmType; // actual alarm type 0150 0151 QDialogButtonBox* mButtonBox; 0152 QAbstractButton* mTryButton; 0153 QAbstractButton* mLoadTemplateButton {nullptr}; 0154 QAbstractButton* mMoreLessButton; 0155 0156 private: 0157 static QList<EditAlarmDlg*> mWindowList; // list of instances 0158 QTabWidget* mTabs; // the tabs in the dialog 0159 StackedScrollGroup* mTabScrollGroup; 0160 int mMainPageIndex; 0161 int mRecurPageIndex; 0162 bool mMainPageShown {false}; // true once the main tab has been displayed 0163 bool mRecurPageShown {false}; // true once the recurrence tab has been displayed 0164 bool mRecurSetDefaultEndDate {true}; // adjust default end date/time when recurrence tab is displayed 0165 0166 // Templates 0167 ButtonGroup* mTemplateTimeGroup; 0168 RadioButton* mTemplateDefaultTime; // no alarm time is specified 0169 RadioButton* mTemplateUseTimeAfter; // alarm time is specified as an offset from current 0170 RadioButton* mTemplateAnyTime; // alarms have date only, no time 0171 RadioButton* mTemplateUseTime; // an alarm time is specified 0172 TimeSpinBox* mTemplateTimeAfter; // the specified offset from the current time 0173 TimeEdit* mTemplateTime; // the alarm time which is specified 0174 QGroupBox* mDeferGroup {nullptr}; 0175 QLabel* mDeferTimeLabel; 0176 QPushButton* mDeferChangeButton {nullptr}; 0177 0178 QLineEdit* mName {nullptr}; 0179 AlarmTimeWidget* mTimeWidget {nullptr}; 0180 LateCancelSelector* mLateCancel; 0181 Reminder* mReminder; // null except for display alarms 0182 CheckBox* mWakeFromSuspend {nullptr}; 0183 CheckBox* mShowInKorganizer {nullptr}; 0184 0185 QFrame* mMoreOptions; // contains options hidden by default 0186 0187 RecurrenceEdit* mRecurrenceEdit; 0188 0189 QString mAlarmMessage; // message text/file name/command/email message 0190 DateTime mAlarmDateTime; 0191 DateTime mDeferDateTime; 0192 bool mUseResourceEventId; // whether to use mResourceEventId 0193 QString mResourceEventId; // if non-null, save alarm in resource containing this event ID 0194 Resource mResource; // resource to save event into, or invalid 0195 int mDeferGroupHeight {0}; // height added by deferred time widget 0196 int mDesktop; // virtual desktop to display the dialog in 0197 QString mEventId; // UID of event being edited, or blank for new event 0198 bool mTemplate; // editing an alarm template 0199 bool mNewAlarm; // editing a new alarm 0200 bool mExpiredRecurrence; // initially a recurrence which has expired 0201 mutable bool mChanged; // controls other than deferral have changed since dialog was displayed 0202 mutable bool mOnlyDeferred; // the only change made in the dialog was to the existing deferral 0203 bool mDesiredReadOnly; // the specified read-only status of the dialog 0204 bool mReadOnly; // the actual read-only status of the dialog 0205 bool mShowingMore {true}; // the More Options button has been clicked 0206 0207 // Initial state of all controls 0208 KAEvent* mSavedEvent {nullptr}; 0209 QString mSavedName; // mName value 0210 QAbstractButton* mSavedTemplateTimeType; // selected button in mTemplateTimeGroup 0211 QTime mSavedTemplateTime; // mTemplateTime value 0212 int mSavedTemplateAfterTime;// mTemplateAfterTime value 0213 QString mSavedTextFileCommandMessage; // mTextMessageEdit/mFileMessageEdit/mCmdCommandEdit/mEmailMessageEdit value 0214 KADateTime mSavedDateTime; // mTimeWidget value 0215 KADateTime mSavedDeferTime; // mDeferDateTime value 0216 int mSavedRecurrenceType; // RecurrenceEdit::RepeatType value 0217 int mSavedLateCancel; // mLateCancel value 0218 bool mSavedWakeFromSuspend; // mWakeFromSuspend status 0219 bool mSavedShowInKorganizer; // mShowInKorganizer status 0220 }; 0221 0222 // vim: et sw=4: