From b77216db4b6d941afb03325e0843509621a283da Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 18 Dec 2017 21:00:05 +0100 Subject: We no longer need the kpackage structure --- components/mailviewer/qml/ErrorPart.qml | 41 +++++++ components/mailviewer/qml/HtmlContent.qml | 81 ++++++++++++++ components/mailviewer/qml/MailDataModel.qml | 159 ++++++++++++++++++++++++++++ components/mailviewer/qml/MailPart.qml | 70 ++++++++++++ components/mailviewer/qml/MailViewer.qml | 44 ++++++++ components/mailviewer/qml/TextContent.qml | 60 +++++++++++ components/mailviewer/qml/main.qml | 30 ++++++ 7 files changed, 485 insertions(+) create mode 100644 components/mailviewer/qml/ErrorPart.qml create mode 100644 components/mailviewer/qml/HtmlContent.qml create mode 100644 components/mailviewer/qml/MailDataModel.qml create mode 100644 components/mailviewer/qml/MailPart.qml create mode 100644 components/mailviewer/qml/MailViewer.qml create mode 100644 components/mailviewer/qml/TextContent.qml create mode 100644 components/mailviewer/qml/main.qml (limited to 'components/mailviewer/qml') diff --git a/components/mailviewer/qml/ErrorPart.qml b/components/mailviewer/qml/ErrorPart.qml new file mode 100644 index 00000000..0e5d9b8e --- /dev/null +++ b/components/mailviewer/qml/ErrorPart.qml @@ -0,0 +1,41 @@ +/* + Copyright (C) 2016 Michael Bohlender, + Copyright (C) 2017 Christian Mollekopf, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.4 + +Item { + id: root + property variant errorType + property string errorString + height: partListView.height + width: parent.width + + Column { + id: partListView + anchors { + top: parent.top + left: parent.left + } + width: parent.width + spacing: 5 + Text { + text: qsTr("An error occured: %1").arg(errorString) + } + } +} diff --git a/components/mailviewer/qml/HtmlContent.qml b/components/mailviewer/qml/HtmlContent.qml new file mode 100644 index 00000000..3ac1bb38 --- /dev/null +++ b/components/mailviewer/qml/HtmlContent.qml @@ -0,0 +1,81 @@ +/* + Copyright (C) 2016 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.4 +import QtQuick.Controls 1.3 +import QtWebEngine 1.4 + +import org.kube.framework 1.0 as Kube + +Item { + id: root + property string content + //We have to give it a minimum size so the html content starts to expand + property int contentHeight: 10; + + height: contentHeight + width: partColumn.width + + WebEngineView { + id: htmlView + anchors.fill: parent + Component.onCompleted: loadHtml(content, "file:///") + onContentsSizeChanged: { + //Resizing pixel by pixel causes some mails to grow indefinitely + if (contentsSize.height >= root.contentHeight + 5) { + root.contentHeight = contentsSize.height + } + } + onLoadingChanged: { + if (loadRequest.status == WebEngineLoadRequest.LoadFailedStatus) { + console.warn("Failed to load html content.") + console.warn("Error is ", loadRequest.errorString) + } + } + settings { + webGLEnabled: false + touchIconsEnabled: false + spatialNavigationEnabled: false + screenCaptureEnabled: false + pluginsEnabled: false + localStorageEnabled: false + localContentCanAccessRemoteUrls: false + localContentCanAccessFileUrls: false + linksIncludedInFocusChain: false + javascriptEnabled: false + javascriptCanOpenWindows: false + javascriptCanAccessClipboard: false + hyperlinkAuditingEnabled: false + fullScreenSupportEnabled: false + errorPageEnabled: false + //defaultTextEncoding: ??? + autoLoadImages: true + autoLoadIconsForPage: false + accelerated2dCanvasEnabled: false + //The webview should not steal focus + focusOnNavigationEnabled: false + } + profile: Kube.WebEngineProfile + onContextMenuRequested: function(request) { + request.accepted = true + } + } + onContentChanged: { + htmlView.loadHtml(content, "file:///"); + } +} diff --git a/components/mailviewer/qml/MailDataModel.qml b/components/mailviewer/qml/MailDataModel.qml new file mode 100644 index 00000000..ec7f8e74 --- /dev/null +++ b/components/mailviewer/qml/MailDataModel.qml @@ -0,0 +1,159 @@ +/* + Copyright (C) 2016 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.4 +import QtQml.Models 2.2 +import org.kube.framework 1.0 as Kube + +DelegateModel { + id: root + + delegate: Item { + id: partColumn + + width: parent.width + height: childrenRect.height + + function getColor(securityLevel) + { + if (securityLevel == "good") { + return Kube.Colors.positiveColor + } + if (securityLevel == "bad") { + return Kube.Colors.negativeColor + } + if (securityLevel == "notsogood") { + return Kube.Colors.warningColor + } + return Kube.Colors.lightgrey + } + + function getDetails(signatureDetails) + { + var details = ""; + if (signatureDetails.noSignaturesFound) { + details += qsTr("This message has been signed but we failed to validate the signature.") + "\n" + } else if (!signatureDetails.signatureIsGood) { + details += qsTr("This message is signed but the signature is invalid.") + "\n" + } else if (signatureDetails.keyMissing) { + details += qsTr("This message has been signed using the key %1.").arg(signatureDetails.keyId) + "\n"; + details += qsTr("The key details are not available.") + "\n"; + return details; + } else { + details += qsTr("This message has been signed using the key %1 by %2.").arg(signatureDetails.keyId).arg(signatureDetails.signer) + "\n"; + if (signatureDetails.keyRevoked) { + details += qsTr("The key was revoked.") + "\n" + } + if (signatureDetails.keyExpired) { + details += qsTr("The key has expired.") + "\n" + } + if (signatureDetails.keyIsTrusted) { + details += qsTr("You are trusting this key.") + "\n" + } + } + return details + } + + Column { + id: buttons + anchors.left: parent.left + anchors.top: parent.top + anchors.rightMargin: Kube.Units.smallSpacing + spacing: Kube.Units.smallSpacing + Kube.IconButton { + id: encryptedButton + width: Kube.Units.gridUnit + height: width + iconName: Kube.Icons.secure + color: getColor(model.securityLevel) + backgroundOpacity: 0.5 + visible: model.encrypted + tooltip: qsTr("This message is encrypted."); + //FIXME make text copyable + // Kube.SelectableItem { + // visualParent: encryptedButton + // text: parent.tooltip + // } + } + Kube.IconButton { + id: signedButton + width: Kube.Units.gridUnit + height: width + iconName: Kube.Icons.signed + color: getColor(model.securityLevel) + backgroundOpacity: 0.5 + visible: model.signed + tooltip: getDetails(model.signatureDetails) + } + } + Rectangle { + id: border + visible: encryptedButton.hovered || signedButton.hovered + anchors.topMargin: Kube.Units.smallSpacing + anchors.top: buttons.bottom + anchors.bottom: partLoader.bottom + anchors.right: buttons.right + width: Kube.Units.smallSpacing + color: getColor(model.securityLevel) + opacity: 0.5 + } + + Loader { + id: partLoader + anchors { + top: parent.top + left: buttons.right + leftMargin: Kube.Units.smallSpacing + right: parent.right + } + height: item ? item.contentHeight : 0 + width: parent.width + } + Component.onCompleted: { + switch (model.type) { + case "plain": + partLoader.setSource("TextContent.qml", + {"content": model.content, + "embedded": model.embedded, + "type": model.type + }) + break + case "html": + partLoader.setSource("HtmlContent.qml", + {"content": model.content, + }) + break; + case "error": + partLoader.setSource("ErrorPart.qml", + { + "errorType": model.errorType, + "errorString": model.errorString, + }) + break; + case "encapsulated": + partLoader.setSource("MailPart.qml", + {"rootIndex": root.modelIndex(index), + "model": root.model, + "sender": model.sender, + "date": model.date + }) + break; + } + } + } +} diff --git a/components/mailviewer/qml/MailPart.qml b/components/mailviewer/qml/MailPart.qml new file mode 100644 index 00000000..e570ebaa --- /dev/null +++ b/components/mailviewer/qml/MailPart.qml @@ -0,0 +1,70 @@ +/* + Copyright (C) 2016 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.4 + +import org.kube.framework 1.0 as Kube + +Item { + id: root + property alias rootIndex: visualModel.rootIndex + property alias model: visualModel.model + property variant sender + property variant date + height: childrenRect.height + + Rectangle { + id: border + anchors { + top: parent.top + left: parent.left + leftMargin: Kube.Units.smallSpacing + } + color: Kube.Colors.lightgrey + height: partListView.height + sender.height + width: Kube.Units.smallSpacing + } + + Text { + id: sender + anchors { + top: parent.top + left: border.right + leftMargin: Kube.Units.smallSpacing + } + + text: qsTr("sent by %1 on %2").arg(root.sender).arg(root.date) + color: "grey" + } + ListView { + id: partListView + anchors { + top: sender.bottom + left: border.right + margins: Kube.Units.smallSpacing + leftMargin: Kube.Units.smallSpacing + } + model: MailDataModel { + id: visualModel + } + spacing: 7 + height: contentHeight + width: parent.width - Kube.Units.smallSpacing * 3 + interactive: false + } +} diff --git a/components/mailviewer/qml/MailViewer.qml b/components/mailviewer/qml/MailViewer.qml new file mode 100644 index 00000000..9031ec17 --- /dev/null +++ b/components/mailviewer/qml/MailViewer.qml @@ -0,0 +1,44 @@ +/* + Copyright (C) 2016 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.4 + +Item { + id: root + property alias rootIndex: visualModel.rootIndex + property alias model: visualModel.model + height: partListView.height + + MailDataModel { + id: visualModel + } + + ListView { + id: partListView + model: visualModel + anchors { + top: parent.top + left: parent.left + margins: 5 + } + spacing: 5 + height: contentHeight + width: parent.width - 10 + interactive: false + } +} diff --git a/components/mailviewer/qml/TextContent.qml b/components/mailviewer/qml/TextContent.qml new file mode 100644 index 00000000..5d8dbc90 --- /dev/null +++ b/components/mailviewer/qml/TextContent.qml @@ -0,0 +1,60 @@ +/* + Copyright (C) 2016 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.7 + +import org.kube.framework 1.0 as Kube + +Item { + id: root + + property string content + property bool embedded: true + property string type + + height: textEdit.height + + TextEdit { + id: textEdit + + anchors { + top: parent.top + left: parent.left + right: parent.right + } + + selectionColor: Kube.Colors.highlightColor + + readOnly: true + selectByMouse: true + + text: content + wrapMode: TextEdit.Wrap + textFormat: Text.RichText + + font.family: Kube.Font.fontFamily + color: embedded ? Kube.Colors.disabledTextColor : Kube.Colors.textColor + onLinkActivated: Qt.openUrlExternally(link) + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text + cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor + } + } +} diff --git a/components/mailviewer/qml/main.qml b/components/mailviewer/qml/main.qml new file mode 100644 index 00000000..e69dd5a2 --- /dev/null +++ b/components/mailviewer/qml/main.qml @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2017 Christian Mollekopf, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 as Controls2 + +Controls2.ApplicationWindow { + id: app + height: 900 + width: 1500 + + MailViewer { + visible: true + } +} -- cgit v1.2.3