1/*
2 This file is part of the kcalcore library.
3
4 Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
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
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22/**
23 @file
24 This file is part of the API for handling calendar data and
25 defines the MemoryCalendar class.
26
27 Very simple implementation of a Calendar that is only in memory
28
29 @author Preston Brown \<pbrown@kde.org\>
30 @author Cornelius Schumacher \<schumacher@kde.org\>
31 */
32#ifndef KCALCORE_MEMORYCALENDAR_H
33#define KCALCORE_MEMORYCALENDAR_H
34
35#include "kcalcore_export.h"
36#include "calendar.h"
37
38namespace KCalCore {
39
40class CalFormat;
41
42/**
43 @brief
44 This class provides a calendar stored in memory.
45*/
46class KCALCORE_EXPORT MemoryCalendar : public Calendar
47{
48public:
49
50 /**
51 A shared pointer to a MemoryCalendar
52 */
53 typedef QSharedPointer<MemoryCalendar> Ptr;
54
55 /**
56 @copydoc Calendar::Calendar(const KDateTime::Spec &)
57 */
58 explicit MemoryCalendar(const KDateTime::Spec &timeSpec);
59
60 /**
61 @copydoc Calendar::Calendar(const QString &)
62 */
63 explicit MemoryCalendar(const QString &timeZoneId);
64
65 /**
66 @copydoc Calendar::~Calendar()
67 */
68 ~MemoryCalendar();
69
70 /**
71 Clears out the current calendar, freeing all used memory etc. etc.
72 */
73 void close();
74
75 /**
76 @copydoc Calendar::deleteIncidence()
77 */
78 bool deleteIncidence(const Incidence::Ptr &incidence);
79
80 /**
81 @copydoc Calendar::deleteIncidenceInstances
82 */
83 bool deleteIncidenceInstances(const Incidence::Ptr &incidence);
84
85 /**
86 @copydoc Calendar::addIncidence()
87 */
88 bool addIncidence(const Incidence::Ptr &incidence);
89
90 // Event Specific Methods //
91
92 /**
93 @copydoc Calendar::addEvent()
94 */
95 bool addEvent(const Event::Ptr &event);
96
97 /**
98 @copydoc Calendar::deleteEvent()
99 */
100 bool deleteEvent(const Event::Ptr &event);
101
102 /**
103 @copydoc Calendar::deleteEventInstances()
104 */
105 bool deleteEventInstances(const Event::Ptr &event);
106
107 /**
108 @copydoc Calendar::deleteAllEvents()
109 */
110 void deleteAllEvents();
111
112 /**
113 @copydoc Calendar::rawEvents(EventSortField, SortDirection)const
114 */
115 Event::List rawEvents(
116 EventSortField sortField = EventSortUnsorted,
117 SortDirection sortDirection = SortDirectionAscending) const;
118
119 /**
120 @copydoc Calendar::rawEvents(const QDate &, const QDate &, const KDateTime::Spec &, bool)const
121 */
122 Event::List rawEvents(const QDate &start, const QDate &end,
123 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
124 bool inclusive = false) const;
125
126 /**
127 Returns an unfiltered list of all Events which occur on the given date.
128
129 @param date request unfiltered Event list for this QDate only.
130 @param timeSpec time zone etc. to interpret @p date, or the calendar's
131 default time spec if none is specified
132 @param sortField specifies the EventSortField.
133 @param sortDirection specifies the SortDirection.
134
135 @return the list of unfiltered Events occurring on the specified QDate.
136 */
137 Event::List rawEventsForDate(
138 const QDate &date, const KDateTime::Spec &timeSpec = KDateTime::Spec(),
139 EventSortField sortField = EventSortUnsorted,
140 SortDirection sortDirection = SortDirectionAscending) const;
141
142 /**
143 @copydoc Calendar::rawEventsForDate(const KDateTime &)const
144 */
145 Event::List rawEventsForDate(const KDateTime &dt) const;
146
147 /**
148 * Returns an incidence by identifier.
149 * @see Incidence::instanceIdentifier()
150 * @since 4.11
151 */
152 Incidence::Ptr instance(const QString &identifier) const;
153
154 /**
155 @copydoc Calendar::event()
156 */
157 Event::Ptr event(
158 const QString &uid,
159 const KDateTime &recurrenceId = KDateTime()) const;
160
161 /**
162 @copydoc Calendar::deletedEvent()
163 */
164 Event::Ptr deletedEvent(
165 const QString &uid, const KDateTime &recurrenceId = KDateTime()) const;
166
167 /**
168 @copydoc Calendar::deletedEvents(EventSortField, SortDirection)const
169 */
170 Event::List deletedEvents(
171 EventSortField sortField = EventSortUnsorted,
172 SortDirection sortDirection = SortDirectionAscending) const;
173
174 /**
175 @copydoc Calendar::eventInstances(const Incidence::Ptr &, EventSortField, SortDirection)const
176 */
177 Event::List eventInstances(
178 const Incidence::Ptr &event,
179 EventSortField sortField = EventSortUnsorted,
180 SortDirection sortDirection = SortDirectionAscending) const;
181
182 // To-do Specific Methods //
183
184 /**
185 @copydoc Calendar::addTodo()
186 */
187 bool addTodo(const Todo::Ptr &todo);
188
189 /**
190 @copydoc Calendar::deleteTodo()
191 */
192 bool deleteTodo(const Todo::Ptr &todo);
193
194 /**
195 @copydoc Calendar::deleteTodoInstances()
196 */
197 bool deleteTodoInstances(const Todo::Ptr &todo);
198
199 /**
200 @copydoc Calendar::deleteAllTodos()
201 */
202 void deleteAllTodos();
203
204 /**
205 @copydoc Calendar::rawTodos(TodoSortField, SortDirection)const
206 */
207 Todo::List rawTodos(
208 TodoSortField sortField = TodoSortUnsorted,
209 SortDirection sortDirection = SortDirectionAscending) const;
210
211 /**
212 @copydoc Calendar::rawTodos(const QDate &, const QDate &, const KDateTime::Spec &, bool)const
213 */
214 Todo::List rawTodos(
215 const QDate &start, const QDate &end,
216 const KDateTime::Spec &timespec = KDateTime::Spec(),
217 bool inclusive = false) const;
218
219 /**
220 @copydoc Calendar::rawTodosForDate()
221 */
222 Todo::List rawTodosForDate(const QDate &date) const;
223
224 /**
225 @copydoc Calendar::todo()
226 */
227 Todo::Ptr todo(const QString &uid,
228 const KDateTime &recurrenceId = KDateTime()) const;
229
230 /**
231 @copydoc Calendar::deletedTodo()
232 */
233 Todo::Ptr deletedTodo(const QString &uid, const KDateTime &recurrenceId = KDateTime()) const;
234
235 /**
236 @copydoc Calendar::deletedTodos(TodoSortField, SortDirection)const
237 */
238 Todo::List deletedTodos(
239 TodoSortField sortField = TodoSortUnsorted,
240 SortDirection sortDirection = SortDirectionAscending) const;
241
242 /**
243 @copydoc Calendar::todoInstances(const Incidence::Ptr &, TodoSortField, SortDirection)const
244 */
245 Todo::List todoInstances(const Incidence::Ptr &todo,
246 TodoSortField sortField = TodoSortUnsorted,
247 SortDirection sortDirection = SortDirectionAscending) const;
248
249 // Journal Specific Methods //
250
251 /**
252 @copydoc Calendar::addJournal()
253 */
254 bool addJournal(const Journal::Ptr &journal);
255
256 /**
257 @copydoc Calendar::deleteJournal()
258 */
259 bool deleteJournal(const Journal::Ptr &journal);
260
261 /**
262 @copydoc Calendar::deleteJournalInstances()
263 */
264 bool deleteJournalInstances(const Journal::Ptr &journal);
265
266 /**
267 @copydoc Calendar::deleteAllJournals()
268 */
269 void deleteAllJournals();
270
271 /**
272 @copydoc Calendar::rawJournals()
273 */
274 Journal::List rawJournals(
275 JournalSortField sortField = JournalSortUnsorted,
276 SortDirection sortDirection = SortDirectionAscending) const;
277
278 /**
279 @copydoc Calendar::rawJournalsForDate()
280 */
281 Journal::List rawJournalsForDate(const QDate &date) const;
282
283 /**
284 @copydoc Calendar::journal()
285 */
286 Journal::Ptr journal(const QString &uid,
287 const KDateTime &recurrenceId = KDateTime()) const;
288
289 /**
290 @copydoc Calendar::deletedJournal()
291 */
292 Journal::Ptr deletedJournal(const QString &uid,
293 const KDateTime &recurrenceId = KDateTime()) const;
294
295 /**
296 @copydoc Calendar::deletedJournals(JournalSortField, SortDirection)const
297 */
298 Journal::List deletedJournals(
299 JournalSortField sortField = JournalSortUnsorted,
300 SortDirection sortDirection = SortDirectionAscending) const;
301
302 /**
303 @copydoc Calendar::journalInstances(const Incidence::Ptr &,
304 JournalSortField, SortDirection)const
305 */
306 Journal::List journalInstances(const Incidence::Ptr &journal,
307 JournalSortField sortField = JournalSortUnsorted,
308 SortDirection sortDirection = SortDirectionAscending) const;
309
310 // Alarm Specific Methods //
311
312 /**
313 @copydoc Calendar::alarms()
314 */
315 Alarm::List alarms(const KDateTime &from, const KDateTime &to) const;
316
317 /**
318 Return a list of Alarms that occur before the specified timestamp.
319
320 @param to is the ending timestamp.
321 @return the list of Alarms occurring before the specified KDateTime.
322 */
323 Alarm::List alarmsTo(const KDateTime &to) const;
324
325 /**
326 @copydoc Calendar::incidenceUpdate(const QString &,const KDateTime &)
327 */
328 void incidenceUpdate(const QString &uid, const KDateTime &recurrenceId);
329
330 /**
331 @copydoc Calendar::incidenceUpdated(const QString &,const KDateTime &)
332 */
333 void incidenceUpdated(const QString &uid, const KDateTime &recurrenceId);
334
335 using QObject::event; // prevent warning about hidden virtual method
336
337protected:
338 /**
339 @copydoc IncidenceBase::virtual_hook()
340 */
341 virtual void virtual_hook(int id, void *data);
342
343private:
344 //@cond PRIVATE
345 class Private;
346 Private *const d;
347 //@endcond
348
349 Q_DISABLE_COPY(MemoryCalendar)
350};
351
352}
353
354#endif
355