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

KCalCore Library

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
35 using namespace KCalCore;
36 
41 //@cond PRIVATE
42 class KCalCore::Attachment::Private
43 {
44 public:
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 
79 Attachment::Attachment(const Attachment &attachment)
80  : d(new Attachment::Private(*attachment.d))
81 {
82 }
83 
84 Attachment::Attachment(const QString &uri, const QString &mime)
85  : d(new Attachment::Private(mime, false))
86 {
87  d->mUri = uri;
88 }
89 
90 Attachment::Attachment(const QByteArray &base64, const QString &mime)
91  : d(new Attachment::Private(mime, true))
92 {
93  d->mEncodedData = base64;
94 }
95 
96 Attachment::~Attachment()
97 {
98  delete d;
99 }
100 
101 bool Attachment::isUri() const
102 {
103  return !d->mBinary;
104 }
105 
106 QString Attachment::uri() const
107 {
108  if (!d->mBinary) {
109  return d->mUri;
110  } else {
111  return QString();
112  }
113 }
114 
115 void Attachment::setUri(const QString &uri)
116 {
117  d->mUri = uri;
118  d->mBinary = false;
119 }
120 
121 bool Attachment::isBinary() const
122 {
123  return d->mBinary;
124 }
125 
126 QByteArray Attachment::data() const
127 {
128  if (d->mBinary) {
129  return d->mEncodedData;
130  } else {
131  return QByteArray();
132  }
133 }
134 
135 QByteArray Attachment::decodedData() const
136 {
137  if (d->mDecodedDataCache.isNull()) {
138  d->mDecodedDataCache = QByteArray::fromBase64(d->mEncodedData);
139  }
140 
141  return d->mDecodedDataCache;
142 }
143 
144 void Attachment::setDecodedData(const QByteArray &data)
145 {
146  setData(data.toBase64());
147  d->mDecodedDataCache = data;
148  d->mSize = d->mDecodedDataCache.size();
149 }
150 
151 void Attachment::setData(const QByteArray &base64)
152 {
153  d->mEncodedData = base64;
154  d->mBinary = true;
155  d->mDecodedDataCache = QByteArray();
156  d->mSize = 0;
157 }
158 
159 uint 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 
171 QString Attachment::mimeType() const
172 {
173  return d->mMimeType;
174 }
175 
176 void Attachment::setMimeType(const QString &mime)
177 {
178  d->mMimeType = mime;
179 }
180 
181 bool Attachment::showInline() const
182 {
183  return d->mShowInline;
184 }
185 
186 void Attachment::setShowInline(bool showinline)
187 {
188  d->mShowInline = showinline;
189 }
190 
191 QString Attachment::label() const
192 {
193  return d->mLabel;
194 }
195 
196 void Attachment::setLabel(const QString &label)
197 {
198  d->mLabel = label;
199 }
200 
201 bool Attachment::isLocal() const
202 {
203  return d->mLocal;
204 }
205 
206 void Attachment::setLocal(bool local)
207 {
208  d->mLocal = local;
209 }
210 
211 Attachment &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 
227 bool 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 
238 bool Attachment::operator!=(const Attachment &a2) const
239 {
240  return !(*this == a2);
241 }
242 
243 QDataStream& 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 
250 QDataStream& 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 
QByteArray
KCalCore::Attachment::operator==
bool operator==(const Attachment &attachment) const
Compare this with attachment for equality.
Definition: attachment.cpp:227
QDataStream
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::size
uint size() const
Returns the size of the attachment, in bytes.
Definition: attachment.cpp:159
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::isUri
bool isUri() const
Returns true if the attachment has a URI; false otherwise.
Definition: attachment.cpp:101
QSharedPointer
KCalCore::Attachment::setDecodedData
void setDecodedData(const QByteArray &data)
Sets the decoded attachment data.
Definition: attachment.cpp:144
KCalCore::Attachment::uri
QString uri() const
Returns the URI of the attachment.
Definition: attachment.cpp:106
KCalCore::Attachment::isLocal
bool isLocal() const
Returns the attachment "local" flag.
Definition: attachment.cpp:201
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::label
QString label() const
Returns the attachment label string.
Definition: attachment.cpp:191
QString
KCalCore::Attachment::setMimeType
void setMimeType(const QString &mime)
Sets the MIME-type of the attachment to mime.
Definition: attachment.cpp:176
KCalCore::operator>>
KCALCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:863
KCalCore::Attachment::decodedData
QByteArray decodedData() const
Returns a QByteArray containing the decoded base64 binary data of the attachment. ...
Definition: attachment.cpp:135
KCalCore::Attachment::~Attachment
~Attachment()
Destroys the attachment.
Definition: attachment.cpp:96
attachment.h
This file is part of the API for handling calendar data and defines the Attachment class...
QByteArray::fromBase64
QByteArray fromBase64(const QByteArray &base64)
KCalCore::Attachment::mimeType
QString mimeType() const
Returns the MIME-type of the attachment.
Definition: attachment.cpp:171
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::operator!=
bool operator!=(const Attachment &attachment) const
Compare this with attachment for inequality.
Definition: attachment.cpp:238
KCalCore::Attachment
Represents information related to an attachment for a Calendar Incidence.
Definition: attachment.h:59
KCalCore::Attachment::setData
void setData(const QByteArray &base64)
Sets the base64 encoded binary blob data of the attachment.
Definition: attachment.cpp:151
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
QByteArray::toBase64
QByteArray toBase64() const
KCalCore::Attachment::operator=
Attachment & operator=(const Attachment &attachment)
Assignment operator.
Definition: attachment.cpp:211
KCalCore::Attachment::setUri
void setUri(const QString &uri)
Sets the URI for this attachment to uri.
Definition: attachment.cpp:115
QByteArray::size
int size() const
KCalCore::operator<<
KCALCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:853
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:36:53 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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