libkcal

recurrence.h

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 
00181     DateTimeList timesInInterval( const QDateTime &start, const QDateTime &end ) const;
00182 
00183 
00189     QDateTime getNextDateTime( const QDateTime& preDateTime ) const;
00196     QDateTime getPreviousDateTime( const QDateTime& afterDateTime ) const;
00197 
00199     int frequency() const;
00201     void setFrequency(int freq);
00202 
00207     int duration() const;
00210     void setDuration(int duration);
00212     int durationTo(const QDateTime &) const;
00214     int durationTo( const QDate &date ) const { return durationTo( QDateTime( date, QTime( 23, 59, 59 ) ) ); }
00215 
00219     QDateTime endDateTime() const;
00223     QDate endDate() const;
00227     void setEndDate( const QDate &endDate );
00230     void setEndDateTime( const QDateTime &endDateTime );
00231 
00232 
00233 
00244     void setMinutely( int freq );
00245 
00259     void setHourly( int freq );
00260 
00274     void setDaily( int freq );
00275 
00287     void setWeekly( int freq, int weekStart = 1 );
00300     void setWeekly( int freq, const QBitArray &days, int weekStart = 1 );
00304     void addWeeklyDays( const QBitArray &days );
00310     int weekStart() const;
00312     QBitArray days() const; // Emulate the old behavior
00313 
00328     void setMonthly( int freq );
00336     void addMonthlyPos( short pos, const QBitArray &days );
00337     void addMonthlyPos( short pos, ushort day );
00342     void addMonthlyDate( short day );
00344     QValueList<RecurrenceRule::WDayPos> monthPositions() const;
00346     // Emulate old behavior
00347     QValueList<int> monthDays() const;
00348 
00371     void setYearly( int freq );
00378     void addYearlyDay( int day );
00387     void addYearlyDate( int date );
00393     void addYearlyMonth( short _rNum );
00410     void addYearlyPos( short pos, const QBitArray &days );
00411 
00417     QValueList<int> yearDays() const;
00425     QValueList<int> yearDates() const;
00434     QValueList<int> yearMonths() const;
00444     QValueList<RecurrenceRule::WDayPos> yearPositions() const;
00445 
00447     static const QDate MAX_DATE;
00448 
00452     void dump() const;
00453 
00454 
00455     // RRULE
00456     RecurrenceRule::List rRules() const;
00457     void addRRule( RecurrenceRule *rrule );
00458     void removeRRule( RecurrenceRule *rrule );
00459     // EXRULE
00460     RecurrenceRule::List exRules() const;
00461     void addExRule( RecurrenceRule *exrule );
00462     void removeExRule( RecurrenceRule *exrule );
00463 
00464     // RDATE
00465     DateTimeList rDateTimes() const;
00466     DateList rDates() const;
00467     void setRDateTimes( const DateTimeList &rdates);
00468     void setRDates( const DateList &rdates);
00469     void addRDateTime( const QDateTime &rdate );
00470     void addRDate( const QDate &rdate );
00471 
00472     // ExDATE
00473     DateTimeList exDateTimes() const;
00474     DateList exDates() const;
00475     void setExDateTimes( const DateTimeList &exdates);
00476     void setExDates( const DateList &exdates);
00477     void addExDateTime( const QDateTime &exdate );
00478     void addExDate( const QDate &exdate );
00479 
00480     RecurrenceRule *defaultRRule( bool create = false ) const;
00481     RecurrenceRule *defaultRRuleConst() const;
00482     void updated();
00483 
00491     void addObserver( Observer *observer );
00498     void removeObserver( Observer *observer );
00499 
00500     void recurrenceChanged( RecurrenceRule * );
00501 
00502   protected:
00503     RecurrenceRule *setNewRecurrenceType( RecurrenceRule::PeriodType type, int freq );
00504 
00505   private:
00506     RecurrenceRule::List mExRules;
00507     RecurrenceRule::List mRRules;
00508     QValueList<QDateTime>mRDateTimes;
00509     QValueList<QDate> mRDates;
00510     QValueList<QDateTime> mExDateTimes;
00511     QValueList<QDate> mExDates;
00512 
00513     QDateTime mStartDateTime;            // date/time of first recurrence
00514     bool mFloating;                      // the recurrence has no time, just a date
00515     bool mRecurReadOnly;
00516 
00517     // Cache the type of the recurrence with the old system (e.g. MonthlyPos)
00518     mutable ushort mCachedType;
00519 
00520     QValueList<Observer*> mObservers;
00521 
00522     class Private;
00523     Private *d;
00524 };
00525 
00526 }
00527 
00528 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys