libkcal

recurrence.h
1/*
2 This file is part of libkcal.
3
4 Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
7 Copyright (C) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23*/
24#ifndef KCAL_RECURRENCE_H
25#define KCAL_RECURRENCE_H
26
27#include <tqstring.h>
28#include <tqbitarray.h>
29#include <tqptrlist.h>
30
31#include "libkcal_export.h"
32#include "recurrencerule.h"
33
34namespace KCal {
35
36class RecurrenceRule;
37
89class LIBKCAL_EXPORT Recurrence : public RecurrenceRule::Observer
90{
91 public:
92 class Observer {
93 public:
94 virtual ~Observer() {}
96 virtual void recurrenceUpdated( Recurrence * ) = 0;
97 };
98
100 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003,
101 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006,
102 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009,
103 rOther = 0x000A, rMax=0x00FF };
104
105 Recurrence();
106 Recurrence( const Recurrence& );
107 virtual ~Recurrence();
108
109 bool operator==( const Recurrence& ) const;
110 bool operator!=( const Recurrence& r ) const { return !operator==(r); }
111
114 TQDateTime startDateTime() const;
116 TQDate startDate() const { return mStartDateTime.date(); }
120 void setStartDateTime( const TQDateTime &start );
124 void setStartDate( const TQDate &start );
125
132 bool doesFloat() const { return mFloating; }
136 void setFloats( bool floats );
137
139 void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; }
141 bool recurReadOnly() const { return mRecurReadOnly; }
142
144 bool doesRecur() const;
147 ushort recurrenceType() const;
150 static ushort recurrenceType( const RecurrenceRule *rrule );
153 bool recursOn( const TQDate &qd ) const;
156 bool recursAt( const TQDateTime & ) const;
159 void unsetRecurs();
161 void clear();
162
167 TQValueList<TQTime> recurTimesOn(const TQDate &date) const;
168
181 DateTimeList timesInInterval( const TQDateTime &start, const TQDateTime &end ) const;
182
183
189 TQDateTime getNextDateTime( const TQDateTime& preDateTime ) const;
196 TQDateTime getPreviousDateTime( const TQDateTime& afterDateTime ) const;
197
199 int frequency() const;
201 void setFrequency(int freq);
202
207 int duration() const;
210 void setDuration(int duration);
212 int durationTo(const TQDateTime &) const;
214 int durationTo( const TQDate &date ) const { return durationTo( TQDateTime( date, TQTime( 23, 59, 59 ) ) ); }
215
219 TQDateTime endDateTime() const;
223 TQDate endDate() const;
227 void setEndDate( const TQDate &endDate );
230 void setEndDateTime( const TQDateTime &endDateTime );
231
232
233
244 void setMinutely( int freq );
245
259 void setHourly( int freq );
260
274 void setDaily( int freq );
275
287 void setWeekly( int freq, int weekStart = 1 );
300 void setWeekly( int freq, const TQBitArray &days, int weekStart = 1 );
304 void addWeeklyDays( const TQBitArray &days );
310 int weekStart() const;
312 TQBitArray days() const; // Emulate the old behavior
313
328 void setMonthly( int freq );
336 void addMonthlyPos( short pos, const TQBitArray &days );
337 void addMonthlyPos( short pos, ushort day );
342 void addMonthlyDate( short day );
344 TQValueList<RecurrenceRule::WDayPos> monthPositions() const;
346 // Emulate old behavior
347 TQValueList<int> monthDays() const;
348
371 void setYearly( int freq );
378 void addYearlyDay( int day );
387 void addYearlyDate( int date );
393 void addYearlyMonth( short _rNum );
410 void addYearlyPos( short pos, const TQBitArray &days );
411
417 TQValueList<int> yearDays() const;
425 TQValueList<int> yearDates() const;
434 TQValueList<int> yearMonths() const;
444 TQValueList<RecurrenceRule::WDayPos> yearPositions() const;
445
447 static const TQDate MAX_DATE;
448
452 void dump() const;
453
454
455 // RRULE
456 RecurrenceRule::List rRules() const;
457 void addRRule( RecurrenceRule *rrule );
458 void removeRRule( RecurrenceRule *rrule );
459 // EXRULE
460 RecurrenceRule::List exRules() const;
461 void addExRule( RecurrenceRule *exrule );
462 void removeExRule( RecurrenceRule *exrule );
463
464 // RDATE
465 DateTimeList rDateTimes() const;
466 DateList rDates() const;
467 void setRDateTimes( const DateTimeList &rdates);
468 void setRDates( const DateList &rdates);
469 void addRDateTime( const TQDateTime &rdate );
470 void addRDate( const TQDate &rdate );
471
472 // ExDATE
473 DateTimeList exDateTimes() const;
474 DateList exDates() const;
475 void setExDateTimes( const DateTimeList &exdates);
476 void setExDates( const DateList &exdates);
477 void addExDateTime( const TQDateTime &exdate );
478 void addExDate( const TQDate &exdate );
479
480 RecurrenceRule *defaultRRule( bool create = false ) const;
481 RecurrenceRule *defaultRRuleConst() const;
482 void updated();
483
491 void addObserver( Observer *observer );
498 void removeObserver( Observer *observer );
499
500 void recurrenceChanged( RecurrenceRule * );
501
502 protected:
503 RecurrenceRule *setNewRecurrenceType( RecurrenceRule::PeriodType type, int freq );
504
505 private:
506 RecurrenceRule::List mExRules;
507 RecurrenceRule::List mRRules;
508 TQValueList<TQDateTime>mRDateTimes;
509 TQValueList<TQDate> mRDates;
510 TQValueList<TQDateTime> mExDateTimes;
511 TQValueList<TQDate> mExDates;
512
513 TQDateTime mStartDateTime; // date/time of first recurrence
514 bool mFloating; // the recurrence has no time, just a date
515 bool mRecurReadOnly;
516
517 // Cache the type of the recurrence with the old system (e.g. MonthlyPos)
518 mutable ushort mCachedType;
519
520 TQValueList<Observer*> mObservers;
521
522 class Private;
523 Private *d;
524};
525
526}
527
528#endif
This class represents a recurrence rule for a calendar incidence.
PeriodType
enum for describing the frequency how an event recurs, if at all.
This class represents a recurrence rule for a calendar incidence.
Definition: recurrence.h:90
static const TQDate MAX_DATE
Upper date limit for recurrences.
Definition: recurrence.h:447
TQDate startDate() const
Return the start date/time of the recurrence.
Definition: recurrence.h:116
void setRecurReadOnly(bool readOnly)
Set if recurrence is read-only or can be changed.
Definition: recurrence.h:139
bool recurReadOnly() const
Returns true if the recurrence is read-only, or false if it can be changed.
Definition: recurrence.h:141
int durationTo(const TQDate &date) const
Returns the number of recurrences up to and including the date specified.
Definition: recurrence.h:214
bool doesFloat() const
Set whether the recurrence has no time, just a date.
Definition: recurrence.h:132
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38