KCalendarCore

freebusy.h
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <[email protected]>
5  SPDX-FileCopyrightText: 2004 Reinhold Kainhofer <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 /**
10  @file
11  This file is part of the API for handling calendar data and
12  defines the FreeBusy class.
13 
14  @author Cornelius Schumacher <[email protected]>
15  @author Reinhold Kainhofer <[email protected]>
16 */
17 
18 #ifndef KCALCORE_FREEBUSY_H
19 #define KCALCORE_FREEBUSY_H
20 
21 #include "event.h"
22 #include "freebusyperiod.h"
23 #include "incidencebase.h"
24 #include "kcalendarcore_export.h"
25 #include "period.h"
26 
27 #include <QMetaType>
28 
29 namespace KCalendarCore
30 {
31 class FreeBusy;
32 
33 /**
34  @brief
35  Provides information about the free/busy time of a calendar.
36 
37  A free/busy is a collection of Periods.
38 
39  @see Period.
40 */
41 class KCALENDARCORE_EXPORT FreeBusy : public IncidenceBase
42 {
43  friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::FreeBusy::Ptr &freebusy);
44  friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::FreeBusy::Ptr &freebusy);
45 
46 public:
47  /**
48  A shared pointer to a FreeBusy object.
49  */
51 
52  /**
53  List of FreeBusy objects.
54  */
55  typedef QVector<Ptr> List;
56 
57  /**
58  Constructs an free/busy without any periods.
59  */
60  FreeBusy();
61 
62  /**
63  Copy constructor.
64  @param other is the free/busy to copy.
65  */
66  FreeBusy(const FreeBusy &other);
67 
68  /**
69  Constructs a free/busy from a list of periods.
70  @param busyPeriods is a list of periods.
71  */
72  explicit FreeBusy(const Period::List &busyPeriods);
73 
74  /**
75  Constructs a free/busy from a list of periods.
76  @param busyPeriods is a list of periods.
77  */
78  explicit FreeBusy(const FreeBusyPeriod::List &busyPeriods);
79 
80  /**
81  Constructs a free/busy from a single period.
82 
83  @param start is the start date/time of the period.
84  @param end is the end date/time of the period.
85  */
86  FreeBusy(const QDateTime &start, const QDateTime &end);
87 
88  /**
89  Constructs a freebusy for a specified list of events given a single period.
90 
91  @param events list of events.
92  @param start is the start date/time of the period.
93  @param end is the end date/time of the period.
94  */
95  FreeBusy(const Event::List &events, const QDateTime &start, const QDateTime &end);
96 
97  /**
98  Destroys a free/busy.
99  */
100  ~FreeBusy() override;
101 
102  /**
103  @copydoc
104  IncidenceBase::type()
105  */
106  Q_REQUIRED_RESULT IncidenceType type() const override;
107 
108  /**
109  @copydoc
110  IncidenceBase::typeStr()
111  */
112  Q_REQUIRED_RESULT QByteArray typeStr() const override;
113 
114  /**
115  Sets the start date/time for the free/busy. Note that this date/time
116  may be later or earlier than all periods within the free/busy.
117 
118  @param start is a QDateTime specifying an start datetime.
119  @see IncidenceBase::dtStart(), setDtEnd().
120  */
121  void setDtStart(const QDateTime &start) override;
122 
123  /**
124  Sets the end datetime for the free/busy. Note that this datetime
125  may be later or earlier than all periods within the free/busy.
126 
127  @param end is a QDateTime specifying an end datetime.
128  @see dtEnd(), setDtStart().
129  */
130  void setDtEnd(const QDateTime &end);
131 
132  /**
133  Returns the end datetime for the free/busy.
134  FIXME: calling addPeriod() does not change mDtEnd. Is that incorrect?
135  @see setDtEnd().
136  */
137  Q_REQUIRED_RESULT virtual QDateTime dtEnd() const;
138 
139  /**
140  @copydoc
141  IncidenceBase::shiftTimes()
142  */
143  void shiftTimes(const QTimeZone &oldZone, const QTimeZone &newZone) override;
144 
145  /**
146  Returns the list of all periods within the free/busy.
147  */
148  Q_REQUIRED_RESULT Period::List busyPeriods() const;
149 
150  /**
151  Returns the list of all periods within the free/busy.
152  */
153  Q_REQUIRED_RESULT FreeBusyPeriod::List fullBusyPeriods() const;
154 
155  /**
156  Adds a period to the freebusy list and sorts the list.
157 
158  @param start is the start datetime of the period.
159  @param end is the end datetime of the period.
160  */
161  void addPeriod(const QDateTime &start, const QDateTime &end);
162 
163  /**
164  Adds a period to the freebusy list and sorts the list.
165 
166  @param start is the start datetime of the period.
167  @param duration is the Duration of the period.
168  */
169  void addPeriod(const QDateTime &start, const Duration &duration);
170 
171  /**
172  Adds a list of periods to the freebusy object and then sorts that list.
173  Use this if you are adding many items, instead of the addPeriod method,
174  to avoid sorting repeatedly.
175 
176  @param list is a list of Period objects.
177  */
178  void addPeriods(const Period::List &list);
179 
180  /**
181  Adds a list of periods to the freebusy object and then sorts that list.
182  Use this if you are adding many items, instead of the addPeriod method,
183  to avoid sorting repeatedly.
184 
185  @param list is a list of FreeBusyPeriod objects.
186  */
187  void addPeriods(const FreeBusyPeriod::List &list);
188 
189  /**
190  Sorts the list of free/busy periods into ascending order.
191  */
192  void sortList();
193 
194  /**
195  Merges another free/busy into this free/busy.
196 
197  @param freebusy is a pointer to a valid FreeBusy object.
198  */
199  void merge(const FreeBusy::Ptr &freebusy);
200 
201  /**
202  @copydoc
203  IncidenceBase::dateTime()
204  */
205  Q_REQUIRED_RESULT QDateTime dateTime(DateTimeRole role) const override;
206 
207  /**
208  @copydoc
209  IncidenceBase::setDateTime()
210  */
211  void setDateTime(const QDateTime &dateTime, DateTimeRole role) override;
212 
213  /**
214  @copydoc
215  IncidenceBase::mimeType()
216  */
217  Q_REQUIRED_RESULT QLatin1String mimeType() const override;
218 
219  /**
220  Returns the Akonadi specific sub MIME type of a KCalendarCore::FreeBusy.
221  */
222  Q_REQUIRED_RESULT static QLatin1String freeBusyMimeType();
223 
224 protected:
225  /**
226  Compare this with @p freebusy for equality.
227  @param freebusy is the FreeBusy to compare.
228  */
229  bool equals(const IncidenceBase &freebusy) const override;
230 
231  /**
232  @copydoc
233  IncidenceBase::assign()
234  */
235  IncidenceBase &assign(const IncidenceBase &other) override;
236 
237  /**
238  @copydoc
239  IncidenceBase::virtual_hook()
240  */
241  void virtual_hook(VirtualHook id, void *data) override;
242 
243 private:
244  /**
245  @copydoc
246  IncidenceBase::accept()
247  */
248  bool accept(Visitor &v, const IncidenceBase::Ptr &incidence) override;
249 
250  /**
251  Disabled, otherwise could be dangerous if you subclass FreeBusy.
252  Use IncidenceBase::operator= which is safe because it calls
253  virtual function assign().
254  @param other is another FreeBusy object to assign to this one.
255  */
256  FreeBusy &operator=(const FreeBusy &other);
257 
258  //@cond PRIVATE
259  class Private;
260  Private *const d;
261  //@endcond
262 };
263 
264 /**
265  Serializes the @p freebusy object into the @p stream.
266 */
267 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalendarCore::FreeBusy::Ptr &freebusy);
268 /**
269  Initializes the @p freebusy object from the @p stream.
270 */
271 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalendarCore::FreeBusy::Ptr &freebusy);
272 }
273 
274 //@cond PRIVATE
275 Q_DECLARE_TYPEINFO(KCalendarCore::FreeBusy::Ptr, Q_MOVABLE_TYPE);
276 Q_DECLARE_METATYPE(KCalendarCore::FreeBusy::Ptr)
277 //@endcond
278 
279 #endif
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:820
This file is part of the API for handling calendar data and defines the Period class.
This class provides the interface for a visitor of calendar components.
Definition: visitor.h:30
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:833
Provides information about the free/busy time of a calendar.
Definition: freebusy.h:41
DateTimeRole
The different types of incidence date/times roles.
An abstract class that provides a common base for all calendar incidence classes. ...
Definition: incidencebase.h:97
Represents a span of time measured in seconds or days.
Definition: duration.h:43
IncidenceType
The different types of incidences, per RFC2445.
This file is part of the API for handling calendar data and defines the IncidenceBase class...
This file is part of the API for handling calendar data and defines the Event class.
QSharedPointer< FreeBusy > Ptr
A shared pointer to a FreeBusy object.
Definition: freebusy.h:50
This file is part of the API for handling calendar data and defines the Period class.
QVector< Ptr > List
List of FreeBusy objects.
Definition: freebusy.h:55
Namespace for all KCalendarCore types.
Definition: alarm.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Sep 24 2021 22:51:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.