• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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 
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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:24:50 by doxygen 1.8.3.1 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.10.5 API Reference

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