diff options
Diffstat (limited to 'components/mailviewer/qml/MailDataModel.qml')
-rw-r--r-- | components/mailviewer/qml/MailDataModel.qml | 159 |
1 files changed, 159 insertions, 0 deletions
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 @@ | |||
1 | /* | ||
2 | Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program; if not, write to the Free Software Foundation, Inc., | ||
16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | ||
18 | |||
19 | import QtQuick 2.4 | ||
20 | import QtQml.Models 2.2 | ||
21 | import org.kube.framework 1.0 as Kube | ||
22 | |||
23 | DelegateModel { | ||
24 | id: root | ||
25 | |||
26 | delegate: Item { | ||
27 | id: partColumn | ||
28 | |||
29 | width: parent.width | ||
30 | height: childrenRect.height | ||
31 | |||
32 | function getColor(securityLevel) | ||
33 | { | ||
34 | if (securityLevel == "good") { | ||
35 | return Kube.Colors.positiveColor | ||
36 | } | ||
37 | if (securityLevel == "bad") { | ||
38 | return Kube.Colors.negativeColor | ||
39 | } | ||
40 | if (securityLevel == "notsogood") { | ||
41 | return Kube.Colors.warningColor | ||
42 | } | ||
43 | return Kube.Colors.lightgrey | ||
44 | } | ||
45 | |||
46 | function getDetails(signatureDetails) | ||
47 | { | ||
48 | var details = ""; | ||
49 | if (signatureDetails.noSignaturesFound) { | ||
50 | details += qsTr("This message has been signed but we failed to validate the signature.") + "\n" | ||
51 | } else if (!signatureDetails.signatureIsGood) { | ||
52 | details += qsTr("This message is signed but the signature is invalid.") + "\n" | ||
53 | } else if (signatureDetails.keyMissing) { | ||
54 | details += qsTr("This message has been signed using the key %1.").arg(signatureDetails.keyId) + "\n"; | ||
55 | details += qsTr("The key details are not available.") + "\n"; | ||
56 | return details; | ||
57 | } else { | ||
58 | details += qsTr("This message has been signed using the key %1 by %2.").arg(signatureDetails.keyId).arg(signatureDetails.signer) + "\n"; | ||
59 | if (signatureDetails.keyRevoked) { | ||
60 | details += qsTr("The key was revoked.") + "\n" | ||
61 | } | ||
62 | if (signatureDetails.keyExpired) { | ||
63 | details += qsTr("The key has expired.") + "\n" | ||
64 | } | ||
65 | if (signatureDetails.keyIsTrusted) { | ||
66 | details += qsTr("You are trusting this key.") + "\n" | ||
67 | } | ||
68 | } | ||
69 | return details | ||
70 | } | ||
71 | |||
72 | Column { | ||
73 | id: buttons | ||
74 | anchors.left: parent.left | ||
75 | anchors.top: parent.top | ||
76 | anchors.rightMargin: Kube.Units.smallSpacing | ||
77 | spacing: Kube.Units.smallSpacing | ||
78 | Kube.IconButton { | ||
79 | id: encryptedButton | ||
80 | width: Kube.Units.gridUnit | ||
81 | height: width | ||
82 | iconName: Kube.Icons.secure | ||
83 | color: getColor(model.securityLevel) | ||
84 | backgroundOpacity: 0.5 | ||
85 | visible: model.encrypted | ||
86 | tooltip: qsTr("This message is encrypted."); | ||
87 | //FIXME make text copyable | ||
88 | // Kube.SelectableItem { | ||
89 | // visualParent: encryptedButton | ||
90 | // text: parent.tooltip | ||
91 | // } | ||
92 | } | ||
93 | Kube.IconButton { | ||
94 | id: signedButton | ||
95 | width: Kube.Units.gridUnit | ||
96 | height: width | ||
97 | iconName: Kube.Icons.signed | ||
98 | color: getColor(model.securityLevel) | ||
99 | backgroundOpacity: 0.5 | ||
100 | visible: model.signed | ||
101 | tooltip: getDetails(model.signatureDetails) | ||
102 | } | ||
103 | } | ||
104 | Rectangle { | ||
105 | id: border | ||
106 | visible: encryptedButton.hovered || signedButton.hovered | ||
107 | anchors.topMargin: Kube.Units.smallSpacing | ||
108 | anchors.top: buttons.bottom | ||
109 | anchors.bottom: partLoader.bottom | ||
110 | anchors.right: buttons.right | ||
111 | width: Kube.Units.smallSpacing | ||
112 | color: getColor(model.securityLevel) | ||
113 | opacity: 0.5 | ||
114 | } | ||
115 | |||
116 | Loader { | ||
117 | id: partLoader | ||
118 | anchors { | ||
119 | top: parent.top | ||
120 | left: buttons.right | ||
121 | leftMargin: Kube.Units.smallSpacing | ||
122 | right: parent.right | ||
123 | } | ||
124 | height: item ? item.contentHeight : 0 | ||
125 | width: parent.width | ||
126 | } | ||
127 | Component.onCompleted: { | ||
128 | switch (model.type) { | ||
129 | case "plain": | ||
130 | partLoader.setSource("TextContent.qml", | ||
131 | {"content": model.content, | ||
132 | "embedded": model.embedded, | ||
133 | "type": model.type | ||
134 | }) | ||
135 | break | ||
136 | case "html": | ||
137 | partLoader.setSource("HtmlContent.qml", | ||
138 | {"content": model.content, | ||
139 | }) | ||
140 | break; | ||
141 | case "error": | ||
142 | partLoader.setSource("ErrorPart.qml", | ||
143 | { | ||
144 | "errorType": model.errorType, | ||
145 | "errorString": model.errorString, | ||
146 | }) | ||
147 | break; | ||
148 | case "encapsulated": | ||
149 | partLoader.setSource("MailPart.qml", | ||
150 | {"rootIndex": root.modelIndex(index), | ||
151 | "model": root.model, | ||
152 | "sender": model.sender, | ||
153 | "date": model.date | ||
154 | }) | ||
155 | break; | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | } | ||