File indexing completed on 2024-04-21 03:52:45
0001 /* 0002 This file is part of the kcalcore library. 0003 0004 SPDX-FileCopyrightText: 2002, 2006, 2010 David Jarvie <djarvie@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 CustomProperties class. 0012 0013 @author David Jarvie \<djarvie@kde.org\> 0014 */ 0015 0016 #ifndef KCALCORE_CUSTOMPROPERTIES_H 0017 #define KCALCORE_CUSTOMPROPERTIES_H 0018 0019 #include "kcalendarcore_export.h" 0020 0021 #include <QMap> 0022 #include <QString> 0023 0024 namespace KCalendarCore 0025 { 0026 /** 0027 @brief 0028 A class to manage custom calendar properties. 0029 0030 This class represents custom calendar properties. 0031 It is used as a base class for classes which represent calendar components. 0032 A custom property name written by the kcalcore library has the form X-KDE-APP-KEY 0033 where APP represents the application name, and KEY distinguishes individual 0034 properties for the application. 0035 In keeping with RFC2445, property names must be composed only of the 0036 characters A-Z, a-z, 0-9 and '-'. 0037 */ 0038 class KCALENDARCORE_EXPORT CustomProperties 0039 { 0040 friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::CustomProperties &properties); 0041 friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::CustomProperties &properties); 0042 0043 public: 0044 /** 0045 Constructs an empty custom properties instance. 0046 */ 0047 CustomProperties(); 0048 0049 /** 0050 Copy constructor. 0051 @param other is the one to copy. 0052 */ 0053 CustomProperties(const CustomProperties &other); 0054 0055 /** 0056 Destructor. 0057 */ 0058 virtual ~CustomProperties(); 0059 0060 /** 0061 Compare this with @p properties for equality. 0062 @param properties is the one to compare. 0063 @warning The comparison is not polymorphic. 0064 */ 0065 bool operator==(const CustomProperties &properties) const; 0066 0067 /** 0068 Create or modify a custom calendar property. 0069 0070 @param app Application name as it appears in the custom property name. 0071 @param key Property identifier specific to the application. 0072 @param value The property's value. A call with a value of QString() 0073 will be ignored. 0074 @see removeCustomProperty(). 0075 */ 0076 void setCustomProperty(const QByteArray &app, const QByteArray &key, const QString &value); 0077 0078 /** 0079 Delete a custom calendar property. 0080 0081 @param app Application name as it appears in the custom property name. 0082 @param key Property identifier specific to the application. 0083 @see setCustomProperty(). 0084 */ 0085 void removeCustomProperty(const QByteArray &app, const QByteArray &key); 0086 0087 /** 0088 Return the value of a custom calendar property. 0089 0090 @param app Application name as it appears in the custom property name. 0091 @param key Property identifier specific to the application. 0092 @return Property value, or QString() if (and only if) the property 0093 does not exist. 0094 */ 0095 Q_REQUIRED_RESULT QString customProperty(const QByteArray &app, const QByteArray &key) const; 0096 0097 /** 0098 Validate and return the full name of a custom calendar property. 0099 0100 @param app Application name as it appears in the custom property name. 0101 @param key Property identifier specific to the application. 0102 @return Full property name, or empty string if it would contain invalid 0103 characters 0104 */ 0105 Q_REQUIRED_RESULT static QByteArray customPropertyName(const QByteArray &app, const QByteArray &key); 0106 0107 /** 0108 Create or modify a non-KDE or non-standard custom calendar property. 0109 0110 @param name Full property name 0111 @param value The property's value. A call with a value of QString() 0112 will be ignored. 0113 @param parameters The formatted list of parameters for the 0114 property. They should be formatted as RFC specifies, that is, 0115 KEY=VALUE;KEY2=VALUE2. We're mostly concerned about passing them 0116 through as-is albeit they can be of course parsed if need be. 0117 @see removeNonKDECustomProperty(). 0118 */ 0119 void setNonKDECustomProperty(const QByteArray &name, const QString &value, const QString ¶meters = QString()); 0120 0121 /** 0122 Delete a non-KDE or non-standard custom calendar property. 0123 0124 @param name Full property name 0125 @see setNonKDECustomProperty(). 0126 */ 0127 void removeNonKDECustomProperty(const QByteArray &name); 0128 0129 /** 0130 Return the value of a non-KDE or non-standard custom calendar property. 0131 0132 @param name Full property name 0133 @return Property value, or QString() if (and only if) the property 0134 does not exist. 0135 */ 0136 Q_REQUIRED_RESULT QString nonKDECustomProperty(const QByteArray &name) const; 0137 0138 /** 0139 Return the parameters of a non-KDE or non-standard custom 0140 calendar property. 0141 0142 @param name Full property name 0143 @return The parameters for the given property. Empty string is 0144 returned if none are set. 0145 */ 0146 Q_REQUIRED_RESULT QString nonKDECustomPropertyParameters(const QByteArray &name) const; 0147 0148 /** 0149 Initialise the alarm's custom calendar properties to the specified 0150 key/value pairs. 0151 @param properties is a QMap of property key/value pairs. 0152 @see customProperties(). 0153 */ 0154 void setCustomProperties(const QMap<QByteArray, QString> &properties); 0155 0156 /** 0157 Returns all custom calendar property key/value pairs. 0158 @see setCustomProperties(). 0159 */ 0160 Q_REQUIRED_RESULT QMap<QByteArray, QString> customProperties() const; 0161 0162 /** 0163 Assignment operator. 0164 @warning The assignment is not polymorphic. 0165 @param other is the CustomProperty to assign. 0166 */ 0167 CustomProperties &operator=(const CustomProperties &other); 0168 0169 protected: 0170 /** 0171 Called before a custom property will be changed. 0172 The default implementation does nothing: override in derived classes 0173 to perform change processing. 0174 */ 0175 virtual void customPropertyUpdate(); 0176 0177 /** 0178 Called when a custom property has been changed. 0179 The default implementation does nothing: override in derived classes 0180 to perform change processing. 0181 */ 0182 virtual void customPropertyUpdated(); 0183 0184 private: 0185 //@cond PRIVATE 0186 class Private; 0187 Private *const d; 0188 //@endcond 0189 }; 0190 0191 /** 0192 Serializes the @p properties object into the @p stream. 0193 */ 0194 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &stream, const KCalendarCore::CustomProperties &properties); 0195 0196 /** 0197 Initializes the @p properties object from the @p stream. 0198 */ 0199 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalendarCore::CustomProperties &properties); 0200 0201 } 0202 0203 #endif