1 | /* |
2 | This file is part of the kcalcore library. |
3 | |
4 | Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> |
6 | Copyright (c) 2006 David Jarvie <software@astrojar.org.uk> |
7 | Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com> |
8 | |
9 | This library is free software; you can redistribute it and/or |
10 | modify it under the terms of the GNU Library General Public |
11 | License as published by the Free Software Foundation; either |
12 | version 2 of the License, or (at your option) any later version. |
13 | |
14 | This library is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | Library General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Library General Public License |
20 | along with this library; see the file COPYING.LIB. If not, write to |
21 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 | Boston, MA 02110-1301, USA. |
23 | */ |
24 | /** |
25 | @file |
26 | This file is part of the API for handling calendar data and |
27 | defines the internal ICalFormatImpl class. |
28 | |
29 | @author Cornelius Schumacher \<schumacher@kde.org\> |
30 | @author Reinhold Kainhofer \<reinhold@kainhofer.com\> |
31 | @author David Jarvie \<software@astrojar.org.uk\> |
32 | */ |
33 | #ifndef KCALCORE_ICALFORMAT_P_H |
34 | #define KCALCORE_ICALFORMAT_P_H |
35 | |
36 | #include "exceptions.h" |
37 | #include "freebusy.h" |
38 | #include "todo.h" |
39 | #include "journal.h" |
40 | #include "event.h" |
41 | #include "person.h" |
42 | #include "calendar.h" |
43 | #include "schedulemessage.h" |
44 | |
45 | #include <KDateTime> |
46 | |
47 | #include <libical/ical.h> |
48 | |
49 | class QDate; |
50 | |
51 | namespace KCalCore { |
52 | |
53 | class Alarm; |
54 | class Attachment; |
55 | class Attendee; |
56 | class Duration; |
57 | class Event; |
58 | class FreeBusy; |
59 | class ICalFormat; |
60 | class ICalTimeZones; |
61 | class Incidence; |
62 | class Journal; |
63 | class Recurrence; |
64 | class RecurrenceRule; |
65 | class Todo; |
66 | |
67 | /** |
68 | Tell the Libical library that we are using ICal Version 2.0. |
69 | @internal |
70 | */ |
71 | #define _ICAL_VERSION "2.0" |
72 | |
73 | /** |
74 | Version of this library implementation |
75 | @internal |
76 | */ |
77 | #define _ICAL_IMPLEMENTATION_VERSION "1.0" |
78 | |
79 | /** |
80 | @brief |
81 | This class provides the libical dependent functions for ICalFormat. |
82 | |
83 | This class implements the iCalendar format. It provides methods for |
84 | loading/saving/converting iCalendar format data into the internal |
85 | representation as Calendar and Incidences. |
86 | |
87 | @internal |
88 | */ |
89 | class ICalFormatImpl |
90 | { |
91 | public: |
92 | /** |
93 | Construct a new iCal format for calendar object. |
94 | @param parent is a pointer to a valid ICalFormat object. |
95 | */ |
96 | explicit ICalFormatImpl(ICalFormat *parent); |
97 | |
98 | /** |
99 | Destructor. |
100 | */ |
101 | virtual ~ICalFormatImpl(); |
102 | |
103 | /** |
104 | Updates a calendar with data from a raw iCalendar. Incidences already |
105 | existing in @p calendar are not affected except that if a new incidence |
106 | with the same UID is found, the existing incidence is replaced. |
107 | */ |
108 | bool populate(const Calendar::Ptr &calendar, icalcomponent *fs, |
109 | bool deleted = false, const QString ¬ebook = QString()); |
110 | |
111 | icalcomponent *writeIncidence(const IncidenceBase::Ptr &incidence, |
112 | iTIPMethod method = iTIPRequest, |
113 | ICalTimeZones *tzList = 0, |
114 | ICalTimeZones *tzUsedList = 0); |
115 | |
116 | icalcomponent *writeTodo(const Todo::Ptr &todo, ICalTimeZones *tzlist = 0, |
117 | ICalTimeZones *tzUsedList = 0); |
118 | |
119 | icalcomponent *writeEvent(const Event::Ptr &event, ICalTimeZones *tzlist = 0, |
120 | ICalTimeZones *tzUsedList = 0); |
121 | |
122 | icalcomponent *writeJournal(const Journal::Ptr &journal, ICalTimeZones *tzlist = 0, |
123 | ICalTimeZones *tzUsedList = 0); |
124 | |
125 | icalcomponent *writeFreeBusy(const FreeBusy::Ptr &freebusy, |
126 | iTIPMethod method = iTIPPublish); |
127 | |
128 | void writeIncidence(icalcomponent *parent, const Incidence::Ptr &incidence, |
129 | ICalTimeZones *tzlist = 0, ICalTimeZones *tzUsedList = 0); |
130 | |
131 | icalproperty *writeDescription(const QString &description, bool isRich = false); |
132 | icalproperty *writeSummary(const QString &summary, bool isRich = false); |
133 | icalproperty *writeLocation(const QString &location, bool isRich = false); |
134 | icalproperty *writeAttendee(const Attendee::Ptr &attendee); |
135 | icalproperty *writeOrganizer(const Person::Ptr &organizer); |
136 | icalproperty *writeAttachment(const Attachment::Ptr &attach); |
137 | icalproperty *writeRecurrenceRule(Recurrence *); |
138 | icalrecurrencetype writeRecurrenceRule(RecurrenceRule *recur); |
139 | icalcomponent *writeAlarm(const Alarm::Ptr &alarm); |
140 | |
141 | QString (icalcomponent *); |
142 | Todo::Ptr readTodo(icalcomponent *vtodo, ICalTimeZones *tzlist); |
143 | Event::Ptr readEvent(icalcomponent *vevent, ICalTimeZones *tzlist); |
144 | FreeBusy::Ptr readFreeBusy(icalcomponent *vfreebusy); |
145 | Journal::Ptr readJournal(icalcomponent *vjournal, ICalTimeZones *tzlist); |
146 | Attendee::Ptr readAttendee(icalproperty *attendee); |
147 | Person::Ptr readOrganizer(icalproperty *organizer); |
148 | Attachment::Ptr readAttachment(icalproperty *attach); |
149 | void readIncidence(icalcomponent *parent, Incidence::Ptr incidence, |
150 | ICalTimeZones *tzlist); |
151 | void readRecurrenceRule(icalproperty *rrule, Incidence::Ptr event); |
152 | void readExceptionRule(icalproperty *rrule, Incidence::Ptr incidence); |
153 | void readRecurrence(const struct icalrecurrencetype &r, |
154 | RecurrenceRule *recur); |
155 | void readAlarm(icalcomponent *alarm, Incidence::Ptr incidence, |
156 | ICalTimeZones *tzlist); |
157 | |
158 | /** |
159 | Returns the PRODID string loaded from calendar file. |
160 | */ |
161 | QString loadedProductId() const; |
162 | |
163 | static icaltimetype writeICalDate(const QDate &); |
164 | |
165 | static QDate readICalDate(icaltimetype); |
166 | |
167 | static icaltimetype writeICalDateTime(const KDateTime &); |
168 | |
169 | static icaltimetype writeICalUtcDateTime(const KDateTime &); |
170 | |
171 | /** |
172 | Creates an ical property from a date/time value. |
173 | If a time zone is specified for the value, a TZID parameter is inserted |
174 | into the ical property, @p tzlist and @p tzUsedList are updated to include |
175 | the time zone. Note that while @p tzlist owns any time zone instances in |
176 | its collection, @p tzUsedList does not. |
177 | |
178 | @param kind kind of property |
179 | @param dt date/time value |
180 | @param tzlist time zones collection |
181 | @param tzUsedList time zones collection, only updated if @p tzlist |
182 | is also specified |
183 | @return property, or null if error. It is the caller's responsibility |
184 | to free the returned property. |
185 | */ |
186 | static icalproperty *writeICalDateTimeProperty(const icalproperty_kind kind, |
187 | const KDateTime &dt, |
188 | ICalTimeZones *tzlist = 0, |
189 | ICalTimeZones *tzUsedList = 0); |
190 | |
191 | /** |
192 | Converts a date/time from ICal format. |
193 | If the property @p p specifies a time zone using the TZID parameter, |
194 | a match is searched for in @p tzlist. If no match is found, the time zone |
195 | is added to @p tzlist. |
196 | |
197 | @param p property from which @p t has been obtained |
198 | @param t ICal format date/time |
199 | @param tzlist time zones collection |
200 | @param utc UTC date/time is expected |
201 | @return date/time, converted to UTC if @p utc is @c true |
202 | */ |
203 | static KDateTime readICalDateTime(icalproperty *p, const icaltimetype &t, |
204 | ICalTimeZones *tzlist, bool utc = false); |
205 | |
206 | /** |
207 | Converts a UTC date/time from ICal format. |
208 | If @p t is not a UTC date/time, it is treated as invalid. |
209 | |
210 | @param p ical parameter to read from |
211 | @param t ICal format date/time |
212 | @param tzlist time zones collection |
213 | @return date/time, or invalid if @p t is not UTC |
214 | */ |
215 | static KDateTime readICalUtcDateTime(icalproperty *p, icaltimetype &t, |
216 | ICalTimeZones *tzlist = 0) |
217 | //TODO: KDE5, move this implementation to icalformat_p.cpp |
218 | { |
219 | return readICalDateTime(p, t, tzlist, true); |
220 | } |
221 | |
222 | /** |
223 | Reads a date or date/time value from a property. |
224 | |
225 | @param p ical parameter to read from |
226 | @param tzlist time zones collection |
227 | @param utc true to read a UTC value, false to allow time zone |
228 | to be specified. |
229 | @return date or date/time, or invalid if property doesn't contain |
230 | a time value. |
231 | */ |
232 | static KDateTime readICalDateTimeProperty(icalproperty *p, |
233 | ICalTimeZones *tzlist, bool utc = false); |
234 | |
235 | /** |
236 | Reads a UTC date/time value from a property. |
237 | @param p is a pointer to a valid icalproperty structure. |
238 | */ |
239 | static KDateTime readICalUtcDateTimeProperty(icalproperty *p) |
240 | { |
241 | return readICalDateTimeProperty(p, 0, true); |
242 | } |
243 | |
244 | static icaldurationtype writeICalDuration(const Duration &duration); |
245 | |
246 | static Duration readICalDuration(icaldurationtype d); |
247 | |
248 | static icaldatetimeperiodtype writeICalDatePeriod(const QDate &date); |
249 | |
250 | icalcomponent *createCalendarComponent(const Calendar::Ptr &calendar = Calendar::Ptr()); |
251 | |
252 | icalcomponent *createScheduleComponent(const IncidenceBase::Ptr &incidence, |
253 | iTIPMethod method); |
254 | |
255 | protected: |
256 | // void dumpIcalRecurrence( const icalrecurrencetype &r ); |
257 | |
258 | private: |
259 | //@cond PRIVATE |
260 | class Private; |
261 | Private *const d; |
262 | //@endcond |
263 | }; |
264 | |
265 | } |
266 | |
267 | #endif |
268 | |