提交 7441f9f9 编写于 作者: P peterq

feature: 设置页面

上级 4a1d77d5
......@@ -2,6 +2,7 @@ package functions
import (
"github.com/peterq/pan-light/pc/dep"
"github.com/peterq/pan-light/pc/pan-download"
"github.com/peterq/pan-light/pc/storage"
"os"
)
......@@ -27,9 +28,16 @@ var baseSyncRoutes = map[string]syncHandler{
},
// 重启
"reboot": func(p map[string]interface{}) (result interface{}) {
dep.DoClose()
os.Exit(2)
return
},
// config
"config": func(p map[string]interface{}) (result interface{}) {
maxParallelCorutineNumber := int(p["maxParallelCorutineNumber"].(float64))
pan_download.Manager().CoroutineNumber = maxParallelCorutineNumber
return true
},
}
var baseAsyncRoutes = map[string]asyncHandler{}
......@@ -39,6 +39,13 @@ Item {
property string defaultDownloadPath: ''
property string lastDownloadPath: ''
property int maxParallelTaskNumber: 1
property int maxParallelCorutineNumber: 512
Component.onCompleted: {
Util.callGoSync('config', {
"maxParallelCorutineNumber": maxParallelCorutineNumber
})
}
}
onPathChanged: {
......
......@@ -411,3 +411,14 @@ function humanSize(size) {
}
return size.toFixed(2) + unit[i]
}
var openSetting = (function () {
var comp = loadComponent(function(){},'../pages/setting-window.qml')
var ins
return function(){
if (!ins || !ins.visible) {
ins = comp.createObject(G.root)
}
return ins
}
})()
import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../js/app.js" as App
import "../js/util.js" as Util
Window {
id: window
flags: Qt.Dialog | Qt.WindowModal | Qt.WindowCloseButtonHint
modality: Qt.ApplicationModal
title: '设置'
minimumHeight: height
minimumWidth: width
maximumHeight: height
maximumWidth: width
visible: true
width: 550
height: 300
Component.onCompleted: {
visible = true
requestActivate()
}
onVisibleChanged: {
if (!visible) {
window.destroy()
}
}
GridLayout {
columns: 3
width: parent.width - 20
y: 20
anchors.horizontalCenter: parent.horizontalCenter
Label {
text: '同时下载任务数'
width: parent.width * 30
Layout.alignment: Qt.AlignRight
}
TextField {
id: taskNumberField
width: parent.width * 30
validator: IntValidator {
bottom: 1
top: 10
}
placeholderText: "任务数"
Component.onCompleted: {
text = App.appState.settings.maxParallelTaskNumber
}
onTextChanged: {
var n = text * 1
if (n <= 0) {
n = 1
}
App.appState.settings.maxParallelTaskNumber = n
}
}
Label {
text: '1-10之间'
}
Label {
text: '每个任务的线程数'
width: parent.width * 30
Layout.alignment: Qt.AlignRight
}
TextField {
width: parent.width * 30
validator: IntValidator {
bottom: 1
top: ~~(1024 / App.appState.settings.maxParallelTaskNumber)
}
placeholderText: "并发数1-" + ~~(1024 / App.appState.settings.maxParallelTaskNumber)
onAccepted: textArea.focus = true
Component.onCompleted: {
text = App.appState.settings.maxParallelCorutineNumber
}
onTextChanged: {
var n = text * 1
if (n <= 0) {
n = 1
}
App.appState.settings.maxParallelCorutineNumber = n
}
}
Label {
text: '线程数 x 任务数小于1024'
}
Label {
text: ''
width: parent.width * 30
Layout.alignment: Qt.AlignRight
}
Button {
text: '重启以生效'
onClicked: {
Util.callGoSync('reboot')
}
}
}
}
......@@ -164,5 +164,6 @@
<file>assets/images/icons/more-down.svg</file>
<file>widget/Resize.qml</file>
<file>assets/images/icons/baidu-cloud.svg</file>
<file>pages/setting-window.qml</file>
</qresource>
</RCC>
......@@ -6,6 +6,7 @@ import "../comps"
import "../js/global.js" as G
import "../js/util.js" as Util
import "../js/app.js" as App
Item {
property Component content
property int shadeWidth: isMax ? 0 : 10
......@@ -14,7 +15,6 @@ Item {
width: parent.width
height: parent.height
Resize {
width: contentContainer.width + 2 * maWidth
height: contentContainer.height + 2 * maWidth
......@@ -42,13 +42,54 @@ Item {
anchors.rightMargin: 5
y: 5
spacing: 10
IconButton {
iconType: 'more-down'
title: '更多'
visible: !!App.appState.transferComp
width: 20
onClicked: {
moreMenu.popup()
Loader {
sourceComponent: App.appState.transferComp ? downMoreBtnComp : null
}
Component {
id: downMoreBtnComp
IconButton {
iconType: 'more-down'
title: '更多'
width: 20
onClicked: {
moreMenu.popup()
}
// 更多菜单
Menu {
id: moreMenu
MenuItem {
text: (App.appState.floatWindow.visible ? '隐藏' : '显示') + '悬浮窗'
onTriggered: {
App.appState.floatWindow.visible = !App.appState.floatWindow.visible
}
}
MenuItem {
text: '设置'
onTriggered: {
Util.openSetting()
}
}
MenuItem {
text: '关于'
onTriggered: {
}
}
MenuItem {
text: '问题反馈'
onTriggered: {
}
}
MenuItem {
text: '重启'
onTriggered: Util.callGoSync("reboot")
}
MenuItem {
text: '退出程序'
onTriggered: Qt.quit()
}
}
}
}
IconButton {
......@@ -92,14 +133,6 @@ Item {
}
}
// DropShadow {
// anchors.fill: contentContainer
// radius: shadeWidth
// samples: shadeWidth
// spread: 0.1
// color: "#80000000"
// source: contentContainer
// }
DropShadow {
anchors.fill: contentContainer
horizontalOffset: -5
......@@ -123,38 +156,4 @@ Item {
Component.onCompleted: {
mainWindow = G.root
}
// 右键菜单
Menu {
id: moreMenu
MenuItem {
text: (App.appState.floatWindow.visible ? '隐藏' : '显示') + '悬浮窗'
onTriggered: {
App.appState.floatWindow.visible = !App.appState.floatWindow.visible
}
}
MenuItem {
text: '设置'
onTriggered: {
}
}
MenuItem {
text: '关于'
onTriggered: {
}
}
MenuItem {
text: '问题反馈'
onTriggered: {
}
}
MenuItem {
text: '重启'
onTriggered: Util.callGoSync("reboot")
}
MenuItem {
text: '退出程序'
onTriggered: Qt.quit()
}
}
}
......@@ -20,9 +20,9 @@ var useVipMap = map[downloader.TaskId]bool{}
func init() {
dep.OnInit(func() {
parallel := 1
parallel := 1024
manager = &downloader.Manager{
CoroutineNumber: parallel,
CoroutineNumber: 32,
SegmentSize: 1024 * 1024 * 2,
WroteToDiskBufferSize: 1024 * 512,
LinkResolver: pan_api.Link,
......@@ -43,6 +43,10 @@ func init() {
})
}
func Manager() *downloader.Manager {
return manager
}
func handleDownloadEvent(event *downloader.DownloadEvent) {
dep.NotifyQml("task.event", map[string]interface{}{
"type": event.Event,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册