libkcal Library API Documentation

recurrence.h

00001 /*
00002     This file is part of libkcal.
00003     Copyright (c) 1998 Preston Brown
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020     Boston, MA 02111-1307, USA.
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     // Prohibit copying
00314     Recurrence(const Recurrence&);
00315     Recurrence &operator=(const Recurrence&);
00316 
00317     short recurs;                        // should be one of the enums.
00318 
00319     int rWeekStart;                      // day which starts the week, Monday=1 .. Sunday=7
00320     QBitArray rDays;                     // array of days during week it recurs
00321 
00322     QPtrList<rMonthPos> rMonthPositions; // list of positions during a month
00323                                          // on which an event recurs
00324 
00325     QPtrList<int> rMonthDays;            // list of days during a month on
00326                                          // which the event recurs
00327 
00328     QPtrList<int> rYearNums;             // either months/days to recur on for rYearly,
00329                                          // sorted in numerical order
00330 
00331     int rFreq;                           // frequency of period
00332 
00333     // one of the following must be specified
00334     int rDuration;                       // num times to recur (inc. first occurrence), -1 = infinite
00335     QDateTime rEndDateTime;              // date/time at which to end recurrence
00336 
00337     QDateTime mRecurStart;               // date/time of first recurrence
00338     bool mFloats;                        // the recurrence has no time, just a date
00339     bool mRecurReadOnly;
00340     int  mRecurExDatesCount;             // number of recurrences (in addition to rDuration) which are excluded
00341 
00342     // Backwards compatibility for KDE < 3.1.
00343     int   mCompatVersion;                // calendar file version for backwards compatibility
00344     short mCompatRecurs;                 // original 'recurs' in old calendar format, or rNone
00345     int   mCompatDuration;               // original 'rDuration' in old calendar format, or 0
00346 
00347     Incidence *mParent;
00348 };
00349 
00350 }
00351 
00352 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:27 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001