ktnefmessage.cppGo 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
00021
00022
00031 #include "ktnefmessage.h"
00032 #include "ktnefattach.h"
00033 #include "lzfu.h"
00034
00035 #include <QtCore/QBuffer>
00036 #include <QtCore/QList>
00037
00038 using namespace KTnef;
00039
00044
00045 class KTnef::KTNEFMessage::MessagePrivate
00046 {
00047 public:
00048 MessagePrivate() {}
00049 ~MessagePrivate();
00050
00051 void clearAttachments();
00052
00053 QList<KTNEFAttach *>attachments_;
00054 };
00055
00056 KTNEFMessage::MessagePrivate::~MessagePrivate()
00057 {
00058 clearAttachments();
00059 }
00060
00061 void KTNEFMessage::MessagePrivate::clearAttachments()
00062 {
00063 while ( !attachments_.isEmpty() ) {
00064 delete attachments_.takeFirst();
00065 }
00066 }
00067
00068
00069 KTNEFMessage::KTNEFMessage() : d( new KTnef::KTNEFMessage::MessagePrivate )
00070 {
00071 }
00072
00073 KTNEFMessage::~KTNEFMessage()
00074 {
00075 delete d;
00076 }
00077
00078 const QList<KTNEFAttach *> &KTNEFMessage::attachmentList() const
00079 {
00080 return d->attachments_;
00081 }
00082
00083 KTNEFAttach *KTNEFMessage::attachment( const QString &filename ) const
00084 {
00085 QList<KTNEFAttach *>::const_iterator it = d->attachments_.constBegin();
00086 for ( ; it != d->attachments_.constEnd(); ++it ) {
00087 if ( (*it)->name() == filename ) {
00088 return *it;
00089 }
00090 }
00091 return 0;
00092 }
00093
00094 void KTNEFMessage::addAttachment( KTNEFAttach *attach )
00095 {
00096 d->attachments_.append( attach );
00097 }
00098
00099 void KTNEFMessage::clearAttachments()
00100 {
00101 d->clearAttachments();
00102 }
00103
00104 QString KTNEFMessage::rtfString() const
00105 {
00106 QVariant prop = property( 0x1009 );
00107 if ( prop.isNull() || prop.type() != QVariant::ByteArray ) {
00108 return QString();
00109 } else {
00110 QByteArray rtf;
00111 QByteArray propArray( prop.toByteArray() );
00112 QBuffer input( &propArray ), output( &rtf );
00113 if ( input.open( QIODevice::ReadOnly ) &&
00114 output.open( QIODevice::WriteOnly ) ) {
00115 lzfu_decompress( &input, &output );
00116 }
00117 return QString( rtf );
00118 }
00119 }
|