00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KCAL_RECURRENCE_H
00023 #define KCAL_RECURRENCE_H
00024
00025 #include <qstring.h>
00026 #include <qbitarray.h>
00027 #include <qptrlist.h>
00028
00029 namespace KCal {
00030
00031 class Incidence;
00032
00036 class Recurrence
00037 {
00038 public:
00040 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003,
00041 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006,
00042 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 };
00043
00045 struct rMonthPos {
00046 QBitArray rDays;
00047 short rPos;
00048 bool negative;
00049 };
00050
00051 Recurrence(Incidence *parent, int compatVersion = 0);
00052 Recurrence(const Recurrence&, Incidence *parent);
00053 ~Recurrence();
00054
00056 QDateTime recurStart() const { return mRecurStart; }
00058 int recurExDatesCount() const { return mRecurExDatesCount; }
00060 void setRecurStart(const QDateTime &start);
00064 void setRecurStart(const QDate &start);
00070 void setFloats(bool f);
00072 void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; }
00074 void setRecurExDatesCount(int count) { if (count >= 0) mRecurExDatesCount = count; }
00079 void setCompatVersion(int version = 0);
00080
00083 ushort doesRecur() const;
00086 bool recursOnPure(const QDate &qd) const;
00089 bool recursAtPure(const QDateTime &) const;
00091 void unsetRecurs();
00092
00099 QDate getNextDate(const QDate& preDate, bool* last = 0) const;
00107 QDateTime getNextDateTime(const QDateTime& preDateTime, bool* last = 0) const;
00114 QDate getPreviousDate(const QDate& afterDate, bool* last = 0) const;
00123 QDateTime getPreviousDateTime(const QDateTime& afterDateTime, bool* last = 0) const;
00124
00126 int frequency() const;
00128 int duration() const;
00131 void setDuration(int duration);
00133 int durationTo(const QDate &) const;
00135 int durationTo(const QDateTime &) const;
00136
00141 QDate endDate() const;
00146 QDateTime endDateTime() const;
00149 QString endDateStr(bool shortfmt=true) const;
00150
00155 void setMinutely(int _rFreq, int duration);
00160 void setMinutely(int _rFreq, const QDateTime &endDateTime);
00161
00166 void setHourly(int _rFreq, int duration);
00171 void setHourly(int _rFreq, const QDateTime &endDateTime);
00172
00177 void setDaily(int _rFreq, int duration);
00182 void setDaily(int _rFreq, const QDate &endDate);
00183
00190 void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1);
00197 void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1);
00199 int weekStart() const { return rWeekStart; }
00201 const QBitArray &days() const;
00202
00208 void setMonthly(short type, int _rFreq, int duration);
00210 void setMonthly(short type, int _rFreq, const QDate &endDate);
00219 void addMonthlyPos(short _rPos, const QBitArray &_rDays);
00223 void addMonthlyDay(short _rDay);
00225 const QPtrList<rMonthPos> &monthPositions() const;
00227 const QPtrList<int> &monthDays() const;
00228
00234 void setYearly(int type, int freq, int duration);
00236 void setYearly(int type, int freq, const QDate &endDate);
00240 void addYearlyNum(short _rNum);
00245 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
00247 const QPtrList<int> &yearNums() const;
00249 const QPtrList<rMonthPos> &yearMonthPositions() const;
00250
00251 protected:
00252 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
00253 struct MonthlyData; friend struct MonthlyData;
00254 struct YearlyMonthData; friend struct YearlyMonthData;
00255 struct YearlyPosData; friend struct YearlyPosData;
00256 struct YearlyDayData; friend struct YearlyDayData;
00257
00258 bool recursSecondly(const QDate &, int secondFreq) const;
00259 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
00260 bool recursDaily(const QDate &) const;
00261 bool recursWeekly(const QDate &) const;
00262 bool recursMonthly(const QDate &) const;
00263 bool recursYearlyByMonth(const QDate &) const;
00264 bool recursYearlyByPos(const QDate &) const;
00265 bool recursYearlyByDay(const QDate &) const;
00266
00267 QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
00268 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
00269
00270 void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
00271 void setDailySub(short type, int freq, int duration);
00272 void setYearly_(short type, int freq, int duration);
00273 int recurCalc(PeriodFunc, QDate &enddate) const;
00274 int recurCalc(PeriodFunc, QDateTime &endtime) const;
00275 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const;
00276 int dailyCalc(PeriodFunc, QDate &enddate) const;
00277 int weeklyCalc(PeriodFunc, QDate &enddate) const;
00278 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
00279 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
00280 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
00281 int monthlyCalc(PeriodFunc, QDate &enddate) const;
00282 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
00283 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
00284 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
00285 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
00286 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
00287 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
00288 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
00289 int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
00290 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
00291 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
00292 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
00293 int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
00294 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
00295 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
00296 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
00297
00298 int countMonthlyPosDays() const;
00299 void getMonthlyPosDays(QValueList<int>&, int daysInMonth,
00300 int startDayOfWeek) const;
00301 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const;
00302 bool getYearlyMonthMonths(int day, QValueList<int>&,
00303 QValueList<int> &leaplist) const;
00304
00305 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
00306 int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
00307 QDate getFirstDateInMonth(const QDate& earliestDate) const;
00308 QDate getLastDateInMonth(const QDate& latestDate) const;
00309 QDate getFirstDateInYear(const QDate& earliestDate) const;
00310 QDate getLastDateInYear(const QDate& latestDate) const;
00311
00312 private:
00313
00314 Recurrence(const Recurrence&);
00315 Recurrence &operator=(const Recurrence&);
00316
00317 short recurs;
00318
00319 int rWeekStart;
00320 QBitArray rDays;
00321
00322 QPtrList<rMonthPos> rMonthPositions;
00323
00324
00325 QPtrList<int> rMonthDays;
00326
00327
00328 QPtrList<int> rYearNums;
00329
00330
00331 int rFreq;
00332
00333
00334 int rDuration;
00335 QDateTime rEndDateTime;
00336
00337 QDateTime mRecurStart;
00338 bool mFloats;
00339 bool mRecurReadOnly;
00340 int mRecurExDatesCount;
00341
00342
00343 int mCompatVersion;
00344 short mCompatRecurs;
00345 int mCompatDuration;
00346
00347 Incidence *mParent;
00348 };
00349
00350 }
00351
00352 #endif