File indexing completed on 2024-04-14 03:50:49
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 /** 0086 @copydoc 0087 CalFormat::toString() 0088 */ 0089 Q_REQUIRED_RESULT QString toString(const Calendar::Ptr &calendar) override; 0090 0091 /** 0092 @copydoc 0093 CalFormat::fromRawString() 0094 */ 0095 Q_REQUIRED_RESULT bool fromRawString(const Calendar::Ptr &calendar, const QByteArray &string) override; 0096 0097 protected: 0098 /** 0099 Translates a VObject of the TODO type into an Event. 0100 @param vtodo is a pointer to a valid VObject object. 0101 */ 0102 Todo::Ptr VTodoToEvent(VObject *vtodo); 0103 0104 /** 0105 Translates a VObject into a Event and returns a pointer to it. 0106 @param vevent is a pointer to a valid VObject object. 0107 */ 0108 Event::Ptr VEventToEvent(VObject *vevent); 0109 0110 /** 0111 Parse TZ tag from vtimezone. 0112 */ 0113 QString parseTZ(const QByteArray &timezone) const; 0114 0115 /** 0116 Parse DAYLIGHT tag from vtimezone. 0117 */ 0118 QString parseDst(QByteArray &timezone) const; 0119 0120 /** 0121 Takes a QDate and returns a string in the format YYYYMMDDTHHMMSS. 0122 @param date is the date to format. 0123 */ 0124 QString qDateToISO(const QDate &date); 0125 0126 /** 0127 Takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS. 0128 @param date is the date to format. 0129 @param zulu if true, then shift the date to UTC. 0130 */ 0131 QString qDateTimeToISO(const QDateTime &date, bool zulu = true); 0132 0133 /** 0134 Takes a string in YYYYMMDDTHHMMSS format and returns a valid QDateTime. 0135 @param dtStr is a QString containing the date to convert. If this value 0136 is invalid, then QDateTime() is returned. 0137 */ 0138 QDateTime ISOToQDateTime(const QString &dtStr); 0139 0140 /** 0141 Takes a string in the YYYYMMDD format and returns a valid QDate. 0142 @param dtStr is a QString containing the date to convert. If this value 0143 is invalid, then QDateTime() is returned. 0144 */ 0145 QDate ISOToQDate(const QString &dtStr); 0146 0147 /** 0148 Parse one of the myriad of ISO8601 timezone offset formats, e.g. 0149 +- hh : mm 0150 +- hh mm 0151 +- hh 0152 0153 @param s string to be parsed. 0154 @param result timezone offset in seconds, if parse succeeded. 0155 @return Whether the parse succeeded or not. 0156 */ 0157 bool parseTZOffsetISO8601(const QString &s, int &result); 0158 0159 /** 0160 Takes a vCalendar tree of VObjects, and puts all of them that have the 0161 "event" property into the dictionary, todos in the todo-list, etc. 0162 */ 0163 void populate(VObject *vcal); 0164 0165 /** 0166 Converts a two letter representation of the day (i.e. MO, TU, WE, etc) and 0167 returns a number 0-6 corresponding to that ordinal day of the week. 0168 @param day is the QString containing the two letter day representation. 0169 */ 0170 int numFromDay(const QString &day); 0171 0172 /** 0173 Converts a status string into an Attendee::PartStat. 0174 @param s is a null-terminated character string containing the status to convert. 0175 0176 @return a valid Attendee::PartStat. If the string provided is empty, null, 0177 or the contents are unrecognized, then Attendee::NeedsAction is returned. 0178 */ 0179 Attendee::PartStat readStatus(const char *s) const; 0180 0181 /** 0182 Converts an Attendee::PartStat into a QByteArray string. 0183 @param status is the Attendee::PartStat to convert. 0184 0185 @return a QByteArray containing the status string. 0186 */ 0187 QByteArray writeStatus(Attendee::PartStat status) const; 0188 0189 void readCustomProperties(VObject *o, const Incidence::Ptr &i); 0190 void writeCustomProperties(VObject *o, const Incidence::Ptr &i); 0191 0192 private: 0193 //@cond PRIVATE 0194 Q_DISABLE_COPY(VCalFormat) 0195 Q_DECLARE_PRIVATE(VCalFormat) 0196 //@endcond 0197 }; 0198 0199 } 0200 0201 #endif