Warning, /network/angelfish/src/contents/ui/Downloads.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick 2.0
0006 import QtQuick.Layouts 1.12
0007 import QtQuick.Controls 2.4 as Controls
0008 
0009 import QtWebEngine 1.7
0010 
0011 import org.kde.kirigami 2.14 as Kirigami
0012 import org.kde.angelfish 1.0
0013 
0014 Kirigami.ScrollablePage {
0015     title: i18n("Downloads")
0016     Kirigami.ColumnView.fillWidth: false
0017 
0018     ListView {
0019         model: DownloadsModel {
0020             id: downloadsModel
0021         }
0022         Kirigami.PlaceholderMessage {
0023             anchors.centerIn: parent
0024             width: parent.width - (Kirigami.Units.largeSpacing * 4)
0025             visible: parent.count === 0
0026             text: i18n("No running downloads")
0027         }
0028         delegate: Kirigami.SwipeListItem {
0029             id: downloadDelegate
0030             required property WebEngineDownloadRequest download
0031             required property var mimeTypeIcon
0032             required property string fileName
0033             required property url url
0034             required property url downloadedFilePath
0035 
0036             required property int index
0037 
0038             onClicked: Qt.openUrlExternally(downloadDelegate.downloadedFilePath)
0039             actions: [
0040                 Kirigami.Action {
0041                     text: i18n("Cancel")
0042                     icon.name: downloadDelegate.download.state === WebEngineDownloadRequest.DownloadInProgress ? "dialog-cancel" : "list-remove"
0043                     onTriggered: downloadsModel.removeDownload(index)
0044                 },
0045                 Kirigami.Action {
0046                     visible: !downloadDelegate.download.isPaused && downloadDelegate.download.state === WebEngineDownloadRequest.DownloadInProgress
0047                     text: i18n("Pause")
0048                     icon.name: "media-playback-pause"
0049                     onTriggered: downloadDelegate.download.pause()
0050                 },
0051                 Kirigami.Action {
0052                     visible: downloadDelegate.download.isPaused && downloadDelegate.download.state === WebEngineDownloadRequest.DownloadInProgress
0053                     text: i18n("Continue")
0054                     icon.name: "media-playback-start"
0055                     onTriggered: downloadDelegate.download.resume();
0056                 }
0057             ]
0058 
0059             contentItem: RowLayout {
0060                 Kirigami.Icon {
0061                     source: downloadDelegate.mimeTypeIcon
0062                     height: Kirigami.Units.iconSizes.medium
0063                     width: height
0064                 }
0065 
0066                 ColumnLayout {
0067                     Layout.fillWidth: true
0068                     Kirigami.Heading {
0069                         Layout.fillWidth: true
0070                         level: 3
0071                         elide: Qt.ElideRight
0072                         text: downloadDelegate.fileName
0073                     }
0074                     Controls.Label {
0075                         Layout.fillWidth: true
0076                         elide: Qt.ElideRight
0077                         text: downloadDelegate.url
0078                     }
0079                     Controls.ProgressBar {
0080                         Layout.fillWidth: true
0081                         visible: downloadDelegate.download.state === WebEngineDownloadRequest.DownloadInProgress
0082                         from: 0
0083                         value: downloadDelegate.download.receivedBytes
0084                         to: downloadDelegate.download.totalBytes
0085                     }
0086                     Controls.Label {
0087                         visible: downloadDelegate.download.state !== WebEngineDownloadRequest.DownloadInProgress
0088                         text: {
0089                             switch (downloadDelegate.download.state) {
0090                             case WebEngineDownloadRequest.DownloadRequested:
0091                                 return i18nc("download state", "Starting…");
0092                             case WebEngineDownloadRequest.DownloadCompleted:
0093                                 return i18n("Completed");
0094                             case WebEngineDownloadRequest.DownloadCancelled:
0095                                 return i18n("Cancelled");
0096                             case WebEngineDownloadRequest.DownloadInterrupted:
0097                                 return i18nc("download state", "Interrupted");
0098                             case WebEngineDownloadRequest.DownloadInProgress:
0099                                 return i18nc("download state", "In progress")
0100                             }
0101                         }
0102                     }
0103                 }
0104             }
0105         }
0106     }
0107 }