summaryrefslogtreecommitdiffstats
path: root/libkcal/attachment.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
commitcc29364f06178f8f6b457384f2ec37a042bd9d43 (patch)
tree7c77a3184c698bbf9d98cef09fb1ba8124daceba /libkcal/attachment.cpp
parent4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff)
downloadtdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz
tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed * Added journal read support to the CalDAV resource * Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkcal/attachment.cpp')
-rw-r--r--libkcal/attachment.cpp111
1 files changed, 88 insertions, 23 deletions
diff --git a/libkcal/attachment.cpp b/libkcal/attachment.cpp
index fc319b735..51858161c 100644
--- a/libkcal/attachment.cpp
+++ b/libkcal/attachment.cpp
@@ -20,34 +20,46 @@
*/
#include "attachment.h"
+#include <kmdcodec.h>
using namespace KCal;
-Attachment::Attachment( const Attachment &attachment)
+Attachment::Attachment( const Attachment &attachment )
{
+ mSize = attachment.mSize;
mMimeType = attachment.mMimeType;
- mData = attachment.mData;
+ mUri = attachment.mUri;
+ mData = qstrdup( attachment.mData );
+ mLabel = attachment.mLabel;
mBinary = attachment.mBinary;
- mShowInline = attachment.mShowInline;
- mLabel = attachment.mLabel;
+ mLocal = attachment.mLocal;
+ mShowInline = attachment.mShowInline;
}
-Attachment::Attachment(const TQString& uri, const TQString& mime)
+Attachment::Attachment( const TQString &uri, const TQString &mime )
{
+ mSize = 0;
mMimeType = mime;
- mData = uri;
+ mUri = uri;
+ mData = 0;
mBinary = false;
- mShowInline = false;
- mLabel = TQString::null;
+ mLocal = false;
+ mShowInline = false;
}
-Attachment::Attachment(const char *base64, const TQString& mime)
+Attachment::Attachment( const char *base64, const TQString &mime )
{
+ mSize = 0;
mMimeType = mime;
- mData = TQString::fromUtf8(base64);
+ mData = qstrdup( base64 );
mBinary = true;
- mShowInline = false;
- mLabel = TQString::null;
+ mLocal = false;
+ mShowInline = false;
+}
+
+Attachment::~Attachment()
+{
+ delete[] mData;
}
bool Attachment::isUri() const
@@ -57,15 +69,16 @@ bool Attachment::isUri() const
TQString Attachment::uri() const
{
- if (!mBinary)
- return mData;
- else
+ if ( !mBinary ) {
+ return mUri;
+ } else {
return TQString::null;
+ }
}
-void Attachment::setUri(const TQString& uri)
+void Attachment::setUri( const TQString &uri )
{
- mData = uri;
+ mUri = uri;
mBinary = false;
}
@@ -76,17 +89,60 @@ bool Attachment::isBinary() const
char *Attachment::data() const
{
- if (mBinary)
- // this method actually return a const char*, but that can't be done because of the uneededly non-const libical API
- return const_cast<char*>( mData.latin1() ); //mData.utf8().data();
- else
+ if ( mBinary ) {
+ return mData;
+ } else {
return 0;
+ }
+}
+
+TQByteArray &Attachment::decodedData()
+{
+ if ( mDataCache.isNull() && mData ) {
+ // base64Decode() sometimes appends a null byte when called
+ // with a TQCString so work on TQByteArray's instead
+ TQByteArray encoded;
+ encoded.duplicate( mData, strlen( mData ) );
+ TQByteArray decoded;
+ KCodecs::base64Decode( encoded, decoded );
+ mDataCache = decoded;
+ }
+
+ return mDataCache;
}
-void Attachment::setData(const char *base64)
+void Attachment::setDecodedData( const TQByteArray &data )
{
- mData = TQString::fromUtf8(base64);
+ TQByteArray encoded;
+ KCodecs::base64Encode( data, encoded );
+
+ encoded.resize( encoded.count() + 1 );
+ encoded[encoded.count()-1] = '\0';
+
+ setData( encoded.data() );
+ mDataCache = data;
+ mSize = mDataCache.size();
+}
+
+void Attachment::setData( const char *base64 )
+{
+ delete[] mData;
+ mData = qstrdup( base64 );
mBinary = true;
+ mDataCache = TQByteArray();
+ mSize = 0;
+}
+
+uint Attachment::size()
+{
+ if ( isUri() ) {
+ return 0;
+ }
+ if ( !mSize ) {
+ mSize = decodedData().size();
+ }
+
+ return mSize;
}
TQString Attachment::mimeType() const
@@ -119,3 +175,12 @@ void Attachment::setLabel( const TQString& label )
mLabel = label;
}
+bool Attachment::isLocal() const
+{
+ return mLocal;
+}
+
+void Attachment::setLocal( bool local )
+{
+ mLocal = local;
+}