KCal Library
attachment.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcal library. 00003 00004 Copyright (c) 2002 Michael Brade <brade@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00032 #include "attachment.h" 00033 00034 #include <QtCore/QByteArray> 00035 00036 using namespace KCal; 00037 00042 //@cond PRIVATE 00043 class KCal::Attachment::Private 00044 { 00045 public: 00046 Private( const QString &mime, bool binary ) 00047 : mSize( 0 ), 00048 mMimeType( mime ), 00049 mData( 0 ), 00050 mBinary( binary ), 00051 mLocal( false ), 00052 mShowInline( false ) 00053 {} 00054 Private( const Private &other ) 00055 : mSize( other.mSize ), 00056 mMimeType( other.mMimeType ), 00057 mUri( other.mUri ), 00058 mData( qstrdup( other.mData ) ), 00059 mLabel( other.mLabel ), 00060 mBinary( other.mBinary ), 00061 mLocal( other.mLocal ), 00062 mShowInline( other.mShowInline ) 00063 {} 00064 ~Private() 00065 { 00066 delete[] mData; 00067 } 00068 00069 QByteArray mDataCache; 00070 uint mSize; 00071 QString mMimeType; 00072 QString mUri; 00073 char *mData; 00074 QString mLabel; 00075 bool mBinary; 00076 bool mLocal; 00077 bool mShowInline; 00078 }; 00079 //@endcond 00080 00081 Attachment::Attachment( const Attachment &attachment ) 00082 : d( new Attachment::Private( *attachment.d ) ) 00083 { 00084 } 00085 00086 Attachment::Attachment( const QString &uri, const QString &mime ) 00087 : d( new Attachment::Private( mime, false ) ) 00088 { 00089 d->mUri = uri; 00090 } 00091 00092 Attachment::Attachment( const char *base64, const QString &mime ) 00093 : d( new Attachment::Private( mime, true ) ) 00094 { 00095 d->mData = qstrdup( base64 ); 00096 } 00097 00098 Attachment::~Attachment() 00099 { 00100 delete d; 00101 } 00102 00103 bool Attachment::isUri() const 00104 { 00105 return !d->mBinary; 00106 } 00107 00108 QString Attachment::uri() const 00109 { 00110 if ( !d->mBinary ) { 00111 return d->mUri; 00112 } else { 00113 return QString(); 00114 } 00115 } 00116 00117 void Attachment::setUri( const QString &uri ) 00118 { 00119 d->mUri = uri; 00120 d->mBinary = false; 00121 } 00122 00123 bool Attachment::isBinary() const 00124 { 00125 return d->mBinary; 00126 } 00127 00128 char *Attachment::data() const 00129 { 00130 if ( d->mBinary ) { 00131 return d->mData; 00132 } else { 00133 return 0; 00134 } 00135 } 00136 00137 QByteArray &Attachment::decodedData() const 00138 { 00139 if ( d->mDataCache.isNull() ) { 00140 d->mDataCache = QByteArray::fromBase64( d->mData ); 00141 } 00142 00143 return d->mDataCache; 00144 } 00145 00146 void Attachment::setDecodedData( const QByteArray &data ) 00147 { 00148 setData( data.toBase64().constData() ); 00149 d->mDataCache = data; 00150 d->mSize = d->mDataCache.size(); 00151 } 00152 00153 void Attachment::setData( const char *base64 ) 00154 { 00155 delete[] d->mData; 00156 d->mData = qstrdup( base64 ); 00157 d->mBinary = true; 00158 d->mDataCache = QByteArray(); 00159 d->mSize = 0; 00160 } 00161 00162 uint Attachment::size() const 00163 { 00164 if ( isUri() ) { 00165 return 0; 00166 } 00167 if ( !d->mSize ) { 00168 d->mSize = decodedData().size(); 00169 } 00170 00171 return d->mSize; 00172 } 00173 00174 QString Attachment::mimeType() const 00175 { 00176 return d->mMimeType; 00177 } 00178 00179 void Attachment::setMimeType( const QString &mime ) 00180 { 00181 d->mMimeType = mime; 00182 } 00183 00184 bool Attachment::showInline() const 00185 { 00186 return d->mShowInline; 00187 } 00188 00189 void Attachment::setShowInline( bool showinline ) 00190 { 00191 d->mShowInline = showinline; 00192 } 00193 00194 QString Attachment::label() const 00195 { 00196 return d->mLabel; 00197 } 00198 00199 void Attachment::setLabel( const QString &label ) 00200 { 00201 d->mLabel = label; 00202 } 00203 00204 bool Attachment::isLocal() const 00205 { 00206 return d->mLocal; 00207 } 00208 00209 void Attachment::setLocal( bool local ) 00210 { 00211 d->mLocal = local; 00212 } 00213 00214 bool Attachment::operator==( const Attachment &a2 ) const 00215 { 00216 return uri() == a2.uri() && 00217 d->mLabel == a2.label() && 00218 d->mLocal == a2.isLocal() && 00219 d->mBinary == a2.isBinary() && 00220 d->mShowInline == a2.showInline() && 00221 size() == a2.size() && 00222 decodedData() == a2.decodedData(); 00223 } 00224 00225 bool Attachment::operator!=( const Attachment &a2 ) const 00226 { 00227 return !( *this == a2 ); 00228 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:52 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:52 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.