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     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     // Prohibit copying
00374     Recurrence(const Recurrence&);
00375     Recurrence &operator=(const Recurrence&);
00376 
00377     short recurs;                        // should be one of the enums.
00378 
00379     int rWeekStart;                      // day which starts the week, Monday=1 .. Sunday=7
00380     QBitArray rDays;                     // array of days during week it recurs
00381 
00382     QPtrList<rMonthPos> rMonthPositions; // list of positions during a month
00383                                          // on which an event recurs
00384 
00385     QPtrList<int> rMonthDays;            // list of days during a month on
00386                                          // which the event recurs
00387 
00388     QPtrList<int> rYearNums;             // either months/days to recur on for rYearly,
00389                                          // sorted in numerical order
00390 
00391     int rFreq;                           // frequency of period
00392 
00393     // one of the following must be specified
00394     int rDuration;                       // num times to recur (inc. first occurrence), -1 = infinite
00395     QDateTime rEndDateTime;              // date/time at which to end recurrence
00396     mutable QDateTime mCachedEndDT;      // calculated end date/time for duration > 0
00397                                          // (calculation can be significant for some recurrences)
00398     mutable bool mUseCachedEndDT;        // true if mCachedEndDT is up to date
00399 
00400     QDateTime mRecurStart;               // date/time of first recurrence
00401     bool mFloats;                        // the recurrence has no time, just a date
00402     bool mRecurReadOnly;
00403     Feb29Type mFeb29YearlyType;          // how to handle yearly recurrences of February 29th
00404     static Feb29Type mFeb29YearlyDefaultType;  // default value for mFeb29YearlyType
00405 
00406     // Backwards compatibility for KDE < 3.1.
00407     int   mCompatVersion;                // calendar file version for backwards compatibility
00408     short mCompatRecurs;                 // original 'recurs' in old calendar format, or rNone
00409     int   mCompatDuration;               // original 'rDuration' in old calendar format, or 0
00410 
00411     Incidence *mParent;
00412 
00413     class Private;
00414     Private *d;
00415 };
00416 
00417 }
00418 
00419 #endif
KDE Logo
This file is part of the documentation for libkcal Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:22 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003