2021-09-30 09:43:29 +00:00
|
|
|
import QtQuick 2.1
|
|
|
|
import QtGraphicalEffects 1.13
|
2021-10-18 10:34:16 +00:00
|
|
|
|
2021-09-30 09:43:29 +00:00
|
|
|
import utils 1.0
|
2021-10-20 09:45:38 +00:00
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
2021-09-30 09:43:29 +00:00
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
|
|
|
id: downloadBar
|
|
|
|
|
|
|
|
property bool isVisible: false
|
|
|
|
property var downloadsModel
|
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)
|
2021-12-07 23:15:17 +00:00
|
|
|
signal addNewDownloadTab()
|
2021-09-30 09:43:29 +00:00
|
|
|
|
|
|
|
visible: isVisible && !!listView.count
|
|
|
|
color: Style.current.background
|
|
|
|
width: parent.width
|
|
|
|
height: 56
|
|
|
|
border.width: 1
|
|
|
|
border.color: Style.current.border
|
|
|
|
|
|
|
|
// This container is to contain the downloaded elements between the parent buttons and hide the overflow
|
|
|
|
Item {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
|
|
|
anchors.right: showAllBtn.left
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
height: listView.height
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: listView
|
|
|
|
orientation: ListView.Horizontal
|
|
|
|
model: downloadsModel
|
|
|
|
height: currentItem ? currentItem.height : 0
|
|
|
|
// This makes it show the newest on the right
|
|
|
|
layoutDirection: Qt.RightToLeft
|
|
|
|
spacing: Style.current.smallPadding
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: {
|
|
|
|
// Children rect shows a warning but this works ¯\_(ツ)_/¯
|
|
|
|
let w = 0
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
w += this.itemAtIndex(i).width + this.spacing
|
|
|
|
}
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
interactive: false
|
|
|
|
delegate: DownloadElement {
|
|
|
|
id: downloadElement
|
|
|
|
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 + 20
|
|
|
|
downloadsMenu.y = -downloadsMenu.height
|
|
|
|
downloadsMenu.open()
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
Connections {
|
2021-12-07 23:15:17 +00:00
|
|
|
target: downloadsMenu
|
2021-09-30 09:43:29 +00:00
|
|
|
onCancelClicked: {
|
|
|
|
isCanceled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: showAllBtn
|
2021-10-20 09:45:38 +00:00
|
|
|
size: StatusBaseButton.Size.Small
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("Show All")
|
2021-09-30 09:43:29 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: closeBtn.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
onClicked: {
|
|
|
|
addNewDownloadTab()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 09:45:38 +00:00
|
|
|
StatusFlatRoundButton {
|
2021-09-30 09:43:29 +00:00
|
|
|
id: closeBtn
|
2021-10-18 10:34:16 +00:00
|
|
|
width: 32
|
|
|
|
height: 32
|
2021-09-30 09:43:29 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
2021-10-18 10:34:16 +00:00
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
2021-10-20 09:45:38 +00:00
|
|
|
icon.name: "close"
|
2021-10-18 10:34:16 +00:00
|
|
|
type: StatusFlatRoundButton.Type.Quaternary
|
|
|
|
onClicked: downloadBar.isVisible = false
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
}
|