Warning, /pim/mimetreeparser/src/quick/qml/MailViewer.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-FileCopyrightText: 2022 Devin Lin <espidev@gmail.com> 0003 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0004 0005 import QtQuick 2.15 0006 import QtQuick.Layouts 1.15 0007 import QtQuick.Controls 2.15 as QQC2 0008 import Qt.labs.platform 1.1 as QLP 0009 0010 import org.kde.pim.mimetreeparser 1.0 0011 import org.kde.kirigami 2.20 as Kirigami 0012 import './private' 0013 0014 Kirigami.ScrollablePage { 0015 id: root 0016 0017 property alias message: mailPartView.message 0018 0019 readonly property string subject: mailPartView.subject 0020 readonly property string from: mailPartView.from 0021 readonly property string sender: mailPartView.sender 0022 readonly property string to: mailPartView.to 0023 readonly property string cc: mailPartView.cc 0024 readonly property string bcc: mailPartView.bcc 0025 readonly property date dateTime: mailPartView.dateTime 0026 0027 /** 0028 * This property holds the url to a custom ical part QML component. 0029 * 0030 * This allow apps to overwrite it and provide special handling for email 0031 * invitation. 0032 */ 0033 property url icalCustomComponent 0034 0035 Kirigami.Theme.colorSet: Kirigami.Theme.View 0036 Kirigami.Theme.inherit: false 0037 0038 padding: Kirigami.Units.largeSpacing 0039 0040 title: i18ndc("mimetreeparser", "@title:window", "Message viewer") 0041 0042 header: QQC2.ToolBar { 0043 id: mailHeader 0044 0045 padding: root.padding 0046 visible: root.from.length > 0 || root.to.length > 0 || root.subject.length > 0 0047 0048 Kirigami.Theme.inherit: false 0049 Kirigami.Theme.colorSet: Kirigami.Theme.View 0050 0051 background: Item { 0052 Rectangle { 0053 anchors.fill: parent 0054 color: Kirigami.Theme.alternateBackgroundColor 0055 } 0056 0057 Kirigami.Separator { 0058 anchors.top: parent.top 0059 anchors.left: parent.left 0060 anchors.right: parent.right 0061 } 0062 0063 Kirigami.Separator { 0064 anchors.bottom: parent.bottom 0065 anchors.left: parent.left 0066 anchors.right: parent.right 0067 } 0068 } 0069 0070 contentItem: GridLayout { 0071 rowSpacing: Kirigami.Units.smallSpacing 0072 columnSpacing: Kirigami.Units.smallSpacing 0073 0074 columns: 3 0075 0076 QQC2.Label { 0077 text: i18ndc("mimetreeparser", "@label", "Subject:") 0078 visible: root.subject.length > 0 0079 0080 Layout.rightMargin: Kirigami.Units.largeSpacing 0081 } 0082 0083 QQC2.Label { 0084 text: root.subject 0085 visible: text.length > 0 0086 elide: Text.ElideRight 0087 0088 Layout.fillWidth: true 0089 } 0090 0091 QQC2.Label { 0092 text: root.dateTime.toLocaleString(Qt.locale(), Locale.ShortFormat) 0093 visible: text.length > 0 0094 horizontalAlignment: Text.AlignRight 0095 } 0096 0097 QQC2.Label { 0098 text: i18ndc("mimetreeparser", "@label", "From:") 0099 visible: root.from.length > 0 0100 0101 Layout.rightMargin: Kirigami.Units.largeSpacing 0102 } 0103 0104 QQC2.Label { 0105 text: root.from 0106 visible: text.length > 0 0107 elide: Text.ElideRight 0108 0109 Layout.fillWidth: true 0110 Layout.columnSpan: 2 0111 } 0112 0113 QQC2.Label { 0114 text: i18ndc("mimetreeparser", "@label", "Sender:") 0115 visible: root.sender.length > 0 && root.sender !== root.from 0116 0117 Layout.rightMargin: Kirigami.Units.largeSpacing 0118 } 0119 0120 QQC2.Label { 0121 visible: root.sender.length > 0 && root.sender !== root.from 0122 text: root.sender 0123 elide: Text.ElideRight 0124 0125 Layout.fillWidth: true 0126 Layout.columnSpan: 2 0127 } 0128 0129 QQC2.Label { 0130 text: i18ndc("mimetreeparser", "@label", "To:") 0131 visible: root.to.length > 0 0132 0133 Layout.rightMargin: Kirigami.Units.largeSpacing 0134 } 0135 0136 QQC2.Label { 0137 text: root.to 0138 elide: Text.ElideRight 0139 visible: root.to.length > 0 0140 0141 Layout.fillWidth: true 0142 Layout.columnSpan: 2 0143 } 0144 0145 QQC2.Label { 0146 text: i18ndc("mimetreeparser", "@label", "CC:") 0147 visible: root.cc.length > 0 0148 0149 Layout.rightMargin: Kirigami.Units.largeSpacing 0150 } 0151 0152 QQC2.Label { 0153 text: root.cc 0154 elide: Text.ElideRight 0155 visible: root.cc.length > 0 0156 0157 Layout.fillWidth: true 0158 Layout.columnSpan: 2 0159 } 0160 0161 QQC2.Label { 0162 text: i18ndc("mimetreeparser", "@label", "BCC:") 0163 visible: root.bcc.length > 0 0164 0165 Layout.rightMargin: Kirigami.Units.largeSpacing 0166 } 0167 0168 QQC2.Label { 0169 text: root.bcc 0170 elide: Text.ElideRight 0171 visible: root.bcc.length > 0 0172 0173 Layout.fillWidth: true 0174 Layout.columnSpan: 2 0175 } 0176 } 0177 } 0178 0179 MailPartView { 0180 id: mailPartView 0181 padding: root.padding 0182 icalCustomComponent: root.icalCustomComponent 0183 } 0184 0185 footer: QQC2.ToolBar { 0186 padding: root.padding 0187 0188 Kirigami.Theme.inherit: false 0189 Kirigami.Theme.colorSet: Kirigami.Theme.View 0190 0191 background: Item { 0192 Kirigami.Separator { 0193 anchors { 0194 left: parent.left 0195 right: parent.right 0196 top: undefined 0197 bottom: parent.bottom 0198 } 0199 } 0200 } 0201 0202 Flow { 0203 anchors.fill: parent 0204 spacing: Kirigami.Units.smallSpacing 0205 Repeater { 0206 model: mailPartView.attachmentModel 0207 0208 delegate: AttachmentDelegate { 0209 id: attachmentDelegate 0210 0211 required property int index 0212 required property string iconName 0213 0214 icon.name: iconName 0215 0216 clip: true 0217 0218 actionIcon: 'download' 0219 actionTooltip: i18ndc("mimetreeparser", "@action:button", "Save attachment") 0220 onClicked: mailPartView.attachmentModel.openAttachment(index) 0221 onPublicKeyImport: mailPartView.attachmentModel.importPublicKey(index) 0222 onExecute: { 0223 const dialog = saveFileDialog.createObject(applicationWindow(), { 0224 fileName: name, 0225 }); 0226 dialog.onAccepted.connect(() => { 0227 mailPartView.attachmentModel.saveAttachmentToPath(0, dialog.file.toString().slice(7)) 0228 }); 0229 dialog.open(); 0230 } 0231 } 0232 } 0233 } 0234 } 0235 0236 Component { 0237 id: saveFileDialog 0238 0239 QLP.FileDialog { 0240 required property string fileName 0241 0242 title: i18ndc("mimetreeparser", "@window:title", "Save Attachment As") 0243 currentFile: QLP.StandardPaths.writableLocation(QLP.StandardPaths.DownloadLocation) + '/' + fileName 0244 folder: QLP.StandardPaths.writableLocation(QLP.StandardPaths.DownloadLocation) 0245 fileMode: QLP.FileDialog.SaveFile 0246 } 0247 } 0248 0249 Connections { 0250 target: mailPartView.attachmentModel 0251 0252 function onInfo(message) { 0253 applicationWindow().showPassiveNotification(message); 0254 } 0255 0256 function onErrorOccurred(message) { 0257 applicationWindow().showPassiveNotification(message); 0258 } 0259 } 0260 }