send progress dialog

This commit is contained in:
2026-04-28 15:21:30 +08:00
parent 7c884a2185
commit b1a81cd90b
7 changed files with 324 additions and 73 deletions

View File

@@ -14,7 +14,6 @@ ApplicationWindow {
property var currentFiles: []
property string currentSenderAlias: ""
property string currentSenderIp: ""
property var receiveProgress: ({})
DropArea {
id: dropArea
@@ -107,7 +106,7 @@ ApplicationWindow {
onAccepted: {
appController.acceptReceive(currentSessionId)
currentSessionId = ""
receiveProgressDialog.open()
}
onRejected: {
@@ -169,23 +168,43 @@ ApplicationWindow {
spacing: 12
Label {
text: qsTr("Receiving from %1...").arg(currentSenderAlias)
text: qsTr("From: %1").arg(appController.currentReceiveSenderAlias)
font.bold: true
}
Label {
text: appController.currentReceiveFileName
? qsTr("%1 (%2/%3)").arg(appController.currentReceiveFileName)
.arg(appController.currentReceiveFileIndex)
.arg(appController.totalReceiveFiles)
: qsTr("Waiting for data...")
elide: Text.ElideMiddle
Layout.maximumWidth: 400
}
ProgressBar {
Layout.fillWidth: true
from: 0
to: 100
value: calculateTotalProgress()
value: appController.receiveProgress
}
Label {
text: qsTr("%1% complete").arg(Math.round(calculateTotalProgress()))
text: qsTr("%1% complete").arg(Math.round(appController.receiveProgress))
color: palette.mid
}
}
property var progressData: ({})
footer: DialogButtonBox {
Button {
text: qsTr("Cancel")
DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
onClicked: {
appController.cancelReceive()
receiveProgressDialog.close()
}
}
}
}
Dialog {
@@ -199,7 +218,13 @@ ApplicationWindow {
spacing: 12
Label {
text: qsTr("Sending files...")
text: appController.currentSendFileName
? qsTr("%1 (%2/%3)").arg(appController.currentSendFileName)
.arg(appController.currentSendFileIndex)
.arg(appController.totalSendFiles)
: qsTr("Preparing...")
elide: Text.ElideMiddle
Layout.maximumWidth: 400
}
ProgressBar {
@@ -244,36 +269,18 @@ ApplicationWindow {
}
}
function onReceiveProgress(sessionId, fileId, progress) {
if (sessionId === currentSessionId) {
receiveProgress[fileId] = progress
receiveProgress = Object.assign({}, receiveProgress)
receiveProgressDialog.progressData = receiveProgress
if (!receiveProgressDialog.visible) {
receiveProgressDialog.open()
}
}
}
function onReceiveCompleted(sessionId) {
if (sessionId === currentSessionId) {
receiveProgressDialog.close()
receiveProgress = {}
currentSessionId = ""
}
receiveProgressDialog.close()
}
function onReceiveError(sessionId, error) {
if (sessionId === currentSessionId) {
receiveProgressDialog.close()
errorDialog.text = error
errorDialog.open()
}
receiveProgressDialog.close()
errorDialog.text = error
errorDialog.open()
}
function onSendProgress(progress) {
if (!sendProgressDialog.visible) {
function onSendingChanged() {
if (appController.sending && !sendProgressDialog.visible) {
sendProgressDialog.open()
}
}
@@ -291,6 +298,12 @@ ApplicationWindow {
errorDialog.open()
}
function onSendCanceled() {
sendProgressDialog.close()
errorDialog.text = qsTr("Transfer canceled by receiver")
errorDialog.open()
}
function onPinRequired(firstAttempt) {
pinDialog.isFirstAttempt = firstAttempt
pinDialog.open()
@@ -369,6 +382,7 @@ ApplicationWindow {
onAccepted: submitPin()
onRejected: {
appController.cancelSend()
sendProgressDialog.close()
close()
}
@@ -436,20 +450,6 @@ ApplicationWindow {
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB"
}
function calculateTotalProgress() {
if (!currentFiles || currentFiles.length === 0) return 0
var total = 0
var count = 0
for (var i = 0; i < currentFiles.length; i++) {
var fileId = currentFiles[i].id
if (receiveProgress[fileId] !== undefined) {
total += receiveProgress[fileId] * 100
count++
}
}
return count > 0 ? total / currentFiles.length : 0
}
Component {
id: homePageComponent
Page {