2021-09-30 09:43:29 +00:00
|
|
|
import QtQuick 2.1
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
2021-09-30 09:43:29 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2021-12-07 23:15:17 +00:00
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
Rectangle {
|
2021-09-30 09:43:29 +00:00
|
|
|
id: downloadView
|
|
|
|
|
|
|
|
property alias downloadsModel: listView.model
|
|
|
|
|
2021-12-07 23:15:17 +00:00
|
|
|
property var downloadsMenu
|
|
|
|
|
2021-09-30 09:43:29 +00:00
|
|
|
signal openDownloadClicked(bool downloadComplete, int index)
|
|
|
|
|
|
|
|
color: Style.current.background
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
StatusListView {
|
2021-09-30 09:43:29 +00:00
|
|
|
id: listView
|
|
|
|
anchors {
|
|
|
|
topMargin: Style.current.bigPadding
|
|
|
|
top: parent.top
|
|
|
|
bottom: parent.bottom
|
|
|
|
bottomMargin: Style.current.bigPadding * 2
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
width: 624
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
|
|
|
delegate: DownloadElement {
|
|
|
|
id: downloadElement
|
|
|
|
width: parent.width
|
|
|
|
isPaused: downloadsModel.downloads[index] && downloadsModel.downloads[index].isPaused
|
|
|
|
primaryText: downloadFileName
|
|
|
|
downloadText: {
|
|
|
|
if (isCanceled) {
|
2022-04-04 11:26:30 +00:00
|
|
|
return qsTr("Cancelled")
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
if (isPaused) {
|
2022-04-04 11:26:30 +00:00
|
|
|
return qsTr("Paused")
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
return `${downloadsModel.downloads[index] ? (downloadsModel.downloads[index].receivedBytes / 1000000).toFixed(2) : 0}/${downloadsModel.downloads[index] ? (downloadsModel.downloads[index].totalBytes / 1000000).toFixed(2) : 0} MB` //"14.4/109 MB, 26 sec left"
|
|
|
|
}
|
|
|
|
downloadComplete: {
|
|
|
|
// listView.count ensures a value is returned even when index is undefined
|
|
|
|
return listView.count > 0 && !!downloadsModel.downloads && !!downloadsModel.downloads[index] &&
|
|
|
|
downloadsModel.downloads[index].receivedBytes >= downloadsModel.downloads[index].totalBytes
|
|
|
|
}
|
|
|
|
onItemClicked: {
|
|
|
|
openDownloadClicked(downloadComplete, index)
|
|
|
|
}
|
|
|
|
onOptionsButtonClicked: {
|
2021-12-07 23:15:17 +00:00
|
|
|
downloadsMenu.index = index
|
|
|
|
downloadsMenu.downloadComplete = Qt.binding(function() {return downloadElement.downloadComplete})
|
|
|
|
downloadsMenu.parent = downloadElement
|
|
|
|
downloadsMenu.x = xVal
|
|
|
|
downloadsMenu.y = downloadView.y - downloadsMenu.height
|
|
|
|
downloadsMenu.open()
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
Connections {
|
2021-12-07 23:15:17 +00:00
|
|
|
target: downloadsMenu
|
2023-01-18 09:25:36 +00:00
|
|
|
function onCancelClicked() {
|
2021-09-30 09:43:29 +00:00
|
|
|
isCanceled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
visible: !listView.count
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 15
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("Downloaded files will appear here.")
|
2021-09-30 09:43:29 +00:00
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
}
|