KCalendarCore

attachment.h
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  SPDX-FileCopyrightText: 2002 Michael Brade <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 /**
9  @file
10  This file is part of the API for handling calendar data and
11  defines the Attachment class.
12 
13  @author Michael Brade <[email protected]>
14 */
15 
16 #ifndef KCALCORE_ATTACHMENT_H
17 #define KCALCORE_ATTACHMENT_H
18 
19 #include "kcalendarcore_export.h"
20 
21 #include <QHash>
22 #include <QString>
23 #include <QSharedDataPointer>
24 #include <QMetaType>
25 
26 namespace KCalendarCore
27 {
28 
29 /**
30  @brief
31  Represents information related to an attachment for a Calendar Incidence.
32 
33  This is not an email message attachment.
34 
35  Calendar Incidence attachments consist of:
36  - A <a href="https://en.wikipedia.org/wiki/Uniform_Resource_Identifier">
37  Uniform Resource Identifier (URI)</a>
38  or a
39  <a href="https://en.wikipedia.org/wiki/Base64#MIME">base64 encoded</a>
40  binary blob.
41  - A <a href="https://en.wikipedia.org/wiki/MIME">
42  Multipurpose Internet Mail Extensions (MIME)</a> type.
43 
44  This class is used to associate files (local or remote) or other resources
45  with a Calendar Incidence.
46 */
47 class KCALENDARCORE_EXPORT Attachment
48 {
49  Q_GADGET
50  Q_PROPERTY(bool isEmpty READ isEmpty)
51  Q_PROPERTY(QString uri READ uri WRITE setUri)
52  Q_PROPERTY(bool isUri READ isUri)
53  Q_PROPERTY(bool isBinary READ isBinary)
54  Q_PROPERTY(int size READ size)
55  Q_PROPERTY(QString mimeType READ mimeType WRITE setMimeType)
56  Q_PROPERTY(bool showInline READ showInline WRITE setShowInline)
57  Q_PROPERTY(QString label READ label WRITE setLabel)
58  Q_PROPERTY(bool isLocal READ isLocal WRITE setLocal)
59 
60 public:
61  /**
62  List of attachments.
63  */
65 
66  /**
67  Constructs an empty attachment.
68  */
69  explicit Attachment();
70 
71  /**
72  Constructs an attachment consisting of a @p uri and a @p mime type.
73 
74  @param uri is the @acronym URI referred to by this attachment.
75  @param mime is the (optional) @acronym MIME type of the @p uri
76  */
77  explicit Attachment(const QString &uri, const QString &mime = QString());
78 
79  /**
80  Constructs an attachment consisting of a binary blob of data
81  and a @p mime type.
82 
83  @param base64 is the binary data in base64 format for the attachment.
84  @param mime is the (optional) @acronym MIME type of the attachment
85  */
86  explicit Attachment(const QByteArray &base64,
87  const QString &mime = QString());
88 
89  /**
90  Constructs an attachment by copying another attachment.
91 
92  @param attachment is the attachment to be copied.
93  */
94  Attachment(const Attachment &attachment);
95 
96  /**
97  Destroys the attachment.
98  */
99  ~Attachment();
100 
101  /**
102  Returns whether this is an empty or default constructed object.
103  */
104  bool isEmpty() const;
105 
106  /**
107  Sets the @acronym URI for this attachment to @p uri.
108 
109  @param uri is the @acronym URI to use for the attachment.
110 
111  @see uri(), isUri()
112  */
113  void setUri(const QString &uri);
114 
115  /**
116  Returns the @acronym URI of the attachment.
117 
118  @see setUri(), isUri()
119  */
120  Q_REQUIRED_RESULT QString uri() const;
121 
122  /**
123  Returns true if the attachment has a @acronym URI; false otherwise.
124 
125  @see uri(), setUri(I), isBinary()
126  */
127  Q_REQUIRED_RESULT bool isUri() const;
128 
129  /**
130  Returns true if the attachment has a binary blob; false otherwise.
131 
132  @see isUri()
133  */
134  Q_REQUIRED_RESULT bool isBinary() const;
135 
136  /**
137  Sets the base64 encoded binary blob data of the attachment.
138 
139  @param base64 contains the base64 encoded binary data.
140 
141  @see data(), decodedData()
142  */
143  void setData(const QByteArray &base64);
144 
145  /**
146  Returns a pointer to a QByteArray containing the base64 encoded
147  binary data of the attachment.
148 
149  @see setData(), setDecodedData()
150  */
151  Q_REQUIRED_RESULT QByteArray data() const;
152 
153  /**
154  Sets the decoded attachment data.
155 
156  @param data is the decoded base64 binary data.
157 
158  @see decodedData(), data()
159  */
160  void setDecodedData(const QByteArray &data);
161 
162  /**
163  Returns a QByteArray containing the decoded base64 binary data of the
164  attachment.
165 
166  @see setDecodedData(), setData()
167  */
168  Q_REQUIRED_RESULT QByteArray decodedData() const;
169 
170  /**
171  Returns the size of the attachment, in bytes.
172  If the attachment is binary (i.e, there is no @acronym URI associated
173  with the attachment) then a value of 0 is returned.
174  */
175  uint size() const;
176 
177  /**
178  Sets the @acronym MIME-type of the attachment to @p mime.
179 
180  @param mime is the string to use for the attachment @acronym MIME-type.
181 
182  @see mimeType()
183  */
184  void setMimeType(const QString &mime);
185 
186  /**
187  Returns the @acronym MIME-type of the attachment.
188 
189  @see setMimeType()
190  */
191  Q_REQUIRED_RESULT QString mimeType() const;
192 
193  /**
194  Sets the attachment "show in-line" option, which is derived from
195  the Calendar Incidence @b X-CONTENT-DISPOSITION parameter.
196 
197  @param showinline is the flag to set (true) or unset (false)
198  for the attachment "show in-line" option.
199 
200  @see showInline()
201  */
202  void setShowInline(bool showinline);
203 
204  /**
205  Returns the attachment "show in-line" flag.
206 
207  @see setShowInline()
208  */
209  Q_REQUIRED_RESULT bool showInline() const;
210 
211  /**
212  Sets the attachment label to @p label, which is derived from
213  the Calendar Incidence @b X-LABEL parameter.
214 
215  @param label is the string to use for the attachment label.
216 
217  @see label()
218  */
219  void setLabel(const QString &label);
220 
221  /**
222  Returns the attachment label string.
223  */
224  Q_REQUIRED_RESULT QString label() const;
225 
226  /**
227  Sets the attachment "local" option, which is derived from the
228  Calendar Incidence @b X-KONTACT-TYPE parameter.
229 
230  @param local is the flag to set (true) or unset (false) for the
231  attachment "local" option.
232 
233  @see local()
234  */
235  void setLocal(bool local);
236 
237  /**
238  Returns the attachment "local" flag.
239  */
240  Q_REQUIRED_RESULT bool isLocal() const;
241 
242  /**
243  Assignment operator.
244  @param attachment is the attachment to assign.
245  */
246  Attachment &operator=(const Attachment &attachment);
247 
248  /**
249  Compare this with @p attachment for equality.
250  @param attachment is the attachment to compare.
251  @return true if the attachments are equal; false otherwise.
252  */
253  bool operator==(const Attachment &attachment) const;
254 
255  /**
256  Compare this with @p attachment for inequality.
257  @param attachment is the attachment to compare.
258  @return true if the attachments are /not/ equal; false otherwise.
259  */
260  bool operator!=(const Attachment &attachment) const;
261 
262 private:
263  //@cond PRIVATE
264  class Private;
266  //@endcond
267 
268  friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::Attachment&);
269  friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::Attachment&);
270 };
271 
272 /**
273  * Attachment serializer.
274  *
275  * @since 4.12
276  */
277 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalendarCore::Attachment&);
278 
279 /**
280  * Attachment deserializer.
281  *
282  * @since 4.12
283  */
284 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &in, KCalendarCore::Attachment&);
285 
286 }
287 
288 //@cond PRIVATE
289 Q_DECLARE_TYPEINFO(KCalendarCore::Attachment, Q_MOVABLE_TYPE);
290 Q_DECLARE_METATYPE(KCalendarCore::Attachment)
291 //@endcond
292 
293 #endif
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:825
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:849
QVector< Attachment > List
List of attachments.
Definition: attachment.h:64
Represents information related to an attachment for a Calendar Incidence.
Definition: attachment.h:47
Namespace for all KCalendarCore types.
Definition: alarm.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Mar 7 2021 22:50:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.