eventdatavisitor.h 2.6 KB
Newer Older
1
/*
2
 * SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org>
3
 *
4
 * SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
8
9
10
 *
 */

#ifndef EVENTDATAVISITOR_H
#define EVENTDATAVISITOR_H

11
#include <KCalendarCore/Visitor>
12
13
14
#include <QMultiHash>
#include <CalendarEvents/CalendarEventsPlugin>

15
class PimDataSource;
16
class BaseEventDataVisitor : public KCalendarCore::Visitor
17
18
19
20
{
public:
    ~BaseEventDataVisitor();

21
22
23
    bool act(const KCalendarCore::Incidence::Ptr &incidence);
    bool act(const KCalendarCore::Event::List &events);
    bool act(const KCalendarCore::Todo::List &todos);
24
25

protected:
Laurent Montel's avatar
Laurent Montel committed
26
    BaseEventDataVisitor(PimDataSource *dataSource, QDate start, QDate end);
27

28
    QString generateUid(const KCalendarCore::Incidence::Ptr &incidence, const QDateTime &recurrenceId = {}) const;
Laurent Montel's avatar
Laurent Montel committed
29
    bool isInRange(QDate start, QDate end) const;
30

31
    QVector<CalendarEvents::EventData> explodeIncidenceOccurences(const CalendarEvents::EventData &ed, const KCalendarCore::Incidence::Ptr &incidence, bool &ok);
32
protected:
33
34
35
    PimDataSource *const mDataSource;
    const QDate mStart;
    const QDate mEnd;
36
37
38
39
40
};

class EventDataVisitor : public BaseEventDataVisitor
{
public:
41
    EventDataVisitor(PimDataSource *dataSource, const QDate &start, const QDate &end);
Laurent Montel's avatar
Laurent Montel committed
42
    ~EventDataVisitor() override;
43

44
    const QMultiHash<QDate, CalendarEvents::EventData> &results() const;
45
46

protected:
47
48
49
    bool visit(const KCalendarCore::Event::Ptr &event) override;
    bool visit(const KCalendarCore::Todo::Ptr &todo) override;
    bool visit(const KCalendarCore::Journal::Ptr &) override
Laurent Montel's avatar
Laurent Montel committed
50
51
52
53
    {
        return false;
    }

54
    bool visit(const KCalendarCore::FreeBusy::Ptr &) override
Laurent Montel's avatar
Laurent Montel committed
55
56
57
58
    {
        return false;
    }

59
private:
60
61
    void insertResult(const CalendarEvents::EventData &result);

62
63
    bool visit(const KCalendarCore::Incidence::Ptr &incidence, CalendarEvents::EventData::EventType eventType);
    CalendarEvents::EventData incidenceData(const KCalendarCore::Incidence::Ptr &incidence) const;
64
65
66
67
68
69
70

    QMultiHash<QDate, CalendarEvents::EventData> mResults;
};

class EventDataIdVisitor : public BaseEventDataVisitor
{
public:
Laurent Montel's avatar
Laurent Montel committed
71
    explicit EventDataIdVisitor(PimDataSource *dataSource, QDate start, QDate end);
72

73
    const QStringList &results() const;
74
75

protected:
76
77
78
    bool visit(const KCalendarCore::Event::Ptr &event) override;
    bool visit(const KCalendarCore::Todo::Ptr &todo) override;
    bool visit(const KCalendarCore::Journal::Ptr &) override
Laurent Montel's avatar
Laurent Montel committed
79
80
81
82
    {
        return false;
    }

83
    bool visit(const KCalendarCore::FreeBusy::Ptr &) override
Laurent Montel's avatar
Laurent Montel committed
84
85
86
    {
        return false;
    }
87
88

private:
89
    bool visit(const KCalendarCore::Incidence::Ptr &incidence);
90

91
92
93
94
    QStringList mResults;
};

#endif