File indexing completed on 2024-04-14 03:50:39

0001 /*
0002   This file is part of the kcalcore library.
0003 
0004   SPDX-FileCopyrightText: 2002 Michael Brade <brade@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 Attachment class.
0012 
0013   @author Michael Brade \<brade@kde.org\>
0014 */
0015 
0016 #ifndef KCALCORE_ATTACHMENT_H
0017 #define KCALCORE_ATTACHMENT_H
0018 
0019 #include "kcalendarcore_export.h"
0020 
0021 #include <QHash>
0022 #include <QMetaType>
0023 #include <QSharedDataPointer>
0024 #include <QString>
0025 
0026 namespace KCalendarCore
0027 {
0028 /**
0029   @brief
0030   Represents information related to an attachment for a Calendar Incidence.
0031 
0032   This is not an email message attachment.
0033 
0034   Calendar Incidence attachments consist of:
0035   - A <a href="https://en.wikipedia.org/wiki/Uniform_Resource_Identifier">
0036     Uniform Resource Identifier (URI)</a>
0037     or a
0038     <a href="https://en.wikipedia.org/wiki/Base64#MIME">base64 encoded</a>
0039     binary blob.
0040   - A <a href="https://en.wikipedia.org/wiki/MIME">
0041     Multipurpose Internet Mail Extensions (MIME)</a> type.
0042 
0043   This class is used to associate files (local or remote) or other resources
0044   with a Calendar Incidence.
0045 */
0046 class KCALENDARCORE_EXPORT Attachment
0047 {
0048     Q_GADGET
0049     Q_PROPERTY(bool isEmpty READ isEmpty)
0050     Q_PROPERTY(QString uri READ uri WRITE setUri)
0051     Q_PROPERTY(bool isUri READ isUri)
0052     Q_PROPERTY(bool isBinary READ isBinary)
0053     Q_PROPERTY(int size READ size)
0054     Q_PROPERTY(QString mimeType READ mimeType WRITE setMimeType)
0055     Q_PROPERTY(bool showInline READ showInline WRITE setShowInline)
0056     Q_PROPERTY(QString label READ label WRITE setLabel)
0057     Q_PROPERTY(bool isLocal READ isLocal WRITE setLocal)
0058 
0059 public:
0060     /**
0061       List of attachments.
0062     */
0063     typedef QList<Attachment> List;
0064 
0065     /**
0066       Constructs an empty attachment.
0067     */
0068     explicit Attachment();
0069 
0070     /**
0071       Constructs an attachment consisting of a @p uri and a @p mime type.
0072 
0073       @param uri is the @acronym URI referred to by this attachment.
0074       @param mime is the (optional) @acronym MIME type of the @p uri
0075     */
0076     explicit Attachment(const QString &uri, const QString &mime = QString());
0077 
0078     /**
0079       Constructs an attachment consisting of a binary blob of data
0080       and a @p mime type.
0081 
0082       @param base64 is the binary data in base64 format for the attachment.
0083       @param mime is the (optional) @acronym MIME type of the attachment
0084     */
0085     explicit Attachment(const QByteArray &base64, const QString &mime = QString());
0086 
0087     /**
0088       Constructs an attachment by copying another attachment.
0089 
0090       @param attachment is the attachment to be copied.
0091     */
0092     Attachment(const Attachment &attachment);
0093 
0094     /**
0095       Destroys the attachment.
0096     */
0097     ~Attachment();
0098 
0099     /**
0100        Returns whether this is an empty or default constructed object.
0101     */
0102     bool isEmpty() const;
0103 
0104     /**
0105       Sets the @acronym URI for this attachment to @p uri.
0106 
0107       @param uri is the @acronym URI to use for the attachment.
0108 
0109       @see uri(), isUri()
0110     */
0111     void setUri(const QString &uri);
0112 
0113     /**
0114       Returns the @acronym URI of the attachment.
0115 
0116       @see setUri(), isUri()
0117     */
0118     Q_REQUIRED_RESULT QString uri() const;
0119 
0120     /**
0121       Returns true if the attachment has a @acronym URI; false otherwise.
0122 
0123       @see uri(), setUri(I), isBinary()
0124     */
0125     Q_REQUIRED_RESULT bool isUri() const;
0126 
0127     /**
0128       Returns true if the attachment has a binary blob; false otherwise.
0129 
0130       @see isUri()
0131     */
0132     Q_REQUIRED_RESULT bool isBinary() const;
0133 
0134     /**
0135       Sets the base64 encoded binary blob data of the attachment.
0136 
0137       @param base64 contains the base64 encoded binary data.
0138 
0139       @see data(), decodedData()
0140     */
0141     void setData(const QByteArray &base64);
0142 
0143     /**
0144       Returns a pointer to a QByteArray containing the base64 encoded
0145       binary data of the attachment.
0146 
0147       @see setData(), setDecodedData()
0148     */
0149     Q_REQUIRED_RESULT QByteArray data() const;
0150 
0151     /**
0152       Sets the decoded attachment data.
0153 
0154       @param data is the decoded base64 binary data.
0155 
0156       @see decodedData(), data()
0157     */
0158     void setDecodedData(const QByteArray &data);
0159 
0160     /**
0161       Returns a QByteArray containing the decoded base64 binary data of the
0162       attachment.
0163 
0164       @see setDecodedData(), setData()
0165     */
0166     Q_REQUIRED_RESULT QByteArray decodedData() const;
0167 
0168     /**
0169       Returns the size of the attachment, in bytes.
0170       If the attachment is binary (i.e, there is no @acronym URI associated
0171       with the attachment) then a value of 0 is returned.
0172     */
0173     uint size() const;
0174 
0175     /**
0176       Sets the @acronym MIME-type of the attachment to @p mime.
0177 
0178       @param mime is the string to use for the attachment @acronym MIME-type.
0179 
0180       @see mimeType()
0181     */
0182     void setMimeType(const QString &mime);
0183 
0184     /**
0185       Returns the @acronym MIME-type of the attachment.
0186 
0187       @see setMimeType()
0188     */
0189     Q_REQUIRED_RESULT QString mimeType() const;
0190 
0191     /**
0192       Sets the attachment "show in-line" option, which is derived from
0193       the Calendar Incidence @b X-CONTENT-DISPOSITION parameter.
0194 
0195       @param showinline is the flag to set (true) or unset (false)
0196       for the attachment "show in-line" option.
0197 
0198       @see showInline()
0199     */
0200     void setShowInline(bool showinline);
0201 
0202     /**
0203       Returns the attachment "show in-line" flag.
0204 
0205       @see setShowInline()
0206     */
0207     Q_REQUIRED_RESULT bool showInline() const;
0208 
0209     /**
0210       Sets the attachment label to @p label, which is derived from
0211       the Calendar Incidence @b X-LABEL parameter.
0212 
0213       @param label is the string to use for the attachment label.
0214 
0215       @see label()
0216     */
0217     void setLabel(const QString &label);
0218 
0219     /**
0220       Returns the attachment label string.
0221     */
0222     Q_REQUIRED_RESULT QString label() const;
0223 
0224     /**
0225       Sets the attachment "local" option, which is derived from the
0226       Calendar Incidence @b X-KONTACT-TYPE parameter.
0227 
0228       @param local is the flag to set (true) or unset (false) for the
0229       attachment "local" option.
0230 
0231       @see local()
0232     */
0233     void setLocal(bool local);
0234 
0235     /**
0236       Returns the attachment "local" flag.
0237     */
0238     Q_REQUIRED_RESULT bool isLocal() const;
0239 
0240     /**
0241       Assignment operator.
0242       @param attachment is the attachment to assign.
0243     */
0244     Attachment &operator=(const Attachment &attachment);
0245 
0246     /**
0247       Compare this with @p attachment for equality.
0248       @param attachment is the attachment to compare.
0249       @return true if the attachments are equal; false otherwise.
0250      */
0251     bool operator==(const Attachment &attachment) const;
0252 
0253     /**
0254       Compare this with @p attachment for inequality.
0255       @param attachment is the attachment to compare.
0256       @return true if the attachments are /not/ equal; false otherwise.
0257      */
0258     bool operator!=(const Attachment &attachment) const;
0259 
0260 private:
0261     //@cond PRIVATE
0262     class Private;
0263     QSharedDataPointer<Private> d;
0264     //@endcond
0265 
0266     friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::Attachment &);
0267     friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::Attachment &);
0268 };
0269 
0270 /**
0271  * Attachment serializer.
0272  *
0273  * @since 4.12
0274  */
0275 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalendarCore::Attachment &);
0276 
0277 /**
0278  * Attachment deserializer.
0279  *
0280  * @since 4.12
0281  */
0282 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &in, KCalendarCore::Attachment &);
0283 
0284 }
0285 
0286 //@cond PRIVATE
0287 Q_DECLARE_TYPEINFO(KCalendarCore::Attachment, Q_RELOCATABLE_TYPE);
0288 Q_DECLARE_METATYPE(KCalendarCore::Attachment)
0289 //@endcond
0290 
0291 #endif