KCal Library
attachment.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00032 #include "attachment.h"
00033
00034 #include <QtCore/QByteArray>
00035
00036 using namespace KCal;
00037
00042
00043 class KCal::Attachment::Private
00044 {
00045 public:
00046 Private( const QString &data, const QString &mime, bool binary )
00047 : mMimeType( mime ),
00048 mData( data ),
00049 mBinary( binary ),
00050 mShowInline( false )
00051 {}
00052 Private( const Private &other )
00053 : mMimeType( other.mMimeType ),
00054 mData( other.mData ),
00055 mLabel( other.mLabel ),
00056 mBinary( other.mBinary ),
00057 mLocal( other.mLocal ),
00058 mShowInline( other.mShowInline )
00059 {}
00060 QByteArray mDataCache;
00061 uint mSize;
00062 QString mMimeType;
00063 QString mData;
00064 QString mLabel;
00065 bool mBinary;
00066 bool mLocal;
00067 bool mShowInline;
00068 };
00069
00070
00071 Attachment::Attachment( const Attachment &attachment )
00072 : d( new Attachment::Private( *attachment.d ) )
00073 {
00074 }
00075
00076 Attachment::Attachment( const QString &uri, const QString &mime )
00077 : d( new Attachment::Private( uri, mime, false ) )
00078 {
00079 d->mLocal = false;
00080 }
00081
00082 Attachment::Attachment( const char *base64, const QString &mime )
00083 : d( new Attachment::Private( QString::fromUtf8( base64 ), mime, true ) )
00084 {
00085 }
00086
00087 Attachment::~Attachment()
00088 {
00089 delete d;
00090 }
00091
00092 bool Attachment::isUri() const
00093 {
00094 return !d->mBinary;
00095 }
00096
00097 QString Attachment::uri() const
00098 {
00099 if ( !d->mBinary ) {
00100 return d->mData;
00101 } else {
00102 return QString();
00103 }
00104 }
00105
00106 void Attachment::setUri( const QString &uri )
00107 {
00108 d->mData = uri;
00109 d->mBinary = false;
00110 }
00111
00112 bool Attachment::isBinary() const
00113 {
00114 return d->mBinary;
00115 }
00116
00117 char *Attachment::data() const
00118 {
00119 if ( d->mBinary ) {
00120 return d->mData.toUtf8().data();
00121 } else {
00122 return 0;
00123 }
00124 }
00125
00126 QByteArray &Attachment::decodedData() const
00127 {
00128 if ( d->mDataCache.isNull() ) {
00129 d->mDataCache = QByteArray::fromBase64( d->mData.toUtf8() );
00130 }
00131
00132 return d->mDataCache;
00133 }
00134
00135 void Attachment::setDecodedData( const QByteArray &data )
00136 {
00137 setData( data.toBase64() );
00138 d->mDataCache = data;
00139 }
00140
00141 void Attachment::setData( const char *base64 )
00142 {
00143 d->mData = QString::fromUtf8( base64 );
00144 d->mBinary = true;
00145 d->mDataCache = QByteArray();
00146 d->mSize = 0;
00147 }
00148
00149 uint Attachment::size() const
00150 {
00151 if ( isUri() ) {
00152 return 0;
00153 }
00154 if ( !d->mSize ) {
00155 d->mSize = decodedData().size();
00156 }
00157
00158 return d->mSize;
00159 }
00160
00161 QString Attachment::mimeType() const
00162 {
00163 return d->mMimeType;
00164 }
00165
00166 void Attachment::setMimeType( const QString &mime )
00167 {
00168 d->mMimeType = mime;
00169 }
00170
00171 bool Attachment::showInline() const
00172 {
00173 return d->mShowInline;
00174 }
00175
00176 void Attachment::setShowInline( bool showinline )
00177 {
00178 d->mShowInline = showinline;
00179 }
00180
00181 QString Attachment::label() const
00182 {
00183 return d->mLabel;
00184 }
00185
00186 void Attachment::setLabel( const QString &label )
00187 {
00188 d->mLabel = label;
00189 }
00190
00191 bool Attachment::isLocal() const
00192 {
00193 return d->mLocal;
00194 }
00195
00196 void Attachment::setLocal( bool local )
00197 {
00198 d->mLocal = local;
00199 }