diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-23 19:13:13 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-23 19:13:13 +0200 |
commit | b968ea8ed364238c57c3e74cf2c122cb897cfbea (patch) | |
tree | 7a2dca2199906413a2d0b7d075ded0e4d5ffb69f /framework/src/domain/mimetreeparser/otp/partnodebodypart.cpp | |
parent | c1ca732bafc60f5c140ef5516e32bd46503bf68c (diff) | |
download | kube-b968ea8ed364238c57c3e74cf2c122cb897cfbea.tar.gz kube-b968ea8ed364238c57c3e74cf2c122cb897cfbea.zip |
Builds but doesn't link, no formatters yet
Diffstat (limited to 'framework/src/domain/mimetreeparser/otp/partnodebodypart.cpp')
-rw-r--r-- | framework/src/domain/mimetreeparser/otp/partnodebodypart.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/framework/src/domain/mimetreeparser/otp/partnodebodypart.cpp b/framework/src/domain/mimetreeparser/otp/partnodebodypart.cpp new file mode 100644 index 00000000..ec509787 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/partnodebodypart.cpp | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | partnodebodypart.cpp | ||
3 | |||
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> | ||
7 | |||
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. | ||
12 | |||
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. | ||
17 | |||
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 | ||
21 | |||
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. | ||
32 | */ | ||
33 | |||
34 | #include "partnodebodypart.h" | ||
35 | #include "nodehelper.h" | ||
36 | #include "objecttreeparser.h" | ||
37 | #include "mimetreeparser_debug.h" | ||
38 | #include <KMime/Content> | ||
39 | |||
40 | #include <QTextCodec> | ||
41 | #include <QUrl> | ||
42 | |||
43 | using namespace MimeTreeParser; | ||
44 | |||
45 | static int serial = 0; | ||
46 | |||
47 | PartNodeBodyPart::PartNodeBodyPart(ObjectTreeParser *otp, ProcessResult *result, KMime::Content *topLevelContent, KMime::Content *content, | ||
48 | NodeHelper *nodeHelper) | ||
49 | : Interface::BodyPart(), mTopLevelContent(topLevelContent), mContent(content), | ||
50 | mDefaultDisplay(Interface::BodyPart::None), mNodeHelper(nodeHelper) | ||
51 | , mObjectTreeParser(otp) | ||
52 | , mProcessResult(result) | ||
53 | {} | ||
54 | |||
55 | QString PartNodeBodyPart::makeLink(const QString &path) const | ||
56 | { | ||
57 | // FIXME: use a PRNG for the first arg, instead of a serial number | ||
58 | return QStringLiteral("x-kmail:/bodypart/%1/%2/%3") | ||
59 | .arg(serial++).arg(mContent->index().toString()) | ||
60 | .arg(QString::fromLatin1(QUrl::toPercentEncoding(path, "/"))); | ||
61 | } | ||
62 | |||
63 | QString PartNodeBodyPart::asText() const | ||
64 | { | ||
65 | if (!mContent->contentType()->isText()) { | ||
66 | return QString(); | ||
67 | } | ||
68 | return mContent->decodedText(); | ||
69 | } | ||
70 | |||
71 | QByteArray PartNodeBodyPart::asBinary() const | ||
72 | { | ||
73 | return mContent->decodedContent(); | ||
74 | } | ||
75 | |||
76 | QString PartNodeBodyPart::contentTypeParameter(const char *param) const | ||
77 | { | ||
78 | return mContent->contentType()->parameter(QString::fromLatin1(param)); | ||
79 | } | ||
80 | |||
81 | QString PartNodeBodyPart::contentDescription() const | ||
82 | { | ||
83 | return mContent->contentDescription()->asUnicodeString(); | ||
84 | } | ||
85 | |||
86 | QString PartNodeBodyPart::contentDispositionParameter(const char *param) const | ||
87 | { | ||
88 | return mContent->contentDisposition()->parameter(QString::fromLatin1(param)); | ||
89 | } | ||
90 | |||
91 | bool PartNodeBodyPart::hasCompleteBody() const | ||
92 | { | ||
93 | qCWarning(MIMETREEPARSER_LOG) << "Sorry, not yet implemented."; | ||
94 | return true; | ||
95 | } | ||
96 | |||
97 | Interface::BodyPartMemento *PartNodeBodyPart::memento() const | ||
98 | { | ||
99 | /*TODO(Andras) Volker suggests to use a ContentIndex->Mememnto mapping | ||
100 | Also review if the reader's bodyPartMemento should be returned or the NodeHelper's one | ||
101 | */ | ||
102 | return mNodeHelper->bodyPartMemento(mContent, "__plugin__"); | ||
103 | } | ||
104 | |||
105 | void PartNodeBodyPart::setBodyPartMemento(Interface::BodyPartMemento *memento) | ||
106 | { | ||
107 | /*TODO(Andras) Volker suggests to use a ContentIndex->Memento mapping | ||
108 | Also review if the reader's bodyPartMemento should be set or the NodeHelper's one */ | ||
109 | mNodeHelper->setBodyPartMemento(mContent, "__plugin__", memento); | ||
110 | } | ||
111 | |||
112 | Interface::BodyPart::Display PartNodeBodyPart::defaultDisplay() const | ||
113 | { | ||
114 | return mDefaultDisplay; | ||
115 | } | ||
116 | |||
117 | void PartNodeBodyPart::setDefaultDisplay(Interface::BodyPart::Display d) | ||
118 | { | ||
119 | mDefaultDisplay = d; | ||
120 | } | ||
121 | |||
122 | Interface::ObjectTreeSource *PartNodeBodyPart::source() const | ||
123 | { | ||
124 | return mObjectTreeParser->mSource; | ||
125 | } | ||