File indexing completed on 2024-11-24 04:44:16

0001 /*
0002     This file is part of the kolab resource - the implementation of the
0003     Kolab storage format. See www.kolab.org for documentation on this.
0004 
0005     SPDX-FileCopyrightText: 2004 Bo Thorsen <bo@sonofthor.dk>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <KCalendarCore/Incidence>
0013 
0014 #include "kolabbase.h"
0015 
0016 class QDomElement;
0017 
0018 namespace KolabV2
0019 {
0020 /**
0021  * This abstract class represents an incidence which has the shared
0022  * fields, of events and tasks and knows how to load/save these
0023  * from/to XML, and from/to a KCalendarCore::Incidence.
0024  */
0025 class Incidence : public KolabBase
0026 {
0027 public:
0028     struct Recurrence {
0029         QString cycle;
0030         QString type;
0031         int interval;
0032         QStringList days; // list of days-of-the-week
0033         QString dayNumber;
0034         QString month;
0035         QString rangeType;
0036         QString range; // date or number or nothing
0037         QList<QDate> exclusions;
0038     };
0039 
0040     struct Attendee : Email {
0041         Attendee()
0042             : requestResponse(true)
0043             , invitationSent(false)
0044         {
0045         }
0046 
0047         QString status;
0048         bool requestResponse;
0049         bool invitationSent;
0050         QString role;
0051         QString delegate;
0052         QString delegator;
0053     };
0054 
0055     explicit Incidence(const QString &tz, const KCalendarCore::Incidence::Ptr &incidence = KCalendarCore::Incidence::Ptr());
0056 
0057 public:
0058     ~Incidence() override;
0059 
0060     void saveTo(const KCalendarCore::Incidence::Ptr &incidence);
0061 
0062     virtual void setPriority(int priority);
0063     virtual int priority() const;
0064 
0065     virtual void setSummary(const QString &summary);
0066     virtual QString summary() const;
0067 
0068     virtual void setLocation(const QString &location);
0069     virtual QString location() const;
0070 
0071     virtual void setOrganizer(const Email &organizer);
0072     virtual Email organizer() const;
0073 
0074     virtual void setStartDate(const QDateTime &startDate);
0075     virtual void setStartDate(const QDate &startDate);
0076     virtual void setStartDate(const QString &startDate);
0077     virtual QDateTime startDate() const;
0078 
0079     virtual void setAlarm(float alarm);
0080     virtual float alarm() const;
0081 
0082     virtual void setRecurrence(KCalendarCore::Recurrence *recur);
0083     virtual Recurrence recurrence() const;
0084 
0085     virtual void addAttendee(const Attendee &attendee);
0086     QList<Attendee> &attendees();
0087     const QList<Attendee> &attendees() const;
0088 
0089     QString type() const override
0090     {
0091         return QStringLiteral("Incidence");
0092     }
0093 
0094     /**
0095      * The internal uid is used as the uid inside KOrganizer whenever
0096      * two or more events with the same uid appear, which KOrganizer
0097      * can't handle. To avoid keep that internal uid from changing all the
0098      * time, it is persisted in the XML between a save and the next load.
0099      */
0100     void setInternalUID(const QString &iuid);
0101     QString internalUID() const;
0102 
0103     // Load the attributes of this class
0104     bool loadAttribute(QDomElement &) override;
0105 
0106     // Save the attributes of this class
0107     bool saveAttributes(QDomElement &) const override;
0108 
0109 protected:
0110     enum FloatingStatus {
0111         Unset,
0112         AllDay,
0113         HasTime,
0114     };
0115 
0116     // Read all known fields from this ical incidence
0117     void setFields(const KCalendarCore::Incidence::Ptr &);
0118 
0119     bool loadAttendeeAttribute(QDomElement &, Attendee &);
0120     void saveAttendeeAttribute(QDomElement &element, const Attendee &attendee) const;
0121     void saveAttendees(QDomElement &element) const;
0122     void saveAttachments(QDomElement &element) const;
0123 
0124     void loadAlarms(const QDomElement &element);
0125     void saveAlarms(QDomElement &element) const;
0126 
0127     void loadRecurrence(const QDomElement &element);
0128     void saveRecurrence(QDomElement &element) const;
0129     void saveCustomAttributes(QDomElement &element) const;
0130     void loadCustomAttributes(QDomElement &element);
0131 
0132     QString productID() const override;
0133 
0134     QString mSummary;
0135     QString mLocation;
0136     Email mOrganizer;
0137     QDateTime mStartDate;
0138     FloatingStatus mFloatingStatus = Unset;
0139     float mAlarm = 0.0;
0140     bool mHasAlarm = false;
0141     Recurrence mRecurrence;
0142     QList<Attendee> mAttendees;
0143     QList<KCalendarCore::Alarm::Ptr> mAlarms;
0144     QList<KCalendarCore::Attachment> mAttachments;
0145     QString mInternalUID;
0146 
0147     struct Custom {
0148         QByteArray key;
0149         QString value;
0150     };
0151     QList<Custom> mCustomList;
0152 
0153     // This is the KCal priority, not the Kolab priority.
0154     // See kcalPriorityToKolab() and kolabPrioritytoKCal().
0155     int mPriority = 0;
0156 };
0157 }