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 (@see Period).
38 */
39 class KCALENDARCORE_EXPORT FreeBusy : public IncidenceBase
40 {
41  friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::FreeBusy::Ptr &freebusy);
42  friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::FreeBusy::Ptr &freebusy);
43 
44 public:
45  /**
46  A shared pointer to a FreeBusy object.
47  */
49 
50  /**
51  List of FreeBusy objects.
52  */
53  typedef QVector<Ptr> List;
54 
55  /**
56  Constructs an free/busy without any periods.
57  */
58  FreeBusy();
59 
60  /**
61  Copy constructor.
62  @param other is the free/busy to copy.
63  */
64  FreeBusy(const FreeBusy &other);
65 
66  /**
67  Constructs a free/busy from a list of periods.
68  @param busyPeriods is a list of periods.
69  */
70  explicit FreeBusy(const Period::List &busyPeriods);
71 
72  /**
73  Constructs a free/busy from a list of periods.
74  @param busyPeriods is a list of periods.
75  */
76  explicit FreeBusy(const FreeBusyPeriod::List &busyPeriods);
77 
78  /**
79  Constructs a free/busy from a single period.
80 
81  @param start is the start date/time of the period.
82  @param end is the end date/time of the period.
83  */
84  FreeBusy(const QDateTime &start, const QDateTime &end);
85 
86  /**
87  Constructs a freebusy for a specified list of events given a single period.
88 
89  @param events list of events.
90  @param start is the start date/time of the period.
91  @param end is the end date/time of the period.
92  */
93  FreeBusy(const Event::List &events, const QDateTime &start, const QDateTime &end);
94 
95  /**
96  Destroys a free/busy.
97  */
98  ~FreeBusy() override;
99 
100  /**
101  @copydoc
102  IncidenceBase::type()
103  */
104  Q_REQUIRED_RESULT IncidenceType type() const override;
105 
106  /**
107  @copydoc
108  IncidenceBase::typeStr()
109  */
110  Q_REQUIRED_RESULT QByteArray typeStr() const override;
111 
112  /**
113  Sets the start date/time for the free/busy. Note that this date/time
114  may be later or earlier than all periods within the free/busy.
115 
116  @param start is a QDateTime specifying an start datetime.
117  @see IncidenceBase::dtStart(), setDtEnd().
118  */
119  void setDtStart(const QDateTime &start) override;
120 
121  /**
122  Sets the end datetime for the free/busy. Note that this datetime
123  may be later or earlier than all periods within the free/busy.
124 
125  @param end is a QDateTime specifying an end datetime.
126  @see dtEnd(), setDtStart().
127  */
128  void setDtEnd(const QDateTime &end);
129 
130  /**
131  Returns the end datetime for the free/busy.
132  FIXME: calling addPeriod() does not change mDtEnd. Is that incorrect?
133  @see setDtEnd().
134  */
135  Q_REQUIRED_RESULT virtual QDateTime dtEnd() const;
136 
137  /**
138  @copydoc
139  IncidenceBase::shiftTimes()
140  */
141  void shiftTimes(const QTimeZone &oldZone, const QTimeZone &newZone) override;
142 
143  /**
144  Returns the list of all periods within the free/busy.
145  */
146  Q_REQUIRED_RESULT Period::List busyPeriods() const;
147 
148  /**
149  Returns the list of all periods within the free/busy.
150  */
151  Q_REQUIRED_RESULT FreeBusyPeriod::List fullBusyPeriods() const;
152 
153  /**
154  Adds a period to the freebusy list and sorts the list.
155 
156  @param start is the start datetime of the period.
157  @param end is the end datetime of the period.
158  */
159  void addPeriod(const QDateTime &start, const QDateTime &end);
160 
161  /**
162  Adds a period to the freebusy list and sorts the list.
163 
164  @param start is the start datetime of the period.
165  @param duration is the Duration of the period.
166  */
167  void addPeriod(const QDateTime &start, const Duration &duration);
168 
169  /**
170  Adds a list of periods to the freebusy object and then sorts that list.
171  Use this if you are adding many items, instead of the addPeriod method,
172  to avoid sorting repeatedly.
173 
174  @param list is a list of Period objects.
175  */
176  void addPeriods(const Period::List &list);
177 
178  /**
179  Adds a list of periods to the freebusy object and then sorts that list.
180  Use this if you are adding many items, instead of the addPeriod method,
181  to avoid sorting repeatedly.
182 
183  @param list is a list of FreeBusyPeriod objects.
184  */
185  void addPeriods(const FreeBusyPeriod::List &list);
186 
187  /**
188  Sorts the list of free/busy periods into ascending order.
189  */
190  void sortList();
191 
192  /**
193  Merges another free/busy into this free/busy.
194 
195  @param freebusy is a pointer to a valid FreeBusy object.
196  */
197  void merge(const FreeBusy::Ptr &freebusy);
198 
199  /**
200  @copydoc
201  IncidenceBase::dateTime()
202  */
203  Q_REQUIRED_RESULT QDateTime dateTime(DateTimeRole role) const override;
204 
205  /**
206  @copydoc
207  IncidenceBase::setDateTime()
208  */
209  void setDateTime(const QDateTime &dateTime, DateTimeRole role) override;
210 
211  /**
212  @copydoc
213  IncidenceBase::mimeType()
214  */
215  Q_REQUIRED_RESULT QLatin1String mimeType() const override;
216 
217  /**
218  Returns the Akonadi specific sub MIME type of a KCalendarCore::FreeBusy.
219  */
220  Q_REQUIRED_RESULT static QLatin1String freeBusyMimeType();
221 
222 protected:
223  /**
224  Compare this with @p freebusy for equality.
225  @param freebusy is the FreeBusy to compare.
226  */
227  bool equals(const IncidenceBase &freebusy) const override;
228 
229  /**
230  @copydoc
231  IncidenceBase::assign()
232  */
233  IncidenceBase &assign(const IncidenceBase &other) override;
234 
235  /**
236  @copydoc
237  IncidenceBase::virtual_hook()
238  */
239  void virtual_hook(VirtualHook id, void *data) override;
240 
241 private:
242  /**
243  @copydoc
244  IncidenceBase::accept()
245  */
246  bool accept(Visitor &v, const IncidenceBase::Ptr &incidence) override;
247 
248  /**
249  Disabled, otherwise could be dangerous if you subclass FreeBusy.
250  Use IncidenceBase::operator= which is safe because it calls
251  virtual function assign().
252  @param other is another FreeBusy object to assign to this one.
253  */
254  FreeBusy &operator=(const FreeBusy &other);
255 
256  //@cond PRIVATE
257  class Private;
258  Private *const d;
259  //@endcond
260 };
261 
262 /**
263  Serializes the @p freebusy object into the @p stream.
264 */
265 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalendarCore::FreeBusy::Ptr &freebusy);
266 /**
267  Initializes the @p freebusy object from the @p stream.
268 */
269 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalendarCore::FreeBusy::Ptr &freebusy);
270 }
271 
272 //@cond PRIVATE
273 Q_DECLARE_TYPEINFO(KCalendarCore::FreeBusy::Ptr, Q_MOVABLE_TYPE);
274 Q_DECLARE_METATYPE(KCalendarCore::FreeBusy::Ptr)
275 //@endcond
276 
277 #endif
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:821
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:834
Provides information about the free/busy time of a calendar.
Definition: freebusy.h:39
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:48
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:53
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 Apr 16 2021 22:50:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.