File indexing completed on 2024-11-24 04:50:39
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com> 0003 // SPDX-License-Identifier: LGPL-2.1-or-later 0004 0005 #pragma once 0006 0007 #include <QObject> 0008 0009 #include <Akonadi/ETMCalendar> 0010 #include <Akonadi/IncidenceChanger> 0011 0012 #include "calendarconfig.h" 0013 #include <Akonadi/CollectionFilterProxyModel> 0014 #include <Akonadi/SearchCollectionHelper> 0015 #include <KConfigWatcher> 0016 0017 class IncidenceWrapper; 0018 0019 namespace Akonadi 0020 { 0021 class ETMViewStateSaver; 0022 class EntityRightsFilterModel; 0023 } 0024 0025 class KDescendantsProxyModel; 0026 class KCheckableProxyModel; 0027 class QAbstractProxyModel; 0028 class QAbstractItemModel; 0029 class ColorProxyModel; 0030 0031 class CalendarManager : public QObject 0032 { 0033 Q_OBJECT 0034 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0035 Q_PROPERTY(QAbstractProxyModel *collections READ collections CONSTANT) 0036 Q_PROPERTY(QAbstractItemModel *todoCollections READ todoCollections CONSTANT) 0037 Q_PROPERTY(QAbstractItemModel *viewCollections READ viewCollections CONSTANT) 0038 Q_PROPERTY(QList<qint64> enabledTodoCollections READ enabledTodoCollections NOTIFY enabledTodoCollectionsChanged) 0039 Q_PROPERTY(Akonadi::CollectionFilterProxyModel *allCalendars READ allCalendars CONSTANT) 0040 Q_PROPERTY(Akonadi::ETMCalendar::Ptr calendar READ calendar CONSTANT) 0041 Q_PROPERTY(Akonadi::IncidenceChanger *incidenceChanger READ incidenceChanger CONSTANT) 0042 Q_PROPERTY(QVariantMap undoRedoData READ undoRedoData NOTIFY undoRedoDataChanged) 0043 0044 public: 0045 explicit CalendarManager(QObject *parent = nullptr); 0046 ~CalendarManager() override; 0047 0048 KCheckableProxyModel *collectionSelectionProxyModel() const; 0049 void setCollectionSelectionProxyModel(KCheckableProxyModel *); 0050 0051 bool loading() const; 0052 QAbstractProxyModel *collections(); 0053 QAbstractItemModel *todoCollections(); 0054 QAbstractItemModel *viewCollections(); 0055 QList<qint64> enabledTodoCollections(); 0056 void refreshEnabledTodoCollections(); 0057 0058 Q_INVOKABLE IncidenceWrapper *createIncidenceWrapper(); 0059 0060 Q_INVOKABLE void save(); 0061 Akonadi::ETMCalendar::Ptr calendar() const; 0062 Akonadi::IncidenceChanger *incidenceChanger() const; 0063 Akonadi::CollectionFilterProxyModel *allCalendars(); 0064 Q_INVOKABLE qint64 defaultCalendarId(IncidenceWrapper *incidenceWrapper); 0065 QVariantMap undoRedoData(); 0066 0067 Q_INVOKABLE Akonadi::Item incidenceItem(KCalendarCore::Incidence::Ptr incidence) const; 0068 Akonadi::Item incidenceItem(const QString &uid) const; 0069 KCalendarCore::Incidence::List childIncidences(const QString &uid) const; 0070 0071 Q_INVOKABLE void addIncidence(IncidenceWrapper *incidenceWrapper); 0072 Q_INVOKABLE void editIncidence(IncidenceWrapper *incidenceWrapper); 0073 Q_INVOKABLE void updateIncidenceDates(IncidenceWrapper *incidenceWrapper, 0074 int startOffset, 0075 int endOffset, 0076 int occurrences = -1, 0077 const QDateTime &occurrenceDate = QDateTime()); 0078 Q_INVOKABLE bool hasChildren(KCalendarCore::Incidence::Ptr incidence); 0079 void deleteAllChildren(KCalendarCore::Incidence::Ptr incidence); 0080 Q_INVOKABLE void deleteIncidence(KCalendarCore::Incidence::Ptr incidence, bool deleteChildren = false); 0081 Q_INVOKABLE void changeIncidenceCollection(KCalendarCore::Incidence::Ptr incidence, qint64 collectionId); 0082 void changeIncidenceCollection(Akonadi::Item item, qint64 collectionId); 0083 Q_INVOKABLE QVariantMap getCollectionDetails(QVariant collectionId); 0084 Q_INVOKABLE void setCollectionColor(qint64 collectionId, const QColor &color); 0085 Q_INVOKABLE QVariant getIncidenceSubclassed(KCalendarCore::Incidence::Ptr incidencePtr); 0086 Q_INVOKABLE void undoAction(); 0087 Q_INVOKABLE void redoAction(); 0088 0089 Q_INVOKABLE void updateAllCollections(); 0090 Q_INVOKABLE void updateCollection(qint64 collectionId); 0091 Q_INVOKABLE void deleteCollection(qint64 collectionId); 0092 Q_INVOKABLE void editCollection(qint64 collectionId); 0093 Q_INVOKABLE void toggleCollection(qint64 collectionId); 0094 0095 private Q_SLOTS: 0096 void delayedInit(); 0097 0098 Q_SIGNALS: 0099 void loadingChanged(); 0100 void calendarChanged(); 0101 void undoRedoDataChanged(); 0102 void enabledTodoCollectionsChanged(); 0103 void updateIncidenceDatesCompleted(); 0104 void collectionColorsChanged(); 0105 void incidenceAdded(); 0106 0107 private: 0108 Akonadi::ETMCalendar::Ptr m_calendar = nullptr; 0109 Akonadi::IncidenceChanger *m_changer = nullptr; 0110 KDescendantsProxyModel *m_flatCollectionTreeModel = nullptr; 0111 ColorProxyModel *m_baseModel = nullptr; 0112 KCheckableProxyModel *m_selectionProxyModel = nullptr; 0113 Akonadi::ETMViewStateSaver *mCollectionSelectionModelStateSaver = nullptr; 0114 Akonadi::CollectionFilterProxyModel *m_allCalendars = nullptr; 0115 Akonadi::CollectionFilterProxyModel *m_eventMimeTypeFilterModel = nullptr; 0116 Akonadi::CollectionFilterProxyModel *m_todoMimeTypeFilterModel = nullptr; 0117 Akonadi::EntityRightsFilterModel *m_allCollectionsRightsFilterModel = nullptr; 0118 Akonadi::EntityRightsFilterModel *m_eventRightsFilterModel = nullptr; 0119 Akonadi::EntityRightsFilterModel *m_todoRightsFilterModel = nullptr; 0120 Akonadi::CollectionFilterProxyModel *m_todoViewCollectionModel = nullptr; 0121 Akonadi::CollectionFilterProxyModel *m_viewCollectionModel = nullptr; 0122 QList<qint64> m_enabledTodoCollections; 0123 KConfigWatcher::Ptr m_colorWatcher; 0124 Akonadi::SearchCollectionHelper mSearchCollectionHelper; 0125 CalendarConfig *m_config = nullptr; 0126 }; 0127 0128 Q_DECLARE_METATYPE(Akonadi::ETMCalendar::Ptr)