00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KCAL_RECURRENCERULE_H
00025 #define KCAL_RECURRENCERULE_H
00026
00027 #include "kcal_export.h"
00028 #include "kcal/listbase.h"
00029 #include "kcal/sortablelist.h"
00030
00031 #include <kdatetime.h>
00032
00033 #include <QtCore/QList>
00034
00035 namespace KCal {
00036
00037
00038 typedef SortableList<KDateTime> DateTimeList;
00039 typedef SortableList<QDate> DateList;
00040
00041 typedef SortableList<QTime> TimeList;
00042
00046 class KCAL_EXPORT RecurrenceRule
00047 {
00048 public:
00049 class RuleObserver
00050 {
00051 public:
00052 virtual ~RuleObserver() {}
00054 virtual void recurrenceChanged( RecurrenceRule * ) = 0;
00055 };
00056 typedef ListBase<RecurrenceRule> List;
00057
00059 enum PeriodType {
00060 rNone = 0,
00061 rSecondly,
00062 rMinutely,
00063 rHourly,
00064 rDaily,
00065 rWeekly,
00066 rMonthly,
00067 rYearly
00068 };
00069
00071 class WDayPos
00072 {
00073 public:
00074 explicit WDayPos( int ps = 0, short dy = 0 ) : mDay( dy ), mPos( ps ) {}
00075 short day() const { return mDay; }
00076 int pos() const { return mPos; }
00077 void setDay( short dy ) { mDay = dy; }
00078 void setPos( int ps ) { mPos = ps; }
00079
00080 bool operator==( const RecurrenceRule::WDayPos &pos2 ) const {
00081 return mDay == pos2.mDay && mPos == pos2.mPos;
00082 }
00083
00084 protected:
00085 short mDay;
00086 int mPos;
00087
00088 };
00089
00090 RecurrenceRule();
00091 RecurrenceRule( const RecurrenceRule &r );
00092 ~RecurrenceRule();
00093
00094 bool operator==( const RecurrenceRule &r ) const;
00095 bool operator!=( const RecurrenceRule &r ) const { return !operator==(r); }
00096 RecurrenceRule &operator=( const RecurrenceRule &r );
00097
00099 void setReadOnly( bool readOnly );
00100
00104 bool isReadOnly() const;
00105
00110 bool recurs() const;
00111 void setRecurrenceType( PeriodType period );
00112 PeriodType recurrenceType() const;
00113
00115 void clear();
00116
00120 uint frequency() const;
00121
00125 void setFrequency( int freq );
00126
00132 KDateTime startDt() const;
00133
00145 void setStartDt( const KDateTime &start );
00146
00149 bool allDay() const;
00150
00155 void setAllDay( bool allDay );
00156
00162 KDateTime endDt( bool *result = 0 ) const;
00163
00166 void setEndDt( const KDateTime &endDateTime );
00167
00172 int duration() const;
00173
00176 void setDuration( int duration );
00177
00179 int durationTo( const KDateTime &dt ) const;
00180
00182 int durationTo( const QDate &date ) const;
00183
00198 void shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec );
00199
00206 bool recursOn( const QDate &date, const KDateTime::Spec &timeSpec ) const;
00207
00214 bool recursAt( const KDateTime &dt ) const;
00215
00223 bool dateMatchesRules( const KDateTime &dt ) const;
00224
00231 TimeList recurTimesOn( const QDate &date, const KDateTime::Spec &timeSpec ) const;
00232
00244 DateTimeList timesInInterval( const KDateTime &start, const KDateTime &end ) const;
00245
00251 KDateTime getNextDate( const KDateTime &preDateTime ) const;
00252
00259 KDateTime getPreviousDate( const KDateTime &afterDateTime ) const;
00260
00261 void setBySeconds( const QList<int> bySeconds );
00262 void setByMinutes( const QList<int> byMinutes );
00263 void setByHours( const QList<int> byHours );
00264
00265 void setByDays( const QList<WDayPos> byDays );
00266 void setByMonthDays( const QList<int> byMonthDays );
00267 void setByYearDays( const QList<int> byYearDays );
00268 void setByWeekNumbers( const QList<int> byWeekNumbers );
00269 void setByMonths( const QList<int> byMonths );
00270 void setBySetPos( const QList<int> bySetPos );
00271 void setWeekStart( short weekStart );
00272
00273 const QList<int> &bySeconds() const;
00274 const QList<int> &byMinutes() const;
00275 const QList<int> &byHours() const;
00276
00277 const QList<WDayPos> &byDays() const;
00278 const QList<int> &byMonthDays() const;
00279 const QList<int> &byYearDays() const;
00280 const QList<int> &byWeekNumbers() const;
00281 const QList<int> &byMonths() const;
00282 const QList<int> &bySetPos() const;
00283 short weekStart() const;
00284
00292 void setRRule( const QString &rrule );
00293 QString rrule() const;
00294
00295 void setDirty();
00303 void addObserver( RuleObserver *observer );
00304
00311 void removeObserver( RuleObserver *observer );
00312
00316 void dump() const;
00317
00318 private:
00319
00320 class Private;
00321 Private *d;
00322
00323 };
00324
00325 }
00326
00327 #endif