MauiKit Calendar

incidencewrapper.h
1// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "calendarmanager.h"
7#include "models/attachmentsmodel.h"
8#include "models/attendeesmodel.h"
9#include "models/recurrenceexceptionsmodel.h"
10
11#include <Akonadi/CollectionIdentificationAttribute>
12#include <Akonadi/Item>
13#include <Akonadi/ItemFetchJob>
14#include <Akonadi/ItemFetchScope>
15#include <Akonadi/ItemMonitor>
16#include <KCalUtils/RecurrenceActions>
17#include <KFormat>
18#include <QByteArray>
19#include <QObject>
20#include <QQmlEngine>
21/**
22 * This class is a wrapper for a KCalendarCore::Incidence::Ptr object.
23 * We can use it to create new incidences, or create incidence pointers from
24 * pre-existing incidences, to more cleanly pass around to our QML code
25 * or to the CalendarManager, which handles the back-end stuff of
26 * adding and editing the incidence in the collection of our choice.
27 */
28
30{
32 QML_ELEMENT
33
34 // Akonadi properties
35 Q_PROPERTY(Akonadi::Item incidenceItem READ incidenceItem WRITE setIncidenceItem NOTIFY incidenceItemChanged)
36 Q_PROPERTY(qint64 collectionId READ collectionId WRITE setCollectionId NOTIFY collectionIdChanged)
37
38 // Incidence properties
39 Q_PROPERTY(KCalendarCore::Incidence::Ptr incidencePtr READ incidencePtr WRITE setIncidencePtr NOTIFY incidencePtrChanged)
40 Q_PROPERTY(KCalendarCore::Incidence::Ptr originalIncidencePtr READ originalIncidencePtr NOTIFY originalIncidencePtrChanged)
41 Q_PROPERTY(int incidenceType READ incidenceType NOTIFY incidenceTypeChanged)
42 Q_PROPERTY(QString incidenceTypeStr READ incidenceTypeStr NOTIFY incidenceTypeStrChanged)
43 Q_PROPERTY(QString incidenceIconName READ incidenceIconName NOTIFY incidenceIconNameChanged)
44 Q_PROPERTY(QString uid READ uid CONSTANT) // TODO: This needs to not be a CONSTANT
45
46 Q_PROPERTY(QString parent READ parent WRITE setParent NOTIFY parentChanged)
47 Q_PROPERTY(IncidenceWrapper *parentIncidence READ parentIncidence NOTIFY parentIncidenceChanged)
48 Q_PROPERTY(QVariantList childIncidences READ childIncidences NOTIFY childIncidencesChanged)
49
50 Q_PROPERTY(QString summary READ summary WRITE setSummary NOTIFY summaryChanged)
51 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
52 Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
53 Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged)
54 Q_PROPERTY(bool hasGeo READ hasGeo CONSTANT) // TODO: This needs to not be a CONSTANT
55 Q_PROPERTY(float geoLatitude READ geoLatitude CONSTANT) // TODO: This needs to not be a CONSTANT
56 Q_PROPERTY(float geoLongitude READ geoLongitude CONSTANT) // TODO: This needs to not be a CONSTANT
57
58 Q_PROPERTY(QDateTime incidenceStart READ incidenceStart WRITE setIncidenceStart NOTIFY incidenceStartChanged)
59 Q_PROPERTY(QString incidenceStartDateDisplay READ incidenceStartDateDisplay NOTIFY incidenceStartDateDisplayChanged)
60 Q_PROPERTY(QString incidenceStartTimeDisplay READ incidenceStartTimeDisplay NOTIFY incidenceStartTimeDisplayChanged)
61 Q_PROPERTY(QDateTime incidenceEnd READ incidenceEnd WRITE setIncidenceEnd NOTIFY incidenceEndChanged)
62 Q_PROPERTY(QString incidenceEndDateDisplay READ incidenceEndDateDisplay NOTIFY incidenceEndDateDisplayChanged)
63 Q_PROPERTY(QString incidenceEndTimeDisplay READ incidenceEndTimeDisplay NOTIFY incidenceEndTimeDisplayChanged)
64 Q_PROPERTY(QByteArray timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged)
65 Q_PROPERTY(int startTimeZoneUTCOffsetMins READ startTimeZoneUTCOffsetMins NOTIFY startTimeZoneUTCOffsetMinsChanged)
66 Q_PROPERTY(int endTimeZoneUTCOffsetMins READ endTimeZoneUTCOffsetMins NOTIFY endTimeZoneUTCOffsetMinsChanged)
67 Q_PROPERTY(KCalendarCore::Duration duration READ duration NOTIFY durationChanged)
68 Q_PROPERTY(QString durationDisplayString READ durationDisplayString NOTIFY durationDisplayStringChanged)
69 Q_PROPERTY(bool allDay READ allDay WRITE setAllDay NOTIFY allDayChanged)
70 Q_PROPERTY(int priority READ priority WRITE setPriority NOTIFY priorityChanged)
71
72 Q_PROPERTY(KCalendarCore::Recurrence *recurrence READ recurrence NOTIFY incidencePtrChanged)
73 Q_PROPERTY(QVariantMap recurrenceData READ recurrenceData NOTIFY recurrenceDataChanged)
74 // Q_PROPERTY(RecurrenceExceptionsModel *recurrenceExceptionsModel READ recurrenceExceptionsModel NOTIFY recurrenceExceptionsModelChanged)
75
76 // Q_PROPERTY(AttendeesModel *attendeesModel READ attendeesModel NOTIFY attendeesModelChanged)
77 Q_PROPERTY(QVariantMap organizer READ organizer NOTIFY organizerChanged)
78 // Q_PROPERTY(KCalendarCore::Attendee::List attendees READ attendees NOTIFY attendeesChanged)
79
80 // Q_PROPERTY(AttachmentsModel *attachmentsModel READ attachmentsModel NOTIFY attachmentsModelChanged)
81
82 Q_PROPERTY(bool todoCompleted READ todoCompleted WRITE setTodoCompleted NOTIFY todoCompletedChanged)
83 Q_PROPERTY(QDateTime todoCompletionDt READ todoCompletionDt NOTIFY todoCompletionDtChanged)
84 Q_PROPERTY(int todoPercentComplete READ todoPercentComplete WRITE setTodoPercentComplete NOTIFY todoPercentCompleteChanged)
85
86 Q_PROPERTY(QString googleConferenceUrl READ googleConferenceUrl NOTIFY googleConferenceUrlChanged)
87
88public:
89 enum RecurrenceIntervals {
90 Daily,
91 Weekly,
92 Monthly,
93 Yearly,
94 };
95 Q_ENUM(RecurrenceIntervals)
96
97 enum IncidenceTypes {
101 };
102 Q_ENUM(IncidenceTypes)
103
104 enum RecurrenceActions {
108 };
109 Q_ENUM(RecurrenceActions)
110
112
113 explicit IncidenceWrapper(QObject *parent = nullptr);
114 ~IncidenceWrapper() override;
115
116 void notifyDataChanged();
117
118 Akonadi::Item incidenceItem() const;
119 void setIncidenceItem(const Akonadi::Item &incidenceItem);
120 KCalendarCore::Incidence::Ptr incidencePtr() const;
121 KCalendarCore::Incidence::Ptr originalIncidencePtr();
122 int incidenceType() const;
123 QString incidenceTypeStr() const;
124 QString incidenceIconName() const;
125 QString uid() const;
126 qint64 collectionId() const;
127 void setCollectionId(qint64 collectionId);
128 QString parent() const;
129 void setParent(QString parent);
130 IncidenceWrapper *parentIncidence();
131 QVariantList childIncidences();
132
133 QString summary() const;
134 void setSummary(const QString &summary);
135 QStringList categories();
136 void setCategories(QStringList categories);
137 QString description() const;
138 void setDescription(const QString &description);
139 QString location() const;
140 void setLocation(const QString &location);
141 bool hasGeo() const;
142 float geoLatitude() const;
143 float geoLongitude() const;
144
145 QDateTime incidenceStart() const;
146 Q_INVOKABLE void setIncidenceStart(const QDateTime &incidenceStart, bool respectTimeZone = false);
147 Q_INVOKABLE void setIncidenceStartDate(int day, int month, int year);
148 Q_INVOKABLE void setIncidenceStartTime(int hours, int minutes);
149 QString incidenceStartDateDisplay() const;
150 QString incidenceStartTimeDisplay() const;
151 QDateTime incidenceEnd() const;
152 Q_INVOKABLE void setIncidenceEnd(const QDateTime &incidenceEnd, bool respectTimeZone = false);
153 Q_INVOKABLE void setIncidenceEndDate(int day, int month, int year);
154 Q_INVOKABLE void setIncidenceEndTime(int hours, int minutes);
155 QString incidenceEndDateDisplay() const;
156 QString incidenceEndTimeDisplay() const;
157 Q_INVOKABLE void setIncidenceTimeToNearestQuarterHour(bool setStartTime = true, bool setEndTime = true);
158 QByteArray timeZone() const;
159 void setTimeZone(const QByteArray &timeZone);
160 int startTimeZoneUTCOffsetMins();
161 int endTimeZoneUTCOffsetMins();
162 KCalendarCore::Duration duration() const;
163 QString durationDisplayString() const;
164 bool allDay() const;
165 void setAllDay(bool allDay);
166 int priority() const;
167 void setPriority(int priority);
168
169 KCalendarCore::Recurrence *recurrence() const;
170 QVariantMap recurrenceData();
171 Q_INVOKABLE void setRecurrenceDataItem(const QString &key, const QVariant &value);
172
173 QVariantMap organizer();
174 KCalendarCore::Attendee::List attendees() const;
175
176 AttendeesModel *attendeesModel();
177 RecurrenceExceptionsModel *recurrenceExceptionsModel();
178 AttachmentsModel *attachmentsModel();
179
180 bool todoCompleted();
181 void setTodoCompleted(bool completed);
182 QDateTime todoCompletionDt();
183 int todoPercentComplete();
184 void setTodoPercentComplete(int todoPercentComplete);
185
186 Q_INVOKABLE void triggerEditMode();
187 Q_INVOKABLE void setNewEvent();
188 Q_INVOKABLE void setNewTodo();
189 Q_INVOKABLE void addAlarms(KCalendarCore::Alarm::List alarms);
190 Q_INVOKABLE void setRegularRecurrence(IncidenceWrapper::RecurrenceIntervals interval, int freq = 1);
191 Q_INVOKABLE void setMonthlyPosRecurrence(short pos, int day);
192 Q_INVOKABLE void setRecurrenceOccurrences(int occurrences);
193 Q_INVOKABLE void clearRecurrences();
194
195 Q_INVOKABLE void setCollection(const Akonadi::Collection &collection);
196
197 QString googleConferenceUrl();
199 void incidenceItemChanged();
200 void incidencePtrChanged(KCalendarCore::Incidence::Ptr incidencePtr);
201 void originalIncidencePtrChanged();
202 void incidenceTypeChanged();
203 void incidenceTypeStrChanged();
204 void incidenceIconNameChanged();
205 void collectionIdChanged();
206 void parentChanged();
207 void parentIncidenceChanged();
208 void childIncidencesChanged();
209
210 void summaryChanged();
211 void categoriesChanged();
212 void descriptionChanged();
213 void locationChanged();
214
215 void incidenceStartChanged();
216 void incidenceStartDateDisplayChanged();
217 void incidenceStartTimeDisplayChanged();
218 void incidenceEndChanged();
219 void incidenceEndDateDisplayChanged();
220 void incidenceEndTimeDisplayChanged();
221 void timeZoneChanged();
222 void startTimeZoneUTCOffsetMinsChanged();
223 void endTimeZoneUTCOffsetMinsChanged();
224 void durationChanged();
225 void durationDisplayStringChanged();
226 void allDayChanged();
227 void priorityChanged();
228
229 void recurrenceDataChanged();
230 void organizerChanged();
231 void attendeesModelChanged();
232 void recurrenceExceptionsModelChanged();
233 void attachmentsModelChanged();
234
235 void todoCompletedChanged();
236 void todoCompletionDtChanged();
237 void todoPercentCompleteChanged();
238 // void attendeesChanged();
239
240 void googleConferenceUrlChanged();
241
242protected:
243 void itemChanged(const Akonadi::Item &item) override;
244
245private:
246 void setIncidencePtr(KCalendarCore::Incidence::Ptr incidencePtr);
247 void setNewIncidence(KCalendarCore::Incidence::Ptr incidence);
248 void updateParentIncidence();
249 void resetChildIncidences();
250 void cleanupChildIncidences();
251
253 KCalendarCore::Incidence::Ptr m_originalIncidence;
254 qint64 m_collectionId = -1; // For when we want to edit, this is temporary
255 // AttendeesModel m_attendeesModel;
256 // RecurrenceExceptionsModel m_recurrenceExceptionsModel;
257 // AttachmentsModel m_attachmentsModel;
258
259 KFormat m_format;
260 Ptr m_parentIncidence;
261 QVariantList m_childIncidences;
262};
This class is a wrapper for a KCalendarCore::Incidence::Ptr object.
Q_ENUM(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.