KCalendarCore

recurrencerule.h
1/*
2 This file is part of the kcalcore library.
3
4 SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org>
5 SPDX-FileCopyrightText: 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
6 SPDX-FileCopyrightText: 2002, 2006, 2007 David Jarvie <djarvie@kde.org>
7 SPDX-FileCopyrightText: 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11#ifndef KCALCORE_RECURRENCERULE_H
12#define KCALCORE_RECURRENCERULE_H
13
14#include "kcalendarcore_export.h"
15
16#include <QDateTime>
17#include <QTimeZone>
18
19class QTimeZone;
20
21namespace KCalendarCore
22{
23// These two are duplicates wrt. incidencebase.h
25/* List of times */
26typedef QList<QTime> TimeList;
27
28/**
29 This class represents a recurrence rule for a calendar incidence.
30*/
31class KCALENDARCORE_EXPORT RecurrenceRule
32{
33public:
34 class RuleObserver
35 {
36 public:
37 virtual ~RuleObserver();
38 /** This method is called on each change of the recurrence object */
39 virtual void recurrenceChanged(RecurrenceRule *) = 0;
40 };
42
43 /** enum for describing the frequency how an event recurs, if at all. */
45 rNone = 0,
46 rSecondly,
47 rMinutely,
48 rHourly,
49 rDaily,
50 rWeekly,
51 rMonthly,
52 rYearly,
53 };
54
55 /** structure for describing the n-th weekday of the month/year. */
56 class KCALENDARCORE_EXPORT WDayPos // krazy:exclude=dpointer
57 {
58 public:
59 explicit WDayPos(int ps = 0, short dy = 0);
60 void setDay(short dy);
61 short day() const;
62 void setPos(int ps);
63 int pos() const;
64
65 bool operator==(const RecurrenceRule::WDayPos &pos2) const;
66 bool operator!=(const RecurrenceRule::WDayPos &pos2) const;
67
68 protected:
69 short mDay; // Weekday, 1=monday, 7=sunday
70 int mPos; // week of the day (-1 for last, 1 for first, 0 for all weeks)
71 // Bounded by -366 and +366, 0 means all weeks in that period
72
73 friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalendarCore::RecurrenceRule::WDayPos &);
75 };
76
80
81 bool operator==(const RecurrenceRule &r) const;
82 bool operator!=(const RecurrenceRule &r) const
83 {
84 return !operator==(r);
85 }
86
87 RecurrenceRule &operator=(const RecurrenceRule &r);
88
89 /** Set if recurrence is read-only or can be changed. */
90 void setReadOnly(bool readOnly);
91
92 /**
93 Returns true if the recurrence is read-only; false if it can be changed.
94 */
95 Q_REQUIRED_RESULT bool isReadOnly() const;
96
97 /**
98 Returns the event's recurrence status. See the enumeration at the top
99 of this file for possible values.
100 */
101 Q_REQUIRED_RESULT bool recurs() const;
102 void setRecurrenceType(PeriodType period);
103 Q_REQUIRED_RESULT PeriodType recurrenceType() const;
104
105 /** Turns off recurrence for the event. */
106 void clear();
107
108 /**
109 Returns the recurrence frequency, in terms of the recurrence time period type.
110 */
111 Q_REQUIRED_RESULT uint frequency() const;
112
113 /**
114 Sets the recurrence frequency, in terms of the recurrence time period type.
115 */
116 void setFrequency(int freq);
117
118 /**
119 Returns the recurrence start date/time.
120 Note that the recurrence does not necessarily occur on the start date/time.
121 For this to happen, it must actually match the rule.
122 */
123 Q_REQUIRED_RESULT QDateTime startDt() const;
124
125 /**
126 Sets the recurrence start date/time.
127 Note that setting the start date/time does not make the recurrence occur
128 on that date/time, it simply sets a lower limit to when the recurrences
129 take place (this applies only for the by- rules, not for i.e. an hourly
130 rule where the startDt is the first occurrence).
131
132 Note that setting @p start to a date-only value does not make an all-day
133 recurrence: to do this, call setAllDay(true).
134
135 @param start the recurrence's start date and time
136 */
137 void setStartDt(const QDateTime &start);
138
139 /** Returns whether the start date has no time associated. All-Day
140 means -- according to rfc2445 -- that the event has no time associate. */
141 Q_REQUIRED_RESULT bool allDay() const;
142
143 /** Sets whether the dtstart is all-day (i.e. has no time attached)
144 *
145 * @param allDay Whether start datetime is all-day
146 */
147 void setAllDay(bool allDay);
148
149 /** Returns the date and time of the last recurrence.
150 * An invalid date is returned if the recurrence has no end.
151 * @param result if non-null, *result is updated to true if successful,
152 * or false if there is no recurrence or its end date cannot be determined.
153 */
154 Q_REQUIRED_RESULT QDateTime endDt(bool *result = nullptr) const;
155
156 /** Sets the date and time of the last recurrence.
157 * @param endDateTime the ending date/time after which to stop recurring. */
158 void setEndDt(const QDateTime &endDateTime);
159
160 /**
161 * Returns -1 if the event recurs infinitely, 0 if the end date is set,
162 * otherwise the total number of recurrences, including the initial occurrence.
163 */
164 Q_REQUIRED_RESULT int duration() const;
165
166 /** Sets the total number of times the event is to occur, including both the
167 * first and last. */
168 void setDuration(int duration);
169
170 /** Returns the number of recurrences up to and including the date/time specified. */
171 Q_REQUIRED_RESULT int durationTo(const QDateTime &dt) const;
172
173 /** Returns the number of recurrences up to and including the date specified. */
174 Q_REQUIRED_RESULT int durationTo(const QDate &date) const;
175
176 /**
177 Shift the times of the rule so that they appear at the same clock
178 time as before but in a new time zone. The shift is done from a viewing
179 time zone rather than from the actual rule time zone.
180
181 For example, shifting a rule whose start time is 09:00 America/New York,
182 using an old viewing time zone (@p oldTz) of Europe/London, to a new time
183 zone (@p newTz) of Europe/Paris, will result in the time being shifted
184 from 14:00 (which is the London time of the rule start) to 14:00 Paris
185 time.
186
187 @param oldTz the time specification which provides the clock times
188 @param newTz the new time specification
189 */
190 void shiftTimes(const QTimeZone &oldTz, const QTimeZone &newTz);
191
192 /** Returns true if the date specified is one on which the event will
193 * recur. The start date returns true only if it actually matches the rule.
194 *
195 * @param date date to check
196 * @param timeZone time specification for @p date
197 */
198 Q_REQUIRED_RESULT bool recursOn(const QDate &date, const QTimeZone &timeZone) const;
199
200 /** Returns true if the date/time specified is one at which the event will
201 * recur. Times are rounded down to the nearest minute to determine the result.
202 * The start date/time returns true only if it actually matches the rule.
203 *
204 * @param dt the date+time to check for recurrency
205 */
206 Q_REQUIRED_RESULT bool recursAt(const QDateTime &dt) const;
207
208 /** Returns true if the date matches the rules. It does not necessarily
209 mean that this is an actual occurrence. In particular, the method does
210 not check if the date is after the end date, or if the frequency interval
211 matches.
212
213 @param dt the date+time to check for matching the rules
214 */
215 Q_REQUIRED_RESULT bool dateMatchesRules(const QDateTime &dt) const;
216
217 /** Returns a list of the times on the specified date at which the
218 * recurrence will occur. The returned times should be interpreted in the
219 * context of @p timeZone.
220 * @param date the date for which to find the recurrence times
221 * @param timeZone time specification for @p date
222 */
223 Q_REQUIRED_RESULT TimeList recurTimesOn(const QDate &date, const QTimeZone &timeZone) const;
224
225 /** Returns a list of all the times at which the recurrence will occur
226 * between two specified times.
227 *
228 * There is a (large) maximum limit to the number of times returned. If due to
229 * this limit the list is incomplete, this is indicated by the last entry being
230 * set to an invalid QDateTime value. If you need further values, call the
231 * method again with a start time set to just after the last valid time returned.
232 * @param start inclusive start of interval
233 * @param end inclusive end of interval
234 * @return list of date/time values
235 */
236 Q_REQUIRED_RESULT QList<QDateTime> timesInInterval(const QDateTime &start, const QDateTime &end) const;
237
238 /** Returns the date and time of the next recurrence, after the specified date/time.
239 * If the recurrence has no time, the next date after the specified date is returned.
240 * @param preDateTime the date/time after which to find the recurrence.
241 * @return date/time of next recurrence, or invalid date if none.
242 */
243 Q_REQUIRED_RESULT QDateTime getNextDate(const QDateTime &preDateTime) const;
244
245 /** Returns the date and time of the last previous recurrence, before the specified date/time.
246 * If a time later than 00:00:00 is specified and the recurrence has no time, 00:00:00 on
247 * the specified date is returned if that date recurs.
248 * @param afterDateTime the date/time before which to find the recurrence.
249 * @return date/time of previous recurrence, or invalid date if none.
250 */
251 Q_REQUIRED_RESULT QDateTime getPreviousDate(const QDateTime &afterDateTime) const;
252
253 void setBySeconds(const QList<int> &bySeconds);
254 void setByMinutes(const QList<int> &byMinutes);
255 void setByHours(const QList<int> &byHours);
256
257 void setByDays(const QList<WDayPos> &byDays);
258 void setByMonthDays(const QList<int> &byMonthDays);
259 void setByYearDays(const QList<int> &byYearDays);
260 void setByWeekNumbers(const QList<int> &byWeekNumbers);
261 void setByMonths(const QList<int> &byMonths);
262 void setBySetPos(const QList<int> &bySetPos);
263 void setWeekStart(short weekStart);
264
265 const QList<int> &bySeconds() const;
266 const QList<int> &byMinutes() const;
267 const QList<int> &byHours() const;
268
269 const QList<WDayPos> &byDays() const;
270 const QList<int> &byMonthDays() const;
271 const QList<int> &byYearDays() const;
272 const QList<int> &byWeekNumbers() const;
273 const QList<int> &byMonths() const;
274 const QList<int> &bySetPos() const;
275 short weekStart() const;
276
277 /**
278 Set the RRULE string for the rule.
279 This is merely stored for future reference. The string is not used in any way
280 by the RecurrenceRule.
281
282 @param rrule the RRULE string
283 */
284 void setRRule(const QString &rrule);
285 Q_REQUIRED_RESULT QString rrule() const;
286
287 void setDirty();
288 /**
289 Installs an observer. Whenever some setting of this recurrence
290 object is changed, the recurrenceUpdated( Recurrence* ) method
291 of each observer will be called to inform it of changes.
292 @param observer the Recurrence::Observer-derived object, which
293 will be installed as an observer of this object.
294 */
295 void addObserver(RuleObserver *observer);
296
297 /**
298 Removes an observer that was added with addObserver. If the
299 given object was not an observer, it does nothing.
300 @param observer the Recurrence::Observer-derived object to
301 be removed from the list of observers of this object.
302 */
303 void removeObserver(RuleObserver *observer);
304
305 /**
306 Debug output.
307 */
308 void dump() const;
309
310private:
311 //@cond PRIVATE
312 class Private;
313 Private *const d;
314 //@endcond
315
316 friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalendarCore::RecurrenceRule *);
317 friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &in, const KCalendarCore::RecurrenceRule *);
318};
319
320/**
321 * RecurrenceRule serializer and deserializer.
322 * @since 4.12
323 */
324KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalendarCore::RecurrenceRule *);
325KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &in, const KCalendarCore::RecurrenceRule *);
326
327/**
328 * RecurrenceRule::WDayPos serializer and deserializer.
329 * @since 4.12
330 */
333}
334
335Q_DECLARE_TYPEINFO(KCalendarCore::RecurrenceRule::WDayPos, Q_RELOCATABLE_TYPE);
336
337#endif
structure for describing the n-th weekday of the month/year.
friend KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::RecurrenceRule::WDayPos &)
RecurrenceRule::WDayPos serializer and deserializer.
This class represents a recurrence rule for a calendar incidence.
PeriodType
enum for describing the frequency how an event recurs, if at all.
friend KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::RecurrenceRule *)
RecurrenceRule serializer and deserializer.
Q_SCRIPTABLE Q_NOREPLY void start()
Namespace for all KCalendarCore types.
Definition alarm.h:37
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition alarm.cpp:833
QList< QDate > DateList
List of dates.
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition alarm.cpp:820
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:39:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.