From e7b821c4308c6ed15daed911184980149cce38ff Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 23 May 2017 10:30:21 +0200 Subject: Always use richtext, and avoid using a browser for simple html --- .../mailviewer/contents/ui/MailDataModel.qml | 7 +++--- components/mailviewer/contents/ui/TextContent.qml | 10 ++++---- framework/qml/MailViewer.qml | 2 +- framework/src/domain/messageparser.h | 1 + framework/src/domain/messageparser_new.cpp | 28 +++++++++++++++++++++- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/components/mailviewer/contents/ui/MailDataModel.qml b/components/mailviewer/contents/ui/MailDataModel.qml index 8a42630a..f4b4e7c7 100644 --- a/components/mailviewer/contents/ui/MailDataModel.qml +++ b/components/mailviewer/contents/ui/MailDataModel.qml @@ -57,15 +57,14 @@ DelegateModel { width: parent.width } Component.onCompleted: { - var isHtml = false - var forcePlain = false + //If the content is not complex, avoid using a full browser + var forcePlain = !model.complexHtmlContent var partType = getPartType(model.type, model.hasModelChildren, forcePlain); switch (partType) { case "plain": partLoader.setSource("TextContent.qml", - {"isHtml": isHtml, - "content": model.content, + {"content": model.content, "embedded": model.embeded, "type": model.type, "debug": debug}) diff --git a/components/mailviewer/contents/ui/TextContent.qml b/components/mailviewer/contents/ui/TextContent.qml index 63573d81..90442b8f 100644 --- a/components/mailviewer/contents/ui/TextContent.qml +++ b/components/mailviewer/contents/ui/TextContent.qml @@ -26,7 +26,6 @@ Item { property string content property bool debug: true property bool embedded: true - property bool isHtml: true property string type width: partColumn.width @@ -43,17 +42,18 @@ Item { width: parent.width spacing: 5 - TextEdit { + TextEdit { width: parent.width readOnly: true selectByMouse: true text: content - wrapMode: Text.WordWrap - textFormat: textItem.isHtml ? Text.RichText : Text.PlainText + wrapMode: TextEdit.Wrap + textFormat: Text.RichText - color: embedded ? Kube.Colors.diabledTextColor : Kube.Colors.textColor + color: embedded ? Kube.Colors.disabledTextColor : Kube.Colors.textColor + onLinkActivated: Qt.openUrlExternally(link) } //BEGIN debug diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml index 01f78fb9..3e118a8d 100644 --- a/framework/qml/MailViewer.qml +++ b/framework/qml/MailViewer.qml @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.4 +import QtQuick 2.7 import QtQuick.Controls 1.4 as Controls1 import QtQuick.Layouts 1.1 diff --git a/framework/src/domain/messageparser.h b/framework/src/domain/messageparser.h index 6d52c4b2..de4d8838 100644 --- a/framework/src/domain/messageparser.h +++ b/framework/src/domain/messageparser.h @@ -70,6 +70,7 @@ public: TypeRole = Qt::UserRole + 1, ContentsRole, ContentRole, + IsComplexHtmlContentRole, IsEmbededRole, SecurityLevelRole, EncryptionErrorType, diff --git a/framework/src/domain/messageparser_new.cpp b/framework/src/domain/messageparser_new.cpp index cb399523..c353becf 100644 --- a/framework/src/domain/messageparser_new.cpp +++ b/framework/src/domain/messageparser_new.cpp @@ -21,6 +21,7 @@ #include "mimetreeparser/interface.h" #include +#include Q_DECLARE_METATYPE(Part *) Q_DECLARE_METATYPE(Content *) @@ -315,6 +316,7 @@ QHash NewModel::roleNames() const QHash roles; roles[TypeRole] = "type"; roles[ContentRole] = "content"; + roles[IsComplexHtmlContentRole] = "complexHtmlContent"; roles[IsEmbededRole] = "embeded"; roles[SecurityLevelRole] = "securityLevel"; roles[EncryptionErrorType] = "errorType"; @@ -422,9 +424,30 @@ QVariant NewModel::data(const QModelIndex &index, int role) const return QString::fromLatin1(content->type()); case IsEmbededRole: return data(index.parent(), IsEmbededRole); + case IsComplexHtmlContentRole: { + const auto contentType = data(index, TypeRole).toString(); + if (contentType == "HtmlContent") { + const auto text = content->encodedContent(); + if (text.contains("encodedContent(); - if (data(index, TypeRole).toString() == "HtmlContent") { + const auto contentType = data(index, TypeRole).toString(); + if (contentType == "HtmlContent") { const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); int pos = 0; while ((pos = rx.indexIn(text, pos)) != -1) { @@ -445,6 +468,9 @@ QVariant NewModel::data(const QModelIndex &index, int role) const text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); } } + } else { //We assume plain + //We alwas do richtext (so we get highlighted links and stuff). + return Qt::convertFromPlainText(text); } return text; } -- cgit v1.2.3