summaryrefslogtreecommitdiffstats
path: root/kalarm/recurrenceedit.h
blob: 82ab954c6009980d5e01958e1f41ebd63ff03920 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 *  recurrenceedit.h  -  widget to edit the event's recurrence definition
 *  Program:  kalarm
 *  Copyright © 2002-2005,2008 by David Jarvie <[email protected]>
 *
 *  Based originally on KOrganizer module koeditorrecurrence.h,
 *  Copyright (c) 2000,2001 Cornelius Schumacher <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef RECURRENCEEDIT_H
#define RECURRENCEEDIT_H

#include <tqframe.h>
#include <tqdatetime.h>
#include <tqvaluelist.h>

#include "datetime.h"
class TQWidgetStack;
class TQGroupBox;
class TQLabel;
class TQListBox;
class TQButton;
class TQPushButton;
class TQBoxLayout;
class SpinBox;
class CheckBox;
class RadioButton;
class DateEdit;
class TimeEdit;
class ButtonGroup;
class RepetitionButton;
class KAEvent;
class Rule;
class NoRule;
class SubDailyRule;
class DailyRule;
class WeeklyRule;
class MonthlyRule;
class YearlyRule;


class RecurrenceEdit : public TQFrame
{
		Q_OBJECT
  
	public:
		// Don't alter the order of these recurrence types
		enum RepeatType { INVALID_RECUR = -1, NO_RECUR, AT_LOGIN, SUBDAILY, DAILY, WEEKLY, MONTHLY, ANNUAL };

		RecurrenceEdit(bool readOnly, TQWidget* parent, const char* name = 0);
		virtual ~RecurrenceEdit()  { }

		/** Set widgets to default values */
		void          setDefaults(const TQDateTime& from);
		/** Initialise according to a specified event */
		void          set(const KAEvent&, bool keepDuration);
		/** Write recurrence settings into an event */
		void          updateEvent(KAEvent&, bool adjustStart);
		TQWidget*      checkData(const TQDateTime& startDateTime, TQString& errorMessage) const;
		RepeatType    repeatType() const                    { return mRuleButtonType; }
		bool          isTimedRepeatType() const             { return mRuleButtonType >= SUBDAILY; }
		int           subRepeatCount(int* subRepeatInterval = 0) const;
		void          setSubRepetition(int reminderMinutes, bool dateOnly);
		void          setStartDate(const TQDate&, const TQDate& today);
		void          setDefaultEndDate(const TQDate&);
		void          setEndDateTime(const DateTime&);
		DateTime      endDateTime() const;
		bool          stateChanged() const;
		void          activateSubRepetition();

		static TQString i18n_Norecur();           // text of 'No recurrence' selection, lower case
		static TQString i18n_NoRecur();           // text of 'No Recurrence' selection, initial capitals
		static TQString i18n_AtLogin();           // text of 'At Login' selection
		static TQString i18n_l_Atlogin();         // text of 'At &login' selection, with 'L' shortcut
		static TQString i18n_HourlyMinutely();    // text of 'Hourly/Minutely'
		static TQString i18n_u_HourlyMinutely();  // text of 'Ho&urly/Minutely' selection, with 'U' shortcut
		static TQString i18n_Daily();             // text of 'Daily' selection
		static TQString i18n_d_Daily();           // text of '&Daily' selection, with 'D' shortcut
		static TQString i18n_Weekly();            // text of 'Weekly' selection
		static TQString i18n_w_Weekly();          // text of '&Weekly' selection, with 'W' shortcut
		static TQString i18n_Monthly();           // text of 'Monthly' selection
		static TQString i18n_m_Monthly();         // text of '&Monthly' selection, with 'M' shortcut
		static TQString i18n_Yearly();            // text of 'Yearly' selection
		static TQString i18n_y_Yearly();          // text of '&Yearly' selection, with 'Y' shortcut

	public slots:
		void          setDateTime(const TQDateTime& start)   { mCurrStartDateTime = start; }

	signals:
		void          shown();
		void          typeChanged(int recurType);   // returns a RepeatType value
		void          frequencyChanged();
		void          repeatNeedsInitialisation();

	protected:
		virtual void  showEvent(TQShowEvent*);

	private slots:
		void          periodClicked(int);
		void          rangeTypeClicked();
		void          repeatCountChanged(int value);
		void          slotAnyTimeToggled(bool);
		void          addException();
		void          changeException();
		void          deleteException();
		void          enableExceptionButtons();

	private:
		void          setRuleDefaults(const TQDate& start);
		void          saveState();

		// Main rule box and choices
		TQWidgetStack*     mRuleStack;
		Rule*             mRule;         // current rule widget, or 0 if NoRule
		NoRule*           mNoRule;
		SubDailyRule*     mSubDailyRule;
		DailyRule*        mDailyRule;
		WeeklyRule*       mWeeklyRule;
		MonthlyRule*      mMonthlyRule;
		YearlyRule*       mYearlyRule;

		ButtonGroup*      mRuleButtonGroup;
		RadioButton*      mNoneButton;
		RadioButton*      mAtLoginButton;
		RadioButton*      mSubDailyButton;
		RadioButton*      mDailyButton;
		RadioButton*      mWeeklyButton;
		RadioButton*      mMonthlyButton;
		RadioButton*      mYearlyButton;
		int               mNoneButtonId;
		int               mAtLoginButtonId;
		int               mSubDailyButtonId;
		int               mDailyButtonId;
		int               mWeeklyButtonId;
		int               mMonthlyButtonId;
		int               mYearlyButtonId;
		RepeatType        mRuleButtonType;
		bool              mDailyShown;       // daily rule has been displayed at some time or other
		bool              mWeeklyShown;      // weekly rule has been displayed at some time or other
		bool              mMonthlyShown;     // monthly rule has been displayed at some time or other
		bool              mYearlyShown;      // yearly rule has been displayed at some time or other

		// Range
		ButtonGroup*      mRangeButtonGroup;
		RadioButton*      mNoEndDateButton;
		RadioButton*      mRepeatCountButton;
		SpinBox*          mRepeatCountEntry;
		TQLabel*           mRepeatCountLabel;
		RadioButton*      mEndDateButton;
		DateEdit*         mEndDateEdit;
		TimeEdit*         mEndTimeEdit;
		CheckBox*         mEndAnyTimeCheckBox;

		// Exceptions
		TQGroupBox*        mExceptionGroup;
		TQListBox*         mExceptionDateList;
		DateEdit*         mExceptionDateEdit;
		TQPushButton*      mChangeExceptionButton;
		TQPushButton*      mDeleteExceptionButton;
		TQValueList<TQDate> mExceptionDates;

		// Current start date and time
		TQDateTime         mCurrStartDateTime;
		RepetitionButton* mSubRepetition;
		bool              mNoEmitTypeChanged;        // suppress typeChanged() signal
		bool              mReadOnly;

		// Initial state of non-rule controls
		TQButton*          mSavedRuleButton;          // which rule button was selected
		TQButton*          mSavedRangeButton;         // which range button was selected
		int               mSavedRecurCount;          // recurrence repeat count
		DateTime          mSavedEndDateTime;         // end date/time
		TQValueList<TQDate> mSavedExceptionDates;      // exception dates
		int               mSavedRepeatInterval;      // sub-repetition interval (via mSubRepetition button)
		int               mSavedRepeatCount;         // sub-repetition count (via mSubRepetition button)
};

#endif // RECURRENCEEDIT_H