karecurrence.h
00001 /* 00002 * karecurrence.h - recurrence with special yearly February 29th handling 00003 * Program: kalarm 00004 * Copyright © 2005,2006 by David Jarvie <software@astrojar.org.uk> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KARECURRENCE_H 00022 #define KARECURRENCE_H 00023 00024 #include <libkcal/recurrence.h> 00025 class DateTime; 00026 00027 00028 class KARecurrence : public KCal::Recurrence 00029 { 00030 public: 00034 enum Type { 00035 NO_RECUR, // does not recur 00036 MINUTELY, // at an hours/minutes interval 00037 DAILY, // daily 00038 WEEKLY, // weekly, on specified weekdays 00039 MONTHLY_POS, // monthly, on specified weekdays in a specified week of the month 00040 MONTHLY_DAY, // monthly, on a specified day of the month 00041 ANNUAL_DATE, // yearly, on a specified date in each of the specified months 00042 ANNUAL_POS // yearly, on specified weekdays in the specified weeks of the specified months 00043 }; 00045 enum Feb29Type { 00046 FEB29_FEB29, // February 29th recurrences are omitted in non-leap years 00047 FEB29_MAR1, // February 29th recurrences are on March 1st in non-leap years 00048 FEB29_FEB28 // February 29th recurrences are on February 28th in non-leap years 00049 }; 00050 00051 KARecurrence() : KCal::Recurrence(), mFeb29Type(FEB29_FEB29), mCachedType(-1) { } 00052 KARecurrence(const KCal::Recurrence& r) : KCal::Recurrence(r) { fix(); } 00053 KARecurrence(const KARecurrence& r) : KCal::Recurrence(r), mFeb29Type(r.mFeb29Type), mCachedType(r.mCachedType) { } 00054 bool set(const TQString& icalRRULE); 00055 bool set(Type t, int freq, int count, const DateTime& start, const TQDateTime& end) 00056 { return set(t, freq, count, -1, start, end); } 00057 bool set(Type t, int freq, int count, const DateTime& start, const TQDateTime& end, Feb29Type f29) 00058 { return set(t, freq, count, f29, start, end); } 00059 bool init(KCal::RecurrenceRule::PeriodType t, int freq, int count, const DateTime& start, const TQDateTime& end) 00060 { return init(t, freq, count, -1, start, end); } 00061 bool init(KCal::RecurrenceRule::PeriodType t, int freq, int count, const DateTime& start, const TQDateTime& end, Feb29Type f29) 00062 { return init(t, freq, count, f29, start, end); } 00063 void fix(); 00064 void writeRecurrence(KCal::Recurrence&) const; 00065 TQDateTime endDateTime() const; 00066 TQDate endDate() const; 00067 bool recursOn(const TQDate&) const; 00068 TQDateTime getNextDateTime(const TQDateTime& preDateTime) const; 00069 TQDateTime getPreviousDateTime(const TQDateTime& afterDateTime) const; 00070 int longestInterval() const; 00071 Type type() const; 00072 static Type type(const KCal::RecurrenceRule*); 00073 static bool dailyType(const KCal::RecurrenceRule*); 00074 Feb29Type feb29Type() const { return mFeb29Type; } 00075 static Feb29Type defaultFeb29Type() { return mDefaultFeb29; } 00076 static void setDefaultFeb29Type(Feb29Type t) { mDefaultFeb29 = t; } 00077 00078 private: 00079 bool set(Type, int freq, int count, int feb29Type, const DateTime& start, const TQDateTime& end); 00080 bool init(KCal::RecurrenceRule::PeriodType, int freq, int count, int feb29Type, const DateTime& start, const TQDateTime& end); 00081 int combineDurations(const KCal::RecurrenceRule*, const KCal::RecurrenceRule*, TQDate& end) const; 00082 int longestWeeklyInterval(const TQBitArray& days, int frequency); 00083 00084 static Feb29Type mDefaultFeb29; 00085 Feb29Type mFeb29Type; // yearly recurrence on Feb 29th (leap years) / Mar 1st (non-leap years) 00086 mutable int mCachedType; 00087 }; 00088 00089 #endif // KARECURRENCE_H