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 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 /**
0009   @file
0010   This file is part of the API for handling calendar data and
0011   defines the Event class.
0012 
0013   @author Cornelius Schumacher \<schumacher@kde.org\>
0014 */
0015 #ifndef KCALCORE_EVENT_H
0016 #define KCALCORE_EVENT_H
0017 
0018 #include "incidence.h"
0019 #include "kcalendarcore_export.h"
0020 
0021 #include <QTimeZone>
0022 
0023 namespace KCalendarCore
0024 {
0025 
0026 class EventPrivate;
0027 
0028 /**
0029   @brief
0030   This class provides an Event in the sense of RFC2445.
0031 */
0032 class KCALENDARCORE_EXPORT Event : public Incidence
0033 {
0034     Q_GADGET
0035     Q_PROPERTY(QDateTime dtEnd READ dtEnd WRITE setDtEnd)
0036     Q_PROPERTY(KCalendarCore::Event::Transparency transparency READ transparency WRITE setTransparency)
0037 public:
0038     /**
0039       The different Event transparency types.
0040     */
0041     enum Transparency {
0042         Opaque, /**< Event appears in free/busy time */
0043         Transparent, /**< Event does @b not appear in free/busy time */
0044     };
0045     Q_ENUM(Transparency)
0046 
0047     /**
0048       A shared pointer to an Event object.
0049     */
0050     typedef QSharedPointer<Event> Ptr;
0051 
0052     /**
0053       List of events.
0054     */
0055     typedef QList<Ptr> List;
0056 
0057     ///@cond PRIVATE
0058     // needed for Akonadi polymorphic payload support
0059     typedef Incidence SuperClass;
0060     ///@endcond
0061 
0062     /**
0063       Constructs an event.
0064     */
0065     Event();
0066 
0067     /**
0068       Copy constructor.
0069       @param other is the event to copy.
0070     */
0071     Event(const Event &other);
0072 
0073     /**
0074       Costructs an event out of an incidence
0075       This constructs allows to make it easy to create an event from a todo.
0076       @param other is the incidence to copy.
0077       @since 4.14
0078     */
0079     Event(const Incidence &other); // krazy:exclude=explicit (copy ctor)
0080 
0081     /**
0082       Destroys the event.
0083     */
0084     ~Event() override;
0085 
0086     /**
0087       @copydoc
0088       IncidenceBase::type()
0089     */
0090     Q_REQUIRED_RESULT IncidenceType type() const override;
0091 
0092     /**
0093       @copydoc
0094       IncidenceBase::typeStr()
0095     */
0096     Q_REQUIRED_RESULT QByteArray typeStr() const override;
0097 
0098     /**
0099       Returns an exact copy of this Event. The caller owns the returned object.
0100     */
0101     Event *clone() const override;
0102 
0103     /**
0104       Sets the incidence starting date/time.
0105 
0106       @param dt is the starting date/time.
0107       @see IncidenceBase::dtStart().
0108     */
0109     void setDtStart(const QDateTime &dt) override;
0110 
0111     /**
0112       Sets the event end date and time.
0113       Important note for all day events: the end date is inclusive,
0114       the event will still occur during dtEnd(). When serializing to iCalendar
0115       DTEND will be dtEnd()+1, because the RFC states that DTEND is exclusive.
0116       @param dtEnd is a QDateTime specifying when the event ends.
0117       @see dtEnd(), dateEnd().
0118     */
0119     void setDtEnd(const QDateTime &dtEnd);
0120 
0121     /**
0122       Returns the event end date and time.
0123       Important note for all day events: the returned end date is inclusive,
0124       the event will still occur during dtEnd(). When serializing to iCalendar
0125       DTEND will be dtEnd()+1, because the RFC states that DTEND is exclusive.
0126       @see setDtEnd().
0127     */
0128     virtual QDateTime dtEnd() const;
0129 
0130     /**
0131       Returns the date when the event ends. This might be different from
0132       dtEnd().date, since the end date/time is non-inclusive. So timed events
0133       ending at 0:00 have their end date on the day before.
0134     */
0135     Q_REQUIRED_RESULT QDate dateEnd() const;
0136 
0137     /**
0138       Returns whether the event has an end date/time.
0139     */
0140     Q_REQUIRED_RESULT bool hasEndDate() const;
0141 
0142     /**
0143       Returns true if the event spans multiple days, otherwise return false.
0144 
0145       For recurring events, it returns true if the first occurrence spans multiple days,
0146       otherwise returns false. Other occurrences might have a different span due to day light
0147       savings changes.
0148 
0149       @param zone If set, looks if the event is multiday for the given zone.
0150       If not set, looks if event this multiday for its zone.
0151     */
0152     Q_REQUIRED_RESULT bool isMultiDay(const QTimeZone &zone = {}) const;
0153 
0154     /**
0155       @copydoc
0156       IncidenceBase::shiftTimes()
0157     */
0158     void shiftTimes(const QTimeZone &oldZone, const QTimeZone &newZone) override;
0159 
0160     /**
0161       Sets the event's time transparency level.
0162       @param transparency is the event Transparency level.
0163     */
0164     void setTransparency(Transparency transparency);
0165 
0166     /**
0167       Returns the event's time transparency level.
0168     */
0169     Q_REQUIRED_RESULT Transparency transparency() const;
0170 
0171     /**
0172       Sets the duration of this event.
0173       @param duration is the event Duration.
0174     */
0175     void setDuration(const Duration &duration) override;
0176 
0177     /**
0178       @copydoc
0179       IncidenceBase::setAllDay().
0180     */
0181     void setAllDay(bool allDay) override;
0182 
0183     /**
0184       @copydoc
0185       IncidenceBase::dateTime()
0186     */
0187     Q_REQUIRED_RESULT QDateTime dateTime(DateTimeRole role) const override;
0188 
0189     /**
0190       @copydoc
0191       IncidenceBase::setDateTime()
0192     */
0193     void setDateTime(const QDateTime &dateTime, DateTimeRole role) override;
0194 
0195     /**
0196       @copydoc
0197       IncidenceBase::mimeType()
0198     */
0199     Q_REQUIRED_RESULT QLatin1String mimeType() const override;
0200 
0201     /**
0202        @copydoc
0203        Incidence::iconName()
0204     */
0205     Q_REQUIRED_RESULT QLatin1String iconName(const QDateTime &recurrenceId = {}) const override;
0206 
0207     /**
0208        @copydoc
0209        Incidence::supportsGroupwareCommunication()
0210     */
0211     Q_REQUIRED_RESULT bool supportsGroupwareCommunication() const override;
0212 
0213     /**
0214        Returns the Akonadi specific sub MIME type of a KCalendarCore::Event.
0215     */
0216     Q_REQUIRED_RESULT static QLatin1String eventMimeType();
0217 
0218 protected:
0219     /**
0220       Compares two events for equality.
0221       @param event is the event to compare.
0222     */
0223     bool equals(const IncidenceBase &event) const override;
0224 
0225     /**
0226       @copydoc
0227       IncidenceBase::assign()
0228     */
0229     IncidenceBase &assign(const IncidenceBase &other) override;
0230 
0231     /**
0232       @copydoc
0233       IncidenceBase::virtual_hook()
0234     */
0235     void virtual_hook(VirtualHook id, void *data) override;
0236 
0237 private:
0238     /**
0239       @copydoc
0240       IncidenceBase::accept()
0241     */
0242     bool accept(Visitor &v, const IncidenceBase::Ptr &incidence) override;
0243 
0244     /**
0245       Disabled, otherwise could be dangerous if you subclass Event.
0246       Use IncidenceBase::operator= which is safe because it calls
0247       virtual function assign().
0248       @param other is another Event object to assign to this one.
0249      */
0250     Event &operator=(const Event &other) = delete;
0251 
0252     // For polymorphic serialization
0253     void serialize(QDataStream &out) const override;
0254     void deserialize(QDataStream &in) override;
0255 
0256     //@cond PRIVATE
0257     Q_DECLARE_PRIVATE(Event)
0258     //@endcond
0259 };
0260 
0261 } // namespace KCalendarCore
0262 
0263 //@cond PRIVATE
0264 Q_DECLARE_TYPEINFO(KCalendarCore::Event::Ptr, Q_RELOCATABLE_TYPE);
0265 Q_DECLARE_METATYPE(KCalendarCore::Event::Ptr)
0266 Q_DECLARE_METATYPE(KCalendarCore::Event *)
0267 //@endcond
0268 
0269 #endif