File indexing completed on 2024-04-21 05:50:57

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef EVENTMODEL_H
0008 #define EVENTMODEL_H
0009 
0010 #include "localcalendar.h"
0011 
0012 #include <QAbstractListModel>
0013 #include <KCalendarCore/Event>
0014 
0015 class SettingsController;
0016 
0017 class EventModel : public QAbstractListModel
0018 {
0019     Q_OBJECT
0020 
0021     Q_PROPERTY(QDate filterdt READ filterdt WRITE setFilterdt NOTIFY filterdtChanged)
0022     Q_PROPERTY(LocalCalendar *calendar READ calendar WRITE setCalendar NOTIFY calendarChanged)
0023     Q_PROPERTY(QString eventCategory READ eventCategory WRITE setEventCategory NOTIFY eventCategoryChanged)
0024 
0025 public:
0026     explicit EventModel(QObject *parent = nullptr);
0027 
0028     enum Roles {
0029         Uid = Qt::UserRole + 1,
0030         LastModified,
0031         ScheduleStartDt,
0032         EventStartDt,
0033         EventDt,
0034         ShiftedEventDt,
0035         ShiftedEventDtLocal,
0036         AllDay,
0037         Description,
0038         Summary,
0039         Location,
0040         Categories,
0041         Priority,
0042         Created,
0043         Secrecy,
0044         ScheduleEndDt,
0045         EventEndDt,
0046         Transparency,
0047         IsRepeating,
0048         RepeatPeriodType,
0049         RepeatEvery,
0050         RepeatStopAfter,
0051         EventCategories,
0052         Url,
0053         ShiftedStartEndDt,
0054         ShiftedStartEndDtLocal,
0055         ShiftedStartEndTime,
0056         ShiftedStartEndTimeLocal,
0057         StartEndDt,
0058         StartEndDtLocal,
0059         Overlapping,
0060         ConferenceTzId
0061     };
0062 
0063     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0064     QHash<int, QByteArray> roleNames() const override;
0065     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0066 
0067     QDate filterdt() const;
0068     void setFilterdt(const QDate &filterDate);
0069 
0070     LocalCalendar *calendar() const;
0071     void setCalendar(LocalCalendar *const calendarPtr);
0072 
0073     QString eventCategory() const;
0074     void setEventCategory(const QString &category);
0075 
0076 public Q_SLOTS:
0077     void loadEvents();
0078 
0079 Q_SIGNALS:
0080     void filterdtChanged();
0081     void calendarChanged();
0082     void eventCategoryChanged();
0083 
0084 private:
0085     /**
0086      * @return The INTERVAL of RFC 5545. It contains a positive integer representing at
0087       which intervals the recurrence rule repeats.
0088      */
0089     int repeatEvery(const int idx) const;
0090 
0091     /**
0092      * @return The COUNT of RFC 5545. It defines the number of occurrences at which to
0093       range-bound the recurrence.  The "DTSTART" property value always
0094       counts as the first occurrence.
0095      */
0096     int repeatStopAfter(const int idx) const;
0097 
0098     /**
0099      * @return The FREQ rule part which identifies the type of recurrence rule
0100      */
0101     ushort repeatPeriodType(const int idx) const;
0102 
0103     /**
0104      * @return The number of events that overlap with a specific event
0105      */
0106     int overlappingEvents(const int idx) const;
0107 
0108     QString formatStartEndTime(const QDateTime &startDtTime, const QDateTime &endDtTime) const;
0109     QString formatStartEndDt(const QDateTime &startDtTime, const QDateTime &endDtTime, bool allDay) const;
0110 
0111     KCalendarCore::Event::List m_events;
0112     QDate m_filterdt;
0113     QString m_category;
0114     LocalCalendar *m_local_calendar;
0115     SettingsController *m_settings_controller;
0116 };
0117 
0118 #endif //EVENTMODEL_H