00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KCAL_RECURRENCE_H
00024 #define KCAL_RECURRENCE_H
00025
00026 #include <qstring.h>
00027 #include <qbitarray.h>
00028 #include <qptrlist.h>
00029
00030 namespace KCal {
00031
00032 class Incidence;
00033
00037 class Recurrence
00038 {
00039 public:
00041 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003,
00042 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006,
00043 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 };
00044
00047 enum Feb29Type {
00048 rMar1,
00049 rFeb28,
00050 rFeb29
00051 };
00052
00054 struct rMonthPos {
00055 QBitArray rDays;
00056 short rPos;
00057 bool negative;
00058 };
00059
00060 Recurrence( Incidence *parent, int compatVersion = 0 );
00061 Recurrence( const Recurrence&, Incidence *parent );
00062 ~Recurrence();
00063
00064 bool operator==( const Recurrence& ) const;
00065 bool operator!=( const Recurrence& r ) const { return !operator==(r); }
00066
00067 Incidence *parent() { return mParent; }
00068
00070 QDateTime recurStart() const { return mRecurStart; }
00072 void setRecurStart(const QDateTime &start);
00076 void setRecurStart(const QDate &start);
00082 void setFloats(bool f);
00086 bool doesFloat() const { return mFloats; }
00087
00089 void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; }
00091 bool recurReadOnly() const { return mRecurReadOnly; }
00092
00097 void setCompatVersion(int version = 0);
00098
00101 ushort doesRecur() const;
00104 bool recursOnPure(const QDate &qd) const;
00107 bool recursAtPure(const QDateTime &) const;
00109 void unsetRecurs();
00110
00115 QValueList<QTime> recurTimesOn(const QDate &date) const;
00116
00123 QDate getNextDate(const QDate& preDate, bool* last = 0) const;
00131 QDateTime getNextDateTime(const QDateTime& preDateTime, bool* last = 0) const;
00138 QDate getPreviousDate(const QDate& afterDate, bool* last = 0) const;
00147 QDateTime getPreviousDateTime(const QDateTime& afterDateTime, bool* last = 0) const;
00148
00150 int frequency() const;
00152 int duration() const;
00155 void setDuration(int duration);
00157 int durationTo(const QDate &) const;
00159 int durationTo(const QDateTime &) const;
00160
00166 QDate endDate(bool* result = 0) const;
00172 QDateTime endDateTime(bool* result = 0) const;
00175 QString endDateStr(bool shortfmt=true) const;
00176
00181 void setMinutely(int _rFreq, int duration);
00186 void setMinutely(int _rFreq, const QDateTime &endDateTime);
00187
00192 void setHourly(int _rFreq, int duration);
00197 void setHourly(int _rFreq, const QDateTime &endDateTime);
00198
00203 void setDaily(int _rFreq, int duration);
00208 void setDaily(int _rFreq, const QDate &endDate);
00209
00216 void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1);
00223 void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1);
00225 int weekStart() const { return rWeekStart; }
00227 const QBitArray &days() const;
00228
00234 void setMonthly(short type, int _rFreq, int duration);
00236 void setMonthly(short type, int _rFreq, const QDate &endDate);
00245 void addMonthlyPos(short _rPos, const QBitArray &_rDays);
00249 void addMonthlyDay(short _rDay);
00251 const QPtrList<rMonthPos> &monthPositions() const;
00253 const QPtrList<int> &monthDays() const;
00254
00260 void setYearly(int type, int freq, int duration);
00262 void setYearly(int type, int freq, const QDate &endDate);
00270 void setYearlyByDate(Feb29Type type, int freq, int duration);
00272 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate);
00280 void setYearlyByDate(int day, Feb29Type type, int freq, int duration);
00282 void setYearlyByDate(int day, Feb29Type type, int freq, const QDate &endDate);
00286 void addYearlyNum(short _rNum);
00291 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
00293 const QPtrList<int> &yearNums() const;
00295 const QPtrList<rMonthPos> &yearMonthPositions() const;
00297 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; }
00299 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; }
00301 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; }
00302
00306 void dump() const;
00307
00308 protected:
00309 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
00310
00311 class MonthlyData;
00312 class YearlyMonthData;
00313 class YearlyPosData;
00314 class YearlyDayData;
00315
00316 bool recursSecondly(const QDate &, int secondFreq) const;
00317 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
00318 bool recursDaily(const QDate &) const;
00319 bool recursWeekly(const QDate &) const;
00320 bool recursMonthly(const QDate &) const;
00321 bool recursYearlyByMonth(const QDate &) const;
00322 bool recursYearlyByPos(const QDate &) const;
00323 bool recursYearlyByDay(const QDate &) const;
00324
00325 QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
00326 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
00327
00328 void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
00329 void setDailySub(short type, int freq, int duration);
00330 void setYearly_(short type, Feb29Type, int freq, int duration);
00331 int recurCalc(PeriodFunc, QDate &enddate) const;
00332 int recurCalc(PeriodFunc, QDateTime &endtime) const;
00333 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const;
00334 int dailyCalc(PeriodFunc, QDate &enddate) const;
00335 int weeklyCalc(PeriodFunc, QDate &enddate) const;
00336 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
00337 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
00338 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
00339 int monthlyCalc(PeriodFunc, QDate &enddate) const;
00340 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
00341 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
00342 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
00343 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
00344 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
00345 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
00346 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
00347 int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
00348 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
00349 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
00350 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
00351 int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
00352 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
00353 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
00354 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
00355
00356 public:
00357 int countMonthlyPosDays() const;
00358 void getMonthlyPosDays(QValueList<int>&, int daysInMonth,
00359 int startDayOfWeek) const;
00360 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const;
00361 bool getYearlyMonthMonths(int day, QValueList<int>&,
00362 QValueList<int> &leaplist) const;
00363 private:
00364
00365 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
00366 int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
00367 QDate getFirstDateInMonth(const QDate& earliestDate) const;
00368 QDate getLastDateInMonth(const QDate& latestDate) const;
00369 QDate getFirstDateInYear(const QDate& earliestDate) const;
00370 QDate getLastDateInYear(const QDate& latestDate) const;
00371
00372 private:
00373
00374 Recurrence(const Recurrence&);
00375 Recurrence &operator=(const Recurrence&);
00376
00377 short recurs;
00378
00379 int rWeekStart;
00380 QBitArray rDays;
00381
00382 QPtrList<rMonthPos> rMonthPositions;
00383
00384
00385 QPtrList<int> rMonthDays;
00386
00387
00388 QPtrList<int> rYearNums;
00389
00390
00391 int rFreq;
00392
00393
00394 int rDuration;
00395 QDateTime rEndDateTime;
00396 mutable QDateTime mCachedEndDT;
00397
00398 mutable bool mUseCachedEndDT;
00399
00400 QDateTime mRecurStart;
00401 bool mFloats;
00402 bool mRecurReadOnly;
00403 Feb29Type mFeb29YearlyType;
00404 static Feb29Type mFeb29YearlyDefaultType;
00405
00406
00407 int mCompatVersion;
00408 short mCompatRecurs;
00409 int mCompatDuration;
00410
00411 Incidence *mParent;
00412
00413 class Private;
00414 Private *d;
00415 };
00416
00417 }
00418
00419 #endif