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 void setFrequency(int freq);
00153
00158 int duration() const;
00161 void setDuration(int duration);
00163 int durationTo(const QDate &) const;
00165 int durationTo(const QDateTime &) const;
00166
00172 QDate endDate(bool* result = 0) const;
00178 QDateTime endDateTime(bool* result = 0) const;
00181 QString endDateStr(bool shortfmt=true) const;
00184 void setEndDate(const QDate &endDate);
00187 void setEndDateTime(const QDateTime &endDateTime);
00188
00193 void setMinutely(int _rFreq, int duration);
00198 void setMinutely(int _rFreq, const QDateTime &endDateTime);
00199
00204 void setHourly(int _rFreq, int duration);
00209 void setHourly(int _rFreq, const QDateTime &endDateTime);
00210
00215 void setDaily(int _rFreq, int duration);
00220 void setDaily(int _rFreq, const QDate &endDate);
00221
00228 void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1);
00235 void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1);
00237 int weekStart() const { return rWeekStart; }
00239 const QBitArray &days() const;
00240
00246 void setMonthly(short type, int _rFreq, int duration);
00248 void setMonthly(short type, int _rFreq, const QDate &endDate);
00257 void addMonthlyPos(short _rPos, const QBitArray &_rDays);
00261 void addMonthlyDay(short _rDay);
00263 const QPtrList<rMonthPos> &monthPositions() const;
00265 const QPtrList<int> &monthDays() const;
00266
00272 void setYearly(int type, int freq, int duration);
00274 void setYearly(int type, int freq, const QDate &endDate);
00282 void setYearlyByDate(Feb29Type type, int freq, int duration);
00284 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate);
00292 void setYearlyByDate(int day, Feb29Type type, int freq, int duration);
00294 void setYearlyByDate(int day, Feb29Type type, int freq, const QDate &endDate);
00298 void addYearlyNum(short _rNum);
00303 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
00305 const QPtrList<int> &yearNums() const;
00307 const QPtrList<rMonthPos> &yearMonthPositions() const;
00309 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; }
00311 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; }
00313 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; }
00314
00318 int countMonthlyPosDays() const;
00324 void getMonthlyPosDays(QValueList<int>& list, int daysInMonth,
00325 int startDayOfWeek) const;
00331 bool getMonthlyDayDays(QValueList<int>& list, int daysInMonth) const;
00340 bool getYearlyMonthMonths(int day, QValueList<int>& list,
00341 QValueList<int> &leaplist) const;
00342
00344 static const QDate MAX_DATE;
00345
00349 void dump() const;
00350
00351 protected:
00352 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
00353
00354 class MonthlyData;
00355 class YearlyMonthData;
00356 class YearlyPosData;
00357 class YearlyDayData;
00358
00359 bool recursSecondly(const QDate &, int secondFreq) const;
00360 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
00361 bool recursDaily(const QDate &) const;
00362 bool recursWeekly(const QDate &) const;
00363 bool recursMonthly(const QDate &) const;
00364 bool recursYearlyByMonth(const QDate &) const;
00365 bool recursYearlyByPos(const QDate &) const;
00366 bool recursYearlyByDay(const QDate &) const;
00367
00368 QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
00369 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
00370
00371 void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
00372 void setDailySub(short type, int freq, int duration);
00373 void setYearly_(short type, Feb29Type, int freq, int duration);
00374 int recurCalc(PeriodFunc, QDate &enddate) const;
00375 int recurCalc(PeriodFunc, QDateTime &endtime) const;
00376 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const;
00377 int dailyCalc(PeriodFunc, QDate &enddate) const;
00378 int weeklyCalc(PeriodFunc, QDate &enddate) const;
00379 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
00380 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
00381 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
00382 int monthlyCalc(PeriodFunc, QDate &enddate) const;
00383 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
00384 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
00385 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
00386 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
00387 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
00388 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
00389 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
00390 int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
00391 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
00392 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
00393 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
00394 int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
00395 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
00396 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
00397 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
00398
00399 private:
00400
00401 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
00402 int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
00403 QDate getFirstDateInMonth(const QDate& earliestDate) const;
00404 QDate getLastDateInMonth(const QDate& latestDate) const;
00405 QDate getFirstDateInYear(const QDate& earliestDate) const;
00406 QDate getLastDateInYear(const QDate& latestDate) const;
00407 int maxIterations() const;
00408
00409
00410 Recurrence(const Recurrence&);
00411 Recurrence &operator=(const Recurrence&);
00412
00413 short recurs;
00414
00415 int rWeekStart;
00416 QBitArray rDays;
00417
00418 QPtrList<rMonthPos> rMonthPositions;
00419
00420
00421 QPtrList<int> rMonthDays;
00422
00423
00424 QPtrList<int> rYearNums;
00425
00426
00427 int rFreq;
00428
00429
00430 int rDuration;
00431 QDateTime rEndDateTime;
00432 mutable QDateTime mCachedEndDT;
00433
00434 mutable bool mUseCachedEndDT;
00435
00436 QDateTime mRecurStart;
00437 bool mFloats;
00438 bool mRecurReadOnly;
00439 Feb29Type mFeb29YearlyType;
00440 static Feb29Type mFeb29YearlyDefaultType;
00441
00442
00443 int mCompatVersion;
00444 short mCompatRecurs;
00445 int mCompatDuration;
00446
00447 Incidence *mParent;
00448
00449 class Private;
00450 Private *d;
00451 };
00452
00453 }
00454
00455 #endif