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