File indexing completed on 2025-01-05 04:49:48
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 * 0006 */ 0007 0008 #pragma once 0009 0010 #include <CalendarEvents/CalendarEventsPlugin> 0011 #include <KCalendarCore/Visitor> 0012 #include <QMultiHash> 0013 0014 class PimDataSource; 0015 class BaseEventDataVisitor : public KCalendarCore::Visitor 0016 { 0017 public: 0018 ~BaseEventDataVisitor() override; 0019 0020 [[nodiscard]] bool act(const KCalendarCore::Incidence::Ptr &incidence); 0021 [[nodiscard]] bool act(const KCalendarCore::Event::List &events); 0022 [[nodiscard]] bool act(const KCalendarCore::Todo::List &todos); 0023 0024 protected: 0025 BaseEventDataVisitor(PimDataSource *dataSource, QDate start, QDate end); 0026 0027 [[nodiscard]] QString generateUid(const KCalendarCore::Incidence::Ptr &incidence, const QDateTime &recurrenceId = {}) const; 0028 [[nodiscard]] bool isInRange(QDate start, QDate end) const; 0029 0030 [[nodiscard]] QList<CalendarEvents::EventData> 0031 explodeIncidenceOccurences(const CalendarEvents::EventData &ed, const KCalendarCore::Incidence::Ptr &incidence, bool &ok); 0032 0033 protected: 0034 PimDataSource *const mDataSource; 0035 const QDate mStart; 0036 const QDate mEnd; 0037 }; 0038 0039 class EventDataVisitor : public BaseEventDataVisitor 0040 { 0041 public: 0042 EventDataVisitor(PimDataSource *dataSource, const QDate &start, const QDate &end); 0043 ~EventDataVisitor() override; 0044 0045 const QMultiHash<QDate, CalendarEvents::EventData> &results() const; 0046 0047 protected: 0048 bool visit(const KCalendarCore::Event::Ptr &event) override; 0049 bool visit(const KCalendarCore::Todo::Ptr &todo) override; 0050 bool visit(const KCalendarCore::Journal::Ptr &) override 0051 { 0052 return false; 0053 } 0054 0055 bool visit(const KCalendarCore::FreeBusy::Ptr &) override 0056 { 0057 return false; 0058 } 0059 0060 private: 0061 void insertResult(const CalendarEvents::EventData &result); 0062 0063 [[nodiscard]] bool visit(const KCalendarCore::Incidence::Ptr &incidence, CalendarEvents::EventData::EventType eventType); 0064 CalendarEvents::EventData incidenceData(const KCalendarCore::Incidence::Ptr &incidence) const; 0065 0066 QMultiHash<QDate, CalendarEvents::EventData> mResults; 0067 }; 0068 0069 class EventDataIdVisitor : public BaseEventDataVisitor 0070 { 0071 public: 0072 explicit EventDataIdVisitor(PimDataSource *dataSource, QDate start, QDate end); 0073 0074 const QStringList &results() const; 0075 0076 protected: 0077 bool visit(const KCalendarCore::Event::Ptr &event) override; 0078 bool visit(const KCalendarCore::Todo::Ptr &todo) override; 0079 bool visit(const KCalendarCore::Journal::Ptr &) override 0080 { 0081 return false; 0082 } 0083 0084 bool visit(const KCalendarCore::FreeBusy::Ptr &) override 0085 { 0086 return false; 0087 } 0088 0089 private: 0090 bool visit(const KCalendarCore::Incidence::Ptr &incidence); 0091 0092 QStringList mResults; 0093 };