1/*
2 This file is part of the kcalcore library.
3
4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
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 defines
26 classes for managing compatibility between different calendar formats.
27
28 @author Cornelius Schumacher \<schumacher@kde.org\>
29 @author Reinhold Kainhofer \<reinhold@kainhofer.com\>
30*/
31
32#ifndef KCALCORE_COMPAT_P_H
33#define KCALCORE_COMPAT_P_H
34
35#include "incidence.h"
36
37#include <QtCore/QtGlobal> // for Q_DISABLE_COPY()
38
39class QDate;
40class QString;
41
42namespace KCalCore {
43
44class Compat;
45
46/**
47 @brief
48 Factory for creating the right Compat object.
49
50 @internal
51*/
52class CompatFactory
53{
54public:
55 /**
56 Creates the appropriate Compat class as determined by the Product ID.
57
58 @param productId is a string containing a valid Product ID from
59 a supported calendar format.
60 @return A pointer to a Compat object which is owned by the caller.
61 */
62 static Compat *createCompat(const QString &productId, const QString &implementationVersion);
63};
64
65/**
66 @brief
67 This class provides compatibility to older or broken calendar files.
68
69 @internal
70*/
71class Compat
72{
73public:
74 /**
75 Constructor.
76 */
77 Compat();
78
79 /**
80 Destructor.
81 */
82 virtual ~Compat();
83
84 /**
85 Fixes the recurrence rule for an incidence.
86 @param incidence is a pointer to an Incidence object that may
87 need its recurrence rule fixed.
88 */
89 virtual void fixRecurrence(const Incidence::Ptr &incidence);
90
91 /**
92 Fixes an empty summary for an incidence.
93 @param incidence is a pointer to an Incidence object that may need
94 its summary fixed.
95 */
96 virtual void fixEmptySummary(const Incidence::Ptr &incidence);
97
98 /**
99 Fixes the alarms list an incidence.
100 @param incidence is a pointer to an Incidence object that may need
101 its alarms fixed.
102 */
103 virtual void fixAlarms(const Incidence::Ptr &incidence);
104
105 /**
106 Fixes the end date for floating events.
107 @param date is the end date to fix.
108 */
109 virtual void fixFloatingEnd(QDate &date);
110
111 /**
112 Fixes the priority.
113 @param priority is the priority value to fix.
114 @return an integer representing a valid priority value.
115 */
116 virtual int fixPriority(int priority);
117
118 /**
119 Returns true if a timezone shift should be used; false otherwise.
120 */
121 virtual bool useTimeZoneShift();
122
123 /**
124 Sets the created and dtstamp.
125 */
126 virtual void setCreatedToDtStamp(const Incidence::Ptr &incidence, const KDateTime &dtstamp);
127
128private:
129 //@cond PRIVATE
130 Q_DISABLE_COPY(Compat)
131 class Private;
132 Private *d;
133 //@endcond
134};
135
136/**
137 @brief
138 Decorator so multiple compatibility classes can be stacked.
139*/
140class CompatDecorator : public Compat
141{
142public:
143 explicit CompatDecorator(Compat *decoratedCompat);
144 virtual ~CompatDecorator();
145
146 /**
147 @copydoc
148 Compat::fixRecurrence()
149 */
150 virtual void fixRecurrence(const Incidence::Ptr &incidence);
151
152 /**
153 @copydoc
154 Compat::fixEmptySummary()
155 */
156 virtual void fixEmptySummary(const Incidence::Ptr &incidence);
157
158 /**
159 @copydoc
160 Compat::fixAlarms()
161 */
162 virtual void fixAlarms(const Incidence::Ptr &incidence);
163
164 /**
165 @copydoc
166 Compat::fixFloatingEnd()
167 */
168 virtual void fixFloatingEnd(QDate &date);
169
170 /**
171 @copydoc
172 Compat::fixPriority()
173 */
174 virtual int fixPriority(int priority);
175
176 /**
177 @copydoc
178 Compat::useTimeZoneShift()
179 */
180 virtual bool useTimeZoneShift();
181
182 /**
183 @copydoc
184 Compat::setCreatedToDtStamp()
185 */
186 virtual void setCreatedToDtStamp(const Incidence::Ptr &incidence, const KDateTime &dtstamp);
187
188private:
189 //@cond PRIVATE
190 Q_DISABLE_COPY(CompatDecorator)
191 class Private;
192 Private *d;
193 //@endcond
194};
195
196/**
197 @brief
198 Compatibility class for KOrganizer pre-3.5 calendar files.
199
200 Before kde 3.5, the start date was not automatically a recurring date.
201 So, if the start date doesn't match the recurrence rule, we need to add
202 an ex-date for the date start. If a duration was given, the DTSTART was
203 only counted if it matched, so by accident this was already the correct
204 behavior, so we don't need to adjust the duration.
205*/
206class CompatPre35 : public Compat
207{
208public:
209 /**
210 @copydoc
211 Compat::fixRecurrence()
212 */
213 virtual void fixRecurrence(const Incidence::Ptr &incidence);
214
215private:
216 //@cond PRIVATE
217 class Private;
218 Private *d;
219 //@endcond
220};
221
222/**
223 @brief
224 Compatibility class for KOrganizer pre-3.4 calendar files.
225*/
226class CompatPre34 : public CompatPre35
227{
228public:
229 /**
230 @copydoc
231 Compat::fixPriority()
232 */
233 virtual int fixPriority(int priority);
234
235private:
236 //@cond PRIVATE
237 class Private;
238 Private *d;
239 //@endcond
240};
241
242/**
243 @brief
244 Compatibility class for KOrganizer pre-3.2 calendar files.
245
246 The recurrence has a specified number of repetitions.
247 Pre-3.2, this was extended by the number of exception dates.
248 This is also rfc 2445-compliant. The duration of an RRULE also counts
249 events that are later excluded via EXDATE or EXRULE.
250*/
251class CompatPre32 : public CompatPre34
252{
253public:
254 /**
255 @copydoc
256 Compat::fixRecurrence()
257 */
258 virtual void fixRecurrence(const Incidence::Ptr &incidence);
259
260private:
261 //@cond PRIVATE
262
263 class Private;
264 Private *d;
265 //@endcond
266};
267
268/**
269 @brief
270 Compatibility class for KOrganizer pre-3.1 calendar files.
271
272 Before kde 3.1, floating events (events without a date) had 0:00 of their
273 last day as the end date. E.g. 28.5.2005 0:00 until 28.5.2005 0:00 for an
274 event that lasted the whole day on May 28, 2005. According to RFC 2445, the
275 end date for such an event needs to be 29.5.2005 0:00.
276
277 Update: We misunderstood rfc 2445 in this regard. For all-day events, the
278 DTEND is the last day of the event. See a mail from the Author or rfc 2445:
279 http://www.imc.org/ietf-calendar/archive1/msg03648.html
280 However, as all other applications also got this wrong, we'll just leave it
281 as it is and use the wrong interpretation (was also discussed on ietf-calsify)
282*/
283class CompatPre31 : public CompatPre32
284{
285public:
286 /**
287 @copydoc
288 Compat::fixFloatingEnd()
289 */
290 virtual void fixFloatingEnd(QDate &date);
291
292 /**
293 @copydoc
294 Compat::fixRecurrence()
295 */
296 virtual void fixRecurrence(const Incidence::Ptr &incidence);
297
298private:
299 //@cond PRIVATE
300 class Private;
301 Private *d;
302 //@endcond
303};
304
305/**
306 @brief
307 Compatibility class for KOrganizer prerelease 3.2 calendar files.
308*/
309class Compat32PrereleaseVersions : public Compat
310{
311public:
312 /**
313 @copydoc
314 Compat::useTimeZoneShift()
315 */
316 virtual bool useTimeZoneShift();
317
318private:
319 //@cond PRIVATE
320 class Private;
321 Private *d;
322 //@endcond
323};
324
325/**
326 @brief
327 Compatibility class for Outlook 9 calendar files.
328
329 In Outlook 9, alarms have the wrong sign. I.e. RFC 2445 says that negative
330 values for the trigger are before the event's start. Outlook/exchange,
331 however used positive values.
332*/
333class CompatOutlook9 : public Compat
334{
335public:
336 /**
337 @copydoc
338 Compat::fixAlarms()
339 */
340 virtual void fixAlarms(const Incidence::Ptr &incidence);
341
342private:
343 //@cond PRIVATE
344 class Private;
345 Private *d;
346 //@endcond
347};
348
349/**
350 @brief
351 Compatibility class for Kontact < 4.10 calendar files.
352*/
353class CompatPre410 : public CompatDecorator
354{
355public:
356 explicit CompatPre410(Compat *decoratedCompat);
357
358 /**
359 @copydoc
360 Compat::setCreatedToDtStamp()
361 */
362 virtual void setCreatedToDtStamp(const Incidence::Ptr &incidence, const KDateTime &dtstamp);
363
364private:
365 //@cond PRIVATE
366 class Private;
367 Private *d;
368 //@endcond
369};
370
371}
372
373#endif
374