AntiClipSettings/qml/OtaPopup.qml

136 lines
3.8 KiB
QML
Raw Normal View History

2024-08-24 22:35:35 +08:00
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
2024-08-26 16:46:41 +08:00
import QtQuick.Dialogs 1.3
2024-08-24 22:35:35 +08:00
import AntiClipSettings 1.0
2024-08-19 09:33:04 +08:00
Popup {
id: root
parent: Overlay.overlay
anchors.centerIn: Overlay.overlay
2024-08-21 09:26:06 +08:00
width: 540
height: 260
2024-08-19 09:33:04 +08:00
modal: true
focus: true
closePolicy: Popup.CloseOnEscape
2024-08-21 16:03:49 +08:00
property bool otaFinished: true
2024-08-19 09:33:04 +08:00
property var onClose
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
RowLayout {
Layout.alignment: Qt.AlignRight
2024-08-21 16:03:49 +08:00
IconButton {
source: "../resources/popup_close.svg"
onClicked: {
2024-08-26 16:46:41 +08:00
if (otaFinished) {
2024-08-21 16:03:49 +08:00
root.close()
2024-08-26 16:46:41 +08:00
} else {
showMessageDialog(2, "OTA升级", "设备正在升级中,请耐心等待...")
2024-08-21 16:03:49 +08:00
}
}
2024-08-19 09:33:04 +08:00
}
}
RowLayout {
spacing: 10
TextField {
id: otaFile
Layout.fillWidth: true
2024-08-21 16:03:49 +08:00
readOnly: true
placeholderText: "请选择升级bin文件"
2024-08-19 09:33:04 +08:00
}
Button {
2024-08-22 18:12:11 +08:00
enabled: otaFinished
2024-08-19 09:33:04 +08:00
text: "选择"
onClicked: fileDialog.open()
}
}
RowLayout {
spacing: 10
ProgressBar {
id: progressBar
Layout.fillWidth: true
from: 0
to: 100
value: 0.0
}
Text {
id: progressText
text: "0%"
verticalAlignment: Text.AlignVCenter
}
}
RowLayout {
Text {
id: otaMessage
text: "请选择升级文件,点击开始按钮升级模组"
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Layout.fillWidth: true
}
Button {
2024-08-22 18:12:11 +08:00
enabled: otaFinished
2024-08-19 09:33:04 +08:00
text: "开始"
Layout.alignment: Qt.AlignRight
onClicked: {
otaMessage.color = "black"
App.upgradeDevice(otaFile.text)
}
}
}
}
onClosed: {
if (onClose)
onClose()
}
FileDialog {
id: fileDialog
nameFilters: ["OTA文件 (*.bin)"]
2024-08-24 22:35:35 +08:00
2024-08-19 09:33:04 +08:00
onAccepted: {
2024-08-26 16:46:41 +08:00
let fileUrl = isQt5 ? fileDialog.fileUrl.toString() : fileDialog.selectedFile.toString()
2024-08-19 09:33:04 +08:00
var localFilePath = fileUrl.startsWith(
"file:///") ? fileUrl.substring(8) : fileUrl
otaFile.text = localFilePath
}
2024-08-24 22:35:35 +08:00
onVisibleChanged: {
2024-08-26 16:46:41 +08:00
if (!isQt5) {
currentFolder = StandardPaths.standardLocations(
StandardPaths.DesktopLocation)[0]
2024-08-24 22:35:35 +08:00
}
}
2024-08-19 09:33:04 +08:00
}
2024-08-21 09:26:06 +08:00
Connections {
target: App
2024-08-26 16:46:41 +08:00
function onCurrentDeviceOtaProgressChanged(status, progress, message) {
if (progress < 0)
progress = 0
otaFinished = !status || (progress >= 100)
2024-08-21 09:26:06 +08:00
progressBar.value = progress
progressText.text = `${progress}%`
2024-08-22 10:48:28 +08:00
otaMessage.text = message
2024-08-26 16:46:41 +08:00
if (progress >= 100) {
2024-08-21 09:26:06 +08:00
otaMessage.color = "green"
}
}
}
2024-08-22 10:48:28 +08:00
onVisibleChanged: {
2024-08-26 16:46:41 +08:00
if (!visible) {
2024-08-22 18:12:11 +08:00
progressBar.value = 0
2024-08-22 10:48:28 +08:00
otaMessage.color = "black"
2024-08-22 18:12:11 +08:00
progressText.text = "0%"
otaMessage.text = "请选择升级文件,点击开始按钮升级模组"
2024-08-22 10:48:28 +08:00
}
}
2024-08-19 09:33:04 +08:00
}