136 lines
3.8 KiB
QML
136 lines
3.8 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Controls 2.15
|
|
import QtQuick.Layouts 1.15
|
|
import QtQuick.Dialogs 1.3
|
|
import AntiClipSettings 1.0
|
|
|
|
Popup {
|
|
id: root
|
|
parent: Overlay.overlay
|
|
anchors.centerIn: Overlay.overlay
|
|
width: 540
|
|
height: 260
|
|
modal: true
|
|
focus: true
|
|
closePolicy: Popup.CloseOnEscape
|
|
property bool otaFinished: true
|
|
property var onClose
|
|
|
|
ColumnLayout {
|
|
anchors.fill: parent
|
|
anchors.margins: 10
|
|
spacing: 10
|
|
|
|
RowLayout {
|
|
Layout.alignment: Qt.AlignRight
|
|
IconButton {
|
|
source: "../resources/popup_close.svg"
|
|
onClicked: {
|
|
if (otaFinished) {
|
|
root.close()
|
|
} else {
|
|
showMessageDialog(2, "OTA升级", "设备正在升级中,请耐心等待...")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
RowLayout {
|
|
spacing: 10
|
|
TextField {
|
|
id: otaFile
|
|
Layout.fillWidth: true
|
|
readOnly: true
|
|
placeholderText: "请选择升级bin文件"
|
|
}
|
|
Button {
|
|
enabled: otaFinished
|
|
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 {
|
|
enabled: otaFinished
|
|
text: "开始"
|
|
Layout.alignment: Qt.AlignRight
|
|
onClicked: {
|
|
otaMessage.color = "black"
|
|
App.upgradeDevice(otaFile.text)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
onClosed: {
|
|
if (onClose)
|
|
onClose()
|
|
}
|
|
|
|
FileDialog {
|
|
id: fileDialog
|
|
nameFilters: ["OTA文件 (*.bin)"]
|
|
|
|
onAccepted: {
|
|
let fileUrl = isQt5 ? fileDialog.fileUrl.toString() : fileDialog.selectedFile.toString()
|
|
var localFilePath = fileUrl.startsWith(
|
|
"file:///") ? fileUrl.substring(8) : fileUrl
|
|
otaFile.text = localFilePath
|
|
}
|
|
onVisibleChanged: {
|
|
if (!isQt5) {
|
|
currentFolder = StandardPaths.standardLocations(
|
|
StandardPaths.DesktopLocation)[0]
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: App
|
|
function onCurrentDeviceOtaProgressChanged(status, progress, message) {
|
|
if (progress < 0)
|
|
progress = 0
|
|
otaFinished = !status || (progress >= 100)
|
|
progressBar.value = progress
|
|
progressText.text = `${progress}%`
|
|
otaMessage.text = message
|
|
if (progress >= 100) {
|
|
otaMessage.color = "green"
|
|
}
|
|
}
|
|
}
|
|
onVisibleChanged: {
|
|
if (!visible) {
|
|
progressBar.value = 0
|
|
otaMessage.color = "black"
|
|
progressText.text = "0%"
|
|
otaMessage.text = "请选择升级文件,点击开始按钮升级模组"
|
|
}
|
|
}
|
|
}
|