1 | /* |
2 | ktnefmessage.cpp |
3 | |
4 | Copyright (C) 2002 Michael Goffioul <kdeprint@swing.be> |
5 | |
6 | This file is part of KTNEF, the KDE TNEF support library/program. |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | */ |
23 | /** |
24 | * @file |
25 | * This file is part of the API for handling TNEF data and |
26 | * defines the KTNEFMessage class. |
27 | * |
28 | * @author Michael Goffioul |
29 | */ |
30 | |
31 | #include "ktnefmessage.h" |
32 | #include "ktnefattach.h" |
33 | #include "lzfu.h" |
34 | |
35 | #include <QtCore/QBuffer> |
36 | #include <QtCore/QList> |
37 | |
38 | using namespace KTnef; |
39 | |
40 | /** |
41 | * Private class that helps to provide binary compatibility between releases. |
42 | * @internal |
43 | */ |
44 | //@cond PRIVATE |
45 | class KTnef::KTNEFMessage::MessagePrivate |
46 | { |
47 | public: |
48 | MessagePrivate() {} |
49 | ~MessagePrivate(); |
50 | |
51 | void clearAttachments(); |
52 | |
53 | QList<KTNEFAttach *>attachments_; |
54 | }; |
55 | |
56 | KTNEFMessage::MessagePrivate::~MessagePrivate() |
57 | { |
58 | clearAttachments(); |
59 | } |
60 | |
61 | void KTNEFMessage::MessagePrivate::clearAttachments() |
62 | { |
63 | while ( !attachments_.isEmpty() ) { |
64 | delete attachments_.takeFirst(); |
65 | } |
66 | } |
67 | //@endcond |
68 | |
69 | KTNEFMessage::KTNEFMessage() : d( new KTnef::KTNEFMessage::MessagePrivate ) |
70 | { |
71 | } |
72 | |
73 | KTNEFMessage::~KTNEFMessage() |
74 | { |
75 | delete d; |
76 | } |
77 | |
78 | const QList<KTNEFAttach *> &KTNEFMessage::attachmentList() const |
79 | { |
80 | return d->attachments_; |
81 | } |
82 | |
83 | KTNEFAttach *KTNEFMessage::attachment( const QString &filename ) const |
84 | { |
85 | QList<KTNEFAttach *>::const_iterator it = d->attachments_.constBegin(); |
86 | for ( ; it != d->attachments_.constEnd(); ++it ) { |
87 | if ( (*it)->name() == filename ) { |
88 | return *it; |
89 | } |
90 | } |
91 | return 0; |
92 | } |
93 | |
94 | void KTNEFMessage::addAttachment( KTNEFAttach *attach ) |
95 | { |
96 | d->attachments_.append( attach ); |
97 | } |
98 | |
99 | void KTNEFMessage::clearAttachments() |
100 | { |
101 | d->clearAttachments(); |
102 | } |
103 | |
104 | QString KTNEFMessage::rtfString() const |
105 | { |
106 | QVariant prop = property( 0x1009 ); |
107 | if ( prop.isNull() || prop.type() != QVariant::ByteArray ) { |
108 | return QString(); |
109 | } else { |
110 | QByteArray rtf; |
111 | QByteArray propArray( prop.toByteArray() ); |
112 | QBuffer input( &propArray ), output( &rtf ); |
113 | if ( input.open( QIODevice::ReadOnly ) && |
114 | output.open( QIODevice::WriteOnly ) ) { |
115 | lzfu_decompress( &input, &output ); |
116 | } |
117 | return QString( rtf ); |
118 | } |
119 | } |
120 | |