2 * editdlg.h - dialog to create or modify an alarm or alarm template
4 * Copyright © 2001-2010 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "alarmtext.h"
33 class QAbstractButton
;
44 class LateCancelSelector
;
45 class AlarmTimeWidget
;
49 class StackedScrollGroup
;
53 class EditAlarmDlg
: public KDialog
57 enum Type
{ NO_TYPE
, DISPLAY
, COMMAND
, EMAIL
, AUDIO
};
58 enum GetResourceType
{
59 RES_PROMPT
, // prompt for resource
60 RES_USE_EVENT_ID
, // use resource containing event, or prompt if not found
61 RES_IGNORE
// don't get resource
64 static EditAlarmDlg
* create(bool Template
, Type
, bool newAlarm
, QWidget
* parent
= 0,
65 GetResourceType
= RES_PROMPT
);
66 static EditAlarmDlg
* create(bool Template
, const KAEvent
*, bool newAlarm
, QWidget
* parent
= 0,
67 GetResourceType
= RES_PROMPT
, bool readOnly
= false);
68 virtual ~EditAlarmDlg();
69 bool getEvent(KAEvent
&, AlarmResource
*&);
71 // Methods to initialise values in the New Alarm dialogue.
72 // N.B. setTime() must be called first to set the date-only characteristic,
73 // followed by setRecurrence() if applicable.
74 void setTime(const DateTime
&); // must be called first to set date-only value
75 void setRecurrence(const KARecurrence
&, int subRepeatInterval
, int subRepeatCount
);
76 void setRepeatAtLogin();
77 virtual void setAction(KAEvent::Action
, const AlarmText
& = AlarmText()) = 0;
78 void setLateCancel(int minutes
);
79 void setShowInKOrganizer(bool);
81 virtual QSize
sizeHint() const { return minimumSizeHint(); }
83 static QString
i18n_chk_ShowInKOrganizer(); // text of 'Show in KOrganizer' checkbox
86 EditAlarmDlg(bool Template
, KAEvent::Action
, QWidget
* parent
= 0,
87 GetResourceType
= RES_PROMPT
);
88 EditAlarmDlg(bool Template
, const KAEvent
*, QWidget
* parent
= 0,
89 GetResourceType
= RES_PROMPT
, bool readOnly
= false);
90 void init(const KAEvent
* event
, bool newAlarm
);
91 virtual void resizeEvent(QResizeEvent
*);
92 virtual void showEvent(QShowEvent
*);
93 virtual void closeEvent(QCloseEvent
*);
94 virtual QString
type_caption(bool newAlarm
) const = 0;
95 virtual void type_init(QWidget
* parent
, QVBoxLayout
* frameLayout
) = 0;
96 virtual void type_initValues(const KAEvent
*) = 0;
97 virtual void type_showOptions(bool more
) = 0;
98 virtual void setReadOnly(bool readOnly
) = 0;
99 virtual void saveState(const KAEvent
*) = 0;
100 virtual bool type_stateChanged() const = 0;
101 virtual void type_setEvent(KAEvent
&, const KDateTime
&, const QString
& text
, int lateCancel
, bool trial
) = 0;
102 virtual int getAlarmFlags() const;
103 virtual bool type_validate(bool trial
) = 0;
104 virtual void type_trySuccessMessage(ShellProcess
*, const QString
& text
) = 0;
105 virtual Reminder
* createReminder(QWidget
* parent
) { Q_UNUSED(parent
); return 0; }
106 virtual CheckBox
* type_createConfirmAckCheckbox(QWidget
* parent
) { Q_UNUSED(parent
); return 0; }
107 virtual bool checkText(QString
& result
, bool showErrorMessage
= true) const = 0;
110 bool isTemplate() const { return mTemplate
; }
111 bool dateOnly() const;
112 bool isTimedRecurrence() const;
113 bool showingMore() const { return mShowingMore
; }
114 Reminder
* reminder() const { return mReminder
; }
115 LateCancelSelector
* lateCancel() const { return mLateCancel
; }
118 virtual void slotTry();
119 virtual void slotHelp(); // Load Template
120 virtual void slotDefault(); // More/Less Options
121 virtual void slotButtonClicked(int button
);
122 void contentsChanged();
125 void slotRecurTypeChange(int repeatType
);
126 void slotRecurFrequencyChange();
127 void slotEditDeferral();
128 void slotShowMainPage();
129 void slotShowRecurrenceEdit();
130 void slotAnyTimeToggled(bool anyTime
);
131 void slotTemplateTimeType(QAbstractButton
*);
132 void slotSetSubRepetition();
133 void slotTrySuccess();
137 void init(const KAEvent
* event
, GetResourceType getResource
);
138 void initValues(const KAEvent
*);
139 void setEvent(KAEvent
&, const QString
& text
, bool trial
);
141 void setRecurTabTitle(const KAEvent
* = 0);
142 virtual bool stateChanged() const;
143 void showOptions(bool more
);
146 KAEvent::Action mAlarmType
; // actual alarm type
148 KTabWidget
* mTabs
; // the tabs in the dialog
149 StackedScrollGroup
* mTabScrollGroup
;
152 bool mMainPageShown
; // true once the main tab has been displayed
153 bool mRecurPageShown
; // true once the recurrence tab has been displayed
154 bool mRecurSetDefaultEndDate
; // adjust default end date/time when recurrence tab is displayed
157 KLineEdit
* mTemplateName
;
158 ButtonGroup
* mTemplateTimeGroup
;
159 RadioButton
* mTemplateDefaultTime
; // no alarm time is specified
160 RadioButton
* mTemplateUseTimeAfter
;// alarm time is specified as an offset from current
161 RadioButton
* mTemplateAnyTime
; // alarms have date only, no time
162 RadioButton
* mTemplateUseTime
; // an alarm time is specified
163 TimeSpinBox
* mTemplateTimeAfter
; // the specified offset from the current time
164 TimeEdit
* mTemplateTime
; // the alarm time which is specified
165 QGroupBox
* mDeferGroup
;
166 QLabel
* mDeferTimeLabel
;
167 QPushButton
* mDeferChangeButton
;
169 AlarmTimeWidget
* mTimeWidget
;
170 LateCancelSelector
* mLateCancel
;
171 Reminder
* mReminder
; // null except for display alarms
172 CheckBox
* mShowInKorganizer
;
174 QFrame
* mMoreOptions
; // contains options hidden by default
175 QPushButton
* mMoreButton
; // shows 'mMoreOptions'
176 QPushButton
* mLessButton
; // hides 'mMoreOptions'
178 RecurrenceEdit
* mRecurrenceEdit
;
180 QString mAlarmMessage
; // message text/file name/command/email message
181 DateTime mAlarmDateTime
;
182 DateTime mDeferDateTime
;
183 QString mResourceEventId
; // if non-empty, save alarm in resource containing this event ID
184 AlarmResource
* mResource
; // resource to save event into, or null
185 int mDeferGroupHeight
; // height added by deferred time widget
186 int mDesktop
; // desktop to display the dialog in
187 bool mTemplate
; // editing an alarm template
188 bool mExpiredRecurrence
; // initially a recurrence which has expired
189 mutable bool mChanged
; // controls other than deferral have changed since dialog was displayed
190 mutable bool mOnlyDeferred
; // the only change made in the dialog was to the existing deferral
191 bool mDesiredReadOnly
; // the specified read-only status of the dialog
192 bool mReadOnly
; // the actual read-only status of the dialog
193 bool mShowingMore
; // the More Options button has been clicked
195 // Initial state of all controls
196 KAEvent
* mSavedEvent
;
197 QString mSavedTemplateName
; // mTemplateName value
198 QAbstractButton
* mSavedTemplateTimeType
; // selected button in mTemplateTimeGroup
199 QTime mSavedTemplateTime
; // mTemplateTime value
200 int mSavedTemplateAfterTime
;// mTemplateAfterTime value
201 QString mSavedTextFileCommandMessage
; // mTextMessageEdit/mFileMessageEdit/mCmdCommandEdit/mEmailMessageEdit value
202 KDateTime mSavedDateTime
; // mTimeWidget value
203 KDateTime mSavedDeferTime
; // mDeferDateTime value
204 int mSavedRecurrenceType
; // RecurrenceEdit::RepeatType value
205 int mSavedLateCancel
; // mLateCancel value
206 bool mSavedShowInKorganizer
; // mShowInKorganizer status