KCalendarCore

memorycalendar.h
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  SPDX-FileCopyrightText: 1998 Preston Brown <[email protected]>
5  SPDX-FileCopyrightText: 2001, 2003 Cornelius Schumacher <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 /**
10  @file
11  This file is part of the API for handling calendar data and
12  defines the MemoryCalendar class.
13 
14  Very simple implementation of a Calendar that is only in memory
15 
16  @author Preston Brown <[email protected]>
17  @author Cornelius Schumacher <[email protected]>
18  */
19 #ifndef KCALCORE_MEMORYCALENDAR_H
20 #define KCALCORE_MEMORYCALENDAR_H
21 
22 #include "calendar.h"
23 #include "kcalendarcore_export.h"
24 
25 namespace KCalendarCore
26 {
27 /**
28  @brief
29  This class provides a calendar stored in memory.
30 */
31 class KCALENDARCORE_EXPORT MemoryCalendar : public Calendar
32 {
33  Q_OBJECT
34 public:
35  /**
36  A shared pointer to a MemoryCalendar
37  */
39 
40  /**
41  @copydoc Calendar::Calendar(const QTimeZone &)
42  */
43  explicit MemoryCalendar(const QTimeZone &timeZone);
44 
45  /**
46  @copydoc Calendar::Calendar(const QString &)
47  */
48  explicit MemoryCalendar(const QByteArray &timeZoneId);
49 
50  /**
51  @copydoc Calendar::~Calendar()
52  */
53  ~MemoryCalendar() override;
54 
55  /**
56  Clears out the current calendar, freeing all used memory etc. etc.
57  */
58  void close() override;
59 
60  /**
61  @copydoc Calendar::doSetTimeZone()
62  */
63  void doSetTimeZone(const QTimeZone &timeZone) override;
64 
65  /**
66  @copydoc Calendar::deleteIncidence()
67  */
68  bool deleteIncidence(const Incidence::Ptr &incidence) override;
69 
70  /**
71  @copydoc Calendar::deleteIncidenceInstances
72  */
73  bool deleteIncidenceInstances(const Incidence::Ptr &incidence) override;
74 
75  /**
76  @copydoc Calendar::addIncidence()
77  */
78  bool addIncidence(const Incidence::Ptr &incidence) override;
79 
80  // Event Specific Methods //
81 
82  /**
83  @copydoc Calendar::addEvent()
84  */
85  bool addEvent(const Event::Ptr &event) override;
86 
87  /**
88  @copydoc Calendar::deleteEvent()
89  */
90  bool deleteEvent(const Event::Ptr &event) override;
91 
92  /**
93  @copydoc Calendar::deleteEventInstances()
94  */
95  bool deleteEventInstances(const Event::Ptr &event) override;
96 
97  /**
98  @copydoc Calendar::rawEvents(EventSortField, SortDirection)const
99  */
100  Q_REQUIRED_RESULT Event::List rawEvents(EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
101 
102  /**
103  @copydoc Calendar::rawEvents(const QDate &, const QDate &, const QTimeZone &, bool)const
104  */
105  Q_REQUIRED_RESULT Event::List rawEvents(const QDate &start, const QDate &end, const QTimeZone &timeZone = {}, bool inclusive = false) const override;
106 
107  /**
108  Returns an unfiltered list of all Events which occur on the given date.
109 
110  @param date request unfiltered Event list for this QDate only.
111  @param timeZone time zone to interpret @p date, or the calendar's
112  default time zone if none is specified
113  @param sortField specifies the EventSortField.
114  @param sortDirection specifies the SortDirection.
115 
116  @return the list of unfiltered Events occurring on the specified QDate.
117  */
118  Q_REQUIRED_RESULT Event::List rawEventsForDate(const QDate &date,
119  const QTimeZone &timeZone = {},
120  EventSortField sortField = EventSortUnsorted,
121  SortDirection sortDirection = SortDirectionAscending) const override;
122 
123 #if KCALENDARCORE_BUILD_DEPRECATED_SINCE(5, 95)
124  /**
125  @copydoc Calendar::rawEventsForDate(const QDateTime &)const
126  */
127  Q_REQUIRED_RESULT Event::List rawEventsForDate(const QDateTime &dt) const override;
128 #endif
129 
130  /**
131  * Returns an incidence by identifier.
132  * @see Incidence::instanceIdentifier()
133  * @since 4.11
134  */
135  Incidence::Ptr instance(const QString &identifier) const;
136 
137  /**
138  @copydoc Calendar::event()
139  */
140  Q_REQUIRED_RESULT Event::Ptr event(const QString &uid, const QDateTime &recurrenceId = {}) const override;
141 
142  /**
143  @copydoc Calendar::deletedEvent()
144  */
145  Q_REQUIRED_RESULT Event::Ptr deletedEvent(const QString &uid, const QDateTime &recurrenceId = {}) const override;
146 
147  /**
148  @copydoc Calendar::deletedEvents(EventSortField, SortDirection)const
149  */
150  Q_REQUIRED_RESULT Event::List deletedEvents(EventSortField sortField = EventSortUnsorted,
151  SortDirection sortDirection = SortDirectionAscending) const override;
152 
153  /**
154  @copydoc Calendar::eventInstances(const Incidence::Ptr &, EventSortField, SortDirection)const
155  */
156  Q_REQUIRED_RESULT Event::List eventInstances(const Incidence::Ptr &event,
157  EventSortField sortField = EventSortUnsorted,
158  SortDirection sortDirection = SortDirectionAscending) const override;
159 
160  // To-do Specific Methods //
161 
162  /**
163  @copydoc Calendar::addTodo()
164  */
165  bool addTodo(const Todo::Ptr &todo) override;
166 
167  /**
168  @copydoc Calendar::deleteTodo()
169  */
170  bool deleteTodo(const Todo::Ptr &todo) override;
171 
172  /**
173  @copydoc Calendar::deleteTodoInstances()
174  */
175  bool deleteTodoInstances(const Todo::Ptr &todo) override;
176 
177  /**
178  @copydoc Calendar::rawTodos(TodoSortField, SortDirection)const
179  */
180  Q_REQUIRED_RESULT Todo::List rawTodos(TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
181 
182  /**
183  @copydoc Calendar::rawTodos(const QDate &, const QDate &, const QTimeZone &, bool)const
184  */
185  Q_REQUIRED_RESULT Todo::List rawTodos(const QDate &start, const QDate &end, const QTimeZone &timeZone = {}, bool inclusive = false) const override;
186 
187  /**
188  @copydoc Calendar::rawTodosForDate()
189  */
190  Q_REQUIRED_RESULT Todo::List rawTodosForDate(const QDate &date) const override;
191 
192  /**
193  @copydoc Calendar::todo()
194  */
195  Q_REQUIRED_RESULT Todo::Ptr todo(const QString &uid, const QDateTime &recurrenceId = {}) const override;
196 
197  /**
198  @copydoc Calendar::deletedTodo()
199  */
200  Q_REQUIRED_RESULT Todo::Ptr deletedTodo(const QString &uid, const QDateTime &recurrenceId = {}) const override;
201 
202  /**
203  @copydoc Calendar::deletedTodos(TodoSortField, SortDirection)const
204  */
205  Q_REQUIRED_RESULT Todo::List deletedTodos(TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
206 
207  /**
208  @copydoc Calendar::todoInstances(const Incidence::Ptr &, TodoSortField, SortDirection)const
209  */
210  Q_REQUIRED_RESULT Todo::List
211  todoInstances(const Incidence::Ptr &todo, TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
212 
213  // Journal Specific Methods //
214 
215  /**
216  @copydoc Calendar::addJournal()
217  */
218  bool addJournal(const Journal::Ptr &journal) override;
219 
220  /**
221  @copydoc Calendar::deleteJournal()
222  */
223  bool deleteJournal(const Journal::Ptr &journal) override;
224 
225  /**
226  @copydoc Calendar::deleteJournalInstances()
227  */
228  bool deleteJournalInstances(const Journal::Ptr &journal) override;
229 
230  /**
231  @copydoc Calendar::rawJournals()
232  */
233  Q_REQUIRED_RESULT Journal::List rawJournals(JournalSortField sortField = JournalSortUnsorted,
234  SortDirection sortDirection = SortDirectionAscending) const override;
235 
236  /**
237  @copydoc Calendar::rawJournalsForDate()
238  */
239  Q_REQUIRED_RESULT Journal::List rawJournalsForDate(const QDate &date) const override;
240 
241  /**
242  @copydoc Calendar::journal()
243  */
244  Journal::Ptr journal(const QString &uid, const QDateTime &recurrenceId = {}) const override;
245 
246  /**
247  @copydoc Calendar::deletedJournal()
248  */
249  Journal::Ptr deletedJournal(const QString &uid, const QDateTime &recurrenceId = {}) const override;
250 
251  /**
252  @copydoc Calendar::deletedJournals(JournalSortField, SortDirection)const
253  */
254  Q_REQUIRED_RESULT Journal::List deletedJournals(JournalSortField sortField = JournalSortUnsorted,
255  SortDirection sortDirection = SortDirectionAscending) const override;
256 
257  /**
258  @copydoc Calendar::journalInstances(const Incidence::Ptr &,
259  JournalSortField, SortDirection)const
260  */
261  Q_REQUIRED_RESULT Journal::List journalInstances(const Incidence::Ptr &journal,
263  SortDirection sortDirection = SortDirectionAscending) const override;
264 
265  // Alarm Specific Methods //
266 
267  /**
268  @copydoc Calendar::alarms()
269  */
270  Q_REQUIRED_RESULT Alarm::List alarms(const QDateTime &from, const QDateTime &to, bool excludeBlockedAlarms = false) const override;
271 
272  /**
273  Return a list of Alarms that occur before the specified timestamp.
274 
275  @param to is the ending timestamp.
276  @return the list of Alarms occurring before the specified QDateTime.
277  */
278  Q_REQUIRED_RESULT Alarm::List alarmsTo(const QDateTime &to) const; // TODO KF6 remove, already defined in Calendar
279 
280  /**
281  Return true if the memory calendar is updating the lastModified field
282  of incidence owned by the calendar on any incidence change.
283 
284  @since 5.80
285  */
286  bool updateLastModifiedOnChange() const;
287 
288  /**
289  Govern if the memory calendar is changing the lastModified field of incidence
290  it owns, on incidence updates.
291 
292  @param update, when true, the lastModified field of an incidence owned by the
293  calendar is set to the current date time on any change of the incidence.
294 
295  @since 5.80
296  */
297  void setUpdateLastModifiedOnChange(bool update);
298 
299  /**
300  @copydoc Calendar::incidenceUpdate(const QString &,const QDateTime &)
301  */
302  void incidenceUpdate(const QString &uid, const QDateTime &recurrenceId) override;
303 
304  /**
305  @copydoc Calendar::incidenceUpdated(const QString &,const QDateTime &)
306  */
307  void incidenceUpdated(const QString &uid, const QDateTime &recurrenceId) override;
308 
309  using QObject::event; // prevent warning about hidden virtual method
310 
311 protected:
312  /**
313  @copydoc IncidenceBase::virtual_hook()
314  */
315  void virtual_hook(int id, void *data) override;
316 
317 private:
318  //@cond PRIVATE
319  class Private;
320  Private *const d;
321  //@endcond
322 
323  Q_DISABLE_COPY(MemoryCalendar)
324 };
325 
326 }
327 
328 #endif
QSharedPointer< MemoryCalendar > Ptr
A shared pointer to a MemoryCalendar.
@ TodoSortUnsorted
Do not sort Todos.
Definition: calendar.h:79
TodoSortField
Calendar Todo sort keys.
Definition: calendar.h:78
JournalSortField
Calendar Journal sort keys.
Definition: calendar.h:92
Namespace for all KCalendarCore types.
Definition: alarm.h:36
Q_SCRIPTABLE Q_NOREPLY void start()
QVector< Ptr > List
List of alarms.
Definition: alarm.h:72
QSharedPointer< Journal > Ptr
A shared pointer to a Journal object.
Definition: journal.h:38
Represents the main calendar class.
Definition: calendar.h:129
EventSortField
Calendar Event sort keys.
Definition: calendar.h:68
virtual bool event(QEvent *e)
QSharedPointer< Incidence > Ptr
A shared pointer to an Incidence.
Definition: incidence.h:119
@ EventSortUnsorted
Do not sort Events.
Definition: calendar.h:69
QSharedPointer< Todo > Ptr
A shared pointer to a Todo object.
Definition: todo.h:39
@ JournalSortUnsorted
Do not sort Journals.
Definition: calendar.h:93
SortDirection
Calendar Incidence sort directions.
Definition: calendar.h:60
AKONADI_CALENDAR_EXPORT KCalendarCore::Journal::Ptr journal(const Akonadi::Item &item)
@ SortDirectionAscending
Sort in ascending order (first to last)
Definition: calendar.h:61
This class provides a calendar stored in memory.
QVector< Ptr > List
List of events.
Definition: event.h:55
QVector< Ptr > List
List of journals.
Definition: journal.h:43
AKONADI_CALENDAR_EXPORT KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item)
QSharedPointer< Event > Ptr
A shared pointer to an Event object.
Definition: event.h:50
QVector< Ptr > List
List of to-dos.
Definition: todo.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat May 21 2022 03:57:37 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.