File indexing completed on 2024-04-21 03:52:48
0001 /* 0002 This file is part of the kcalcore library. 0003 0004 SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 SPDX-FileCopyrightText: 2006 David Jarvie <djarvie@kde.org> 0007 SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com> 0008 0009 SPDX-License-Identifier: LGPL-2.0-or-later 0010 */ 0011 /** 0012 @file 0013 This file is part of the API for handling calendar data and 0014 defines the internal ICalFormatImpl class. 0015 0016 @author Cornelius Schumacher \<schumacher@kde.org\> 0017 @author Reinhold Kainhofer \<reinhold@kainhofer.com\> 0018 @author David Jarvie \<djarvie@kde.org\> 0019 */ 0020 #ifndef KCALCORE_ICALFORMAT_P_H 0021 #define KCALCORE_ICALFORMAT_P_H 0022 0023 #include "calendar.h" 0024 #include "event.h" 0025 #include "exceptions.h" 0026 #include "freebusy.h" 0027 #include "journal.h" 0028 #include "person.h" 0029 #include "schedulemessage.h" 0030 #include "todo.h" 0031 0032 #include <libical/ical.h> 0033 0034 #include <memory> 0035 0036 class QDate; 0037 0038 namespace KCalendarCore 0039 { 0040 class Alarm; 0041 class Attachment; 0042 class Attendee; 0043 class Compat; 0044 class Conference; 0045 class Duration; 0046 class Event; 0047 class FreeBusy; 0048 class ICalFormat; 0049 class ICalTimeZoneCache; 0050 class Incidence; 0051 class Journal; 0052 class Recurrence; 0053 class RecurrenceRule; 0054 class Todo; 0055 0056 using TimeZoneList = QList<QTimeZone>; 0057 0058 /** 0059 Tell the Libical library that we are using ICal Version 2.0. 0060 @internal 0061 */ 0062 #define _ICAL_VERSION "2.0" 0063 0064 /** 0065 Version of this library implementation 0066 @internal 0067 */ 0068 #define _ICAL_IMPLEMENTATION_VERSION "1.0" 0069 0070 /** 0071 @brief 0072 This class provides the libical dependent functions for ICalFormat. 0073 0074 This class implements the iCalendar format. It provides methods for 0075 loading/saving/converting iCalendar format data into the internal 0076 representation as Calendar and Incidences. 0077 0078 @internal 0079 */ 0080 class ICalFormatImpl 0081 { 0082 public: 0083 /** 0084 Construct a new iCal format for calendar object. 0085 @param parent is a pointer to a valid ICalFormat object. 0086 */ 0087 explicit ICalFormatImpl(ICalFormat *parent); 0088 0089 /** 0090 Destructor. 0091 */ 0092 ~ICalFormatImpl(); 0093 0094 /** 0095 Updates a calendar with data from a raw iCalendar. Incidences already 0096 existing in @p calendar are not affected except that if a new incidence 0097 with the same UID is found, the existing incidence is replaced. 0098 */ 0099 bool populate(const Calendar::Ptr &calendar, icalcomponent *fs); 0100 0101 Incidence::Ptr readOneIncidence(icalcomponent *calendar, const ICalTimeZoneCache *tzlist); 0102 0103 icalcomponent *writeIncidence(const IncidenceBase::Ptr &incidence, iTIPMethod method = iTIPRequest, TimeZoneList *tzUsedList = nullptr); 0104 0105 icalcomponent *writeTodo(const Todo::Ptr &todo, TimeZoneList *tzUsedList = nullptr); 0106 0107 icalcomponent *writeEvent(const Event::Ptr &event, TimeZoneList *tzUsedList = nullptr); 0108 0109 icalcomponent *writeJournal(const Journal::Ptr &journal, TimeZoneList *tzUsedList = nullptr); 0110 0111 icalcomponent *writeFreeBusy(const FreeBusy::Ptr &freebusy, iTIPMethod method = iTIPPublish); 0112 0113 void writeIncidence(icalcomponent *parent, const Incidence::Ptr &incidence, TimeZoneList *tzUsedList = nullptr); 0114 0115 icalproperty *writeDescription(const QString &description, bool isRich = false); 0116 icalproperty *writeSummary(const QString &summary, bool isRich = false); 0117 icalproperty *writeLocation(const QString &location, bool isRich = false); 0118 icalproperty *writeAttendee(const Attendee &attendee); 0119 icalproperty *writeOrganizer(const Person &organizer); 0120 icalproperty *writeAttachment(const Attachment &attach); 0121 icalproperty *writeRecurrenceRule(Recurrence *); 0122 icalrecurrencetype writeRecurrenceRule(RecurrenceRule *recur); 0123 icalcomponent *writeAlarm(const Alarm::Ptr &alarm); 0124 icalproperty *writeConference(const Conference &conference); 0125 0126 QString extractErrorProperty(icalcomponent *); 0127 Todo::Ptr readTodo(icalcomponent *vtodo, const ICalTimeZoneCache *tzList); 0128 Event::Ptr readEvent(icalcomponent *vevent, const ICalTimeZoneCache *tzList); 0129 FreeBusy::Ptr readFreeBusy(icalcomponent *vfreebusy); 0130 Journal::Ptr readJournal(icalcomponent *vjournal, const ICalTimeZoneCache *tzList); 0131 Attendee readAttendee(icalproperty *attendee); 0132 Person readOrganizer(icalproperty *organizer); 0133 Attachment readAttachment(icalproperty *attach); 0134 void readIncidence(icalcomponent *parent, const Incidence::Ptr &incidence, const ICalTimeZoneCache *tzList); 0135 void readRecurrenceRule(icalproperty *rrule, const Incidence::Ptr &event); 0136 void readExceptionRule(icalproperty *rrule, const Incidence::Ptr &incidence); 0137 void readRecurrence(const struct icalrecurrencetype &r, RecurrenceRule *recur); 0138 void readAlarm(icalcomponent *alarm, const Incidence::Ptr &incidence); 0139 Conference readConference(icalproperty *conference); 0140 0141 /** 0142 Returns the PRODID string loaded from calendar file. 0143 */ 0144 QString loadedProductId() const; 0145 0146 static icaltimetype writeICalDate(const QDate &); 0147 0148 static QDate readICalDate(const icaltimetype &); 0149 0150 static icaltimetype writeICalDateTime(const QDateTime &, bool dayOnly = false); 0151 0152 static icaltimetype writeICalUtcDateTime(const QDateTime &, bool dayOnly = false); 0153 0154 /** 0155 Creates an ical property from a date/time value. 0156 If a time zone is specified for the value, a TZID parameter is inserted 0157 into the ical property, @p tzlist and @p tzUsedList are updated to include 0158 the time zone. Note that while @p tzlist owns any time zone instances in 0159 its collection, @p tzUsedList does not. 0160 0161 @param kind kind of property 0162 @param dt date/time value 0163 @param tzlist time zones collection 0164 @param tzUsedList time zones collection, only updated if @p tzlist 0165 is also specified 0166 @return property, or null if error. It is the caller's responsibility 0167 to free the returned property. 0168 */ 0169 static icalproperty *writeICalDateTimeProperty(const icalproperty_kind kind, const QDateTime &dt, TimeZoneList *tzUsedList = nullptr); 0170 0171 /** 0172 Converts a date/time from ICal format. 0173 0174 @param p property from which @p t has been obtained 0175 @param t ICal format date/time 0176 @param utc UTC date/time is expected 0177 @return date/time, converted to UTC if @p utc is @c true 0178 */ 0179 static QDateTime readICalDateTime(icalproperty *p, const icaltimetype &t, const ICalTimeZoneCache *tzList, bool utc = false); 0180 0181 /** 0182 Converts a UTC date/time from ICal format. 0183 If @p t is not a UTC date/time, it is treated as invalid. 0184 0185 @param p ical parameter to read from 0186 @param t ICal format date/time 0187 @return date/time, or invalid if @p t is not UTC 0188 */ 0189 static QDateTime readICalUtcDateTime(icalproperty *p, icaltimetype &t, const ICalTimeZoneCache *tzList = nullptr) 0190 { 0191 return readICalDateTime(p, t, tzList, true); 0192 } 0193 0194 /** 0195 Reads a date or date/time value from a property. 0196 0197 @param p ical parameter to read from 0198 @param utc true to read a UTC value, false to allow time zone 0199 to be specified. 0200 @return date or date/time, or invalid if property doesn't contain 0201 a time value. 0202 */ 0203 static QDateTime readICalDateTimeProperty(icalproperty *p, const ICalTimeZoneCache *tzList, bool utc = false, bool *allDay = nullptr); 0204 0205 /** 0206 Reads a UTC date/time value from a property. 0207 @param p is a pointer to a valid icalproperty structure. 0208 */ 0209 static QDateTime readICalUtcDateTimeProperty(icalproperty *p, const ICalTimeZoneCache *tzList, bool *allDay = nullptr) 0210 { 0211 return readICalDateTimeProperty(p, tzList, true, allDay); 0212 } 0213 0214 static icaldurationtype writeICalDuration(const Duration &duration); 0215 0216 static Duration readICalDuration(const icaldurationtype &d); 0217 0218 static icaldatetimeperiodtype writeICalDatePeriod(const QDate &date); 0219 0220 icalcomponent *createCalendarComponent(const Calendar::Ptr &calendar = Calendar::Ptr()); 0221 0222 icalcomponent *createScheduleComponent(const IncidenceBase::Ptr &incidence, iTIPMethod method); 0223 0224 protected: 0225 // void dumpIcalRecurrence( const icalrecurrencetype &r ); 0226 0227 private: 0228 void writeIncidenceBase(icalcomponent *parent, const IncidenceBase::Ptr &); 0229 void readIncidenceBase(icalcomponent *parent, const IncidenceBase::Ptr &); 0230 void writeCustomProperties(icalcomponent *parent, CustomProperties *); 0231 void readCustomProperties(icalcomponent *parent, CustomProperties *); 0232 0233 ICalFormat *mParent = nullptr; 0234 QString mLoadedProductId; // PRODID string loaded from calendar file 0235 Event::List mEventsRelate; // events with relations 0236 Todo::List mTodosRelate; // todos with relations 0237 std::unique_ptr<Compat> mCompat; 0238 }; 0239 0240 } 0241 0242 #endif