Warning, /network/neochat/src/qml/FileDelegate.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2018-2019 Black Hat <bhat@encom.eu.org> 0002 // SPDX-License-Identifier: GPL-3.0-only 0003 0004 import QtQuick 0005 import QtQuick.Controls as QQC2 0006 import QtQuick.Layouts 0007 import Qt.labs.platform 0008 import Qt.labs.qmlmodels 0009 0010 import org.kde.coreaddons 0011 import org.kde.kirigami as Kirigami 0012 0013 import org.kde.neochat 0014 import org.kde.neochat.config 0015 0016 /** 0017 * @brief A timeline delegate for an file message. 0018 * 0019 * @inherit MessageDelegate 0020 */ 0021 MessageDelegate { 0022 id: root 0023 0024 /** 0025 * @brief The media info for the event. 0026 * 0027 * This should consist of the following: 0028 * - source - The mxc URL for the media. 0029 * - mimeType - The MIME type of the media. 0030 * - mimeIcon - The MIME icon name. 0031 * - size - The file size in bytes. 0032 */ 0033 required property var mediaInfo 0034 0035 /** 0036 * @brief Whether the media has been downloaded. 0037 */ 0038 readonly property bool downloaded: root.progressInfo && root.progressInfo.completed 0039 0040 /** 0041 * @brief Whether the file should be automatically opened when downloaded. 0042 */ 0043 property bool autoOpenFile: false 0044 0045 onDownloadedChanged: { 0046 itineraryModel.path = root.progressInfo.localPath; 0047 if (autoOpenFile) { 0048 openSavedFile(); 0049 } 0050 } 0051 0052 onOpenContextMenu: RoomManager.viewEventMenu(eventId, author, delegateType, plainText, "", "", mediaInfo.mimeType, progressInfo) 0053 0054 function saveFileAs() { 0055 const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay); 0056 dialog.open(); 0057 dialog.currentFile = dialog.folder + "/" + root.room.fileNameToDownload(root.eventId); 0058 } 0059 0060 function openSavedFile() { 0061 UrlHelper.openUrl(root.progressInfo.localPath); 0062 } 0063 0064 bubbleContent: ColumnLayout { 0065 spacing: Kirigami.Units.largeSpacing 0066 RowLayout { 0067 spacing: Kirigami.Units.largeSpacing 0068 0069 states: [ 0070 State { 0071 name: "downloadedInstant" 0072 when: root.progressInfo.completed && autoOpenFile 0073 0074 PropertyChanges { 0075 target: openButton 0076 icon.name: "document-open" 0077 onClicked: openSavedFile() 0078 } 0079 0080 PropertyChanges { 0081 target: downloadButton 0082 icon.name: "download" 0083 QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to download its file", "Download") 0084 onClicked: saveFileAs() 0085 } 0086 }, 0087 State { 0088 name: "downloaded" 0089 when: root.progressInfo.completed && !autoOpenFile 0090 0091 PropertyChanges { 0092 target: openButton 0093 visible: false 0094 } 0095 0096 PropertyChanges { 0097 target: downloadButton 0098 icon.name: "document-open" 0099 QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to open its downloaded file with an appropriate application", "Open File") 0100 onClicked: openSavedFile() 0101 } 0102 }, 0103 State { 0104 name: "downloading" 0105 when: root.progressInfo.active 0106 0107 PropertyChanges { 0108 target: openButton 0109 visible: false 0110 } 0111 0112 PropertyChanges { 0113 target: sizeLabel 0114 text: i18nc("file download progress", "%1 / %2", Format.formatByteSize(root.progressInfo.progress), Format.formatByteSize(root.progressInfo.total)) 0115 } 0116 PropertyChanges { 0117 target: downloadButton 0118 icon.name: "media-playback-stop" 0119 QQC2.ToolTip.text: i18nc("tooltip for a button on a message; stops downloading the message's file", "Stop Download") 0120 onClicked: root.room.cancelFileTransfer(root.eventId) 0121 } 0122 }, 0123 State { 0124 name: "raw" 0125 when: true 0126 0127 PropertyChanges { 0128 target: downloadButton 0129 onClicked: root.saveFileAs() 0130 } 0131 } 0132 ] 0133 0134 Kirigami.Icon { 0135 source: root.mediaInfo.mimeIcon 0136 fallback: "unknown" 0137 } 0138 0139 ColumnLayout { 0140 spacing: 0 0141 QQC2.Label { 0142 Layout.fillWidth: true 0143 text: root.display 0144 wrapMode: Text.Wrap 0145 elide: Text.ElideRight 0146 } 0147 QQC2.Label { 0148 id: sizeLabel 0149 Layout.fillWidth: true 0150 text: Format.formatByteSize(root.mediaInfo.size) 0151 opacity: 0.7 0152 elide: Text.ElideRight 0153 maximumLineCount: 1 0154 } 0155 } 0156 0157 QQC2.Button { 0158 id: openButton 0159 icon.name: "document-open" 0160 onClicked: { 0161 autoOpenFile = true; 0162 root.room.downloadTempFile(root.eventId); 0163 } 0164 0165 QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to open its downloaded file with an appropriate application", "Open File") 0166 QQC2.ToolTip.visible: hovered 0167 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0168 } 0169 0170 QQC2.Button { 0171 id: downloadButton 0172 icon.name: "download" 0173 0174 QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to download its file", "Download") 0175 QQC2.ToolTip.visible: hovered 0176 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0177 } 0178 0179 Component { 0180 id: fileDialog 0181 0182 FileDialog { 0183 fileMode: FileDialog.SaveFile 0184 folder: Config.lastSaveDirectory.length > 0 ? Config.lastSaveDirectory : StandardPaths.writableLocation(StandardPaths.DownloadLocation) 0185 onAccepted: { 0186 Config.lastSaveDirectory = folder; 0187 Config.save(); 0188 if (autoOpenFile) { 0189 UrlHelper.copyTo(root.progressInfo.localPath, file); 0190 } else { 0191 root.room.download(root.eventId, file); 0192 } 0193 } 0194 } 0195 } 0196 } 0197 Repeater { 0198 id: itinerary 0199 model: ItineraryModel { 0200 id: itineraryModel 0201 connection: root.room.connection 0202 } 0203 delegate: DelegateChooser { 0204 role: "type" 0205 DelegateChoice { 0206 roleValue: "TrainReservation" 0207 delegate: ColumnLayout { 0208 Kirigami.Separator { 0209 Layout.fillWidth: true 0210 } 0211 RowLayout { 0212 QQC2.Label { 0213 text: model.name 0214 } 0215 QQC2.Label { 0216 text: model.coach ? i18n("Coach: %1, Seat: %2", model.coach, model.seat) : "" 0217 visible: model.coach 0218 opacity: 0.7 0219 } 0220 } 0221 RowLayout { 0222 Layout.fillWidth: true 0223 ColumnLayout { 0224 QQC2.Label { 0225 text: model.departureStation + (model.departurePlatform ? (" [" + model.departurePlatform + "]") : "") 0226 } 0227 QQC2.Label { 0228 text: model.departureTime 0229 opacity: 0.7 0230 } 0231 } 0232 Item { 0233 Layout.fillWidth: true 0234 } 0235 ColumnLayout { 0236 QQC2.Label { 0237 text: model.arrivalStation + (model.arrivalPlatform ? (" [" + model.arrivalPlatform + "]") : "") 0238 } 0239 QQC2.Label { 0240 text: model.arrivalTime 0241 opacity: 0.7 0242 Layout.alignment: Qt.AlignRight 0243 } 0244 } 0245 } 0246 } 0247 } 0248 DelegateChoice { 0249 roleValue: "LodgingReservation" 0250 delegate: ColumnLayout { 0251 Kirigami.Separator { 0252 Layout.fillWidth: true 0253 } 0254 QQC2.Label { 0255 text: model.name 0256 } 0257 QQC2.Label { 0258 text: i18nc("<start time> - <end time>", "%1 - %2", model.startTime, model.endTime) 0259 } 0260 QQC2.Label { 0261 text: model.address 0262 } 0263 } 0264 } 0265 } 0266 } 0267 QQC2.Button { 0268 icon.name: "map-globe" 0269 text: i18nc("@action", "Send to KDE Itinerary") 0270 QQC2.ToolTip.visible: hovered 0271 QQC2.ToolTip.text: text 0272 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0273 onClicked: itineraryModel.sendToItinerary() 0274 visible: itinerary.count > 0 0275 } 0276 } 0277 }