1/*
2 This file is part of the kcalcore library.
3
4 Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22/**
23 @file
24 This file is part of the API for handling calendar data and
25 defines the FreeBusy class.
26
27 @author Cornelius Schumacher \<schumacher@kde.org\>
28 @author Reinhold Kainhofer \<reinhold@kainhofer.com\>
29*/
30
31#ifndef KCALCORE_FREEBUSY_H
32#define KCALCORE_FREEBUSY_H
33
34#include "kcalcore_export.h"
35#include "event.h"
36#include "freebusyperiod.h"
37#include "incidencebase.h"
38#include "period.h"
39
40#include <QtCore/QMetaType>
41
42namespace KCalCore {
43
44class FreeBusy;
45
46/**
47 @brief
48 Provides information about the free/busy time of a calendar.
49
50 A free/busy is a collection of Periods (@see Period).
51*/
52class KCALCORE_EXPORT FreeBusy : public IncidenceBase
53{
54 friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s,
55 const KCalCore::FreeBusy::Ptr &freebusy);
56 friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s,
57 KCalCore::FreeBusy::Ptr &freebusy);
58
59public:
60
61 /**
62 A shared pointer to a FreeBusy object.
63 */
64 typedef QSharedPointer<FreeBusy> Ptr;
65
66 /**
67 List of FreeBusy objects.
68 */
69 typedef QVector<Ptr> List;
70
71 /**
72 Constructs an free/busy without any periods.
73 */
74 FreeBusy();
75
76 /**
77 Copy constructor.
78 @param other is the free/busy to copy.
79 */
80 FreeBusy(const FreeBusy &other);
81
82 /**
83 Constructs a free/busy from a list of periods.
84 @param busyPeriods is a list of periods.
85 */
86 explicit FreeBusy(const Period::List &busyPeriods);
87
88 /**
89 Constructs a free/busy from a list of periods.
90 @param busyPeriods is a list of periods.
91 */
92 explicit FreeBusy(const FreeBusyPeriod::List &busyPeriods);
93
94 /**
95 Constructs a free/busy from a single period.
96
97 @param start is the start date/time of the period.
98 @param end is the end date/time of the period.
99 */
100 FreeBusy(const KDateTime &start, const KDateTime &end);
101
102 /**
103 Constructs a freebusy for a specified list of events given a single period.
104
105 @param events list of events.
106 @param start is the start date/time of the period.
107 @param end is the end date/time of the period.
108 */
109 FreeBusy(const Event::List &events, const KDateTime &start, const KDateTime &end);
110
111 /**
112 Destroys a free/busy.
113 */
114 ~FreeBusy();
115
116 /**
117 @copydoc
118 IncidenceBase::type()
119 */
120 IncidenceType type() const;
121
122 /**
123 @copydoc
124 IncidenceBase::typeStr()
125 */
126 QByteArray typeStr() const;
127
128 /**
129 Sets the start date/time for the free/busy. Note that this date/time
130 may be later or earlier than all periods within the free/busy.
131
132 @param start is a KDateTime specifying an start datetime.
133 @see IncidenceBase::dtStart(), setDtEnd().
134 */
135 virtual void setDtStart(const KDateTime &start);
136
137 /**
138 Sets the end datetime for the free/busy. Note that this datetime
139 may be later or earlier than all periods within the free/busy.
140
141 @param end is a KDateTime specifying an end datetime.
142 @see dtEnd(), setDtStart().
143 */
144 void setDtEnd(const KDateTime &end);
145
146 /**
147 Returns the end datetime for the free/busy.
148 FIXME: calling addPeriod() does not change mDtEnd. Is that incorrect?
149 @see setDtEnd().
150 */
151 virtual KDateTime dtEnd() const;
152
153 /**
154 @copydoc
155 IncidenceBase::shiftTimes()
156 */
157 virtual void shiftTimes(const KDateTime::Spec &oldSpec,
158 const KDateTime::Spec &newSpec);
159
160 /**
161 Returns the list of all periods within the free/busy.
162 */
163 Period::List busyPeriods() const;
164
165 /**
166 Returns the list of all periods within the free/busy.
167 */
168 FreeBusyPeriod::List fullBusyPeriods() const;
169
170 /**
171 Adds a period to the freebusy list and sorts the list.
172
173 @param start is the start datetime of the period.
174 @param end is the end datetime of the period.
175 */
176 void addPeriod(const KDateTime &start, const KDateTime &end);
177
178 /**
179 Adds a period to the freebusy list and sorts the list.
180
181 @param start is the start datetime of the period.
182 @param duration is the Duration of the period.
183 */
184 void addPeriod(const KDateTime &start, const Duration &duration);
185
186 /**
187 Adds a list of periods to the freebusy object and then sorts that list.
188 Use this if you are adding many items, instead of the addPeriod method,
189 to avoid sorting repeatedly.
190
191 @param list is a list of Period objects.
192 */
193 void addPeriods(const Period::List &list);
194
195 /**
196 Adds a list of periods to the freebusy object and then sorts that list.
197 Use this if you are adding many items, instead of the addPeriod method,
198 to avoid sorting repeatedly.
199
200 @param list is a list of FreeBusyPeriod objects.
201 */
202 void addPeriods(const FreeBusyPeriod::List &list);
203
204 /**
205 Sorts the list of free/busy periods into ascending order.
206 */
207 void sortList();
208
209 /**
210 Merges another free/busy into this free/busy.
211
212 @param freebusy is a pointer to a valid FreeBusy object.
213 */
214 void merge(FreeBusy::Ptr freebusy);
215
216 /**
217 @copydoc
218 IncidenceBase::dateTime()
219 */
220 KDateTime dateTime(DateTimeRole role) const;
221
222 /**
223 @copydoc
224 IncidenceBase::setDateTime()
225 */
226 void setDateTime(const KDateTime &dateTime, DateTimeRole role);
227
228 /**
229 @copydoc
230 IncidenceBase::mimeType()
231 */
232 QLatin1String mimeType() const;
233
234 /**
235 Returns the Akonadi specific sub MIME type of a KCalCore::FreeBusy.
236 */
237 static QLatin1String freeBusyMimeType();
238
239protected:
240 /**
241 Compare this with @p freebusy for equality.
242 @param freebusy is the FreeBusy to compare.
243 */
244 virtual bool equals(const IncidenceBase &freebusy) const;
245
246 /**
247 @copydoc
248 IncidenceBase::assign()
249 */
250 virtual IncidenceBase &assign(const IncidenceBase &other);
251
252 /**
253 @copydoc
254 IncidenceBase::virtual_hook()
255 */
256 virtual void virtual_hook(int id, void *data);
257
258private:
259 /**
260 @copydoc
261 IncidenceBase::accept()
262 */
263 bool accept(Visitor &v, IncidenceBase::Ptr incidence);
264
265 /**
266 Disabled, otherwise could be dangerous if you subclass FreeBusy.
267 Use IncidenceBase::operator= which is safe because it calls
268 virtual function assign().
269 @param other is another FreeBusy object to assign to this one.
270 */
271 FreeBusy &operator=(const FreeBusy &other);
272
273 //@cond PRIVATE
274 class Private;
275 Private *const d;
276 //@endcond
277};
278
279/**
280 Serializes the @p freebusy object into the @p stream.
281*/
282KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream,
283 const KCalCore::FreeBusy::Ptr &freebusy);
284/**
285 Initializes the @p freebusy object from the @p stream.
286*/
287KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream,
288 KCalCore::FreeBusy::Ptr &freebusy);
289}
290
291//@cond PRIVATE
292Q_DECLARE_TYPEINFO(KCalCore::FreeBusy::Ptr, Q_MOVABLE_TYPE);
293Q_DECLARE_METATYPE(KCalCore::FreeBusy::Ptr)
294//@endcond
295
296#endif
297