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

KCal Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kcal
attachment.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcal 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 #include <QtCore/QByteArray>
35 
36 using namespace KCal;
37 
42 //@cond PRIVATE
43 class KCal::Attachment::Private
44 {
45  public:
46  Private( const QString &mime, bool binary )
47  : mSize( 0 ),
48  mMimeType( mime ),
49  mData( 0 ),
50  mBinary( binary ),
51  mLocal( false ),
52  mShowInline( false )
53  {}
54  Private( const Private &other )
55  : mSize( other.mSize ),
56  mMimeType( other.mMimeType ),
57  mUri( other.mUri ),
58  mData( qstrdup( other.mData ) ),
59  mLabel( other.mLabel ),
60  mBinary( other.mBinary ),
61  mLocal( other.mLocal ),
62  mShowInline( other.mShowInline )
63  {}
64  ~Private()
65  {
66  delete[] mData;
67  }
68 
69  QByteArray mDataCache;
70  uint mSize;
71  QString mMimeType;
72  QString mUri;
73  char *mData;
74  QString mLabel;
75  bool mBinary;
76  bool mLocal;
77  bool mShowInline;
78 };
79 //@endcond
80 
81 Attachment::Attachment( const Attachment &attachment )
82  : d( new Attachment::Private( *attachment.d ) )
83 {
84 }
85 
86 Attachment::Attachment( const QString &uri, const QString &mime )
87  : d( new Attachment::Private( mime, false ) )
88 {
89  d->mUri = uri;
90 }
91 
92 Attachment::Attachment( const char *base64, const QString &mime )
93  : d( new Attachment::Private( mime, true ) )
94 {
95  d->mData = qstrdup( base64 );
96 }
97 
98 Attachment::~Attachment()
99 {
100  delete d;
101 }
102 
103 bool Attachment::isUri() const
104 {
105  return !d->mBinary;
106 }
107 
108 QString Attachment::uri() const
109 {
110  if ( !d->mBinary ) {
111  return d->mUri;
112  } else {
113  return QString();
114  }
115 }
116 
117 void Attachment::setUri( const QString &uri )
118 {
119  d->mUri = uri;
120  d->mBinary = false;
121 }
122 
123 bool Attachment::isBinary() const
124 {
125  return d->mBinary;
126 }
127 
128 char *Attachment::data() const
129 {
130  if ( d->mBinary ) {
131  return d->mData;
132  } else {
133  return 0;
134  }
135 }
136 
137 QByteArray &Attachment::decodedData() const
138 {
139  if ( d->mDataCache.isNull() ) {
140  d->mDataCache = QByteArray::fromBase64( d->mData );
141  }
142 
143  return d->mDataCache;
144 }
145 
146 void Attachment::setDecodedData( const QByteArray &data )
147 {
148  setData( data.toBase64().constData() );
149  d->mDataCache = data;
150  d->mSize = d->mDataCache.size();
151 }
152 
153 void Attachment::setData( const char *base64 )
154 {
155  delete[] d->mData;
156  d->mData = qstrdup( base64 );
157  d->mBinary = true;
158  d->mDataCache = QByteArray();
159  d->mSize = 0;
160 }
161 
162 uint Attachment::size() const
163 {
164  if ( isUri() ) {
165  return 0;
166  }
167  if ( !d->mSize ) {
168  d->mSize = decodedData().size();
169  }
170 
171  return d->mSize;
172 }
173 
174 QString Attachment::mimeType() const
175 {
176  return d->mMimeType;
177 }
178 
179 void Attachment::setMimeType( const QString &mime )
180 {
181  d->mMimeType = mime;
182 }
183 
184 bool Attachment::showInline() const
185 {
186  return d->mShowInline;
187 }
188 
189 void Attachment::setShowInline( bool showinline )
190 {
191  d->mShowInline = showinline;
192 }
193 
194 QString Attachment::label() const
195 {
196  return d->mLabel;
197 }
198 
199 void Attachment::setLabel( const QString &label )
200 {
201  d->mLabel = label;
202 }
203 
204 bool Attachment::isLocal() const
205 {
206  return d->mLocal;
207 }
208 
209 void Attachment::setLocal( bool local )
210 {
211  d->mLocal = local;
212 }
213 
214 bool Attachment::operator==( const Attachment &a2 ) const
215 {
216  return uri() == a2.uri() &&
217  d->mLabel == a2.label() &&
218  d->mLocal == a2.isLocal() &&
219  d->mBinary == a2.isBinary() &&
220  d->mShowInline == a2.showInline() &&
221  size() == a2.size() &&
222  decodedData() == a2.decodedData();
223 }
224 
225 bool Attachment::operator!=( const Attachment &a2 ) const
226 {
227  return !( *this == a2 );
228 }
KCal::Attachment::operator!=
bool operator!=(const Attachment &a2) const
Returns true if two attachments aren't equal.
Definition: attachment.cpp:225
KCal::Attachment::data
char * data() const
Returns a pointer to a character string containing the base64 encoded binary data of the attachment...
Definition: attachment.cpp:128
KCal::Attachment::isBinary
bool isBinary() const
Returns true if the attachment has a binary blob; false otherwise.
Definition: attachment.cpp:123
KCal::Attachment::isUri
bool isUri() const
Returns true if the attachment has a URI; false otherwise.
Definition: attachment.cpp:103
KCal::Attachment::~Attachment
~Attachment()
Destroys the attachment.
Definition: attachment.cpp:98
KCal::Attachment::operator==
bool operator==(const Attachment &a2) const
Returns true if two attachments are equal.
Definition: attachment.cpp:214
KCal::Attachment::showInline
bool showInline() const
Returns the attachment "show in-line" flag.
Definition: attachment.cpp:184
KCal::Attachment::size
uint size() const
Returns the size of the attachment, in bytes.
Definition: attachment.cpp:162
KCal::Attachment::label
QString label() const
Returns the attachment label string.
Definition: attachment.cpp:194
KCal::Attachment::mimeType
QString mimeType() const
Returns the MIME-type of the attachment.
Definition: attachment.cpp:174
KCal::Attachment::setMimeType
void setMimeType(const QString &mime)
Sets the MIME-type of the attachment to mime.
Definition: attachment.cpp:179
KCal::Attachment::decodedData
QByteArray & decodedData() const
Returns a QByteArray containing the decoded base64 binary data of the attachment. ...
Definition: attachment.cpp:137
KCal::Attachment
Represents information related to an attachment for a Calendar Incidence.
Definition: attachment.h:57
KCal::Attachment::uri
QString uri() const
Returns the URI of the attachment.
Definition: attachment.cpp:108
KCal::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:189
attachment.h
This file is part of the API for handling calendar data and defines the Attachment class...
KCal::Attachment::setData
void setData(const char *base64)
Sets the base64 encoded binary blob data of the attachment.
Definition: attachment.cpp:153
KCal::Attachment::Attachment
Attachment(const QString &uri, const QString &mime=QString())
Constructs an attachment consisting of a uri and a mime type.
Definition: attachment.cpp:86
KCal::Attachment::isLocal
bool isLocal() const
Returns the attachment "local" flag.
Definition: attachment.cpp:204
KCal::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:209
KCal::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:199
KCal::Attachment::setDecodedData
void setDecodedData(const QByteArray &data)
Sets the decoded attachment data.
Definition: attachment.cpp:146
KCal::Attachment::setUri
void setUri(const QString &uri)
Sets the URI for this attachment to uri.
Definition: attachment.cpp:117
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

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