File indexing completed on 2024-05-19 05:11:14
0001 /* 0002 SPDX-FileCopyrightText: 2011 Sérgio Martins <sergio.martins@kdab.com> 0003 SPDX-FileCopyrightText: 2012 Sérgio Martins <iamsergio@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "akonadi-calendar_export.h" 0011 0012 #include <Akonadi/Collection> 0013 #include <Akonadi/Item> 0014 #include <KCalendarCore/Incidence> 0015 #include <KCalendarCore/MemoryCalendar> 0016 0017 #include <memory> 0018 0019 namespace Akonadi 0020 { 0021 class CalendarBasePrivate; 0022 class IncidenceChanger; 0023 0024 /** 0025 * @short The base class for all akonadi aware calendars. 0026 * 0027 * Because it inherits KCalendarCore::Calendar, it provides seamless integration 0028 * with KCalendarCore and KCalUtils libraries eliminating any need for adapter 0029 * ( akonadi<->KCalendarCore ) classes. 0030 * 0031 * @see ETMCalendar 0032 * @see FetchJobCalendar 0033 * 0034 * @author Sérgio Martins <sergio.martins@kdab.com> 0035 * @since 4.11 0036 */ 0037 class AKONADI_CALENDAR_EXPORT CalendarBase : public KCalendarCore::MemoryCalendar 0038 { 0039 Q_OBJECT 0040 public: 0041 using Ptr = QSharedPointer<CalendarBase>; 0042 0043 /** 0044 * Constructs a CalendarBase object. 0045 */ 0046 explicit CalendarBase(QObject *parent = nullptr); 0047 0048 /** 0049 * Destroys the calendar. 0050 */ 0051 ~CalendarBase() override; 0052 0053 /** 0054 * Returns the Item containing the incidence with uid @p uid or an invalid Item 0055 * if the incidence isn't found. 0056 * @see Use item(Incidence::Ptr) instead where possible. This function doesn't take exceptions (recurrenceId) into account (and thus always returns the main 0057 * event). 0058 */ 0059 [[nodiscard]] Akonadi::Item item(const QString &uid) const; 0060 0061 /** 0062 * Returns the Item containing @p incidence or an invalid Item if the incidence isn't found. 0063 */ 0064 [[nodiscard]] Akonadi::Item item(const KCalendarCore::Incidence::Ptr &incidence) const; 0065 0066 /** 0067 * Returns the Item with @p id or an invalid Item if not found. 0068 */ 0069 [[nodiscard]] Akonadi::Item item(Akonadi::Item::Id) const; 0070 0071 /** 0072 * Returns the list of items contained in this calendar that belong to the specified collection. 0073 * @see incidences() 0074 * @since 4.12 0075 */ 0076 [[nodiscard]] Akonadi::Item::List items(Akonadi::Collection::Id = -1) const; 0077 0078 /** 0079 * Returns the item list that corresponds to the @p incidenceList. 0080 */ 0081 [[nodiscard]] Akonadi::Item::List itemList(const KCalendarCore::Incidence::List &incidenceList) const; 0082 0083 /** 0084 * Returns the child incidences of the parent identified by @p parentUid. 0085 * Only the direct children are returned 0086 * @param parentUid identifier of the parent incidence 0087 *///TODO: unit-test 0088 [[nodiscard]] KCalendarCore::Incidence::List childIncidences(const QString &parentUid) const; 0089 0090 /** 0091 * Returns the child incidences of the parent identified by @p parentId. 0092 * Only the direct children are returned 0093 * @param parentId identifier of the parent item 0094 */ 0095 [[nodiscard]] KCalendarCore::Incidence::List childIncidences(Item::Id parentId) const; 0096 0097 /** 0098 * Returns the child items of the parent identified by @p parentUid. 0099 * Only the direct children are returned 0100 * @param parentUid identifier of the parent incidence 0101 */ 0102 [[nodiscard]] Akonadi::Item::List childItems(const QString &parentUid) const; 0103 0104 /** 0105 * Returns the child items of the parent identified by @p parentId. 0106 * Only the direct children are returned 0107 * @param parentId identifier of the parent item 0108 */ 0109 [[nodiscard]] Akonadi::Item::List childItems(Item::Id parentId) const; 0110 0111 /** 0112 * Adds an Event to the calendar. 0113 * It's added to akonadi in the background @see createFinished(). 0114 * @param event the event to be added 0115 */ 0116 bool addEvent(const KCalendarCore::Event::Ptr &event) override; 0117 0118 /** 0119 * Deletes an Event from the calendar. 0120 * It's removed from akonadi in the background @see deleteFinished(). 0121 * @param event the event to be deleted 0122 */ 0123 bool deleteEvent(const KCalendarCore::Event::Ptr &event) override; 0124 0125 /** 0126 * Adds a Todo to the calendar. 0127 * It's added to akonadi in the background @see createFinished(). 0128 * @param todo the todo to add 0129 */ 0130 bool addTodo(const KCalendarCore::Todo::Ptr &todo) override; 0131 0132 /** 0133 * Deletes a Todo from the calendar. 0134 * It's removed from akonadi in the background @see deleteFinished(). 0135 * @param todo the todo to delete 0136 */ 0137 bool deleteTodo(const KCalendarCore::Todo::Ptr &todo) override; 0138 0139 /** 0140 * Adds a Journal to the calendar. 0141 * It's added to akonadi in the background @see createFinished(). 0142 * @param journal the journal to add 0143 */ 0144 bool addJournal(const KCalendarCore::Journal::Ptr &journal) override; 0145 0146 /** 0147 * Deletes a Journal from the calendar. 0148 * It's removed from akonadi in the background @see deleteFinished(). 0149 * @param journal the journal to delete 0150 */ 0151 bool deleteJournal(const KCalendarCore::Journal::Ptr &journal) override; 0152 0153 /** 0154 * Adds an incidence to the calendar. 0155 * It's added to akonadi in the background @see createFinished(). 0156 * @param incidence the incidence to add 0157 */ 0158 bool addIncidence(const KCalendarCore::Incidence::Ptr &incidence) override; 0159 0160 /** 0161 * Deletes an incidence from the calendar. 0162 * It's removed from akonadi in the background @see deleteFinished(). 0163 * @param incidence the incidence to delete 0164 */ 0165 bool deleteIncidence(const KCalendarCore::Incidence::Ptr &incidence) override; 0166 0167 /** 0168 Call this to tell the calendar that you're adding a batch of incidences. 0169 So it doesn't, for example, ask the destination for each incidence. 0170 0171 @see endBatchAdding() 0172 */ 0173 void startBatchAdding() override; 0174 0175 /** 0176 * Tells the Calendar that you stopped adding a batch of incidences. 0177 * @see startBatchAdding() 0178 */ 0179 void endBatchAdding() override; 0180 0181 /** 0182 * Returns the IncidenceChanger used by this calendar to make changes in akonadi. 0183 * Use this if you need the defaults used by CalendarBase. 0184 */ 0185 [[nodiscard]] Akonadi::IncidenceChanger *incidenceChanger() const; 0186 0187 /** 0188 * Modifies an incidence. 0189 * The incidence with the same uid as @p newIncidence will be updated with the contents of 0190 * @param newIncidence the incidence to modify 0191 */ 0192 bool modifyIncidence(const KCalendarCore::Incidence::Ptr &newIncidence); 0193 0194 Q_SIGNALS: 0195 /** 0196 * This signal is emitted when an incidence is created in akonadi through 0197 * add{Incidence,Event,Todo,Journal} 0198 * @param success the success of the operation 0199 * @param errorMessage if @p success is false, contains the error message 0200 */ 0201 void createFinished(bool success, const QString &errorMessage); 0202 0203 /** 0204 * This signal is emitted when an incidence is deleted in akonadi through 0205 * delete{Incidence,Event,Todo,Journal} 0206 * @param success the success of the operation 0207 * @param errorMessage if @p success is false, contains the error message 0208 */ 0209 void deleteFinished(bool success, const QString &errorMessage); 0210 0211 /** 0212 * This signal is emitted when an incidence is modified in akonadi through 0213 * modifyIncidence(). 0214 * @param success the success of the operation 0215 * @param errorMessage if @p success is false, contains the error message 0216 */ 0217 void modifyFinished(bool success, const QString &errorMessage); 0218 0219 protected: 0220 Q_DECLARE_PRIVATE(CalendarBase) 0221 std::unique_ptr<CalendarBasePrivate> const d_ptr; 0222 CalendarBase(CalendarBasePrivate *const d, QObject *parent); 0223 0224 friend class Scheduler; 0225 }; 0226 }