diff --git a/plugins/messageviewer/bodypartformatter/autotests/diffdata/diff-akonadiconsole-16.12-master-ref.diff b/plugins/messageviewer/bodypartformatter/autotests/diffdata/diff-akonadiconsole-16.12-master-ref.diff
--- a/plugins/messageviewer/bodypartformatter/autotests/diffdata/diff-akonadiconsole-16.12-master-ref.diff
+++ b/plugins/messageviewer/bodypartformatter/autotests/diffdata/diff-akonadiconsole-16.12-master-ref.diff
@@ -1,4 +1,4 @@
-
diff --git a/CMakeLists.txt b/CMakeLists.txt
+diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4ef75c..258dcc1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1096,5 +1096,4 @@
virtual ~TagPropertiesDialog();
Akonadi::Tag tag() const;
-
-
\ No newline at end of file
+
diff --git a/plugins/messageviewer/bodypartformatter/autotests/diffdata/kcontact1-ref.diff b/plugins/messageviewer/bodypartformatter/autotests/diffdata/kcontact1-ref.diff
--- a/plugins/messageviewer/bodypartformatter/autotests/diffdata/kcontact1-ref.diff
+++ b/plugins/messageviewer/bodypartformatter/autotests/diffdata/kcontact1-ref.diff
@@ -1,4 +1,4 @@
-
commit 93f6aaf446133e05826a4d8e50e2da8ffac7c28f
+commit 93f6aaf446133e05826a4d8e50e2da8ffac7c28f
Author: David Faure <faure@kde.org>
Date: Mon Apr 17 20:41:55 2017 +0200
@@ -475,5 +475,4 @@
currentVCard.addLine(vCardLine);
}
-
-
\ No newline at end of file
+
diff --git a/plugins/messageviewer/bodypartformatter/autotests/diffdata/test1-ref.diff b/plugins/messageviewer/bodypartformatter/autotests/diffdata/test1-ref.diff
--- a/plugins/messageviewer/bodypartformatter/autotests/diffdata/test1-ref.diff
+++ b/plugins/messageviewer/bodypartformatter/autotests/diffdata/test1-ref.diff
@@ -1,4 +1,4 @@
-
diff --git a/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp b/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
+diff --git a/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp b/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
index b69f56c0..2cc4ab92 100644
--- a/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
+++ b/plugins/messageviewer/bodypartformatter/ms-tnef/application_ms-tnef.cpp
@@ -11,5 +11,4 @@
const QString iconName = QUrl::fromLocalFile(MessageViewer::Util::iconPathForMimetype(att->mimeTag(),
KIconLoader::Desktop, attFileName)).url();
-
-
\ No newline at end of file
+
diff --git a/plugins/messageviewer/bodypartformatter/autotests/diffhighlightertest.cpp b/plugins/messageviewer/bodypartformatter/autotests/diffhighlightertest.cpp
--- a/plugins/messageviewer/bodypartformatter/autotests/diffhighlightertest.cpp
+++ b/plugins/messageviewer/bodypartformatter/autotests/diffhighlightertest.cpp
@@ -21,11 +21,17 @@
#include "../xdiff/diffhighlighter.h"
#include
+#include
#include
DiffHighlighterTest::DiffHighlighterTest(QObject *parent)
: QObject(parent)
{
+ QStandardPaths::setTestModeEnabled(true);
+ // trick the highlighter into using the light color theme
+ auto pal = QGuiApplication::palette();
+ pal.setColor(QPalette::Base, Qt::white);
+ QGuiApplication::setPalette(pal);
}
QString readDiffFile(const QString &diffFile)
diff --git a/plugins/messageviewer/bodypartformatter/xdiff/CMakeLists.txt b/plugins/messageviewer/bodypartformatter/xdiff/CMakeLists.txt
--- a/plugins/messageviewer/bodypartformatter/xdiff/CMakeLists.txt
+++ b/plugins/messageviewer/bodypartformatter/xdiff/CMakeLists.txt
@@ -4,6 +4,11 @@
add_library(messageviewer_bodypartformatter_text_xdiff MODULE ${messageviewer_bodypartformatter_text_xdiff_PART_SRCS})
-target_link_libraries(messageviewer_bodypartformatter_text_xdiff Qt5::Core KF5::I18n KF5::CoreAddons KF5::IconThemes KF5::WidgetsAddons KF5::MessageViewer KF5::SyntaxHighlighting)
+target_link_libraries(messageviewer_bodypartformatter_text_xdiff
+ Qt5::Core
+ KF5::MessageViewer
+ KF5::SyntaxHighlighting
+ Grantlee5::Templates
+)
install(TARGETS messageviewer_bodypartformatter_text_xdiff DESTINATION ${KDE_INSTALL_PLUGINDIR}/messageviewer/bodypartformatter)
diff --git a/plugins/messageviewer/bodypartformatter/xdiff/diffhighlighter.cpp b/plugins/messageviewer/bodypartformatter/xdiff/diffhighlighter.cpp
--- a/plugins/messageviewer/bodypartformatter/xdiff/diffhighlighter.cpp
+++ b/plugins/messageviewer/bodypartformatter/xdiff/diffhighlighter.cpp
@@ -21,16 +21,18 @@
#include
#include
#include
+
+#include
#include
DiffHighlighter::DiffHighlighter()
{
mDef = mRepo.definitionForName(QStringLiteral("Diff"));
setDefinition(mDef);
- setTheme(/*(palette().color(QPalette::Base).lightness() < 128)
- ? mRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)*/
- /*:*/ mRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
+ setTheme(QGuiApplication::palette().color(QPalette::Base).lightness() < 128
+ ? mRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)
+ : mRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
}
DiffHighlighter::~DiffHighlighter()
@@ -40,16 +42,7 @@
void DiffHighlighter::highlightDiff(const QString &str)
{
mOutputDiff.clear();
-
- static const QLatin1String tableStyle(
- "style=\""
- "text-align: left; "
- "border: solid black 1px; "
- "padding: 0.5em; "
- "margin: 0em;\"");
-
- mOutputDiff = QStringLiteral("
");
- mOutputDiff += QStringLiteral("
');
+ mOutputDiff = QStringLiteral("");
KSyntaxHighlighting::State state;
@@ -61,8 +54,7 @@
state = highlightLine(mCurrentLine, state);
mOutputDiff += QLatin1Char('\n');
}
- mOutputDiff += QLatin1Char('\n');
- mOutputDiff += QLatin1String("
");
+ mOutputDiff += QLatin1String("\n");
}
void DiffHighlighter::applyFormat(int offset, int length, const KSyntaxHighlighting::Format &format)
diff --git a/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.cpp b/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.cpp
--- a/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.cpp
+++ b/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.cpp
@@ -31,58 +31,60 @@
#include "diffhighlighter.h"
-#include
-#include
-#include
+#include
+#include
+#include
+
+#include
#include
-#include
+#include
namespace {
-// TODO: Show filename header to make it possible to save the patch.
// FIXME: The box should only be as wide as necessary.
-class Formatter : public MimeTreeParser::Interface::BodyPartFormatter
+class Formatter : public MessageViewer::MessagePartRendererBase
{
public:
- Result format(MimeTreeParser::Interface::BodyPart *bodyPart, MimeTreeParser::HtmlWriter *writer) const override
+ bool render(const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter *htmlWriter, MessageViewer::RenderContext *context) const override
{
- if (!writer) {
- return Ok;
- }
-
- if (bodyPart->defaultDisplay() == MimeTreeParser::Interface::BodyPart::AsIcon) {
- return AsIcon;
- }
-
- const QString diff = bodyPart->asText();
- if (diff.isEmpty()) {
- return AsIcon;
- }
-
- DiffHighlighter highLighter;
- highLighter.highlightDiff(diff);
- const QString html = highLighter.outputDiff();
- writer->write(html);
-
- return Ok;
+ Q_UNUSED(context);
+ auto mp = msgPart.dynamicCast();
+ if (!mp || mp->isHidden() || mp->text().isEmpty() || mp->asIcon() != MimeTreeParser::NoIcon)
+ return false;
+
+ const bool diffMimeType = msgPart->content()->contentType()->mimeType() == "text/x-patch"
+ || msgPart->content()->contentType()->mimeType() == "text/x-diff";
+ const bool diffFileName = msgPart->content()->contentType()->name().endsWith(QLatin1String(".diff"))
+ || msgPart->content()->contentType()->name().endsWith(QLatin1String(".patch"));
+ if (!diffMimeType && !diffFileName)
+ return false;
+
+ auto c = MessageViewer::MessagePartRendererManager::self()->createContext();
+ c.insert(QStringLiteral("block"), msgPart.data());
+ c.insert(QStringLiteral("content"), QVariant::fromValue([msgPart](Grantlee::OutputStream *stream) {
+ DiffHighlighter highLighter;
+ highLighter.highlightDiff(msgPart->text());
+ *stream << highLighter.outputDiff();
+ }));
+
+ auto t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/textmessagepart.html"));
+ Grantlee::OutputStream s(htmlWriter->stream());
+ t->render(&s, &c);
+ return true;
}
-
- // unhide the overload with three arguments
- using MimeTreeParser::Interface::BodyPartFormatter::format;
};
-class Plugin : public QObject, public MimeTreeParser::Interface::BodyPartFormatterPlugin
+class Plugin : public QObject, public MessageViewer::MessagePartRenderPlugin
{
Q_OBJECT
- Q_INTERFACES(MimeTreeParser::Interface::BodyPartFormatterPlugin)
+ Q_INTERFACES(MessageViewer::MessagePartRenderPlugin)
Q_PLUGIN_METADATA(IID "com.kde.messageviewer.bodypartformatter" FILE "text_xdiff.json")
public:
- const MimeTreeParser::Interface::BodyPartFormatter *bodyPartFormatter(int idx) const override
+ MessageViewer::MessagePartRendererBase* renderer(int index) override
{
- if (idx == 0) {
+ if (index == 0)
return new Formatter();
- }
return nullptr;
}
};
diff --git a/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.json b/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.json
--- a/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.json
+++ b/plugins/messageviewer/bodypartformatter/xdiff/text_xdiff.json
@@ -1,5 +1,3 @@
-{ "formatter":
- [
- { "mimetype": "text/x-patch" }
- ]
+{
+ "renderer": [ { "type": "MimeTreeParser::AttachmentMessagePart" } ]
}