diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-23 10:30:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-23 10:30:21 +0200 |
commit | e7b821c4308c6ed15daed911184980149cce38ff (patch) | |
tree | bdf19f2bc06253aa283dbb1ff56458091737cad5 | |
parent | 7f90b1ddab470a414833ffadd4fdefc2382ab6fc (diff) | |
download | kube-e7b821c4308c6ed15daed911184980149cce38ff.tar.gz kube-e7b821c4308c6ed15daed911184980149cce38ff.zip |
Always use richtext, and avoid using a browser for simple html
-rw-r--r-- | components/mailviewer/contents/ui/MailDataModel.qml | 7 | ||||
-rw-r--r-- | components/mailviewer/contents/ui/TextContent.qml | 10 | ||||
-rw-r--r-- | framework/qml/MailViewer.qml | 2 | ||||
-rw-r--r-- | framework/src/domain/messageparser.h | 1 | ||||
-rw-r--r-- | 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 { | |||
57 | width: parent.width | 57 | width: parent.width |
58 | } | 58 | } |
59 | Component.onCompleted: { | 59 | Component.onCompleted: { |
60 | var isHtml = false | 60 | //If the content is not complex, avoid using a full browser |
61 | var forcePlain = false | 61 | var forcePlain = !model.complexHtmlContent |
62 | var partType = getPartType(model.type, model.hasModelChildren, forcePlain); | 62 | var partType = getPartType(model.type, model.hasModelChildren, forcePlain); |
63 | 63 | ||
64 | switch (partType) { | 64 | switch (partType) { |
65 | case "plain": | 65 | case "plain": |
66 | partLoader.setSource("TextContent.qml", | 66 | partLoader.setSource("TextContent.qml", |
67 | {"isHtml": isHtml, | 67 | {"content": model.content, |
68 | "content": model.content, | ||
69 | "embedded": model.embeded, | 68 | "embedded": model.embeded, |
70 | "type": model.type, | 69 | "type": model.type, |
71 | "debug": debug}) | 70 | "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 { | |||
26 | property string content | 26 | property string content |
27 | property bool debug: true | 27 | property bool debug: true |
28 | property bool embedded: true | 28 | property bool embedded: true |
29 | property bool isHtml: true | ||
30 | property string type | 29 | property string type |
31 | 30 | ||
32 | width: partColumn.width | 31 | width: partColumn.width |
@@ -43,17 +42,18 @@ Item { | |||
43 | width: parent.width | 42 | width: parent.width |
44 | spacing: 5 | 43 | spacing: 5 |
45 | 44 | ||
46 | TextEdit { | 45 | TextEdit { |
47 | width: parent.width | 46 | width: parent.width |
48 | 47 | ||
49 | readOnly: true | 48 | readOnly: true |
50 | selectByMouse: true | 49 | selectByMouse: true |
51 | 50 | ||
52 | text: content | 51 | text: content |
53 | wrapMode: Text.WordWrap | 52 | wrapMode: TextEdit.Wrap |
54 | textFormat: textItem.isHtml ? Text.RichText : Text.PlainText | 53 | textFormat: Text.RichText |
55 | 54 | ||
56 | color: embedded ? Kube.Colors.diabledTextColor : Kube.Colors.textColor | 55 | color: embedded ? Kube.Colors.disabledTextColor : Kube.Colors.textColor |
56 | onLinkActivated: Qt.openUrlExternally(link) | ||
57 | } | 57 | } |
58 | 58 | ||
59 | //BEGIN debug | 59 | //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 @@ | |||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | import QtQuick 2.4 | 19 | import QtQuick 2.7 |
20 | import QtQuick.Controls 1.4 as Controls1 | 20 | import QtQuick.Controls 1.4 as Controls1 |
21 | import QtQuick.Layouts 1.1 | 21 | import QtQuick.Layouts 1.1 |
22 | 22 | ||
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: | |||
70 | TypeRole = Qt::UserRole + 1, | 70 | TypeRole = Qt::UserRole + 1, |
71 | ContentsRole, | 71 | ContentsRole, |
72 | ContentRole, | 72 | ContentRole, |
73 | IsComplexHtmlContentRole, | ||
73 | IsEmbededRole, | 74 | IsEmbededRole, |
74 | SecurityLevelRole, | 75 | SecurityLevelRole, |
75 | EncryptionErrorType, | 76 | 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 @@ | |||
21 | #include "mimetreeparser/interface.h" | 21 | #include "mimetreeparser/interface.h" |
22 | 22 | ||
23 | #include <QDebug> | 23 | #include <QDebug> |
24 | #include <QTextDocument> | ||
24 | 25 | ||
25 | Q_DECLARE_METATYPE(Part *) | 26 | Q_DECLARE_METATYPE(Part *) |
26 | Q_DECLARE_METATYPE(Content *) | 27 | Q_DECLARE_METATYPE(Content *) |
@@ -315,6 +316,7 @@ QHash<int, QByteArray> NewModel::roleNames() const | |||
315 | QHash<int, QByteArray> roles; | 316 | QHash<int, QByteArray> roles; |
316 | roles[TypeRole] = "type"; | 317 | roles[TypeRole] = "type"; |
317 | roles[ContentRole] = "content"; | 318 | roles[ContentRole] = "content"; |
319 | roles[IsComplexHtmlContentRole] = "complexHtmlContent"; | ||
318 | roles[IsEmbededRole] = "embeded"; | 320 | roles[IsEmbededRole] = "embeded"; |
319 | roles[SecurityLevelRole] = "securityLevel"; | 321 | roles[SecurityLevelRole] = "securityLevel"; |
320 | roles[EncryptionErrorType] = "errorType"; | 322 | roles[EncryptionErrorType] = "errorType"; |
@@ -422,9 +424,30 @@ QVariant NewModel::data(const QModelIndex &index, int role) const | |||
422 | return QString::fromLatin1(content->type()); | 424 | return QString::fromLatin1(content->type()); |
423 | case IsEmbededRole: | 425 | case IsEmbededRole: |
424 | return data(index.parent(), IsEmbededRole); | 426 | return data(index.parent(), IsEmbededRole); |
427 | case IsComplexHtmlContentRole: { | ||
428 | const auto contentType = data(index, TypeRole).toString(); | ||
429 | if (contentType == "HtmlContent") { | ||
430 | const auto text = content->encodedContent(); | ||
431 | if (text.contains("<!DOCTYPE html PUBLIC")) { | ||
432 | return true; | ||
433 | } | ||
434 | //Media queries are too advanced | ||
435 | if (text.contains("@media")) { | ||
436 | return true; | ||
437 | } | ||
438 | if (text.contains("<style")) { | ||
439 | return true; | ||
440 | } | ||
441 | return false; | ||
442 | } else { | ||
443 | return false; | ||
444 | } | ||
445 | break; | ||
446 | } | ||
425 | case ContentRole: { | 447 | case ContentRole: { |
426 | auto text = content->encodedContent(); | 448 | auto text = content->encodedContent(); |
427 | if (data(index, TypeRole).toString() == "HtmlContent") { | 449 | const auto contentType = data(index, TypeRole).toString(); |
450 | if (contentType == "HtmlContent") { | ||
428 | const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); | 451 | const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); |
429 | int pos = 0; | 452 | int pos = 0; |
430 | while ((pos = rx.indexIn(text, pos)) != -1) { | 453 | while ((pos = rx.indexIn(text, pos)) != -1) { |
@@ -445,6 +468,9 @@ QVariant NewModel::data(const QModelIndex &index, int role) const | |||
445 | text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); | 468 | text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); |
446 | } | 469 | } |
447 | } | 470 | } |
471 | } else { //We assume plain | ||
472 | //We alwas do richtext (so we get highlighted links and stuff). | ||
473 | return Qt::convertFromPlainText(text); | ||
448 | } | 474 | } |
449 | return text; | 475 | return text; |
450 | } | 476 | } |