184 lines
5.3 KiB
QML
184 lines
5.3 KiB
QML
|
|
import QtQuick 2.15
|
|||
|
|
import QtQuick.Window 2.15
|
|||
|
|
import QtQuick.Controls 2.15
|
|||
|
|
import QtQuick.Layouts 1.15
|
|||
|
|
import QtMultimedia 5.15
|
|||
|
|
import DelegateUI 1.0
|
|||
|
|
import QmlTool 1.0
|
|||
|
|
import Qt.labs.platform 1.1 // 系统托盘支持
|
|||
|
|
import FileTransfer 1.0
|
|||
|
|
import "../MyGlobals" 1.0
|
|||
|
|
import "../Component" 1.0
|
|||
|
|
|
|||
|
|
DelWindow {
|
|||
|
|
width: 800
|
|||
|
|
height: 600
|
|||
|
|
visible: false
|
|||
|
|
title: qsTr("下载任务")
|
|||
|
|
captionBar.topButtonVisible: true
|
|||
|
|
captionBar.winIconDelegate: Image {
|
|||
|
|
source: "qrc:/image/logo.png"
|
|||
|
|
width: 20
|
|||
|
|
height: 20
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Shortcut {
|
|||
|
|
sequences: ["Esc"]
|
|||
|
|
onActivated: close()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function showEx(){
|
|||
|
|
x = GlobalVars.main_Window.x + GlobalVars.main_Window.width
|
|||
|
|
y = GlobalVars.main_Window.y
|
|||
|
|
show();
|
|||
|
|
width = 800
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
property var downloadModel: []
|
|||
|
|
|
|||
|
|
function flushQuest(){
|
|||
|
|
listView.model = downloadModel
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Timer {
|
|||
|
|
id: timer
|
|||
|
|
interval: 10
|
|||
|
|
running: true
|
|||
|
|
repeat: true
|
|||
|
|
onTriggered: {
|
|||
|
|
var obj = downloadModel[0];
|
|||
|
|
//未开始的任务
|
|||
|
|
if(!obj)return;
|
|||
|
|
//需要是未完成的任务
|
|||
|
|
if(obj.status !== 3){
|
|||
|
|
//上一个指令已完成开始检测下一个指令
|
|||
|
|
if(obj.instruction){
|
|||
|
|
obj.instruction = false;
|
|||
|
|
//还有下一个指令
|
|||
|
|
if(obj.questInstruction.length > 0){
|
|||
|
|
var ins = obj.questInstruction.shift();
|
|||
|
|
ins(obj);
|
|||
|
|
}
|
|||
|
|
//指令已全部做完
|
|||
|
|
else{
|
|||
|
|
var successobj = downloadModel.shift()
|
|||
|
|
successobj.status = 3
|
|||
|
|
downloadModel.push(successobj);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
flushQuest()
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Component.onCompleted: {
|
|||
|
|
GlobalVars.downlad_quest_window = this;
|
|||
|
|
FileTransfer.downloadCompleted.connect(downloadCompleted)
|
|||
|
|
FileTransfer.downloadProgressChanged.connect(progressChanged)
|
|||
|
|
FileTransfer.uploadCompleted.connect(uploadCompleted)
|
|||
|
|
FileTransfer.uploadProgressChanged.connect(progressChanged)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Component.onDestruction: {
|
|||
|
|
FileTransfer.downloadCompleted.disconnect(downloadCompleted)
|
|||
|
|
FileTransfer.downloadProgressChanged.disconnect(progressChanged)
|
|||
|
|
FileTransfer.uploadCompleted.disconnect(uploadCompleted)
|
|||
|
|
FileTransfer.uploadProgressChanged.disconnect(progressChanged)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//下载完成的信号
|
|||
|
|
function downloadCompleted(success, message) {
|
|||
|
|
var obj = downloadModel[0];
|
|||
|
|
if(!obj)return;
|
|||
|
|
if(message === "quest"){
|
|||
|
|
if (success) {
|
|||
|
|
obj.instruction = true;
|
|||
|
|
} else {
|
|||
|
|
var successobj = downloadModel.shift()
|
|||
|
|
successobj.status = 3
|
|||
|
|
successobj.error = 1
|
|||
|
|
downloadModel.push(successobj);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//进度的信号
|
|||
|
|
function progressChanged(rate,add){
|
|||
|
|
var obj = downloadModel[0];
|
|||
|
|
if(!obj)return;
|
|||
|
|
obj.progress = rate * 100.0;
|
|||
|
|
}
|
|||
|
|
//上传完成的信号
|
|||
|
|
function uploadCompleted(success, message) {
|
|||
|
|
var obj = downloadModel[0];
|
|||
|
|
if(!obj)return;
|
|||
|
|
if(message === "quest"){
|
|||
|
|
if (success) {
|
|||
|
|
obj.instruction = true;
|
|||
|
|
} else {
|
|||
|
|
var successobj = downloadModel.shift()
|
|||
|
|
successobj.status = 3
|
|||
|
|
successobj.error = 1
|
|||
|
|
downloadModel.push(successobj);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function addQuest(filename,questinstruction){
|
|||
|
|
downloadModel.unshift({
|
|||
|
|
//文件名
|
|||
|
|
fileName: filename,
|
|||
|
|
//任务指令
|
|||
|
|
questInstruction:questinstruction,
|
|||
|
|
//指令完成状态
|
|||
|
|
instruction:true,
|
|||
|
|
//进度条默认0
|
|||
|
|
progress: 0,
|
|||
|
|
//任务创建时间
|
|||
|
|
remainingTime: Math.floor(Date.now() / 1000),
|
|||
|
|
//任务状态
|
|||
|
|
status: 0,
|
|||
|
|
//失败Flag
|
|||
|
|
error:0
|
|||
|
|
})
|
|||
|
|
showEx();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Rectangle{
|
|||
|
|
anchors.fill:parent
|
|||
|
|
anchors.topMargin: 45
|
|||
|
|
anchors.margins: 15
|
|||
|
|
color:"transparent"
|
|||
|
|
radius:8
|
|||
|
|
border.color: DelTheme.isDark ? "#23272e" : "#f0f4f7"
|
|||
|
|
border.width: 3
|
|||
|
|
|
|||
|
|
// 任务列表
|
|||
|
|
ScrollView {
|
|||
|
|
anchors.fill:parent
|
|||
|
|
anchors.margins: 3
|
|||
|
|
|
|||
|
|
ListView {
|
|||
|
|
id: listView
|
|||
|
|
model: downloadModel
|
|||
|
|
clip: true
|
|||
|
|
|
|||
|
|
delegate: DownloadItemDelegate {
|
|||
|
|
width: listView.width
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// // 底部状态栏
|
|||
|
|
// CustomProgressBar {
|
|||
|
|
// anchors.bottom: parent.bottom
|
|||
|
|
// anchors.left: parent.left
|
|||
|
|
// anchors.right: parent.right
|
|||
|
|
// anchors.margins: 15
|
|||
|
|
// height: 35
|
|||
|
|
// antialiasing: true
|
|||
|
|
// }
|
|||
|
|
}
|