SVN_SILENT made messages (after extraction)
[kdepim.git] / kalarm / editdlg.h
blobbb721a449c570eec972f7d95657fd100b083422c
1 /*
2 * editdlg.h - dialog to create or modify an alarm or alarm template
3 * Program: kalarm
4 * Copyright © 2001-2015 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.
21 #ifndef EDITDLG_H
22 #define EDITDLG_H
24 #include <kalarmcal/alarmtext.h>
25 #include <kalarmcal/datetime.h>
26 #include <kalarmcal/kaevent.h>
28 #include <AkonadiCore/collection.h>
30 #include <QDialog>
31 #include <QTime>
33 class QLabel;
34 class QShowEvent;
35 class QResizeEvent;
36 class QAbstractButton;
37 class QGroupBox;
38 class QFrame;
39 class QVBoxLayout;
40 class QLineEdit;
41 class QTabWidget;
42 class ButtonGroup;
43 class TimeEdit;
44 class RadioButton;
45 class CheckBox;
46 class LateCancelSelector;
47 class AlarmTimeWidget;
48 class RecurrenceEdit;
49 class Reminder;
50 class StackedScrollGroup;
51 class TimeSpinBox;
52 class QDialogButtonBox;
54 using namespace KAlarmCal;
57 class EditAlarmDlg : public QDialog
59 Q_OBJECT
60 public:
61 enum Type { NO_TYPE, DISPLAY, COMMAND, EMAIL, AUDIO };
62 enum GetResourceType {
63 RES_PROMPT, // prompt for resource
64 RES_USE_EVENT_ID, // use resource containing event, or prompt if not found
65 RES_IGNORE // don't get resource
68 static EditAlarmDlg* create(bool Template, Type, QWidget* parent = Q_NULLPTR,
69 GetResourceType = RES_PROMPT);
70 static EditAlarmDlg* create(bool Template, const KAEvent*, bool newAlarm, QWidget* parent = Q_NULLPTR,
71 GetResourceType = RES_PROMPT, bool readOnly = false);
72 virtual ~EditAlarmDlg();
73 bool getEvent(KAEvent&, Akonadi::Collection&);
75 // Methods to initialise values in the New Alarm dialogue.
76 // N.B. setTime() must be called first to set the date-only characteristic,
77 // followed by setRecurrence() if applicable.
78 void setTime(const DateTime&); // must be called first to set date-only value
79 void setRecurrence(const KARecurrence&, const KCalCore::Duration& subRepeatInterval, int subRepeatCount);
80 void setRepeatAtLogin();
81 virtual void setAction(KAEvent::SubAction, const AlarmText& = AlarmText()) = 0;
82 void setLateCancel(int minutes);
83 void setShowInKOrganizer(bool);
85 QSize sizeHint() const Q_DECL_OVERRIDE { return minimumSizeHint(); }
87 static int instanceCount();
88 static QString i18n_chk_ShowInKOrganizer(); // text of 'Show in KOrganizer' checkbox
90 protected:
91 EditAlarmDlg(bool Template, KAEvent::SubAction, QWidget* parent = Q_NULLPTR,
92 GetResourceType = RES_PROMPT);
93 EditAlarmDlg(bool Template, const KAEvent*, bool newAlarm, QWidget* parent = Q_NULLPTR,
94 GetResourceType = RES_PROMPT, bool readOnly = false);
95 void init(const KAEvent* event);
96 void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE;
97 void showEvent(QShowEvent*) Q_DECL_OVERRIDE;
98 void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE;
99 bool eventFilter(QObject*, QEvent*) Q_DECL_OVERRIDE;
100 virtual QString type_caption() const = 0;
101 virtual void type_init(QWidget* parent, QVBoxLayout* frameLayout) = 0;
102 virtual void type_initValues(const KAEvent*) = 0;
103 virtual void type_showOptions(bool more) = 0;
104 virtual void setReadOnly(bool readOnly) = 0;
105 virtual void saveState(const KAEvent*) = 0;
106 virtual bool type_stateChanged() const = 0;
107 virtual void type_setEvent(KAEvent&, const KDateTime&, const QString& text, int lateCancel, bool trial) = 0;
108 virtual KAEvent::Flags getAlarmFlags() const;
109 virtual bool type_validate(bool trial) = 0;
110 virtual void type_aboutToTry() {}
111 virtual void type_executedTry(const QString& text, void* obj) { Q_UNUSED(text); Q_UNUSED(obj); }
112 virtual Reminder* createReminder(QWidget* parent) { Q_UNUSED(parent); return Q_NULLPTR; }
113 virtual CheckBox* type_createConfirmAckCheckbox(QWidget* parent) { Q_UNUSED(parent); return Q_NULLPTR; }
114 virtual bool checkText(QString& result, bool showErrorMessage = true) const = 0;
116 void showMainPage();
117 bool isTemplate() const { return mTemplate; }
118 bool isNewAlarm() const { return mNewAlarm; }
119 bool dateOnly() const;
120 bool isTimedRecurrence() const;
121 bool showingMore() const { return mShowingMore; }
122 Reminder* reminder() const { return mReminder; }
123 LateCancelSelector* lateCancel() const { return mLateCancel; }
125 protected Q_SLOTS:
126 virtual void slotTry();
127 virtual void slotHelp(); // Load Template
128 virtual void slotDefault(); // More/Less Options
129 void slotButtonClicked(QAbstractButton *button);
130 void contentsChanged();
132 private Q_SLOTS:
133 void slotRecurTypeChange(int repeatType);
134 void slotRecurFrequencyChange();
135 void slotEditDeferral();
136 void slotShowMainPage();
137 void slotShowRecurrenceEdit();
138 void slotAnyTimeToggled(bool anyTime);
139 void slotTemplateTimeType(QAbstractButton*);
140 void slotSetSubRepetition();
141 void slotResize();
142 void focusFixTimer();
144 private:
145 void init(const KAEvent* event, GetResourceType getResource);
146 void initValues(const KAEvent*);
147 void setEvent(KAEvent&, const QString& text, bool trial);
148 bool validate();
149 void setRecurTabTitle(const KAEvent* = Q_NULLPTR);
150 virtual bool stateChanged() const;
151 void showOptions(bool more);
153 protected:
154 KAEvent::SubAction mAlarmType; // actual alarm type
156 QDialogButtonBox* mButtonBox;
157 QAbstractButton* mTryButton;
158 QAbstractButton* mLoadTemplateButton;
159 QAbstractButton* mMoreLessButton;
161 private:
162 static QList<EditAlarmDlg*> mWindowList; // list of instances
163 QTabWidget* mTabs; // the tabs in the dialog
164 StackedScrollGroup* mTabScrollGroup;
165 int mMainPageIndex;
166 int mRecurPageIndex;
167 bool mMainPageShown; // true once the main tab has been displayed
168 bool mRecurPageShown; // true once the recurrence tab has been displayed
169 bool mRecurSetDefaultEndDate; // adjust default end date/time when recurrence tab is displayed
171 // Templates
172 QLineEdit* mTemplateName;
173 ButtonGroup* mTemplateTimeGroup;
174 RadioButton* mTemplateDefaultTime; // no alarm time is specified
175 RadioButton* mTemplateUseTimeAfter;// alarm time is specified as an offset from current
176 RadioButton* mTemplateAnyTime; // alarms have date only, no time
177 RadioButton* mTemplateUseTime; // an alarm time is specified
178 TimeSpinBox* mTemplateTimeAfter; // the specified offset from the current time
179 TimeEdit* mTemplateTime; // the alarm time which is specified
180 QGroupBox* mDeferGroup;
181 QLabel* mDeferTimeLabel;
182 QPushButton* mDeferChangeButton;
184 AlarmTimeWidget* mTimeWidget;
185 LateCancelSelector* mLateCancel;
186 Reminder* mReminder; // null except for display alarms
187 CheckBox* mShowInKorganizer;
189 QFrame* mMoreOptions; // contains options hidden by default
191 RecurrenceEdit* mRecurrenceEdit;
193 QString mAlarmMessage; // message text/file name/command/email message
194 DateTime mAlarmDateTime;
195 DateTime mDeferDateTime;
196 Akonadi::Item::Id mCollectionItemId; // if >=0, save alarm in collection containing this item ID
197 Akonadi::Collection mCollection; // collection to save event into, or null
198 int mDeferGroupHeight; // height added by deferred time widget
199 int mDesktop; // desktop to display the dialog in
200 QString mEventId; // UID of event being edited, or blank for new event
201 bool mTemplate; // editing an alarm template
202 bool mNewAlarm; // editing a new alarm
203 bool mExpiredRecurrence; // initially a recurrence which has expired
204 mutable bool mChanged; // controls other than deferral have changed since dialog was displayed
205 mutable bool mOnlyDeferred; // the only change made in the dialog was to the existing deferral
206 bool mDesiredReadOnly; // the specified read-only status of the dialog
207 bool mReadOnly; // the actual read-only status of the dialog
208 bool mShowingMore; // the More Options button has been clicked
210 // Initial state of all controls
211 KAEvent* mSavedEvent;
212 QString mSavedTemplateName; // mTemplateName value
213 QAbstractButton* mSavedTemplateTimeType; // selected button in mTemplateTimeGroup
214 QTime mSavedTemplateTime; // mTemplateTime value
215 int mSavedTemplateAfterTime;// mTemplateAfterTime value
216 QString mSavedTextFileCommandMessage; // mTextMessageEdit/mFileMessageEdit/mCmdCommandEdit/mEmailMessageEdit value
217 KDateTime mSavedDateTime; // mTimeWidget value
218 KDateTime mSavedDeferTime; // mDeferDateTime value
219 int mSavedRecurrenceType; // RecurrenceEdit::RepeatType value
220 int mSavedLateCancel; // mLateCancel value
221 bool mSavedShowInKorganizer; // mShowInKorganizer status
224 #endif // EDITDLG_H
226 // vim: et sw=4: