File indexing completed on 2024-04-28 15:19:08

0001 /*
0002   This file is part of the kcalcore library.
0003 
0004   SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org>
0005   SPDX-FileCopyrightText: 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
0006 
0007   SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 /**
0010   @file
0011   This file is part of the API for handling calendar data and
0012   defines the MemoryCalendar class.
0013 
0014   Very simple implementation of a Calendar that is only in memory
0015 
0016   @author Preston Brown \<pbrown@kde.org\>
0017   @author Cornelius Schumacher \<schumacher@kde.org\>
0018  */
0019 #ifndef KCALCORE_MEMORYCALENDAR_H
0020 #define KCALCORE_MEMORYCALENDAR_H
0021 
0022 #include "calendar.h"
0023 #include "kcalendarcore_export.h"
0024 
0025 namespace KCalendarCore
0026 {
0027 /**
0028   @brief
0029   This class provides a calendar stored in memory.
0030 */
0031 class KCALENDARCORE_EXPORT MemoryCalendar : public Calendar
0032 {
0033     Q_OBJECT
0034 public:
0035     /**
0036       A shared pointer to a MemoryCalendar
0037     */
0038     typedef QSharedPointer<MemoryCalendar> Ptr;
0039 
0040     /**
0041       @copydoc Calendar::Calendar(const QTimeZone &)
0042     */
0043     explicit MemoryCalendar(const QTimeZone &timeZone);
0044 
0045     /**
0046       @copydoc Calendar::Calendar(const QString &)
0047     */
0048     explicit MemoryCalendar(const QByteArray &timeZoneId);
0049 
0050     /**
0051       @copydoc Calendar::~Calendar()
0052     */
0053     ~MemoryCalendar() override;
0054 
0055     /**
0056       Clears out the current calendar, freeing all used memory etc. etc.
0057     */
0058     void close() override;
0059 
0060     /**
0061       @copydoc Calendar::doSetTimeZone()
0062     */
0063     void doSetTimeZone(const QTimeZone &timeZone) override;
0064 
0065     /**
0066       @copydoc Calendar::deleteIncidence()
0067     */
0068     bool deleteIncidence(const Incidence::Ptr &incidence) override;
0069 
0070     /**
0071        @copydoc Calendar::deleteIncidenceInstances
0072     */
0073     bool deleteIncidenceInstances(const Incidence::Ptr &incidence) override;
0074 
0075     /**
0076        @copydoc Calendar::addIncidence()
0077     */
0078     bool addIncidence(const Incidence::Ptr &incidence) override;
0079 
0080     // Event Specific Methods //
0081 
0082     /**
0083       @copydoc Calendar::addEvent()
0084     */
0085     bool addEvent(const Event::Ptr &event) override;
0086 
0087     /**
0088       @copydoc Calendar::deleteEvent()
0089     */
0090     bool deleteEvent(const Event::Ptr &event) override;
0091 
0092     /**
0093       @copydoc Calendar::deleteEventInstances()
0094     */
0095     bool deleteEventInstances(const Event::Ptr &event) override;
0096 
0097     /**
0098       @copydoc Calendar::rawEvents(EventSortField, SortDirection)const
0099     */
0100     Q_REQUIRED_RESULT Event::List rawEvents(EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
0101 
0102     /**
0103       @copydoc Calendar::rawEvents(const QDate &, const QDate &, const QTimeZone &, bool)const
0104     */
0105     Q_REQUIRED_RESULT Event::List rawEvents(const QDate &start, const QDate &end, const QTimeZone &timeZone = {}, bool inclusive = false) const override;
0106 
0107     /**
0108       Returns an unfiltered list of all Events which occur on the given date.
0109 
0110       @param date request unfiltered Event list for this QDate only.
0111       @param timeZone time zone to interpret @p date, or the calendar's
0112                       default time zone if none is specified
0113       @param sortField specifies the EventSortField.
0114       @param sortDirection specifies the SortDirection.
0115 
0116       @return the list of unfiltered Events occurring on the specified QDate.
0117     */
0118     Q_REQUIRED_RESULT Event::List rawEventsForDate(const QDate &date,
0119                                                    const QTimeZone &timeZone = {},
0120                                                    EventSortField sortField = EventSortUnsorted,
0121                                                    SortDirection sortDirection = SortDirectionAscending) const override;
0122 
0123 #if KCALENDARCORE_BUILD_DEPRECATED_SINCE(5, 95)
0124     /**
0125       @copydoc Calendar::rawEventsForDate(const QDateTime &)const
0126     */
0127     Q_REQUIRED_RESULT Event::List rawEventsForDate(const QDateTime &dt) const override;
0128 #endif
0129 
0130     /**
0131      * Returns an incidence by identifier.
0132      * @see Incidence::instanceIdentifier()
0133      * @since 4.11
0134      */
0135     Incidence::Ptr instance(const QString &identifier) const;
0136 
0137     /**
0138       @copydoc Calendar::event()
0139     */
0140     Q_REQUIRED_RESULT Event::Ptr event(const QString &uid, const QDateTime &recurrenceId = {}) const override;
0141 
0142     /**
0143       @copydoc Calendar::deletedEvent()
0144     */
0145     Q_REQUIRED_RESULT Event::Ptr deletedEvent(const QString &uid, const QDateTime &recurrenceId = {}) const override;
0146 
0147     /**
0148       @copydoc Calendar::deletedEvents(EventSortField, SortDirection)const
0149     */
0150     Q_REQUIRED_RESULT Event::List deletedEvents(EventSortField sortField = EventSortUnsorted,
0151                                                 SortDirection sortDirection = SortDirectionAscending) const override;
0152 
0153     /**
0154       @copydoc Calendar::eventInstances(const Incidence::Ptr &, EventSortField, SortDirection)const
0155     */
0156     Q_REQUIRED_RESULT Event::List eventInstances(const Incidence::Ptr &event,
0157                                                  EventSortField sortField = EventSortUnsorted,
0158                                                  SortDirection sortDirection = SortDirectionAscending) const override;
0159 
0160     // To-do Specific Methods //
0161 
0162     /**
0163       @copydoc Calendar::addTodo()
0164     */
0165     bool addTodo(const Todo::Ptr &todo) override;
0166 
0167     /**
0168       @copydoc Calendar::deleteTodo()
0169     */
0170     bool deleteTodo(const Todo::Ptr &todo) override;
0171 
0172     /**
0173       @copydoc Calendar::deleteTodoInstances()
0174     */
0175     bool deleteTodoInstances(const Todo::Ptr &todo) override;
0176 
0177     /**
0178       @copydoc Calendar::rawTodos(TodoSortField, SortDirection)const
0179     */
0180     Q_REQUIRED_RESULT Todo::List rawTodos(TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
0181 
0182     /**
0183        @copydoc Calendar::rawTodos(const QDate &, const QDate &, const QTimeZone &, bool)const
0184     */
0185     Q_REQUIRED_RESULT Todo::List rawTodos(const QDate &start, const QDate &end, const QTimeZone &timeZone = {}, bool inclusive = false) const override;
0186 
0187     /**
0188       @copydoc Calendar::rawTodosForDate()
0189     */
0190     Q_REQUIRED_RESULT Todo::List rawTodosForDate(const QDate &date) const override;
0191 
0192     /**
0193       @copydoc Calendar::todo()
0194     */
0195     Q_REQUIRED_RESULT Todo::Ptr todo(const QString &uid, const QDateTime &recurrenceId = {}) const override;
0196 
0197     /**
0198       @copydoc Calendar::deletedTodo()
0199     */
0200     Q_REQUIRED_RESULT Todo::Ptr deletedTodo(const QString &uid, const QDateTime &recurrenceId = {}) const override;
0201 
0202     /**
0203       @copydoc Calendar::deletedTodos(TodoSortField, SortDirection)const
0204     */
0205     Q_REQUIRED_RESULT Todo::List deletedTodos(TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
0206 
0207     /**
0208       @copydoc Calendar::todoInstances(const Incidence::Ptr &, TodoSortField, SortDirection)const
0209     */
0210     Q_REQUIRED_RESULT Todo::List
0211     todoInstances(const Incidence::Ptr &todo, TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending) const override;
0212 
0213     // Journal Specific Methods //
0214 
0215     /**
0216       @copydoc Calendar::addJournal()
0217     */
0218     bool addJournal(const Journal::Ptr &journal) override;
0219 
0220     /**
0221       @copydoc Calendar::deleteJournal()
0222     */
0223     bool deleteJournal(const Journal::Ptr &journal) override;
0224 
0225     /**
0226       @copydoc Calendar::deleteJournalInstances()
0227     */
0228     bool deleteJournalInstances(const Journal::Ptr &journal) override;
0229 
0230     /**
0231       @copydoc Calendar::rawJournals()
0232     */
0233     Q_REQUIRED_RESULT Journal::List rawJournals(JournalSortField sortField = JournalSortUnsorted,
0234                                                 SortDirection sortDirection = SortDirectionAscending) const override;
0235 
0236     /**
0237       @copydoc Calendar::rawJournalsForDate()
0238     */
0239     Q_REQUIRED_RESULT Journal::List rawJournalsForDate(const QDate &date) const override;
0240 
0241     /**
0242       @copydoc Calendar::journal()
0243     */
0244     Journal::Ptr journal(const QString &uid, const QDateTime &recurrenceId = {}) const override;
0245 
0246     /**
0247       @copydoc Calendar::deletedJournal()
0248     */
0249     Journal::Ptr deletedJournal(const QString &uid, const QDateTime &recurrenceId = {}) const override;
0250 
0251     /**
0252       @copydoc Calendar::deletedJournals(JournalSortField, SortDirection)const
0253     */
0254     Q_REQUIRED_RESULT Journal::List deletedJournals(JournalSortField sortField = JournalSortUnsorted,
0255                                                     SortDirection sortDirection = SortDirectionAscending) const override;
0256 
0257     /**
0258       @copydoc Calendar::journalInstances(const Incidence::Ptr &,
0259                                           JournalSortField, SortDirection)const
0260     */
0261     Q_REQUIRED_RESULT Journal::List journalInstances(const Incidence::Ptr &journal,
0262                                                      JournalSortField sortField = JournalSortUnsorted,
0263                                                      SortDirection sortDirection = SortDirectionAscending) const override;
0264 
0265     // Alarm Specific Methods //
0266 
0267     /**
0268       @copydoc Calendar::alarms()
0269     */
0270     Q_REQUIRED_RESULT Alarm::List alarms(const QDateTime &from, const QDateTime &to, bool excludeBlockedAlarms = false) const override;
0271 
0272     /**
0273       Return a list of Alarms that occur before the specified timestamp.
0274 
0275       @param to is the ending timestamp.
0276       @return the list of Alarms occurring before the specified QDateTime.
0277     */
0278     Q_REQUIRED_RESULT Alarm::List alarmsTo(const QDateTime &to) const; // TODO KF6 remove, already defined in Calendar
0279 
0280     /**
0281       Return true if the memory calendar is updating the lastModified field
0282       of incidence owned by the calendar on any incidence change.
0283 
0284       @since 5.80
0285     */
0286     bool updateLastModifiedOnChange() const;
0287 
0288     /**
0289       Govern if the memory calendar is changing the lastModified field of incidence
0290       it owns, on incidence updates.
0291 
0292       @param update, when true, the lastModified field of an incidence owned by the
0293       calendar is set to the current date time on any change of the incidence.
0294 
0295       @since 5.80
0296     */
0297     void setUpdateLastModifiedOnChange(bool update);
0298 
0299     /**
0300       @copydoc Calendar::incidenceUpdate(const QString &,const QDateTime &)
0301     */
0302     void incidenceUpdate(const QString &uid, const QDateTime &recurrenceId) override;
0303 
0304     /**
0305       @copydoc Calendar::incidenceUpdated(const QString &,const QDateTime &)
0306     */
0307     void incidenceUpdated(const QString &uid, const QDateTime &recurrenceId) override;
0308 
0309     using QObject::event; // prevent warning about hidden virtual method
0310 
0311 protected:
0312     /**
0313       @copydoc IncidenceBase::virtual_hook()
0314     */
0315     void virtual_hook(int id, void *data) override;
0316 
0317 private:
0318     //@cond PRIVATE
0319     class Private;
0320     Private *const d;
0321     //@endcond
0322 
0323     Q_DISABLE_COPY(MemoryCalendar)
0324 };
0325 
0326 }
0327 
0328 #endif