summaryrefslogtreecommitdiffabout
path: root/libkcal/recurrence.h
Unidiff
Diffstat (limited to 'libkcal/recurrence.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/recurrence.h26
1 files changed, 14 insertions, 12 deletions
diff --git a/libkcal/recurrence.h b/libkcal/recurrence.h
index b13d14f..5b5aab1 100644
--- a/libkcal/recurrence.h
+++ b/libkcal/recurrence.h
@@ -3,49 +3,51 @@
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> 5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_RECURRENCE_H 22#ifndef KCAL_RECURRENCE_H
23#define KCAL_RECURRENCE_H 23#define KCAL_RECURRENCE_H
24 24
25#include <qstring.h> 25#include <qstring.h>
26#include <qbitarray.h> 26#include <qbitarray.h>
27#include <qptrlist.h> 27#include <q3ptrlist.h>
28//Added by qt3to4:
29#include <Q3ValueList>
28 30
29namespace KCal { 31namespace KCal {
30 32
31class Incidence; 33class Incidence;
32 34
33/** 35/**
34 This class represents a recurrence rule for a calendar incidence. 36 This class represents a recurrence rule for a calendar incidence.
35*/ 37*/
36class Recurrence 38class Recurrence
37{ 39{
38 public: 40 public:
39 /** enumeration for describing how an event recurs, if at all. */ 41 /** enumeration for describing how an event recurs, if at all. */
40 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003, 42 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003,
41 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006, 43 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006,
42 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 }; 44 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 };
43 45
44 /** Enumeration for specifying what date yearly recurrences of February 29th occur 46 /** Enumeration for specifying what date yearly recurrences of February 29th occur
45 * in non-leap years. */ 47 * in non-leap years. */
46 enum Feb29Type { 48 enum Feb29Type {
47 rMar1, // recur on March 1st (default) 49 rMar1, // recur on March 1st (default)
48 rFeb28, // recur on February 28th 50 rFeb28, // recur on February 28th
49 rFeb29 // only recur on February 29th, i.e. don't recur in non-leap years 51 rFeb29 // only recur on February 29th, i.e. don't recur in non-leap years
50 }; 52 };
51 53
@@ -227,96 +229,96 @@ class Recurrence
227 const QBitArray &days() const; 229 const QBitArray &days() const;
228 230
229 /** Sets an event to recur monthly. 231 /** Sets an event to recur monthly.
230 * @var type rMonthlyPos or rMonthlyDay 232 * @var type rMonthlyPos or rMonthlyDay
231 * @var _rFreq the frequency to recur, e.g. 3 for every third month. 233 * @var _rFreq the frequency to recur, e.g. 3 for every third month.
232 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 234 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
233 */ 235 */
234 void setMonthly(short type, int _rFreq, int duration); 236 void setMonthly(short type, int _rFreq, int duration);
235 /** same as above, but with ending date not number of recurrences */ 237 /** same as above, but with ending date not number of recurrences */
236 void setMonthly(short type, int _rFreq, const QDate &endDate); 238 void setMonthly(short type, int _rFreq, const QDate &endDate);
237 /** Adds a position to the recursMonthlyPos recurrence rule, if it is 239 /** Adds a position to the recursMonthlyPos recurrence rule, if it is
238 * set. 240 * set.
239 * @var _rPos the position in the month for the recurrence, with valid 241 * @var _rPos the position in the month for the recurrence, with valid
240 * values being 1-5 (5 weeks max in a month). 242 * values being 1-5 (5 weeks max in a month).
241 * @var _rDays the days for the position to recur on (bit 0 = Monday). 243 * @var _rDays the days for the position to recur on (bit 0 = Monday).
242 * Example: _rPos = 2, and bits 0 and 2 are set in _rDays: 244 * Example: _rPos = 2, and bits 0 and 2 are set in _rDays:
243 * the rule is to repeat every 2nd Monday and Wednesday in the month. 245 * the rule is to repeat every 2nd Monday and Wednesday in the month.
244 */ 246 */
245 void addMonthlyPos(short _rPos, const QBitArray &_rDays); 247 void addMonthlyPos(short _rPos, const QBitArray &_rDays);
246 /** Adds a position the the recursMonthlyDay list. 248 /** Adds a position the the recursMonthlyDay list.
247 * @var _rDay the date in the month to recur. 249 * @var _rDay the date in the month to recur.
248 */ 250 */
249 void addMonthlyDay(short _rDay); 251 void addMonthlyDay(short _rDay);
250 /** Returns list of day positions in months. */ 252 /** Returns list of day positions in months. */
251 const QPtrList<rMonthPos> &monthPositions() const; 253 const Q3PtrList<rMonthPos> &monthPositions() const;
252 /** Returns list of day numbers of a month. */ 254 /** Returns list of day numbers of a month. */
253 const QPtrList<int> &monthDays() const; 255 const Q3PtrList<int> &monthDays() const;
254 256
255 /** Sets an event to recur yearly. 257 /** Sets an event to recur yearly.
256 * @var type rYearlyMonth, rYearlyPos or rYearlyDay 258 * @var type rYearlyMonth, rYearlyPos or rYearlyDay
257 * @var freq the frequency to recur, e.g. 3 for every third year. 259 * @var freq the frequency to recur, e.g. 3 for every third year.
258 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 260 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
259 */ 261 */
260 void setYearly(int type, int freq, int duration); 262 void setYearly(int type, int freq, int duration);
261 /** Sets an event to recur yearly ending at \a endDate. */ 263 /** Sets an event to recur yearly ending at \a endDate. */
262 void setYearly(int type, int freq, const QDate &endDate); 264 void setYearly(int type, int freq, const QDate &endDate);
263 /** Sets an event to recur yearly on specified dates. 265 /** Sets an event to recur yearly on specified dates.
264 * The dates must be specified by calling addYearlyNum(). 266 * The dates must be specified by calling addYearlyNum().
265 * @var type the way recurrences of February 29th are to be handled in non-leap years. 267 * @var type the way recurrences of February 29th are to be handled in non-leap years.
266 * @var freq the frequency to recur, e.g. 3 for every third year. 268 * @var freq the frequency to recur, e.g. 3 for every third year.
267 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 269 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
268 */ 270 */
269 void setYearlyByDate(Feb29Type type, int freq, int duration); 271 void setYearlyByDate(Feb29Type type, int freq, int duration);
270 /** Sets an event to recur yearly ending at \a endDate. */ 272 /** Sets an event to recur yearly ending at \a endDate. */
271 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate); 273 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate);
272 /** Adds position of day or month in year. 274 /** Adds position of day or month in year.
273 * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called 275 * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called
274 * to add positions within the month. */ 276 * to add positions within the month. */
275 void addYearlyNum(short _rNum); 277 void addYearlyNum(short _rNum);
276 /** Adds a position to the recursYearlyPos recurrence rule, if it is set. 278 /** Adds a position to the recursYearlyPos recurrence rule, if it is set.
277 * N.B. addYearlyNum() must also be called to add recurrence months. 279 * N.B. addYearlyNum() must also be called to add recurrence months.
278 * Parameters are the same as for addMonthlyPos(). 280 * Parameters are the same as for addMonthlyPos().
279 */ 281 */
280 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays); 282 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
281 /** Returns positions of days or months in year. */ 283 /** Returns positions of days or months in year. */
282 const QPtrList<int> &yearNums() const; 284 const Q3PtrList<int> &yearNums() const;
283 /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */ 285 /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */
284 const QPtrList<rMonthPos> &yearMonthPositions() const; 286 const Q3PtrList<rMonthPos> &yearMonthPositions() const;
285 /** Returns how yearly recurrences of February 29th are handled. */ 287 /** Returns how yearly recurrences of February 29th are handled. */
286 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; } 288 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; }
287 /** Sets the default method for handling yearly recurrences of February 29th. */ 289 /** Sets the default method for handling yearly recurrences of February 29th. */
288 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; } 290 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; }
289 /** Returns the default method for handling yearly recurrences of February 29th. */ 291 /** Returns the default method for handling yearly recurrences of February 29th. */
290 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; } 292 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; }
291 void addYearlyMonth(short _rPos ); // added LR 293 void addYearlyMonth(short _rPos ); // added LR
292 /** 294 /**
293 Debug output. 295 Debug output.
294 */ 296 */
295 void dump() const; 297 void dump() const;
296 QString recurrenceText() const; 298 QString recurrenceText() const;
297 bool getYearlyMonthMonths(int day, QValueList<int>&, 299 bool getYearlyMonthMonths(int day, Q3ValueList<int>&,
298 QValueList<int> &leaplist) const; 300 Q3ValueList<int> &leaplist) const;
299 301
300 protected: 302 protected:
301 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE }; 303 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
302 struct MonthlyData; friend struct MonthlyData; 304 struct MonthlyData; friend struct MonthlyData;
303 struct YearlyMonthData; friend struct YearlyMonthData; 305 struct YearlyMonthData; friend struct YearlyMonthData;
304 struct YearlyPosData; friend struct YearlyPosData; 306 struct YearlyPosData; friend struct YearlyPosData;
305 struct YearlyDayData; friend struct YearlyDayData; 307 struct YearlyDayData; friend struct YearlyDayData;
306 308
307 bool recursSecondly(const QDate &, int secondFreq) const; 309 bool recursSecondly(const QDate &, int secondFreq) const;
308 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const; 310 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
309 bool recursDaily(const QDate &) const; 311 bool recursDaily(const QDate &) const;
310 bool recursWeekly(const QDate &) const; 312 bool recursWeekly(const QDate &) const;
311 bool recursMonthly(const QDate &) const; 313 bool recursMonthly(const QDate &) const;
312 bool recursYearlyByMonth(const QDate &) const; 314 bool recursYearlyByMonth(const QDate &) const;
313 bool recursYearlyByPos(const QDate &) const; 315 bool recursYearlyByPos(const QDate &) const;
314 bool recursYearlyByDay(const QDate &) const; 316 bool recursYearlyByDay(const QDate &) const;
315 317
316 QDate getNextDateNoTime(const QDate& preDate, bool* last) const; 318 QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
317 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const; 319 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
318 320
319 void addMonthlyPos_(short _rPos, const QBitArray &_rDays); 321 void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
320 void setDailySub(short type, int freq, int duration); 322 void setDailySub(short type, int freq, int duration);
321 void setYearly_(short type, Feb29Type, int freq, int duration); 323 void setYearly_(short type, Feb29Type, int freq, int duration);
322 int recurCalc(PeriodFunc, QDate &enddate) const; 324 int recurCalc(PeriodFunc, QDate &enddate) const;
@@ -324,76 +326,76 @@ class Recurrence
324 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const; 326 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const;
325 int dailyCalc(PeriodFunc, QDate &enddate) const; 327 int dailyCalc(PeriodFunc, QDate &enddate) const;
326 int weeklyCalc(PeriodFunc, QDate &enddate) const; 328 int weeklyCalc(PeriodFunc, QDate &enddate) const;
327 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const; 329 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
328 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const; 330 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
329 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const; 331 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
330 int monthlyCalc(PeriodFunc, QDate &enddate) const; 332 int monthlyCalc(PeriodFunc, QDate &enddate) const;
331 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const; 333 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
332 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const; 334 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
333 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const; 335 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
334 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const; 336 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
335 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const; 337 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
336 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const; 338 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
337 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const; 339 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
338 int yearlyPosCalc(PeriodFunc, QDate &enddate) const; 340 int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
339 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const; 341 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
340 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const; 342 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
341 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const; 343 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
342 int yearlyDayCalc(PeriodFunc, QDate &enddate) const; 344 int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
343 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const; 345 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
344 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const; 346 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
345 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const; 347 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
346 348
347 int countMonthlyPosDays() const; 349 int countMonthlyPosDays() const;
348 void getMonthlyPosDays(QValueList<int>&, int daysInMonth, 350 void getMonthlyPosDays(Q3ValueList<int>&, int daysInMonth,
349 int startDayOfWeek) const; 351 int startDayOfWeek) const;
350 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const; 352 bool getMonthlyDayDays(Q3ValueList<int>&, int daysInMonth) const;
351 353
352 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const; 354 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
353 int getLastDayInWeek(int endDay, bool useWeekStart = true) const; 355 int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
354 QDate getFirstDateInMonth(const QDate& earliestDate) const; 356 QDate getFirstDateInMonth(const QDate& earliestDate) const;
355 QDate getLastDateInMonth(const QDate& latestDate) const; 357 QDate getLastDateInMonth(const QDate& latestDate) const;
356 QDate getFirstDateInYear(const QDate& earliestDate) const; 358 QDate getFirstDateInYear(const QDate& earliestDate) const;
357 QDate getLastDateInYear(const QDate& latestDate) const; 359 QDate getLastDateInYear(const QDate& latestDate) const;
358 360
359 private: 361 private:
360 // Prohibit copying 362 // Prohibit copying
361 Recurrence(const Recurrence&); 363 Recurrence(const Recurrence&);
362 Recurrence &operator=(const Recurrence&); 364 Recurrence &operator=(const Recurrence&);
363 365
364 short recurs; // should be one of the enums. 366 short recurs; // should be one of the enums.
365 367
366 int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7 368 int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7
367 QBitArray rDays; // array of days during week it recurs 369 QBitArray rDays; // array of days during week it recurs
368 370
369 QPtrList<rMonthPos> rMonthPositions; // list of positions during a month 371 Q3PtrList<rMonthPos> rMonthPositions; // list of positions during a month
370 // on which an event recurs 372 // on which an event recurs
371 373
372 QPtrList<int> rMonthDays; // list of days during a month on 374 Q3PtrList<int> rMonthDays; // list of days during a month on
373 // which the event recurs 375 // which the event recurs
374 376
375 QPtrList<int> rYearNums; // either months/days to recur on for rYearly, 377 Q3PtrList<int> rYearNums; // either months/days to recur on for rYearly,
376 // sorted in numerical order 378 // sorted in numerical order
377 379
378 int rFreq; // frequency of period 380 int rFreq; // frequency of period
379 381
380 // one of the following must be specified 382 // one of the following must be specified
381 int rDuration; // num times to recur (inc. first occurrence), -1 = infinite 383 int rDuration; // num times to recur (inc. first occurrence), -1 = infinite
382 QDateTime rEndDateTime; // date/time at which to end recurrence 384 QDateTime rEndDateTime; // date/time at which to end recurrence
383 385
384 QDateTime mRecurStart; // date/time of first recurrence 386 QDateTime mRecurStart; // date/time of first recurrence
385 bool mFloats; // the recurrence has no time, just a date 387 bool mFloats; // the recurrence has no time, just a date
386 bool mRecurReadOnly; 388 bool mRecurReadOnly;
387 int mRecurExDatesCount; // number of recurrences (in addition to rDuration) which are excluded 389 int mRecurExDatesCount; // number of recurrences (in addition to rDuration) which are excluded
388 Feb29Type mFeb29YearlyType; // how to handle yearly recurrences of February 29th 390 Feb29Type mFeb29YearlyType; // how to handle yearly recurrences of February 29th
389 static Feb29Type mFeb29YearlyDefaultType; // default value for mFeb29YearlyType 391 static Feb29Type mFeb29YearlyDefaultType; // default value for mFeb29YearlyType
390 392
391 // Backwards compatibility for KDE < 3.1. 393 // Backwards compatibility for KDE < 3.1.
392 int mCompatVersion; // calendar file version for backwards compatibility 394 int mCompatVersion; // calendar file version for backwards compatibility
393 short mCompatRecurs; // original 'recurs' in old calendar format, or rNone 395 short mCompatRecurs; // original 'recurs' in old calendar format, or rNone
394 int mCompatDuration; // original 'rDuration' in old calendar format, or 0 396 int mCompatDuration; // original 'rDuration' in old calendar format, or 0
395 397
396 Incidence *mParent; 398 Incidence *mParent;
397}; 399};
398 400
399} 401}