File indexing completed on 2024-04-28 11:34:14

0001 /*
0002   This file is part of the kcalcore library.
0003 
0004   SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org>
0005   SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <schumacher@kde.org>
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 VCalFormat base class.
0013 
0014   This class implements the vCalendar format. It provides methods for
0015   loading/saving/converting vCalendar format data into the internal
0016   representation as Calendar and Incidences.
0017 
0018   @brief
0019   vCalendar format implementation.
0020 
0021   @author Preston Brown \<pbrown@kde.org\>
0022   @author Cornelius Schumacher \<schumacher@kde.org\>
0023 */
0024 
0025 #ifndef KCALCORE_VCALFORMAT_H
0026 #define KCALCORE_VCALFORMAT_H
0027 
0028 #include "attendee.h"
0029 #include "calformat.h"
0030 #include "event.h"
0031 #include "journal.h"
0032 #include "kcalendarcore_export.h"
0033 #include "todo.h"
0034 
0035 struct VObject;
0036 
0037 class QDate;
0038 
0039 #define _VCAL_VERSION "1.0"
0040 
0041 /* extensions for iMIP / iTIP */
0042 #define ICOrganizerProp "X-ORGANIZER"
0043 #define ICMethodProp "X-METHOD"
0044 #define ICRequestStatusProp "X-REQUEST-STATUS"
0045 
0046 namespace KCalendarCore
0047 {
0048 class Event;
0049 class Todo;
0050 class VCalFormatPrivate;
0051 
0052 /**
0053   @brief
0054   vCalendar format implementation.
0055 
0056   This class implements the vCalendar format. It provides methods for
0057   loading/saving/converting vCalendar format data into the internal
0058   representation as Calendar and Incidences.
0059 */
0060 class KCALENDARCORE_EXPORT VCalFormat : public CalFormat
0061 {
0062 public:
0063     /**
0064       Constructor a new vCalendar Format object.
0065     */
0066     VCalFormat();
0067 
0068     /**
0069       Destructor.
0070     */
0071     ~VCalFormat() override;
0072 
0073     /**
0074       @copydoc
0075       CalFormat::load()
0076     */
0077     bool load(const Calendar::Ptr &calendar, const QString &fileName) override;
0078 
0079     /**
0080       @copydoc
0081       CalFormat::save()
0082     */
0083     bool save(const Calendar::Ptr &calendar, const QString &fileName) override;
0084 
0085 #if KCALENDARCORE_BUILD_DEPRECATED_SINCE(5, 97)
0086     /**
0087       @copydoc
0088       CalFormat::fromString()
0089     */
0090     KCALENDARCORE_DEPRECATED_VERSION(5, 97, "use fromString(const Calendar::Ptr &calendar, const QString &string, const QString &notebook)")
0091     bool fromString(const Calendar::Ptr &calendar, const QString &string, bool deleted, const QString &notebook = QString()) override;
0092     using CalFormat::fromString;
0093 #endif
0094 
0095     /**
0096       @copydoc
0097       CalFormat::toString()
0098     */
0099     Q_REQUIRED_RESULT QString toString(const Calendar::Ptr &calendar, const QString &notebook = QString(), bool deleted = false) override;
0100 
0101     /**
0102       @copydoc
0103       CalFormat::fromRawString()
0104     */
0105     Q_REQUIRED_RESULT bool
0106     fromRawString(const Calendar::Ptr &calendar, const QByteArray &string, bool deleted = false, const QString &notebook = QString()) override;
0107 
0108 protected:
0109     /**
0110       Translates a VObject of the TODO type into an Event.
0111       @param vtodo is a pointer to a valid VObject object.
0112     */
0113     Todo::Ptr VTodoToEvent(VObject *vtodo);
0114 
0115     /**
0116       Translates a VObject into a Event and returns a pointer to it.
0117       @param vevent is a pointer to a valid VObject object.
0118     */
0119     Event::Ptr VEventToEvent(VObject *vevent);
0120 
0121     /**
0122       Parse TZ tag from vtimezone.
0123     */
0124     QString parseTZ(const QByteArray &timezone) const;
0125 
0126     /**
0127       Parse DAYLIGHT tag from vtimezone.
0128     */
0129     QString parseDst(QByteArray &timezone) const;
0130 
0131     /**
0132       Takes a QDate and returns a string in the format YYYYMMDDTHHMMSS.
0133       @param date is the date to format.
0134     */
0135     QString qDateToISO(const QDate &date);
0136 
0137     /**
0138       Takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS.
0139       @param date is the date to format.
0140       @param zulu if true, then shift the date to UTC.
0141     */
0142     QString qDateTimeToISO(const QDateTime &date, bool zulu = true);
0143 
0144     /**
0145       Takes a string in YYYYMMDDTHHMMSS format and returns a valid QDateTime.
0146       @param dtStr is a QString containing the date to convert. If this value
0147       is invalid, then QDateTime() is returned.
0148     */
0149     QDateTime ISOToQDateTime(const QString &dtStr);
0150 
0151     /**
0152       Takes a string in the YYYYMMDD format and returns a valid QDate.
0153       @param dtStr is a QString containing the date to convert. If this value
0154       is invalid, then QDateTime() is returned.
0155     */
0156     QDate ISOToQDate(const QString &dtStr);
0157 
0158     /**
0159       Parse one of the myriad of ISO8601 timezone offset formats, e.g.
0160       +- hh : mm
0161       +- hh mm
0162       +- hh
0163 
0164       @param s string to be parsed.
0165       @param result timezone offset in seconds, if parse succeeded.
0166       @return Whether the parse succeeded or not.
0167     */
0168     bool parseTZOffsetISO8601(const QString &s, int &result);
0169 
0170     /**
0171       Takes a vCalendar tree of VObjects, and puts all of them that have the
0172       "event" property into the dictionary, todos in the todo-list, etc.
0173     */
0174     void populate(VObject *vcal, bool deleted = false, const QString &notebook = QString());
0175 
0176     /**
0177       Converts a two letter representation of the day (i.e. MO, TU, WE, etc) and
0178       returns a number 0-6 corresponding to that ordinal day of the week.
0179       @param day is the QString containing the two letter day representation.
0180     */
0181     int numFromDay(const QString &day);
0182 
0183     /**
0184       Converts a status string into an Attendee::PartStat.
0185       @param s is a null-terminated character string containing the status to convert.
0186 
0187       @return a valid Attendee::PartStat.  If the string provided is empty, null,
0188       or the contents are unrecognized, then Attendee::NeedsAction is returned.
0189     */
0190     Attendee::PartStat readStatus(const char *s) const;
0191 
0192     /**
0193       Converts an Attendee::PartStat into a QByteArray string.
0194       @param status is the Attendee::PartStat to convert.
0195 
0196       @return a QByteArray containing the status string.
0197     */
0198     QByteArray writeStatus(Attendee::PartStat status) const;
0199 
0200     void readCustomProperties(VObject *o, const Incidence::Ptr &i);
0201     void writeCustomProperties(VObject *o, const Incidence::Ptr &i);
0202 
0203 protected:
0204 #if KCALENDARCORE_BUILD_DEPRECATED_SINCE(5, 96)
0205     /**
0206       @copydoc
0207       IncidenceBase::virtual_hook()
0208     */
0209     void virtual_hook(int id, void *data) override;
0210 #endif
0211 
0212 private:
0213     //@cond PRIVATE
0214     Q_DISABLE_COPY(VCalFormat)
0215     Q_DECLARE_PRIVATE(VCalFormat)
0216 #if KCALENDARCORE_BUILD_DEPRECATED_SINCE(5, 96)
0217     void *unused; // former dptr, just kept for ABI compatibility
0218 #endif
0219     //@endcond
0220 };
0221 
0222 }
0223 
0224 #endif