able to send file

This commit is contained in:
2026-04-27 16:08:40 +08:00
parent 71ea3dbd01
commit bfe271550e
6 changed files with 419 additions and 15 deletions

View File

@@ -15,6 +15,7 @@ ApplicationWindow {
property string currentSenderAlias: ""
property string currentSenderIp: ""
property var receiveProgress: ({})
property string selectedDeviceFingerprint: ""
StackView {
id: stackView
@@ -25,6 +26,21 @@ ApplicationWindow {
}
}
FileDialog {
id: fileDialog
title: qsTr("Select Files to Send")
fileMode: FileDialog.OpenFiles
onAccepted: {
var paths = []
for (var i = 0; i < selectedFiles.length; i++) {
paths.push(selectedFiles[i].toString().replace("file://", ""))
}
if (paths.length > 0 && selectedDeviceFingerprint !== "") {
appController.sendFiles(selectedDeviceFingerprint, paths)
}
}
}
Dialog {
id: receiveDialog
anchors.centerIn: parent
@@ -73,7 +89,7 @@ ApplicationWindow {
}
Label {
text: formatSize(modelData.size)
color: "gray"
color: palette.mid
}
}
}
@@ -87,7 +103,7 @@ ApplicationWindow {
}
Dialog {
id: progressDialog
id: receiveProgressDialog
anchors.centerIn: parent
modal: true
closePolicy: Popup.NoAutoClose
@@ -97,12 +113,10 @@ ApplicationWindow {
spacing: 12
Label {
id: progressLabel
text: qsTr("Receiving from %1...").arg(currentSenderAlias)
}
ProgressBar {
id: totalProgressBar
Layout.fillWidth: true
from: 0
to: 100
@@ -110,14 +124,53 @@ ApplicationWindow {
}
Label {
text: qsTr("%1% complete").arg(Math.round(totalProgressBar.value))
color: "gray"
text: qsTr("%1% complete").arg(Math.round(calculateTotalProgress()))
color: palette.mid
}
}
property var progressData: ({})
}
Dialog {
id: sendProgressDialog
anchors.centerIn: parent
modal: true
closePolicy: Popup.NoAutoClose
title: qsTr("Sending Files")
ColumnLayout {
spacing: 12
Label {
text: qsTr("Sending files...")
}
ProgressBar {
Layout.fillWidth: true
from: 0
to: 100
value: appController.sendProgress
}
Label {
text: qsTr("%1% complete").arg(Math.round(appController.sendProgress))
color: palette.mid
}
}
footer: DialogButtonBox {
Button {
text: qsTr("Cancel")
DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
onClicked: {
appController.cancelSend()
sendProgressDialog.close()
}
}
}
}
Connections {
target: appController
@@ -129,6 +182,7 @@ ApplicationWindow {
if (appController.quickSave) {
appController.acceptReceive(sessionId)
receiveProgressDialog.open()
} else {
receiveDialog.open()
}
@@ -138,13 +192,17 @@ ApplicationWindow {
if (sessionId === currentSessionId) {
receiveProgress[fileId] = progress
receiveProgress = Object.assign({}, receiveProgress)
progressDialog.progressData = receiveProgress
receiveProgressDialog.progressData = receiveProgress
if (!receiveProgressDialog.visible) {
receiveProgressDialog.open()
}
}
}
function onReceiveCompleted(sessionId) {
if (sessionId === currentSessionId) {
progressDialog.close()
receiveProgressDialog.close()
receiveProgress = {}
currentSessionId = ""
}
@@ -152,11 +210,29 @@ ApplicationWindow {
function onReceiveError(sessionId, error) {
if (sessionId === currentSessionId) {
progressDialog.close()
receiveProgressDialog.close()
errorDialog.text = error
errorDialog.open()
}
}
function onSendProgress(progress) {
if (!sendProgressDialog.visible) {
sendProgressDialog.open()
}
}
function onSendCompleted(sessionId) {
sendProgressDialog.close()
successDialog.text = qsTr("Files sent successfully!")
successDialog.open()
}
function onSendError(error) {
sendProgressDialog.close()
errorDialog.text = error
errorDialog.open()
}
}
Dialog {
@@ -172,6 +248,19 @@ ApplicationWindow {
}
}
Dialog {
id: successDialog
anchors.centerIn: parent
modal: true
standardButtons: Dialog.Ok
title: qsTr("Success")
property alias text: successLabel.text
Label {
id: successLabel
}
}
function formatSize(bytes) {
if (bytes < 1024) return bytes + " B"
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB"
@@ -242,8 +331,10 @@ ApplicationWindow {
padding: 12
background: Rectangle {
color: Qt.lighter("gray", 1.8)
color: "transparent"
radius: 8
border.color: palette.mid
border.width: 1
}
RowLayout {
@@ -257,19 +348,28 @@ ApplicationWindow {
}
Label {
text: "%1:%2".arg(modelData.ip).arg(modelData.port)
color: "gray"
color: palette.mid
font.pixelSize: 12
}
}
Button {
text: qsTr("Send")
enabled: !appController.sending
onClicked: {
// TODO: send to this device
selectedDeviceFingerprint = modelData.fingerprint
fileDialog.open()
}
}
}
}
Label {
anchors.centerIn: parent
text: qsTr("No devices found")
color: palette.mid
visible: deviceListView.count === 0
}
}
RowLayout {