File indexing completed on 2024-04-21 03:52:46

0001 /*
0002   This file is part of the kcalcore library.
0003 
0004   SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <schumacher@kde.org>
0005   SPDX-FileCopyrightText: 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0006 
0007   SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 /**
0010   @file
0011   This file is part of the API for handling calendar data and
0012   defines the FreeBusy class.
0013 
0014   @author Cornelius Schumacher \<schumacher@kde.org\>
0015   @author Reinhold Kainhofer \<reinhold@kainhofer.com\>
0016 */
0017 
0018 #ifndef KCALCORE_FREEBUSY_H
0019 #define KCALCORE_FREEBUSY_H
0020 
0021 #include "event.h"
0022 #include "freebusyperiod.h"
0023 #include "incidencebase.h"
0024 #include "kcalendarcore_export.h"
0025 #include "period.h"
0026 
0027 #include <QMetaType>
0028 
0029 namespace KCalendarCore
0030 {
0031 
0032 class FreeBusyPrivate;
0033 
0034 /**
0035   @brief
0036   Provides information about the free/busy time of a calendar.
0037 
0038   A free/busy is a collection of Periods.
0039   
0040   @see Period.
0041 */
0042 class KCALENDARCORE_EXPORT FreeBusy : public IncidenceBase
0043 {
0044     friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::FreeBusy::Ptr &freebusy);
0045     friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::FreeBusy::Ptr &freebusy);
0046 
0047 public:
0048     /**
0049       A shared pointer to a FreeBusy object.
0050     */
0051     typedef QSharedPointer<FreeBusy> Ptr;
0052 
0053     /**
0054       List of FreeBusy objects.
0055     */
0056     typedef QList<Ptr> List;
0057 
0058     /**
0059       Constructs an free/busy without any periods.
0060     */
0061     FreeBusy();
0062 
0063     /**
0064       Copy constructor.
0065       @param other is the free/busy to copy.
0066     */
0067     FreeBusy(const FreeBusy &other);
0068 
0069     /**
0070       Constructs a free/busy from a list of periods.
0071       @param busyPeriods is a list of periods.
0072     */
0073     explicit FreeBusy(const Period::List &busyPeriods);
0074 
0075     /**
0076       Constructs a free/busy from a list of periods.
0077       @param busyPeriods is a list of periods.
0078     */
0079     explicit FreeBusy(const FreeBusyPeriod::List &busyPeriods);
0080 
0081     /**
0082       Constructs a free/busy from a single period.
0083 
0084       @param start is the start date/time of the period.
0085       @param end is the end date/time of the period.
0086     */
0087     FreeBusy(const QDateTime &start, const QDateTime &end);
0088 
0089     /**
0090       Constructs a freebusy for a specified list of events given a single period.
0091 
0092       @param events list of events.
0093       @param start is the start date/time of the period.
0094       @param end is the end date/time of the period.
0095     */
0096     FreeBusy(const Event::List &events, const QDateTime &start, const QDateTime &end);
0097 
0098     /**
0099       Destroys a free/busy.
0100     */
0101     ~FreeBusy() override;
0102 
0103     /**
0104       @copydoc
0105       IncidenceBase::type()
0106     */
0107     Q_REQUIRED_RESULT IncidenceType type() const override;
0108 
0109     /**
0110       @copydoc
0111       IncidenceBase::typeStr()
0112     */
0113     Q_REQUIRED_RESULT QByteArray typeStr() const override;
0114 
0115     /**
0116       Sets the start date/time for the free/busy. Note that this date/time
0117       may be later or earlier than all periods within the free/busy.
0118 
0119       @param start is a QDateTime specifying an start datetime.
0120       @see IncidenceBase::dtStart(), setDtEnd().
0121     */
0122     void setDtStart(const QDateTime &start) override;
0123 
0124     /**
0125       Sets the end datetime for the free/busy. Note that this datetime
0126       may be later or earlier than all periods within the free/busy.
0127 
0128       @param end is a QDateTime specifying an end datetime.
0129       @see dtEnd(), setDtStart().
0130     */
0131     void setDtEnd(const QDateTime &end);
0132 
0133     /**
0134       Returns the end datetime for the free/busy.
0135       FIXME: calling addPeriod() does not change mDtEnd. Is that incorrect?
0136       @see setDtEnd().
0137     */
0138     Q_REQUIRED_RESULT virtual QDateTime dtEnd() const;
0139 
0140     /**
0141       @copydoc
0142       IncidenceBase::shiftTimes()
0143     */
0144     void shiftTimes(const QTimeZone &oldZone, const QTimeZone &newZone) override;
0145 
0146     /**
0147       Returns the list of all periods within the free/busy.
0148     */
0149     Q_REQUIRED_RESULT Period::List busyPeriods() const;
0150 
0151     /**
0152       Returns the list of all periods within the free/busy.
0153     */
0154     Q_REQUIRED_RESULT FreeBusyPeriod::List fullBusyPeriods() const;
0155 
0156     /**
0157       Adds a period to the freebusy list and sorts the list.
0158 
0159       @param start is the start datetime of the period.
0160       @param end is the end datetime of the period.
0161     */
0162     void addPeriod(const QDateTime &start, const QDateTime &end);
0163 
0164     /**
0165       Adds a period to the freebusy list and sorts the list.
0166 
0167       @param start is the start datetime of the period.
0168       @param duration is the Duration of the period.
0169     */
0170     void addPeriod(const QDateTime &start, const Duration &duration);
0171 
0172     /**
0173       Adds a list of periods to the freebusy object and then sorts that list.
0174       Use this if you are adding many items, instead of the addPeriod method,
0175       to avoid sorting repeatedly.
0176 
0177       @param list is a list of Period objects.
0178     */
0179     void addPeriods(const Period::List &list);
0180 
0181     /**
0182       Adds a list of periods to the freebusy object and then sorts that list.
0183       Use this if you are adding many items, instead of the addPeriod method,
0184       to avoid sorting repeatedly.
0185 
0186       @param list is a list of FreeBusyPeriod objects.
0187     */
0188     void addPeriods(const FreeBusyPeriod::List &list);
0189 
0190     /**
0191       Sorts the list of free/busy periods into ascending order.
0192     */
0193     void sortList();
0194 
0195     /**
0196       Merges another free/busy into this free/busy.
0197 
0198       @param freebusy is a pointer to a valid FreeBusy object.
0199     */
0200     void merge(const FreeBusy::Ptr &freebusy);
0201 
0202     /**
0203       @copydoc
0204       IncidenceBase::dateTime()
0205     */
0206     Q_REQUIRED_RESULT QDateTime dateTime(DateTimeRole role) const override;
0207 
0208     /**
0209       @copydoc
0210       IncidenceBase::setDateTime()
0211     */
0212     void setDateTime(const QDateTime &dateTime, DateTimeRole role) override;
0213 
0214     /**
0215        @copydoc
0216        IncidenceBase::mimeType()
0217     */
0218     Q_REQUIRED_RESULT QLatin1String mimeType() const override;
0219 
0220     /**
0221        Returns the Akonadi specific sub MIME type of a KCalendarCore::FreeBusy.
0222     */
0223     Q_REQUIRED_RESULT static QLatin1String freeBusyMimeType();
0224 
0225 protected:
0226     /**
0227       Compare this with @p freebusy for equality.
0228       @param freebusy is the FreeBusy to compare.
0229     */
0230     bool equals(const IncidenceBase &freebusy) const override;
0231 
0232     /**
0233       @copydoc
0234       IncidenceBase::assign()
0235     */
0236     IncidenceBase &assign(const IncidenceBase &other) override;
0237 
0238     /**
0239       @copydoc
0240       IncidenceBase::virtual_hook()
0241     */
0242     void virtual_hook(VirtualHook id, void *data) override;
0243 
0244 private:
0245 
0246     Q_DECLARE_PRIVATE(FreeBusy)
0247 
0248     /**
0249      @copydoc
0250      IncidenceBase::accept()
0251     */
0252     bool accept(Visitor &v, const IncidenceBase::Ptr &incidence) override;
0253 
0254     /**
0255       Disabled, otherwise could be dangerous if you subclass FreeBusy.
0256       Use IncidenceBase::operator= which is safe because it calls
0257       virtual function assign().
0258       @param other is another FreeBusy object to assign to this one.
0259      */
0260     FreeBusy &operator=(const FreeBusy &other) = delete;
0261 };
0262 
0263 /**
0264   Serializes the @p freebusy object into the @p stream.
0265 */
0266 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalendarCore::FreeBusy::Ptr &freebusy);
0267 /**
0268   Initializes the @p freebusy object from the @p stream.
0269 */
0270 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalendarCore::FreeBusy::Ptr &freebusy);
0271 }
0272 
0273 //@cond PRIVATE
0274 Q_DECLARE_TYPEINFO(KCalendarCore::FreeBusy::Ptr, Q_RELOCATABLE_TYPE);
0275 Q_DECLARE_METATYPE(KCalendarCore::FreeBusy::Ptr)
0276 //@endcond
0277 
0278 #endif