KCalendarCore

attachment.cpp
Go to the documentation of this file.
1/*
2 This file is part of the kcalcore library.
3
4 SPDX-FileCopyrightText: 2002 Michael Brade <brade@kde.org>
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 @brief
14 Represents information related to an attachment for a Calendar Incidence.
15
16 @author Michael Brade <brade@kde.org>
17*/
18
19#include "attachment.h"
20#include <QDataStream>
21
22using namespace KCalendarCore;
23
24/**
25 Private class that helps to provide binary compatibility between releases.
26 @internal
27*/
28//@cond PRIVATE
29class Q_DECL_HIDDEN KCalendarCore::Attachment::Private : public QSharedData
30{
31public:
32 Private() = default;
33 Private(const QString &mime, bool binary)
34 : mMimeType(mime)
35 , mBinary(binary)
36 {
37 }
38 Private(const Private &other) = default;
39
40 ~Private()
41 {
42 }
43
44 mutable uint mSize = 0;
45 mutable QByteArray mDecodedDataCache;
46 QString mMimeType;
47 QString mUri;
48 QByteArray mEncodedData;
49 QString mLabel;
50 bool mBinary = false;
51 bool mLocal = false;
52 bool mShowInline = false;
53};
54//@endcond
55
57 : d(new Attachment::Private)
58{
59}
60
61Attachment::Attachment(const Attachment &attachment) = default;
62
63Attachment::Attachment(const QString &uri, const QString &mime)
64 : d(new Attachment::Private(mime, false))
65{
66 d->mUri = uri;
67}
68
69Attachment::Attachment(const QByteArray &base64, const QString &mime)
70 : d(new Attachment::Private(mime, true))
71{
72 d->mEncodedData = base64;
73}
74
75Attachment::~Attachment() = default;
76
77bool Attachment::isEmpty() const
78{
79 return d->mMimeType.isEmpty() && d->mUri.isEmpty() && d->mEncodedData.isEmpty();
80}
81
82bool Attachment::isUri() const
83{
84 return !d->mBinary;
85}
86
87QString Attachment::uri() const
88{
89 if (!d->mBinary) {
90 return d->mUri;
91 } else {
92 return QString();
93 }
94}
95
97{
98 d->mUri = uri;
99 d->mBinary = false;
100}
101
102bool Attachment::isBinary() const
103{
104 return d->mBinary;
105}
106
108{
109 if (d->mBinary) {
110 return d->mEncodedData;
111 } else {
112 return QByteArray();
113 }
114}
115
117{
118 if (d->mDecodedDataCache.isNull()) {
119 d->mDecodedDataCache = QByteArray::fromBase64(d->mEncodedData);
120 }
121
122 return d->mDecodedDataCache;
123}
124
126{
128 d->mDecodedDataCache = data;
129 d->mSize = d->mDecodedDataCache.size();
130}
131
133{
134 d->mEncodedData = base64;
135 d->mBinary = true;
136 d->mDecodedDataCache = QByteArray();
137 d->mSize = 0;
138}
139
140uint Attachment::size() const
141{
142 if (isUri()) {
143 return 0;
144 }
145 if (!d->mSize) {
146 d->mSize = decodedData().size();
147 }
148
149 return d->mSize;
150}
151
152QString Attachment::mimeType() const
153{
154 return d->mMimeType;
155}
156
158{
159 d->mMimeType = mime;
160}
161
162bool Attachment::showInline() const
163{
164 return d->mShowInline;
165}
166
167void Attachment::setShowInline(bool showinline)
168{
169 d->mShowInline = showinline;
170}
171
172QString Attachment::label() const
173{
174 return d->mLabel;
175}
176
178{
179 d->mLabel = label;
180}
181
182bool Attachment::isLocal() const
183{
184 return d->mLocal;
185}
186
187void Attachment::setLocal(bool local)
188{
189 d->mLocal = local;
190}
191
192Attachment &Attachment::operator=(const Attachment &other) = default;
193
195{
196 return uri() == a2.uri() //
197 && d->mLabel == a2.label() //
198 && d->mLocal == a2.isLocal() //
199 && d->mBinary == a2.isBinary() //
200 && d->mShowInline == a2.showInline() //
201 && size() == a2.size() //
202 && decodedData() == a2.decodedData();
203}
204
206{
207 return !(*this == a2);
208}
209
211{
212 out << a.d->mSize << a.d->mMimeType << a.d->mUri << a.d->mEncodedData << a.d->mLabel << a.d->mBinary << a.d->mLocal << a.d->mShowInline;
213 return out;
214}
215
217{
218 in >> a.d->mSize >> a.d->mMimeType >> a.d->mUri >> a.d->mEncodedData >> a.d->mLabel >> a.d->mBinary >> a.d->mLocal >> a.d->mShowInline;
219 return in;
220}
221
222#include "moc_attachment.cpp"
This file is part of the API for handling calendar data and defines the Attachment class.
Represents information related to an attachment for a Calendar Incidence.
Definition attachment.h:47
QByteArray decodedData() const
Returns a QByteArray containing the decoded base64 binary data of the attachment.
bool operator==(const Attachment &attachment) const
Compare this with attachment for equality.
void setDecodedData(const QByteArray &data)
Sets the decoded attachment data.
QByteArray data() const
Returns a pointer to a QByteArray containing the base64 encoded binary data of the attachment.
~Attachment()
Destroys the attachment.
bool operator!=(const Attachment &attachment) const
Compare this with attachment for inequality.
void setLocal(bool local)
Sets the attachment "local" option, which is derived from the Calendar Incidence X-KONTACT-TYPE param...
void setData(const QByteArray &base64)
Sets the base64 encoded binary blob data of the attachment.
void setShowInline(bool showinline)
Sets the attachment "show in-line" option, which is derived from the Calendar Incidence X-CONTENT-DIS...
void setUri(const QString &uri)
Sets the URI for this attachment to uri.
void setMimeType(const QString &mime)
Sets the MIME-type of the attachment to mime.
void setLabel(const QString &label)
Sets the attachment label to label, which is derived from the Calendar Incidence X-LABEL parameter.
Attachment & operator=(const Attachment &attachment)
Assignment operator.
Attachment()
Constructs an empty attachment.
Namespace for all KCalendarCore types.
Definition alarm.h:37
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition alarm.cpp:833
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition alarm.cpp:820
QByteArray fromBase64(const QByteArray &base64, Base64Options options)
bool isEmpty() const const
qsizetype size() const const
QByteArray toBase64(Base64Options options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:47 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.