libkcal

recurrence.h

Go to the documentation of this file.
00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 1998 Preston Brown <pbrown@kde.org>
00005     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00006     Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
00007     Copyright (C) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Library General Public
00011     License as published by the Free Software Foundation; either
00012     version 2 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Library General Public License for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with this library; see the file COPYING.LIB.  If not, write to
00021     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022     Boston, MA 02110-1301, USA.
00023 */
00024 #ifndef KCAL_RECURRENCE_H
00025 #define KCAL_RECURRENCE_H
00026 
00027 #include <qstring.h>
00028 #include <qbitarray.h>
00029 #include <qptrlist.h>
00030 
00031 #include "libkcal_export.h"
00032 #include "recurrencerule.h"
00033 
00034 namespace KCal {
00035 
00036 class RecurrenceRule;
00037 
00089 class LIBKCAL_EXPORT Recurrence : public RecurrenceRule::Observer
00090 {
00091   public:
00092     class Observer {
00093       public:
00094         virtual ~Observer() {}
00096         virtual void recurrenceUpdated( Recurrence * ) = 0;
00097     };
00098 
00100     enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003,
00101            rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006,
00102            rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009,
00103            rOther = 0x000A, rMax=0x00FF };
00104 
00105     Recurrence();
00106     Recurrence( const Recurrence& );
00107     virtual ~Recurrence();
00108 
00109     bool operator==( const Recurrence& ) const;
00110     bool operator!=( const Recurrence& r ) const  { return !operator==(r); }
00111 
00114     QDateTime startDateTime() const;
00116     QDate startDate() const   { return mStartDateTime.date(); }
00120     void setStartDateTime( const QDateTime &start );
00124     void setStartDate( const QDate &start );
00125 
00132     bool doesFloat() const { return mFloating; }
00136     void setFloats( bool floats );
00137 
00139     void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; }
00141     bool recurReadOnly() const  { return mRecurReadOnly; }
00142 
00144     bool doesRecur() const;
00147     ushort recurrenceType() const;
00150     static ushort recurrenceType( const RecurrenceRule *rrule );
00153     bool recursOn( const QDate &qd ) const;
00156     bool recursAt( const QDateTime & ) const;
00159     void unsetRecurs();
00161     void clear();
00162 
00167     QValueList<QTime> recurTimesOn(const QDate &date) const;
00168 
00174     QDateTime getNextDateTime( const QDateTime& preDateTime ) const;
00181     QDateTime getPreviousDateTime( const QDateTime& afterDateTime ) const;
00182 
00184     int frequency() const;
00186     void setFrequency(int freq);
00187 
00192     int duration() const;
00195     void setDuration(int duration);
00197     int durationTo(const QDateTime &) const;
00199     int durationTo( const QDate &date ) const { return durationTo( QDateTime( date, QTime( 23, 59, 59 ) ) ); }
00200 
00204     QDateTime endDateTime() const;
00208     QDate endDate() const;
00212     void setEndDate( const QDate &endDate );
00215     void setEndDateTime( const QDateTime &endDateTime );
00216 
00217 
00218 
00229     void setMinutely( int freq );
00230 
00244     void setHourly( int freq );
00245 
00259     void setDaily( int freq );
00260 
00272     void setWeekly( int freq, int weekStart = 1 );
00285     void setWeekly( int freq, const QBitArray &days, int weekStart = 1 );
00289     void addWeeklyDays( const QBitArray &days );
00295     int weekStart() const;
00297     QBitArray days() const; // Emulate the old behavior
00298 
00313     void setMonthly( int freq );
00321     void addMonthlyPos( short pos, const QBitArray &days );
00322     void addMonthlyPos( short pos, ushort day );
00327     void addMonthlyDate( short day );
00329     QValueList<RecurrenceRule::WDayPos> monthPositions() const;
00331     // Emulate old behavior
00332     QValueList<int> monthDays() const;
00333 
00356     void setYearly( int freq );
00363     void addYearlyDay( int day );
00372     void addYearlyDate( int date );
00378     void addYearlyMonth( short _rNum );
00395     void addYearlyPos( short pos, const QBitArray &days );
00396 
00402     QValueList<int> yearDays() const;
00410     QValueList<int> yearDates() const;
00419     QValueList<int> yearMonths() const;
00429     QValueList<RecurrenceRule::WDayPos> yearPositions() const;
00430 
00432     static const QDate MAX_DATE;
00433 
00437     void dump() const;
00438 
00439 
00440     // RRULE
00441     RecurrenceRule::List rRules() const;
00442     void addRRule( RecurrenceRule *rrule );
00443     void removeRRule( RecurrenceRule *rrule );
00444     // EXRULE
00445     RecurrenceRule::List exRules() const;
00446     void addExRule( RecurrenceRule *exrule );
00447     void removeExRule( RecurrenceRule *exrule );
00448 
00449     // RDATE
00450     DateTimeList rDateTimes() const;
00451     DateList rDates() const;
00452     void setRDateTimes( const DateTimeList &rdates);
00453     void setRDates( const DateList &rdates);
00454     void addRDateTime( const QDateTime &rdate );
00455     void addRDate( const QDate &rdate );
00456 
00457     // ExDATE
00458     DateTimeList exDateTimes() const;
00459     DateList exDates() const;
00460     void setExDateTimes( const DateTimeList &exdates);
00461     void setExDates( const DateList &exdates);
00462     void addExDateTime( const QDateTime &exdate );
00463     void addExDate( const QDate &exdate );
00464 
00465     RecurrenceRule *defaultRRule( bool create = false ) const;
00466     RecurrenceRule *defaultRRuleConst() const;
00467     void updated();
00468 
00476     void addObserver( Observer *observer );
00483     void removeObserver( Observer *observer );
00484 
00485     void recurrenceChanged( RecurrenceRule * );
00486 
00487   protected:
00488     RecurrenceRule *setNewRecurrenceType( RecurrenceRule::PeriodType type, int freq );
00489 
00490   private:
00491     RecurrenceRule::List mExRules;
00492     RecurrenceRule::List mRRules;
00493     QValueList<QDateTime>mRDateTimes;
00494     QValueList<QDate> mRDates;
00495     QValueList<QDateTime> mExDateTimes;
00496     QValueList<QDate> mExDates;
00497 
00498     QDateTime mStartDateTime;            // date/time of first recurrence
00499     bool mFloating;                      // the recurrence has no time, just a date
00500     bool mRecurReadOnly;
00501 
00502     // Cache the type of the recurrence with the old system (e.g. MonthlyPos)
00503     mutable ushort mCachedType;
00504 
00505     QValueList<Observer*> mObservers;
00506 
00507     class Private;
00508     Private *d;
00509 };
00510 
00511 }
00512 
00513 #endif