Warning, /pim/mimetreeparser/src/quick/qml/private/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 import org.kde.pim.mimetreeparser 1.0
0010 import org.kde.kirigami 2.19 as Kirigami
0011 
0012 DelegateModel {
0013     id: root
0014 
0015     property string searchString: ""
0016     property bool autoLoadImages: false
0017     property int padding: Kirigami.Units.largeSpacing
0018     property url icalCustomComponent
0019 
0020     delegate: RowLayout {
0021         id: partColumn
0022 
0023         width: ListView.view.width - Kirigami.Units.largeSpacing
0024         x: Kirigami.Units.smallSpacing
0025 
0026         function getType(securityLevel) {
0027             if (securityLevel === PartModel.Good) {
0028                 return Kirigami.MessageType.Positive
0029             }
0030             if (securityLevel === PartModel.Bad) {
0031                 return Kirigami.MessageType.Error
0032             }
0033             if (securityLevel === PartModel.NotSoGood) {
0034                 return Kirigami.MessageType.Warning
0035             }
0036             return Kirigami.MessageType.Information
0037         }
0038 
0039         function getColor(securityLevel) {
0040             if (securityLevel === PartModel.Good) {
0041                 return Kirigami.Theme.positiveTextColor
0042             }
0043             if (securityLevel === PartModel.Bad) {
0044                 return Kirigami.Theme.negativeTextColor
0045             }
0046             if (securityLevel === PartModel.NotSoGood) {
0047                 return Kirigami.Theme.neutralTextColor
0048             }
0049             return "transparent"
0050         }
0051 
0052         function getDetails(signatureDetails) {
0053             let details = "";
0054             if (signatureDetails.keyMissing) {
0055                 details += i18ndc("mimetreeparser", "@label", "This message has been signed using the certificate %1.", signatureDetails.keyId) + "\n";
0056                 details += i18ndc("mimetreeparser", "@label", "The certificate details are not available.")
0057             } else {
0058                 details += i18ndc("mimetreeparser", "@label", "This message has been signed using the certificate %1 by %2.", signatureDetails.keyId, signatureDetails.signer) + "\n";
0059                 if (signatureDetails.keyRevoked) {
0060                     details += "\n" + i18ndc("mimetreeparser", "@label", "The certificate was revoked.")
0061                 }
0062                 if (signatureDetails.keyExpired) {
0063                     details += "\n" + i18ndc("mimetreeparser", "@label", "The certificate has expired.")
0064                 }
0065                 if (signatureDetails.keyIsTrusted) {
0066                     details += "\n" + i18ndc("mimetreeparser", "@label", "You are trusting this certificate.")
0067                 }
0068                 if (!signatureDetails.signatureIsGood && !signatureDetails.keyRevoked && !signatureDetails.keyExpired && !signatureDetails.keyIsTrusted) {
0069                     details += "\n" + i18ndc("mimetreeparser", "@label", "The signature is invalid.")
0070                 }
0071             }
0072             return details
0073         }
0074 
0075         QQC2.Control {
0076             Layout.preferredWidth: Kirigami.Units.smallSpacing
0077             Layout.fillHeight: true
0078 
0079             visible: model.encrypted
0080 
0081             background: Rectangle {
0082                 id: border
0083 
0084                 color: getColor(model.securityLevel)
0085                 opacity: 0.5
0086             }
0087 
0088             QQC2.ToolTip.text: getDetails(model.encryptionSecurityLevel)
0089             QQC2.ToolTip.visible: hovered
0090             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0091         }
0092 
0093         ColumnLayout {
0094             Banner {
0095                 iconName: "mail-encrypted"
0096                 type: getType(model.encryptionSecurityLevel)
0097                 visible: model.encrypted
0098                 text: !model.encryptionDetails.keyId ? i18n("This message is encrypted but we don't have the certificate for it.") : i18n("This message is encrypted to the certificate: %1", model.encryptionDetails.keyId);
0099 
0100                 Layout.fillWidth: true
0101             }
0102 
0103             Banner {
0104                 iconName: 'mail-signed'
0105                 visible: model.signed
0106                 type: getType(model.signatureSecurityLevel)
0107                 text: getDetails(model.signatureDetails)
0108 
0109                 Layout.fillWidth: true
0110             }
0111 
0112             Loader {
0113                 id: partLoader
0114 
0115                 Layout.preferredHeight: item ? item.contentHeight : 0
0116                 Layout.fillWidth: true
0117                 Layout.leftMargin: root.padding
0118                 Layout.rightMargin: root.padding
0119 
0120                 Component.onCompleted: {
0121                     switch (model.type + 0) {
0122                         case PartModel.Plain:
0123                             partLoader.setSource("TextPart.qml", {
0124                                 content: model.content,
0125                                 embedded: model.embedded,
0126                             })
0127                             break
0128                         case PartModel.Html:
0129                             partLoader.setSource("HtmlPart.qml", {
0130                                 content: model.content,
0131                             })
0132                             break;
0133                         case PartModel.Error:
0134                             partLoader.setSource("ErrorPart.qml", {
0135                                 errorType: model.errorType,
0136                                 errorString: model.errorString,
0137                             })
0138                             break;
0139                         case PartModel.Encapsulated:
0140                             partLoader.setSource("MailPart.qml", {
0141                                 rootIndex: root.modelIndex(index),
0142                                 model: root.model,
0143                                 sender: model.sender,
0144                                 date: model.date,
0145                             })
0146                             break;
0147                         case PartModel.Ical:
0148                             partLoader.setSource(root.icalCustomComponent ? root.icalCustomComponent : "ICalPart.qml", {
0149                                 content: model.content,
0150                             })
0151                             break;
0152                     }
0153                 }
0154 
0155                 Binding {
0156                     target: partLoader.item
0157                     property: "searchString"
0158                     value: root.searchString
0159                     when: partLoader.status === Loader.Ready
0160                 }
0161                 Binding {
0162                     target: partLoader.item
0163                     property: "autoLoadImages"
0164                     value: root.autoLoadImages
0165                     when: partLoader.status === Loader.Ready
0166                 }
0167             }
0168         }
0169     }
0170 }