korganizer

koeditorrecurrence.h
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
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.
10 
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.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 #ifndef _KOEDITORRECURRENCE_H
25 #define _KOEDITORRECURRENCE_H
26 
27 #include <tqdatetime.h>
28 #include <tqwidget.h>
29 #include <tqbitarray.h>
30 
31 #include <kdialogbase.h>
32 
33 #include <libkcal/incidencebase.h>
34 
35 class TQWidgetStack;
36 class TQSpinBox;
37 class TQRadioButton;
38 class TQGroupBox;
39 class TQCheckBox;
40 
41 class KDateEdit;
42 namespace KCal {
43 class Incidence;
44 }
45 using namespace KCal;
46 
47 class RecurBase : public TQWidget
48 {
49  public:
50  RecurBase( TQWidget *parent = 0, const char *name = 0 );
51 
52  void setFrequency( int );
53  int frequency();
54  // FIXME: If we want to adjust the recurrence when the start/due date change,
55  // we need to reimplement this method in the derived classes!
56  void setDateTimes( const TQDateTime &/*start*/, const TQDateTime &/*end*/ ) {}
57 
58  TQWidget *frequencyEdit();
59 
60  protected:
61  static TQComboBox *createWeekCountCombo( TQWidget *parent=0, const char *name=0 );
62  static TQComboBox *createWeekdayCombo( TQWidget *parent=0, const char *name=0 );
63  static TQComboBox *createMonthNameCombo( TQWidget *parent=0, const char *name=0 );
64  TQBoxLayout *createFrequencySpinBar( TQWidget *parent, TQLayout *layout,
65  TQString everyText, TQString unitText );
66 
67  private:
68  TQSpinBox *mFrequencyEdit;
69 };
70 
71 class RecurDaily : public RecurBase
72 {
73  public:
74  RecurDaily( TQWidget *parent = 0, const char *name = 0 );
75 };
76 
77 class RecurWeekly : public RecurBase
78 {
79  public:
80  RecurWeekly( TQWidget *parent = 0, const char *name = 0 );
81 
82  void setDays( const TQBitArray & );
83  TQBitArray days();
84 
85  private:
86  TQCheckBox *mDayBoxes[7];
87 };
88 
89 class RecurMonthly : public RecurBase
90 {
91  public:
92  RecurMonthly( TQWidget *parent = 0, const char *name = 0 );
93 
94  void setByDay( int day );
95  void setByPos( int count, int weekday );
96 
97  bool byDay();
98  bool byPos();
99 
100  int day();
101 
102  int count();
103  int weekday();
104 
105  private:
106  TQRadioButton *mByDayRadio;
107  TQComboBox *mByDayCombo;
108 
109  TQRadioButton *mByPosRadio;
110  TQComboBox *mByPosCountCombo;
111  TQComboBox *mByPosWeekdayCombo;
112 };
113 
114 class RecurYearly : public RecurBase
115 {
116  public:
117  enum YearlyType { byDay, byPos, byMonth };
118 
119  RecurYearly( TQWidget *parent = 0, const char *name = 0 );
120 
121  void setByDay( int day );
122  void setByPos( int count, int weekday, int month );
123  void setByMonth( int day, int month );
124 
125  YearlyType getType();
126 
127  int day();
128  int posCount();
129  int posWeekday();
130  int posMonth();
131  int monthDay();
132  int month();
133 
134  private:
135  TQRadioButton *mByMonthRadio;
136  TQRadioButton *mByPosRadio;
137  TQRadioButton *mByDayRadio;
138 
139  TQSpinBox *mByMonthSpin;
140  TQComboBox *mByMonthCombo;
141 
142  TQComboBox *mByPosDayCombo;
143  TQComboBox *mByPosWeekdayCombo;
144  TQComboBox *mByPosMonthCombo;
145 
146  TQSpinBox *mByDaySpin;
147 };
148 
149 class RecurrenceChooser : public TQWidget
150 {
151  TQ_OBJECT
152 
153  public:
154  RecurrenceChooser( TQWidget *parent = 0, const char *name = 0 );
155 
156  enum { Daily, Weekly, Monthly, Yearly };
157 
158  void setType( int );
159  int type();
160 
161  signals:
162  void chosen( int );
163 
164  protected slots:
165  void emitChoice();
166 
167  private:
168  TQComboBox *mTypeCombo;
169 
170  TQRadioButton *mDailyButton;
171  TQRadioButton *mWeeklyButton;
172  TQRadioButton *mMonthlyButton;
173  TQRadioButton *mYearlyButton;
174 };
175 
176 class ExceptionsBase
177 {
178  public:
179  virtual void setDates( const DateList & ) = 0;
180  virtual DateList dates() = 0;
181 };
182 
183 class ExceptionsWidget : public TQWidget, public ExceptionsBase
184 {
185  TQ_OBJECT
186 
187  public:
188  ExceptionsWidget( TQWidget *parent = 0, const char *name = 0 );
189 
190  void setDates( const DateList & );
191  DateList dates();
192 
193  protected slots:
194  void addException();
195  void changeException();
196  void deleteException();
197 
198  private:
199  KDateEdit *mExceptionDateEdit;
200  TQListBox *mExceptionList;
201  DateList mExceptionDates;
202 };
203 
204 class ExceptionsDialog : public KDialogBase, public ExceptionsBase
205 {
206  public:
207  ExceptionsDialog( TQWidget *parent, const char *name = 0 );
208 
209  void setDates( const DateList & );
210  DateList dates();
211 
212  private:
213  ExceptionsWidget *mExceptions;
214 };
215 
216 class RecurrenceRangeBase
217 {
218  public:
219  virtual void setDefaults( const TQDateTime &from ) = 0;
220 
221  virtual void setDuration( int ) = 0;
222  virtual int duration() = 0;
223 
224  virtual void setEndDate( const TQDate & ) = 0;
225  virtual TQDate endDate() = 0;
226 
227  virtual void setDateTimes( const TQDateTime &start,
228  const TQDateTime &end = TQDateTime() ) = 0;
229 };
230 
231 class RecurrenceRangeWidget : public TQWidget, public RecurrenceRangeBase
232 {
233  TQ_OBJECT
234 
235  public:
236  RecurrenceRangeWidget( TQWidget *parent = 0, const char *name = 0 );
237 
238  void setDefaults( const TQDateTime &from );
239 
240  void setDuration( int );
241  int duration();
242 
243  void setEndDate( const TQDate & );
244  TQDate endDate();
245 
246  void setDateTimes( const TQDateTime &start,
247  const TQDateTime &end = TQDateTime() );
248 
249  protected slots:
250  void showCurrentRange();
251 
252  private:
253  TQGroupBox *mRangeGroupBox;
254  TQLabel *mStartDateLabel;
255  TQRadioButton *mNoEndDateButton;
256  TQRadioButton *mEndDurationButton;
257  TQSpinBox *mEndDurationEdit;
258  TQRadioButton *mEndDateButton;
259  KDateEdit *mEndDateEdit;
260 };
261 
262 class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase
263 {
264  public:
265  RecurrenceRangeDialog( TQWidget *parent = 0, const char *name = 0 );
266 
267  void setDefaults( const TQDateTime &from );
268 
269  void setDuration( int );
270  int duration();
271 
272  void setEndDate( const TQDate & );
273  TQDate endDate();
274 
275  void setDateTimes( const TQDateTime &start,
276  const TQDateTime &end = TQDateTime() );
277 
278  private:
279  RecurrenceRangeWidget *mRecurrenceRangeWidget;
280 };
281 
282 class KOEditorRecurrence : public TQWidget
283 {
284  TQ_OBJECT
285 
286  public:
287  KOEditorRecurrence ( TQWidget *parent = 0, const char *name = 0 );
288  virtual ~KOEditorRecurrence();
289 
290  enum { Daily, Weekly, Monthly, Yearly };
291 
293  void setDefaults( const TQDateTime &from, const TQDateTime &to, bool allday );
295  void readIncidence( Incidence * );
297  void writeIncidence( Incidence * );
298 
300  bool validateInput();
301 
302  bool doesRecur();
303 
304  void saveValues();
305  void restoreValues();
306 
307  public slots:
308  void setRecurrenceEnabled( bool );
309  void setDateTimes( const TQDateTime &start, const TQDateTime &end );
310  void setDateTimeStr( const TQString & );
311 
312  signals:
313  void dateTimesChanged( const TQDateTime &start, const TQDateTime &end );
314 
315  protected slots:
316  void showCurrentRule( int );
317  void showExceptionsDialog();
318  void showRecurrenceRangeDialog();
319 
320  private:
321  Recurrence mSaveRec;
322  TQCheckBox *mEnabledCheck;
323 
324  TQGroupBox *mTimeGroupBox;
325  TQLabel *mDateTimeLabel;
326 
327  TQGroupBox *mRuleBox;
328  TQWidgetStack *mRuleStack;
329  RecurrenceChooser *mRecurrenceChooser;
330 
331  RecurDaily *mDaily;
332  RecurWeekly *mWeekly;
333  RecurMonthly *mMonthly;
334  RecurYearly *mYearly;
335 
336  RecurrenceRangeBase *mRecurrenceRange;
337  RecurrenceRangeWidget *mRecurrenceRangeWidget;
338  RecurrenceRangeDialog *mRecurrenceRangeDialog;
339  TQPushButton *mRecurrenceRangeButton;
340 
341  ExceptionsBase *mExceptions;
342  ExceptionsDialog *mExceptionsDialog;
343  ExceptionsWidget *mExceptionsWidget;
344  TQPushButton *mExceptionsButton;
345 
346  TQDateTime mEventStartDt;
347 };
348 
349 class KOEditorRecurrenceDialog : public KDialogBase
350 {
351  TQ_OBJECT
352 
353  public:
354  KOEditorRecurrenceDialog( TQWidget *parent );
355  KOEditorRecurrence* editor() const { return mRecurrence; }
356 
357  protected slots:
358  void slotOk();
359  void slotCancel();
360 
361  private:
362  KOEditorRecurrence *mRecurrence;
363  bool mRecurEnabled;
364 };
365 
366 #endif