• 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.12
  • 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 
34 using namespace KCalCore;
35 
40 //@cond PRIVATE
41 class KCalCore::Attachment::Private
42 {
43 public:
44  Private(const QString &mime, bool binary)
45  : mSize(0),
46  mMimeType(mime),
47  mBinary(binary),
48  mLocal(false),
49  mShowInline(false)
50  {}
51  Private(const Private &other)
52  : mSize(other.mSize),
53  mMimeType(other.mMimeType),
54  mUri(other.mUri),
55  mEncodedData(other.mEncodedData),
56  mLabel(other.mLabel),
57  mBinary(other.mBinary),
58  mLocal(other.mLocal),
59  mShowInline(other.mShowInline)
60  {}
61 
62  ~Private()
63  {
64  }
65 
66  QByteArray mDecodedDataCache;
67  uint mSize;
68  QString mMimeType;
69  QString mUri;
70  QByteArray mEncodedData;
71  QString mLabel;
72  bool mBinary;
73  bool mLocal;
74  bool mShowInline;
75 };
76 //@endcond
77 
78 Attachment::Attachment(const Attachment &attachment)
79  : d(new Attachment::Private(*attachment.d))
80 {
81 }
82 
83 Attachment::Attachment(const QString &uri, const QString &mime)
84  : d(new Attachment::Private(mime, false))
85 {
86  d->mUri = uri;
87 }
88 
89 Attachment::Attachment(const QByteArray &base64, const QString &mime)
90  : d(new Attachment::Private(mime, true))
91 {
92  d->mEncodedData = base64;
93 }
94 
95 Attachment::~Attachment()
96 {
97  delete d;
98 }
99 
100 bool Attachment::isUri() const
101 {
102  return !d->mBinary;
103 }
104 
105 QString Attachment::uri() const
106 {
107  if (!d->mBinary) {
108  return d->mUri;
109  } else {
110  return QString();
111  }
112 }
113 
114 void Attachment::setUri(const QString &uri)
115 {
116  d->mUri = uri;
117  d->mBinary = false;
118 }
119 
120 bool Attachment::isBinary() const
121 {
122  return d->mBinary;
123 }
124 
125 QByteArray Attachment::data() const
126 {
127  if (d->mBinary) {
128  return d->mEncodedData;
129  } else {
130  return QByteArray();
131  }
132 }
133 
134 QByteArray Attachment::decodedData() const
135 {
136  if (d->mDecodedDataCache.isNull()) {
137  d->mDecodedDataCache = QByteArray::fromBase64(d->mEncodedData);
138  }
139 
140  return d->mDecodedDataCache;
141 }
142 
143 void Attachment::setDecodedData(const QByteArray &data)
144 {
145  setData(data.toBase64());
146  d->mDecodedDataCache = data;
147  d->mSize = d->mDecodedDataCache.size();
148 }
149 
150 void Attachment::setData(const QByteArray &base64)
151 {
152  d->mEncodedData = base64;
153  d->mBinary = true;
154  d->mDecodedDataCache = QByteArray();
155  d->mSize = 0;
156 }
157 
158 uint Attachment::size() const
159 {
160  if (isUri()) {
161  return 0;
162  }
163  if (!d->mSize) {
164  d->mSize = decodedData().size();
165  }
166 
167  return d->mSize;
168 }
169 
170 QString Attachment::mimeType() const
171 {
172  return d->mMimeType;
173 }
174 
175 void Attachment::setMimeType(const QString &mime)
176 {
177  d->mMimeType = mime;
178 }
179 
180 bool Attachment::showInline() const
181 {
182  return d->mShowInline;
183 }
184 
185 void Attachment::setShowInline(bool showinline)
186 {
187  d->mShowInline = showinline;
188 }
189 
190 QString Attachment::label() const
191 {
192  return d->mLabel;
193 }
194 
195 void Attachment::setLabel(const QString &label)
196 {
197  d->mLabel = label;
198 }
199 
200 bool Attachment::isLocal() const
201 {
202  return d->mLocal;
203 }
204 
205 void Attachment::setLocal(bool local)
206 {
207  d->mLocal = local;
208 }
209 
210 Attachment &Attachment::operator=(const Attachment &other)
211 {
212  if (this != &other) {
213  d->mSize = other.d->mSize;
214  d->mMimeType = other.d->mMimeType;
215  d->mUri = other.d->mUri;
216  d->mEncodedData = other.d->mEncodedData;
217  d->mLabel = other.d->mLabel;
218  d->mBinary = other.d->mBinary;
219  d->mLocal = other.d->mLocal;
220  d->mShowInline = other.d->mShowInline;
221  }
222 
223  return *this;
224 }
225 
226 bool Attachment::operator==(const Attachment &a2) const
227 {
228  return uri() == a2.uri() &&
229  d->mLabel == a2.label() &&
230  d->mLocal == a2.isLocal() &&
231  d->mBinary == a2.isBinary() &&
232  d->mShowInline == a2.showInline() &&
233  size() == a2.size() &&
234  decodedData() == a2.decodedData();
235 }
236 
237 bool Attachment::operator!=(const Attachment &a2) const
238 {
239  return !(*this == a2);
240 }
241 
242 QDataStream& KCalCore::operator<<(QDataStream &out, const KCalCore::Attachment::Ptr &a)
243 {
244  if (a)
245  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;
246  return out;
247 }
248 
249 QDataStream& KCalCore::operator>>(QDataStream &in, const KCalCore::Attachment::Ptr &a)
250 {
251  if (a)
252  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;
253  return in;
254 }
255 
KCalCore::Attachment::Ptr
QSharedPointer< Attachment > Ptr
A shared pointer to an Attachment object.
Definition: attachment.h:65
KCalCore::Attachment::operator==
bool operator==(const Attachment &attachment) const
Compare this with attachment for equality.
Definition: attachment.cpp:226
KCalCore::Attachment::isBinary
bool isBinary() const
Returns true if the attachment has a binary blob; false otherwise.
Definition: attachment.cpp:120
KCalCore::Attachment::showInline
bool showInline() const
Returns the attachment "show in-line" flag.
Definition: attachment.cpp:180
KCalCore::Attachment::size
uint size() const
Returns the size of the attachment, in bytes.
Definition: attachment.cpp:158
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:83
KCalCore::Attachment::isUri
bool isUri() const
Returns true if the attachment has a URI; false otherwise.
Definition: attachment.cpp:100
KCalCore::Attachment::setDecodedData
void setDecodedData(const QByteArray &data)
Sets the decoded attachment data.
Definition: attachment.cpp:143
KCalCore::Attachment::uri
QString uri() const
Returns the URI of the attachment.
Definition: attachment.cpp:105
KCalCore::Attachment::isLocal
bool isLocal() const
Returns the attachment "local" flag.
Definition: attachment.cpp:200
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:195
KCalCore::Attachment::label
QString label() const
Returns the attachment label string.
Definition: attachment.cpp:190
KCalCore::Attachment::setMimeType
void setMimeType(const QString &mime)
Sets the MIME-type of the attachment to mime.
Definition: attachment.cpp:175
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:134
KCalCore::Attachment::~Attachment
~Attachment()
Destroys the attachment.
Definition: attachment.cpp:95
attachment.h
This file is part of the API for handling calendar data and defines the Attachment class...
KCalCore::Attachment::mimeType
QString mimeType() const
Returns the MIME-type of the attachment.
Definition: attachment.cpp:170
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:205
KCalCore::Attachment::operator!=
bool operator!=(const Attachment &attachment) const
Compare this with attachment for inequality.
Definition: attachment.cpp:237
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:150
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:185
KCalCore::Attachment::operator=
Attachment & operator=(const Attachment &attachment)
Assignment operator.
Definition: attachment.cpp:210
KCalCore::Attachment::setUri
void setUri(const QString &uri)
Sets the URI for this attachment to uri.
Definition: attachment.cpp:114
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:125
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:57 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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