• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

  • kcalcore
attachment.cpp
Go to the documentation of this file.
1/*
2 This file is part of the kcalcore library.
3
4 Copyright (c) 2002 Michael Brade <brade@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
32#include "attachment.h"
33#include <QDataStream>
34
35using namespace KCalCore;
36
41//@cond PRIVATE
42class KCalCore::Attachment::Private
43{
44public:
45 Private(const QString &mime, bool binary)
46 : mSize(0),
47 mMimeType(mime),
48 mBinary(binary),
49 mLocal(false),
50 mShowInline(false)
51 {}
52 Private(const Private &other)
53 : mSize(other.mSize),
54 mMimeType(other.mMimeType),
55 mUri(other.mUri),
56 mEncodedData(other.mEncodedData),
57 mLabel(other.mLabel),
58 mBinary(other.mBinary),
59 mLocal(other.mLocal),
60 mShowInline(other.mShowInline)
61 {}
62
63 ~Private()
64 {
65 }
66
67 QByteArray mDecodedDataCache;
68 uint mSize;
69 QString mMimeType;
70 QString mUri;
71 QByteArray mEncodedData;
72 QString mLabel;
73 bool mBinary;
74 bool mLocal;
75 bool mShowInline;
76};
77//@endcond
78
79Attachment::Attachment(const Attachment &attachment)
80 : d(new Attachment::Private(*attachment.d))
81{
82}
83
84Attachment::Attachment(const QString &uri, const QString &mime)
85 : d(new Attachment::Private(mime, false))
86{
87 d->mUri = uri;
88}
89
90Attachment::Attachment(const QByteArray &base64, const QString &mime)
91 : d(new Attachment::Private(mime, true))
92{
93 d->mEncodedData = base64;
94}
95
96Attachment::~Attachment()
97{
98 delete d;
99}
100
101bool Attachment::isUri() const
102{
103 return !d->mBinary;
104}
105
106QString Attachment::uri() const
107{
108 if (!d->mBinary) {
109 return d->mUri;
110 } else {
111 return QString();
112 }
113}
114
115void Attachment::setUri(const QString &uri)
116{
117 d->mUri = uri;
118 d->mBinary = false;
119}
120
121bool Attachment::isBinary() const
122{
123 return d->mBinary;
124}
125
126QByteArray Attachment::data() const
127{
128 if (d->mBinary) {
129 return d->mEncodedData;
130 } else {
131 return QByteArray();
132 }
133}
134
135QByteArray Attachment::decodedData() const
136{
137 if (d->mDecodedDataCache.isNull()) {
138 d->mDecodedDataCache = QByteArray::fromBase64(d->mEncodedData);
139 }
140
141 return d->mDecodedDataCache;
142}
143
144void Attachment::setDecodedData(const QByteArray &data)
145{
146 setData(data.toBase64());
147 d->mDecodedDataCache = data;
148 d->mSize = d->mDecodedDataCache.size();
149}
150
151void Attachment::setData(const QByteArray &base64)
152{
153 d->mEncodedData = base64;
154 d->mBinary = true;
155 d->mDecodedDataCache = QByteArray();
156 d->mSize = 0;
157}
158
159uint Attachment::size() const
160{
161 if (isUri()) {
162 return 0;
163 }
164 if (!d->mSize) {
165 d->mSize = decodedData().size();
166 }
167
168 return d->mSize;
169}
170
171QString Attachment::mimeType() const
172{
173 return d->mMimeType;
174}
175
176void Attachment::setMimeType(const QString &mime)
177{
178 d->mMimeType = mime;
179}
180
181bool Attachment::showInline() const
182{
183 return d->mShowInline;
184}
185
186void Attachment::setShowInline(bool showinline)
187{
188 d->mShowInline = showinline;
189}
190
191QString Attachment::label() const
192{
193 return d->mLabel;
194}
195
196void Attachment::setLabel(const QString &label)
197{
198 d->mLabel = label;
199}
200
201bool Attachment::isLocal() const
202{
203 return d->mLocal;
204}
205
206void Attachment::setLocal(bool local)
207{
208 d->mLocal = local;
209}
210
211Attachment &Attachment::operator=(const Attachment &other)
212{
213 if (this != &other) {
214 d->mSize = other.d->mSize;
215 d->mMimeType = other.d->mMimeType;
216 d->mUri = other.d->mUri;
217 d->mEncodedData = other.d->mEncodedData;
218 d->mLabel = other.d->mLabel;
219 d->mBinary = other.d->mBinary;
220 d->mLocal = other.d->mLocal;
221 d->mShowInline = other.d->mShowInline;
222 }
223
224 return *this;
225}
226
227bool Attachment::operator==(const Attachment &a2) const
228{
229 return uri() == a2.uri() &&
230 d->mLabel == a2.label() &&
231 d->mLocal == a2.isLocal() &&
232 d->mBinary == a2.isBinary() &&
233 d->mShowInline == a2.showInline() &&
234 size() == a2.size() &&
235 decodedData() == a2.decodedData();
236}
237
238bool Attachment::operator!=(const Attachment &a2) const
239{
240 return !(*this == a2);
241}
242
243QDataStream& KCalCore::operator<<(QDataStream &out, const KCalCore::Attachment::Ptr &a)
244{
245 if (a)
246 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;
247 return out;
248}
249
250QDataStream& KCalCore::operator>>(QDataStream &in, const KCalCore::Attachment::Ptr &a)
251{
252 if (a)
253 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;
254 return in;
255}
256
attachment.h
This file is part of the API for handling calendar data and defines the Attachment class.
KCalCore::Attachment
Represents information related to an attachment for a Calendar Incidence.
Definition attachment.h:60
KCalCore::Attachment::decodedData
QByteArray decodedData() const
Returns a QByteArray containing the decoded base64 binary data of the attachment.
Definition attachment.cpp:135
KCalCore::Attachment::uri
QString uri() const
Returns the URI of the attachment.
Definition attachment.cpp:106
KCalCore::Attachment::isBinary
bool isBinary() const
Returns true if the attachment has a binary blob; false otherwise.
Definition attachment.cpp:121
KCalCore::Attachment::showInline
bool showInline() const
Returns the attachment "show in-line" flag.
Definition attachment.cpp:181
KCalCore::Attachment::operator==
bool operator==(const Attachment &attachment) const
Compare this with attachment for equality.
Definition attachment.cpp:227
KCalCore::Attachment::mimeType
QString mimeType() const
Returns the MIME-type of the attachment.
Definition attachment.cpp:171
KCalCore::Attachment::setDecodedData
void setDecodedData(const QByteArray &data)
Sets the decoded attachment data.
Definition attachment.cpp:144
KCalCore::Attachment::isUri
bool isUri() const
Returns true if the attachment has a URI; false otherwise.
Definition attachment.cpp:101
KCalCore::Attachment::data
QByteArray data() const
Returns a pointer to a QByteArray containing the base64 encoded binary data of the attachment.
Definition attachment.cpp:126
KCalCore::Attachment::Attachment
Attachment(const QString &uri, const QString &mime=QString())
Constructs an attachment consisting of a uri and a mime type.
Definition attachment.cpp:84
KCalCore::Attachment::size
uint size() const
Returns the size of the attachment, in bytes.
Definition attachment.cpp:159
KCalCore::Attachment::isLocal
bool isLocal() const
Returns the attachment "local" flag.
Definition attachment.cpp:201
KCalCore::Attachment::~Attachment
~Attachment()
Destroys the attachment.
Definition attachment.cpp:96
KCalCore::Attachment::operator!=
bool operator!=(const Attachment &attachment) const
Compare this with attachment for inequality.
Definition attachment.cpp:238
KCalCore::Attachment::setLocal
void setLocal(bool local)
Sets the attachment "local" option, which is derived from the Calendar Incidence X-KONTACT-TYPE param...
Definition attachment.cpp:206
KCalCore::Attachment::setData
void setData(const QByteArray &base64)
Sets the base64 encoded binary blob data of the attachment.
Definition attachment.cpp:151
KCalCore::Attachment::label
QString label() const
Returns the attachment label string.
Definition attachment.cpp:191
KCalCore::Attachment::setShowInline
void setShowInline(bool showinline)
Sets the attachment "show in-line" option, which is derived from the Calendar Incidence X-CONTENT-DIS...
Definition attachment.cpp:186
KCalCore::Attachment::setUri
void setUri(const QString &uri)
Sets the URI for this attachment to uri.
Definition attachment.cpp:115
KCalCore::Attachment::setMimeType
void setMimeType(const QString &mime)
Sets the MIME-type of the attachment to mime.
Definition attachment.cpp:176
KCalCore::Attachment::setLabel
void setLabel(const QString &label)
Sets the attachment label to label, which is derived from the Calendar Incidence X-LABEL parameter.
Definition attachment.cpp:196
KCalCore::Attachment::operator=
Attachment & operator=(const Attachment &attachment)
Assignment operator.
Definition attachment.cpp:211
KCalCore::Attachment::Ptr
QSharedPointer< Attachment > Ptr
A shared pointer to an Attachment object.
Definition attachment.h:65
KCalCore
TODO: KDE5:
Definition alarm.h:47
KCalCore::operator>>
KCALCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &)
Alarm deserializer.
Definition alarm.cpp:863
KCalCore::operator<<
KCALCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &)
Alarm serializer.
Definition alarm.cpp:853
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

Skip menu "KCalCore Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal