libkcal Library API Documentation

recurrence.h

00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 1998 Preston Brown
00005     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00006     Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021     Boston, MA 02111-1307, USA.
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,    // recur on March 1st (default)
00049            rFeb28,   // recur on February 28th
00050            rFeb29    // only recur on February 29th, i.e. don't recur in non-leap years
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     // Prohibit copying
00410     Recurrence(const Recurrence&);
00411     Recurrence &operator=(const Recurrence&);
00412 
00413     short recurs;                        // should be one of the enums.
00414 
00415     int rWeekStart;                      // day which starts the week, Monday=1 .. Sunday=7
00416     QBitArray rDays;                     // array of days during week it recurs
00417 
00418     QPtrList<rMonthPos> rMonthPositions; // list of positions during a month
00419                                          // on which an event recurs
00420 
00421     QPtrList<int> rMonthDays;            // list of days during a month on
00422                                          // which the event recurs
00423 
00424     QPtrList<int> rYearNums;             // either months/days to recur on for rYearly,
00425                                          // sorted in numerical order
00426 
00427     int rFreq;                           // frequency of period
00428 
00429     // one of the following must be specified
00430     int rDuration;                       // num times to recur (inc. first occurrence), -1 = infinite, 0 means end date is set
00431     QDateTime rEndDateTime;              // date/time at which to end recurrence
00432     mutable QDateTime mCachedEndDT;      // calculated end date/time for duration > 0
00433                                          // (calculation can be significant for some recurrences)
00434     mutable bool mUseCachedEndDT;        // true if mCachedEndDT is up to date
00435 
00436     QDateTime mRecurStart;               // date/time of first recurrence
00437     bool mFloats;                        // the recurrence has no time, just a date
00438     bool mRecurReadOnly;
00439     Feb29Type mFeb29YearlyType;          // how to handle yearly recurrences of February 29th
00440     static Feb29Type mFeb29YearlyDefaultType;  // default value for mFeb29YearlyType
00441 
00442     // Backwards compatibility for KDE < 3.1.
00443     int   mCompatVersion;                // calendar file version for backwards compatibility
00444     short mCompatRecurs;                 // original 'recurs' in old calendar format, or rNone
00445     int   mCompatDuration;               // original 'rDuration' in old calendar format, or 0
00446 
00447     Incidence *mParent;
00448 
00449     class Private;
00450     Private *d;
00451 };
00452 
00453 }
00454 
00455 #endif
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 17 09:52:51 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003