KCal Library
recurrencerule.h
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
00142 void setStartDt( const KDateTime &start );
00143
00146 bool allDay() const;
00147
00152 void setAllDay( bool allDay );
00153
00159 KDateTime endDt( bool *result = 0 ) const;
00160
00163 void setEndDt( const KDateTime &endDateTime );
00164
00169 int duration() const;
00170
00173 void setDuration( int duration );
00174
00176 int durationTo( const KDateTime &dt ) const;
00177
00179 int durationTo( const QDate &date ) const;
00180
00195 void shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec );
00196
00203 bool recursOn( const QDate &date, const KDateTime::Spec &timeSpec ) const;
00204
00211 bool recursAt( const KDateTime &dt ) const;
00212
00220 bool dateMatchesRules( const KDateTime &dt ) const;
00221
00228 TimeList recurTimesOn( const QDate &date, const KDateTime::Spec &timeSpec ) const;
00229
00241 DateTimeList timesInInterval( const KDateTime &start, const KDateTime &end ) const;
00242
00248 KDateTime getNextDate( const KDateTime &preDateTime ) const;
00249
00256 KDateTime getPreviousDate( const KDateTime &afterDateTime ) const;
00257
00258 void setBySeconds( const QList<int> bySeconds );
00259 void setByMinutes( const QList<int> byMinutes );
00260 void setByHours( const QList<int> byHours );
00261
00262 void setByDays( const QList<WDayPos> byDays );
00263 void setByMonthDays( const QList<int> byMonthDays );
00264 void setByYearDays( const QList<int> byYearDays );
00265 void setByWeekNumbers( const QList<int> byWeekNumbers );
00266 void setByMonths( const QList<int> byMonths );
00267 void setBySetPos( const QList<int> bySetPos );
00268 void setWeekStart( short weekStart );
00269
00270 const QList<int> &bySeconds() const;
00271 const QList<int> &byMinutes() const;
00272 const QList<int> &byHours() const;
00273
00274 const QList<WDayPos> &byDays() const;
00275 const QList<int> &byMonthDays() const;
00276 const QList<int> &byYearDays() const;
00277 const QList<int> &byWeekNumbers() const;
00278 const QList<int> &byMonths() const;
00279 const QList<int> &bySetPos() const;
00280 short weekStart() const;
00281
00289 void setRRule( const QString &rrule );
00290 QString rrule() const;
00291
00292 void setDirty();
00300 void addObserver( RuleObserver *observer );
00301
00308 void removeObserver( RuleObserver *observer );
00309
00313 void dump() const;
00314
00315 private:
00316
00317 class Private;
00318 Private *d;
00319
00320 };
00321
00322 }
00323
00324 #endif