kalarm

karecurrence.h
1/*
2 * karecurrence.h - recurrence with special yearly February 29th handling
3 * Program: kalarm
4 * Copyright © 2005,2006 by David Jarvie <software@astrojar.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef KARECURRENCE_H
22#define KARECURRENCE_H
23
24#include <libkcal/recurrence.h>
25class DateTime;
26
27
28class KARecurrence : public KCal::Recurrence
29{
30 public:
34 enum Type {
35 NO_RECUR, // does not recur
36 MINUTELY, // at an hours/minutes interval
37 DAILY, // daily
38 WEEKLY, // weekly, on specified weekdays
39 MONTHLY_POS, // monthly, on specified weekdays in a specified week of the month
40 MONTHLY_DAY, // monthly, on a specified day of the month
41 ANNUAL_DATE, // yearly, on a specified date in each of the specified months
42 ANNUAL_POS // yearly, on specified weekdays in the specified weeks of the specified months
43 };
45 enum Feb29Type {
46 FEB29_FEB29, // February 29th recurrences are omitted in non-leap years
47 FEB29_MAR1, // February 29th recurrences are on March 1st in non-leap years
48 FEB29_FEB28 // February 29th recurrences are on February 28th in non-leap years
49 };
50
51 KARecurrence() : KCal::Recurrence(), mFeb29Type(FEB29_FEB29), mCachedType(-1) { }
52 KARecurrence(const KCal::Recurrence& r) : KCal::Recurrence(r) { fix(); }
53 KARecurrence(const KARecurrence& r) : KCal::Recurrence(r), mFeb29Type(r.mFeb29Type), mCachedType(r.mCachedType) { }
54 bool set(const TQString& icalRRULE);
55 bool set(Type t, int freq, int count, const DateTime& start, const TQDateTime& end)
56 { return set(t, freq, count, -1, start, end); }
57 bool set(Type t, int freq, int count, const DateTime& start, const TQDateTime& end, Feb29Type f29)
58 { return set(t, freq, count, f29, start, end); }
59 bool init(KCal::RecurrenceRule::PeriodType t, int freq, int count, const DateTime& start, const TQDateTime& end)
60 { return init(t, freq, count, -1, start, end); }
61 bool init(KCal::RecurrenceRule::PeriodType t, int freq, int count, const DateTime& start, const TQDateTime& end, Feb29Type f29)
62 { return init(t, freq, count, f29, start, end); }
63 void fix();
64 void writeRecurrence(KCal::Recurrence&) const;
65 TQDateTime endDateTime() const;
66 TQDate endDate() const;
67 bool recursOn(const TQDate&) const;
68 TQDateTime getNextDateTime(const TQDateTime& preDateTime) const;
69 TQDateTime getPreviousDateTime(const TQDateTime& afterDateTime) const;
70 int longestInterval() const;
71 Type type() const;
72 static Type type(const KCal::RecurrenceRule*);
73 static bool dailyType(const KCal::RecurrenceRule*);
74 Feb29Type feb29Type() const { return mFeb29Type; }
75 static Feb29Type defaultFeb29Type() { return mDefaultFeb29; }
76 static void setDefaultFeb29Type(Feb29Type t) { mDefaultFeb29 = t; }
77
78 private:
79 bool set(Type, int freq, int count, int feb29Type, const DateTime& start, const TQDateTime& end);
80 bool init(KCal::RecurrenceRule::PeriodType, int freq, int count, int feb29Type, const DateTime& start, const TQDateTime& end);
81 int combineDurations(const KCal::RecurrenceRule*, const KCal::RecurrenceRule*, TQDate& end) const;
82 int longestWeeklyInterval(const TQBitArray& days, int frequency);
83
84 static Feb29Type mDefaultFeb29;
85 Feb29Type mFeb29Type; // yearly recurrence on Feb 29th (leap years) / Mar 1st (non-leap years)
86 mutable int mCachedType;
87};
88
89#endif // KARECURRENCE_H