Warning, /plasma-mobile/raven/src/contents/ui/mailpartview/MailPartModel.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2016 Michael Bohlender <michael.bohlender@kdemail.net>
0002 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick 2.15
0006 import QtQuick.Controls 2.15 as QQC2
0007 import QtQuick.Layouts 1.15
0008 import QtQml.Models 2.2
0009 
0010 import org.kde.raven 1.0
0011 import org.kde.kirigami 2.19 as Kirigami
0012 
0013 DelegateModel {
0014     id: root
0015 
0016     property string searchString: ""
0017     property bool autoLoadImages: false
0018 
0019     delegate: Item {
0020         id: partColumn
0021 
0022         width: ListView.view.width
0023         height: childrenRect.height
0024 
0025         function getType(securityLevel) {
0026             if (securityLevel == "good") {
0027                 return Kirigami.MessageType.Positive
0028             }
0029             if (securityLevel == "bad") {
0030                 return Kirigami.MessageType.Error
0031             }
0032             if (securityLevel == "notsogood") {
0033                 return Kirigami.MessageType.Warning
0034             }
0035             return Kirigami.MessageType.Information
0036         }
0037 
0038         function getColor(securityLevel) {
0039             if (securityLevel == "good") {
0040                 return Kirigami.Theme.positiveTextColor
0041             }
0042             if (securityLevel == "bad") {
0043                 return Kirigami.Theme.negativeTextColor
0044             }
0045             if (securityLevel == "notsogood") {
0046                 return Kirigami.Theme.neutralTextColor
0047             }
0048             return Kirigami.Theme.disabledColor
0049         }
0050 
0051         function getDetails(signatureDetails) {
0052             let details = "";
0053             if (signatureDetails.keyMissing) {
0054                 details += i18n("This message has been signed using the key %1.", signatureDetails.keyId) + "\n";
0055                 details += i18n("The key details are not available.") + "\n";
0056             } else {
0057                 details += i18n("This message has been signed using the key %1 by %2.", signatureDetails.keyId, signatureDetails.signer) + "\n";
0058                 if (signatureDetails.keyRevoked) {
0059                     details += i18n("The key was revoked.") + "\n"
0060                 }
0061                 if (signatureDetails.keyExpired) {
0062                     details += i18n("The key has expired.") + "\n"
0063                 }
0064                 if (signatureDetails.keyIsTrusted) {
0065                     details += i18n("You are trusting this key.") + "\n"
0066                 }
0067                 if (!signatureDetails.signatureIsGood && !signatureDetails.keyRevoked && !signatureDetails.keyExpired && !signatureDetails.keyIsTrusted) {
0068                     details += i18n("The signature is invalid.") + "\n"
0069                 }
0070             }
0071             return details
0072         }
0073 
0074         ColumnLayout {
0075             id: buttons
0076             anchors {
0077                 left: parent.left
0078                 right: parent.right
0079                 top: parent.top
0080             }
0081             spacing: Kirigami.Units.smallSpacing
0082 
0083             Kirigami.InlineMessage {
0084                 id: encryptedButton
0085                 Layout.fillWidth: true
0086                 Layout.maximumWidth: parent.width
0087                 icon.name: 'mail-encrypted'
0088                 type: getType(model.encryptionSecurityLevel)
0089                 visible: model.encrypted
0090                 text: model.encryptionDetails.keyId == "" ? i18n("This message is encrypted but we don't have the key for it.") : i18n("This message is encrypted to the key: %1", model.encryptionDetails.keyId);
0091             }
0092             Kirigami.InlineMessage {
0093                 id: signedButton
0094                 Layout.fillWidth: true
0095                 Layout.maximumWidth: parent.width
0096                 icon.name: 'mail-signed'
0097                 visible: model.signed
0098                 type: getType(model.signatureSecurityLevel)
0099                 text: getDetails(model.signatureDetails)
0100             }
0101 
0102             Loader {
0103                 id: partLoader
0104                 Layout.preferredHeight: item ? item.contentHeight : 0
0105                 Layout.maximumWidth: parent.width
0106                 Layout.fillWidth: true
0107                 Binding {
0108                     target: partLoader.item
0109                     property: "searchString"
0110                     value: root.searchString
0111                     when: partLoader.status === Loader.Ready
0112                 }
0113                 Binding {
0114                     target: partLoader.item
0115                     property: "autoLoadImages"
0116                     value: root.autoLoadImages
0117                     when: partLoader.status === Loader.Ready
0118                 }
0119             }
0120             Component.onCompleted: {
0121                 switch (model.type) {
0122                     case "plain":
0123                         partLoader.setSource("TextPart.qml", {
0124                             content: model.content,
0125                             embedded: model.embedded,
0126                             type: model.type
0127                         })
0128                         break
0129                     case "html":
0130                         partLoader.setSource("HtmlPart.qml", {
0131                             content: model.content,
0132                         })
0133                         break;
0134                     case "error":
0135                         partLoader.setSource("ErrorPart.qml", {
0136                             errorType: model.errorType,
0137                             errorString: model.errorString,
0138                         })
0139                         break;
0140                     case "encapsulated":
0141                         partLoader.setSource("MailPart.qml", {
0142                             rootIndex: root.modelIndex(index),
0143                             model: root.model,
0144                             sender: model.sender,
0145                             date: model.date,
0146                         })
0147                         break;
0148                     case "ical":
0149                         partLoader.setSource("ICalPart.qml", {
0150                             content: model.content,
0151                         })
0152                         break;
0153                 }
0154             }
0155         }
0156     }
0157 }