eventdatavisitor.h 3.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/*
 * Copyright (C) 2016  Daniel Vrátil <dvratil@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef EVENTDATAVISITOR_H
#define EVENTDATAVISITOR_H

#include <KCalCore/Visitor>
#include <QMultiHash>
#include <CalendarEvents/CalendarEventsPlugin>

namespace Akonadi
{
class ETMCalendar;
}

class BaseEventDataVisitor : public KCalCore::Visitor
{
public:
    ~BaseEventDataVisitor();

    bool act(const KCalCore::Incidence::Ptr &incidence);
    bool act(const KCalCore::Event::List &events);
    bool act(const KCalCore::Todo::List &todos);

protected:
    BaseEventDataVisitor(Akonadi::ETMCalendar *calendar, const QDate &start, const QDate &end);

    QString generateUid(const KCalCore::Incidence::Ptr &incidence, const KDateTime &recurrenceId = KDateTime()) const;
    bool isInRange(const QDate &start, const QDate &end) const;

47 48 49
    QVector<CalendarEvents::EventData> explodeIncidenceOccurences(const CalendarEvents::EventData &ed,
                                                                  const KCalCore::Incidence::Ptr &incidence,
                                                                  bool &ok);
50 51 52
    // can be overridden by unit-tests
    virtual qint64 itemIdForIncidence(const KCalCore::Incidence::Ptr &incidence) const;

53 54 55 56 57 58 59 60 61 62 63 64
protected:
    Akonadi::ETMCalendar *mCalendar;
    QDate mStart;
    QDate mEnd;
};

class EventDataVisitor : public BaseEventDataVisitor
{
public:
    EventDataVisitor(Akonadi::ETMCalendar *calendar, const QDate &start, const QDate &end);
    ~EventDataVisitor();

65
    const QMultiHash<QDate, CalendarEvents::EventData> &results() const;
66 67 68 69 70 71 72

protected:
    bool visit(const KCalCore::Event::Ptr &event) Q_DECL_OVERRIDE;
    bool visit(const KCalCore::Todo::Ptr &todo) Q_DECL_OVERRIDE;
    bool visit(const KCalCore::Journal::Ptr &) Q_DECL_OVERRIDE { return false; }
    bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; }
private:
73
    bool visit(const KCalCore::Incidence::Ptr &incidence, CalendarEvents::EventData::EventType eventType);
74 75 76 77 78 79 80 81 82 83 84 85
    CalendarEvents::EventData incidenceData(const KCalCore::Incidence::Ptr &incidence) const;

    QMultiHash<QDate, CalendarEvents::EventData> mResults;

};


class EventDataIdVisitor : public BaseEventDataVisitor
{
public:
    explicit EventDataIdVisitor(Akonadi::ETMCalendar *calendar, const QDate &start, const QDate &end);

86
    const QStringList &results() const;
87 88 89 90 91 92 93 94

protected:
    bool visit(const KCalCore::Event::Ptr &event) Q_DECL_OVERRIDE;
    bool visit(const KCalCore::Todo::Ptr &todo) Q_DECL_OVERRIDE;
    bool visit(const KCalCore::Journal::Ptr &) Q_DECL_OVERRIDE { return false; }
    bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; }

private:
95 96
    bool visit(const KCalCore::Incidence::Ptr &incidence);

97 98 99 100 101
    QStringList mResults;
};


#endif