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() ) {
00102 mDataCache = KCodecs::base64Decode( QCString( mData ) );
00103 }
00104
00105 return mDataCache;
00106 }
00107
00108 void Attachment::setDecodedData( const QByteArray &data )
00109 {
00110 setData( KCodecs::base64Encode( QCString( data.data() ) ) );
00111 mDataCache = data;
00112 mSize = mDataCache.size();
00113 }
00114
00115 void Attachment::setData( const char *base64 )
00116 {
00117 delete[] mData;
00118 mData = qstrdup( base64 );
00119 mBinary = true;
00120 mDataCache = QByteArray();
00121 mSize = 0;
00122 }
00123
00124 uint Attachment::size()
00125 {
00126 if ( isUri() ) {
00127 return 0;
00128 }
00129 if ( !mSize ) {
00130 mSize = decodedData().size();
00131 }
00132
00133 return mSize;
00134 }
00135
00136 QString Attachment::mimeType() const
00137 {
00138 return mMimeType;
00139 }
00140
00141 void Attachment::setMimeType(const QString& mime)
00142 {
00143 mMimeType = mime;
00144 }
00145
00146 bool Attachment::showInline() const
00147 {
00148 return mShowInline;
00149 }
00150
00151 void Attachment::setShowInline( bool showinline )
00152 {
00153 mShowInline = showinline;
00154 }
00155
00156 QString Attachment::label() const
00157 {
00158 return mLabel;
00159 }
00160
00161 void Attachment::setLabel( const QString& label )
00162 {
00163 mLabel = label;
00164 }
00165
00166 bool Attachment::isLocal() const
00167 {
00168 return mLocal;
00169 }
00170
00171 void Attachment::setLocal( bool local )
00172 {
00173 mLocal = local;
00174 }
|