libkcal
attachment.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "attachment.h"
00023 #include <kmdcodec.h>
00024
00025 using namespace KCal;
00026
00027 Attachment::Attachment( const Attachment &attachment )
00028 {
00029 mSize = attachment.mSize;
00030 mMimeType = attachment.mMimeType;
00031 mUri = attachment.mUri;
00032 mData = qstrdup( attachment.mData );
00033 mLabel = attachment.mLabel;
00034 mBinary = attachment.mBinary;
00035 mLocal = attachment.mLocal;
00036 mShowInline = attachment.mShowInline;
00037 }
00038
00039 Attachment::Attachment( const QString &uri, const QString &mime )
00040 {
00041 mSize = 0;
00042 mMimeType = mime;
00043 mUri = uri;
00044 mData = 0;
00045 mBinary = false;
00046 mLocal = false;
00047 mShowInline = false;
00048 }
00049
00050 Attachment::Attachment( const char *base64, const QString &mime )
00051 {
00052 mSize = 0;
00053 mMimeType = mime;
00054 mData = qstrdup( base64 );
00055 mBinary = true;
00056 mLocal = false;
00057 mShowInline = false;
00058 }
00059
00060 Attachment::~Attachment()
00061 {
00062 delete[] mData;
00063 }
00064
00065 bool Attachment::isUri() const
00066 {
00067 return !mBinary;
00068 }
00069
00070 QString Attachment::uri() const
00071 {
00072 if ( !mBinary ) {
00073 return mUri;
00074 } else {
00075 return QString::null;
00076 }
00077 }
00078
00079 void Attachment::setUri( const QString &uri )
00080 {
00081 mUri = uri;
00082 mBinary = false;
00083 }
00084
00085 bool Attachment::isBinary() const
00086 {
00087 return mBinary;
00088 }
00089
00090 char *Attachment::data() const
00091 {
00092 if ( mBinary ) {
00093 return mData;
00094 } else {
00095 return 0;
00096 }
00097 }
00098
00099 QByteArray &Attachment::decodedData()
00100 {
00101 if ( mDataCache.isNull() && mData ) {
00102
00103
00104 QByteArray encoded;
00105 encoded.duplicate( mData, strlen( mData ) );
00106 QByteArray decoded;
00107 KCodecs::base64Decode( encoded, decoded );
00108 mDataCache = decoded;
00109 }
00110
00111 return mDataCache;
00112 }
00113
00114 void Attachment::setDecodedData( const QByteArray &data )
00115 {
00116 QByteArray encoded;
00117 KCodecs::base64Encode( data, encoded );
00118 setData( encoded.data() );
00119 mDataCache = data;
00120 mSize = mDataCache.size();
00121 }
00122
00123 void Attachment::setData( const char *base64 )
00124 {
00125 delete[] mData;
00126 mData = qstrdup( base64 );
00127 mBinary = true;
00128 mDataCache = QByteArray();
00129 mSize = 0;
00130 }
00131
00132 uint Attachment::size()
00133 {
00134 if ( isUri() ) {
00135 return 0;
00136 }
00137 if ( !mSize ) {
00138 mSize = decodedData().size();
00139 }
00140
00141 return mSize;
00142 }
00143
00144 QString Attachment::mimeType() const
00145 {
00146 return mMimeType;
00147 }
00148
00149 void Attachment::setMimeType(const QString& mime)
00150 {
00151 mMimeType = mime;
00152 }
00153
00154 bool Attachment::showInline() const
00155 {
00156 return mShowInline;
00157 }
00158
00159 void Attachment::setShowInline( bool showinline )
00160 {
00161 mShowInline = showinline;
00162 }
00163
00164 QString Attachment::label() const
00165 {
00166 return mLabel;
00167 }
00168
00169 void Attachment::setLabel( const QString& label )
00170 {
00171 mLabel = label;
00172 }
00173
00174 bool Attachment::isLocal() const
00175 {
00176 return mLocal;
00177 }
00178
00179 void Attachment::setLocal( bool local )
00180 {
00181 mLocal = local;
00182 }
|