doc update to 4.11
[kdepim.git] / messageviewer / partnodebodypart.cpp
blob8c5f61fa104e3f0165f52ce1cc88f64154ced782
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 partnodebodypart.cpp
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2004 Marc Mutz <mutz@kde.org>,
6 Ingo Kloecker <kloecker@kde.org>
8 KMail is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 KMail is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 In addition, as a special exception, the copyright holders give
23 permission to link the code of this program with any edition of
24 the Qt library by Trolltech AS, Norway (or with modified versions
25 of Qt that use the same license as Qt), and distribute linked
26 combinations including the two. You must obey the GNU General
27 Public License in all respects for all of the code used other than
28 Qt. If you modify this file, you may extend this exception to
29 your version of the file, but you are not obligated to do so. If
30 you do not wish to do so, delete this exception statement from
31 your version.
37 #include "partnodebodypart.h"
38 #include "nodehelper.h"
40 #include <kurl.h>
42 #include <kmime/kmime_content.h>
44 #include <KDebug>
46 #include <QTextCodec>
48 using namespace MessageViewer;
50 static int serial = 0;
52 PartNodeBodyPart::PartNodeBodyPart( KMime::Content *topLevelContent, KMime::Content *content,
53 NodeHelper *nodeHelper, const QTextCodec * codec )
54 : Interface::BodyPart(), mTopLevelContent( topLevelContent ), mContent( content ), mCodec( codec ),
55 mDefaultDisplay( Interface::BodyPart::None ), mNodeHelper( nodeHelper )
58 QString PartNodeBodyPart::makeLink( const QString & path ) const {
59 // FIXME: use a PRNG for the first arg, instead of a serial number
60 return QString::fromLatin1( "x-kmail:/bodypart/%1/%2/%3" )
61 .arg( serial++ ).arg( mContent->index().toString() )
62 .arg( QString::fromLatin1( KUrl::toPercentEncoding( path, "/" ) ) );
65 QString PartNodeBodyPart::asText() const {
66 if ( !mContent->contentType()->isText() )
67 return QString();
68 return mContent->decodedText();
71 QByteArray PartNodeBodyPart::asBinary() const {
72 return mContent->decodedContent();
75 QString PartNodeBodyPart::contentTypeParameter( const char * param ) const {
76 return mContent->contentType()->parameter( param );
79 QString PartNodeBodyPart::contentDescription() const {
80 return mContent->contentDescription()->asUnicodeString();
83 QString PartNodeBodyPart::contentDispositionParameter( const char * param ) const {
84 return mContent->contentDisposition()->parameter( param );
87 bool PartNodeBodyPart::hasCompleteBody() const {
88 kWarning() << "Sorry, not yet implemented.";
89 return true;
92 Interface::BodyPartMemento * PartNodeBodyPart::memento() const {
93 /*TODO(Andras) Volker suggests to use a ContentIndex->Mememnto mapping
94 Also review if the reader's bodyPartMemento should be returned or the NodeHelper's one
96 return mNodeHelper->bodyPartMemento( mContent, "__plugin__" );
99 void PartNodeBodyPart::setBodyPartMemento( Interface::BodyPartMemento * memento ) {
100 /*TODO(Andras) Volker suggests to use a ContentIndex->Memento mapping
101 Also review if the reader's bodyPartMemento should be set or the NodeHelper's one */
102 mNodeHelper->setBodyPartMemento( mContent, "__plugin__" , memento );
105 Interface::BodyPart::Display PartNodeBodyPart::defaultDisplay() const {
106 return mDefaultDisplay;
109 void PartNodeBodyPart::setDefaultDisplay( Interface::BodyPart::Display d ){
110 mDefaultDisplay = d;