moment/src/qml/Chat/FileTransfer/Transfer.qml

195 lines
5.8 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../../Base"
import "../../utils.js" as Utils
HColumnLayout {
id: transfer
property bool guiPaused: false
2019-12-06 16:44:25 -04:00
property int msLeft: model.time_left || 0
property int uploaded: model.uploaded
readonly property int speed: model.speed
readonly property int totalSize: model.total_size
readonly property string status: model.status
readonly property bool paused: status === "Paused" || guiPaused
2019-12-06 16:44:25 -04:00
Behavior on msLeft { HNumberAnimation { duration: 1000 } }
Behavior on uploaded { HNumberAnimation { duration: 1000 }}
Behavior on height { HNumberAnimation {} }
HRowLayout {
2019-12-06 16:44:25 -04:00
HIcon {
svgName: "uploading"
colorize:
status === "Error" ? theme.colors.negativeBackground :
status === "Paused" ? theme.colors.middleBackground :
theme.icons.colorize
Layout.preferredWidth: theme.baseElementsHeight
Layout.fillHeight: true
}
HLabel {
id: statusLabel
elide: expand ? Text.ElideNone : Text.ElideRight
wrapMode: expand ? Text.Wrap : Text.NoWrap
2019-12-06 16:44:25 -04:00
color: status === "Error" ?
theme.colors.errorText : theme.colors.text
text:
2019-12-06 16:44:25 -04:00
status === "Uploading" ? fileName :
2019-12-06 16:44:25 -04:00
status === "Caching" ?
qsTr("Caching %1...").arg(fileName) :
2019-12-06 16:44:25 -04:00
model.error === "MatrixForbidden" ?
qsTr("Forbidden file type or quota exceeded: %1")
.arg(fileName) :
2019-12-06 16:44:25 -04:00
model.error === "MatrixTooLarge" ?
qsTr("Too large for this server: %1").arg(fileName) :
2019-12-06 16:44:25 -04:00
model.error === "IsADirectoryError" ?
qsTr("Can't upload folders, need a file: %1").arg(filePath) :
2019-12-06 16:44:25 -04:00
model.error === "FileNotFoundError" ?
qsTr("Non-existant file: %1").arg(filePath) :
2019-12-06 16:44:25 -04:00
model.error === "PermissionError" ?
qsTr("No permission to read this file: %1").arg(filePath) :
2019-12-06 16:44:25 -04:00
qsTr("Unknown error for %1: %2 - %3")
.arg(filePath).arg(model.error).arg(model.error_args)
topPadding: theme.spacing / 2
bottomPadding: topPadding
leftPadding: theme.spacing / 1.5
rightPadding: leftPadding
Layout.fillWidth: true
2019-12-06 16:44:25 -04:00
property bool expand: status === "Error"
readonly property string fileName:
model.filepath.split("/").slice(-1)[0]
readonly property string filePath:
model.filepath.replace(/^file:\/\//, "")
HoverHandler { id: statusLabelHover }
HToolTip {
text: parent.truncated ? parent.text : ""
visible: text && statusLabelHover.hovered
}
}
HSpacer {}
2019-12-06 16:44:25 -04:00
Repeater {
model: [
msLeft ? qsTr("-%1").arg(Utils.formatDuration(msLeft)) : "",
2019-12-06 16:44:25 -04:00
speed ? qsTr("%1/s").arg(CppUtils.formattedBytes(speed)) : "",
2019-12-06 16:44:25 -04:00
qsTr("%1/%2").arg(CppUtils.formattedBytes(uploaded))
.arg(CppUtils.formattedBytes(totalSize)),
]
2019-12-06 16:44:25 -04:00
HLabel {
text: modelData
visible: text && Layout.preferredWidth > 0
leftPadding: theme.spacing / 1.5
rightPadding: leftPadding
2019-12-06 16:44:25 -04:00
Layout.preferredWidth:
status === "Uploading" ? implicitWidth : 0
2019-12-06 16:44:25 -04:00
Behavior on Layout.preferredWidth { HNumberAnimation {} }
}
}
HButton {
visible: Layout.preferredWidth > 0
padded: false
icon.name: transfer.paused ?
"upload-resume" : "upload-pause"
icon.color: transfer.paused ?
theme.colors.positiveBackground :
theme.colors.middleBackground
toolTip.text: transfer.paused ?
qsTr("Resume") : qsTr("Pause")
onClicked: {
transfer.guiPaused = ! transfer.guiPaused
py.setattr(
model.monitor, "pause", transfer.guiPaused,
)
}
Layout.preferredWidth:
2019-12-06 16:44:25 -04:00
status === "Uploading" ?
theme.baseElementsHeight : 0
Layout.fillHeight: true
Behavior on Layout.preferredWidth { HNumberAnimation {} }
}
2019-12-06 16:44:25 -04:00
HButton {
icon.name: "upload-cancel"
icon.color: theme.colors.negativeBackground
padded: false
onClicked: {
// Python might take a sec to cancel, but we want
// immediate visual feedback
transfer.height = 0
// Python will delete this model item on cancel
py.call(py.getattr(model.task, "cancel"))
}
Layout.preferredWidth: theme.baseElementsHeight
Layout.fillHeight: true
}
TapHandler {
2019-12-06 16:44:25 -04:00
onTapped: if (status !== "Error")
statusLabel.expand = ! statusLabel.expand
}
}
HProgressBar {
id: progressBar
visible: Layout.maximumHeight !== 0
2019-12-06 16:44:25 -04:00
indeterminate: status !== "Uploading"
value: uploaded
to: totalSize
// TODO: bake this in hprogressbar
foregroundColor:
2019-12-06 16:44:25 -04:00
status === "Error" ?
theme.controls.progressBar.errorForeground :
transfer.paused ?
theme.controls.progressBar.pausedForeground :
theme.controls.progressBar.foreground
Layout.fillWidth: true
Layout.maximumHeight:
2019-12-06 16:44:25 -04:00
status === "Error" && indeterminate ? 0 : -1
Behavior on Layout.maximumHeight { HNumberAnimation {} }
}
}