File indexing completed on 2024-05-05 05:28:20
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef INCIDENCE_MODEL_H 0008 #define INCIDENCE_MODEL_H 0009 0010 #include <QAbstractListModel> 0011 #include <KCalendarCore/Incidence> 0012 #include <KCalendarCore/Event> 0013 #include <KCalendarCore/Todo> 0014 #include <KCalendarCore/CalFilter> 0015 #include "localcalendar.h" 0016 0017 using namespace KCalendarCore; 0018 0019 class IncidenceModel : public QAbstractListModel 0020 { 0021 Q_OBJECT 0022 0023 Q_PROPERTY(int filterMode READ filterMode WRITE setFilterMode NOTIFY filterModeChanged) 0024 Q_PROPERTY(QDate filterDt READ filterDt WRITE setFilterDt NOTIFY filterDtChanged) 0025 Q_PROPERTY(int filterHour READ filterHour WRITE setFilterHour NOTIFY filterHourChanged) 0026 Q_PROPERTY(bool filterHideCompleted READ filterHideCompleted WRITE setFilterHideCompleted NOTIFY filterHideCompletedChanged) 0027 Q_PROPERTY(QLocale appLocale READ appLocale WRITE setAppLocale NOTIFY appLocaleChanged) 0028 0029 public: 0030 explicit IncidenceModel(QObject *parent = nullptr); 0031 ~IncidenceModel() override; 0032 0033 enum FilterModes { 0034 Invalid = 0, 0035 HourIncidences, 0036 HourEvents, 0037 HourTodos, 0038 DayIncidences, 0039 DayEvents, 0040 DayTodos, 0041 AllIncidences, 0042 AllEvents, 0043 AllTodos, 0044 OrganizerName 0045 }; 0046 0047 enum Roles { 0048 Uid = Qt::UserRole + 1, 0049 LastModified, 0050 DtStart, 0051 AllDay, 0052 Description, 0053 Summary, 0054 Location, 0055 Categories, 0056 Priority, 0057 Created, 0058 Secrecy, 0059 EndDate, 0060 IsRepeating, 0061 RepeatPeriodType, 0062 RepeatEvery, 0063 RepeatStopAfter, 0064 DisplayStartDate, 0065 Completed, 0066 IncidenceType, 0067 DisplayStartEndTime, 0068 DisplayDueDate, 0069 DisplayDueTime, 0070 DisplayStartTime, 0071 DisplayType, 0072 Due, 0073 ValidStartDt, 0074 ValidEndDt, 0075 ValidDueDt, 0076 AttendeeEmails, 0077 DisplayAttendeeEmails, 0078 DisplaytAttendeeNames, 0079 IncidenceStatus 0080 }; 0081 0082 // Copied from KCalendarCore::Incidence 0083 enum Status { 0084 StatusNone, /**< No status */ 0085 StatusTentative, /**< event is tentative */ 0086 StatusConfirmed, /**< event is definite */ 0087 StatusCompleted, /**< to-do completed */ 0088 StatusNeedsAction, /**< to-do needs action */ 0089 StatusCanceled, /**< event or to-do canceled; journal removed */ 0090 StatusInProcess, /**< to-do in process */ 0091 StatusDraft, /**< journal is draft */ 0092 StatusFinal, /**< journal is final */ 0093 StatusX, /**< a non-standard status string */ 0094 }; 0095 Q_ENUM(Status) 0096 0097 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0098 QHash<int, QByteArray> roleNames() const override; 0099 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0100 0101 QDate filterDt() const; 0102 void setFilterDt(const QDate &filterDate); 0103 0104 int filterHour() const; 0105 void setFilterHour(const int hour); 0106 0107 int filterMode() const; 0108 void setFilterMode(const int mode); 0109 0110 bool filterHideCompleted() const; 0111 void setFilterHideCompleted(const bool hideCompleted); 0112 0113 QLocale appLocale() const; 0114 void setAppLocale(const QLocale &qmlLocale); 0115 0116 Q_SIGNALS: 0117 void filterDtChanged(); 0118 void filterHourChanged(); 0119 void filterHideCompletedChanged(); 0120 void calendarFilterChanged(); 0121 void calendarChanged(); 0122 void filterModeChanged(); 0123 void appLocaleChanged(); 0124 0125 private: 0126 /** 0127 * @return The INTERVAL of RFC 5545. It contains a positive integer representing at 0128 which intervals the recurrence rule repeats. 0129 */ 0130 int repeatEvery(const int idx) const; 0131 0132 /** 0133 * @return The COUNT of RFC 5545. It defines the number of occurrences at which to 0134 range-bound the recurrence. The "DTSTART" property value always 0135 counts as the first occurrence. 0136 */ 0137 int repeatStopAfter(const int idx) const; 0138 0139 /** 0140 * return The FREQ rule part which identifies the type of recurrence rule 0141 */ 0142 ushort repeatPeriodType(const int idx) const; 0143 0144 void loadIncidences(); 0145 Incidence::List hourIncidences() const; 0146 Incidence::List hourEvents() const; 0147 Incidence::List hourTodos() const; 0148 Incidence::List dayIncidences() const; 0149 Incidence::List dayEvents() const; 0150 Incidence::List dayTodos() const; 0151 Incidence::List allIncidences() const; 0152 Incidence::List allEvents() const; 0153 Incidence::List allTodos() const; 0154 Incidence::List toIncidences(const Event::List &eventList) const; 0155 Incidence::List toIncidences(const Todo::List &todoList) const; 0156 Incidence::List toIncidences(const Event::List &eventList, const Todo::List &todoList) const; 0157 QString displayStartEndTime(const int idx) const; 0158 QString eventDisplayStartEndTime(const Event::Ptr event) const; 0159 QString displayStartDate(const int idx) const; 0160 QString displayDueDate(const int idx) const; 0161 QString displayDueTime(const int idx) const; 0162 QString displayStartTime(const int idx) const; 0163 bool isHourEvent(const Event::Ptr event) const; 0164 bool withinFilter(const KCalendarCore::Event::Ptr event, const QDate &filterDate) const; 0165 void setCalendarFilter(); 0166 QStringList attendeeEmails(const int idx) const; 0167 QStringList attendeeNames(const int idx) const; 0168 0169 int m_filter_mode; 0170 QDate m_filter_dt; 0171 int m_filter_hour; 0172 bool m_filter_hide_completed; 0173 LocalCalendar *m_calendar; 0174 Incidence::List m_incidences; 0175 QLocale m_locale; 0176 CalFilter *m_cal_filter; 0177 }; 0178 0179 #endif //INCIDENCE_MODEL_H