-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.qml
551 lines (521 loc) · 16.6 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
import QtQuick 6
import QtQuick.Window 6
import QtQuick.Controls 6
import QtQuick.Layouts 6
import QtQuick.Controls.Material 6
ApplicationWindow {
id: main
title: "磁力链接搜索"
width: 1280
height: 720
minimumWidth: 960
minimumHeight: 540
visible: true
visibility: Window.Windowed
Material.theme: Material.Dark
Connections {
target : backend
function onLoadStateChanged(state, page_num) {
switch(state) {
case "error":
search.text = "搜索"
search.enabled = true
message_info.text = "加载错误,请稍后重试"
message_timer.start()
break
case "loading":
search.text = "正在搜索"
search.enabled = false
page_up.enabled = false
page_down.enabled = false
break
case "loaded":
search.text = "搜索"
search.enabled = true
page_up.enabled = page > 1
page_down.enabled = page < page_num
break
}
}
}
Component.onCompleted: {
var rules_data = backend.get_rules()
for (var i = 0; i < rules_data.length; i++) {
rules_model.append({
'key': rules_data[i]['key'],
'value': rules_data[i]['value'],
})
if (rules_data[i]['pro']) {
rules_pro_model.append({
'key': rules_data[i]['key'],
'value': rules_data[i]['value'],
})
}
}
rules.currentIndex = 0
var config = backend.get_config()
proxy_enable.checked = config["proxy"]["enable"]
if (config["proxy"]["type"] === "http") {
proxy_type_http.checked = true
} else if (config["proxy"]["type"] === "socks5") {
proxy_type_socks5.checked = true
}
proxy_host.text = config["proxy"]["host"]
proxy_port.text = config["proxy"]["port"]
proxy_username.text = config["proxy"]["username"]
proxy_password.text = config["proxy"]["password"]
}
Popup {
id: qr_code_popup
anchors.centerIn: parent
width: 360
height: 360
Image {
id: qr_code
anchors.fill: parent
}
}
Popup {
id: message_popup
x: (main.width-width)/2
y: 0
width: 200
height: 36
enter: Transition {
PropertyAnimation {
property: "y"
to: 36
duration: 200
}
}
exit: Transition {
PropertyAnimation {
property: "y"
to: 0
duration: 200
}
}
Label {
id: message_info
anchors.centerIn: parent
font.pointSize: 10
text: "消息提示"
}
}
Timer {
id: message_timer
interval: 1000
repeat: true
triggeredOnStart: true
property int message_show: 3
onTriggered: {
if (message_show == 3) {
message_popup.open()
}
message_show -= 1
if (message_show == 0) {
message_show = 3
message_timer.stop()
message_popup.close()
}
}
}
ApplicationWindow {
id: setting_window
title: "设置"
width: 600
height: 480
minimumWidth: 600
minimumHeight: 480
maximumWidth: 600
maximumHeight: 480
flags: Qt.Dialog
modality: Qt.WindowModal
Material.theme: Material.Dark
visible: false
ColumnLayout {
anchors.fill: parent
anchors.margins: 20
focus: true
RowLayout {
Layout.fillHeight: true
Layout.fillWidth: true
ListModel {
id: setting_menu_list
ListElement {
name: "搜索设置"
}
ListElement {
name: "代理设置"
}
ListElement {
name: "缓存设置"
}
}
Component {
id: setting_menu_item
ItemDelegate {
width: parent.width
height: 36
highlighted: ListView.isCurrentItem
RowLayout {
anchors.fill: parent
Layout.fillHeight: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter | Qt.AlignVCenter
Label {
text: model.name
Layout.leftMargin: 8
Layout.rightMargin: 8
Layout.fillWidth: true
}
}
onClicked: {
setting_menu.currentIndex = index
setting_menu_content.currentIndex = index
}
}
}
ListView {
id: setting_menu
Layout.minimumWidth: 120
Layout.fillHeight: true
spacing: 8
model: setting_menu_list
delegate: setting_menu_item
}
ToolSeparator {
bottomPadding: -52
topPadding: 0
Layout.fillHeight: true
}
StackLayout {
id: setting_menu_content
currentIndex: 0
Layout.minimumWidth: 400
Layout.fillHeight: true
Layout.fillWidth: true
Item {
Label {
text: "搜索设置"
}
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
GridLayout {
rowSpacing: 16
columnSpacing: 20
anchors {
top: parent.top
left: parent.left
right: parent.right
rightMargin: 36
}
columns: 2
Label { text: "启用代理" }
Switch {
id: proxy_enable
text: checked ? "是" : "否"
hoverEnabled: false
}
Label { text: "代理类型" }
RowLayout {
width: 100
height: 100
RadioButton {
id: proxy_type_http
text: "HTTP"
hoverEnabled: false
}
RadioButton {
id: proxy_type_socks5
text: "SOCKS5"
hoverEnabled: false
}
}
Label { text: "代理地址" }
TextField {
id: proxy_host
Layout.fillWidth: true
hoverEnabled: false
selectByMouse: true
}
Label { text: "代理端口" }
TextField {
id: proxy_port
Layout.fillWidth: true
hoverEnabled: false
selectByMouse: true
validator: IntValidator { bottom: 0; top: 65535 }
}
Label { text: "代理账号" }
TextField {
id: proxy_username
Layout.fillWidth: true
hoverEnabled: false
selectByMouse: true
}
Label { text: "代理密码" }
TextField {
id: proxy_password
Layout.fillWidth: true
hoverEnabled: false
selectByMouse: true
echoMode: TextInput.Password
}
}
}
Item {
Label {
text: "缓存设置"
}
}
}
}
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Button {
text: "确定"
onClicked: {
console.log("保存")
}
}
Button {
text: "取消"
onClicked: close()
}
}
}
}
menuBar: MenuBar {
Menu {
title: "磁力链接搜索"
MenuItem {
text: "搜索设置"
onTriggered: {
setting_window.visible = true
}
}
MenuItem {
id: list_pro_ctrl
text: "只加载优质规则"
onTriggered: {
switch(text) {
case "只加载优质规则":
rules.model = rules_pro_model
list_pro_ctrl.text = "加载全部规则"
break
case "加载全部规则":
rules.model = rules_model
list_pro_ctrl.text = "只加载优质规则"
break
}
}
}
MenuItem {
text: "退出"
onTriggered: Qt.quit()
}
}
Menu {
title: "扩展功能"
MenuItem {
text: "网盘搜索"
onTriggered: {
console.log("网盘搜索")
}
}
MenuItem {
text: "视频下载"
onTriggered: {
console.log("视频下载")
}
}
}
Menu {
title: "帮助"
MenuItem {
text: "使用手册"
onTriggered: console.log("打开网页")
}
MenuItem {
text: "关于"
onTriggered: console.log("检查更新等")
}
}
}
ListModel { id: rules_pro_model }
ListModel { id: rules_model }
property int page: 1
Item {
id: search_info
height: 80
ComboBox {
id: rules
x: 36
y: 20
width: 180
model: rules_model
textRole: "value"
valueRole: "key"
}
TextField {
id: search_terms
text: "龙珠"
width: 480
anchors {
top: rules.top
left: rules.right
leftMargin: 20
}
hoverEnabled: false
selectByMouse: true
placeholderText: "搜索词"
font.pointSize: 12
}
Button {
id: search
width: 80
anchors {
top: search_terms.top
left: search_terms.right
leftMargin: 20
}
text: "搜索"
onClicked: {
backend.search(rules.currentValue, search_terms.text, page)
}
}
Button {
id: page_up
width: 40
anchors {
top: search_terms.top
left: search.right
leftMargin: 20
}
text: "▲"
enabled: false
onClicked: {
if (page === 1) {
return
}
page -= 1
backend.search(rules.currentValue, search_terms.text, page)
}
}
Button {
id: page_down
width: 40
anchors {
top: search_terms.top
left: page_up.right
leftMargin: 10
}
text: "▼"
enabled: false
onClicked: {
page += 1
backend.search(rules.currentValue, search_terms.text, page)
}
}
}
ListView {
id: search_result
anchors {
top: search_info.bottom
right: parent.right
bottom: parent.bottom
left: parent.left
topMargin: 20
rightMargin: 36
bottomMargin: 20
leftMargin: 36
}
spacing: 20
clip: true
ScrollBar.vertical: ScrollBar {}
boundsBehavior: Flickable.StopAtBounds
model: backend.search_result_model
delegate: Item {
width: main.width - 80
height: 80
Column {
id: info
anchors {
left: parent.left
right: handler.left
verticalCenter: parent.verticalCenter
}
Label {
anchors {
left: parent.left
right: parent.right
rightMargin: 16
}
text: model.name
font.pixelSize: 16
bottomPadding: 20
clip: true
}
Row {
spacing: 20
Label {
text: "热度: " + model.hot
color: "gray"
font.pixelSize: 12
}
Label {
text: "文件大小: " + model.size
color: "gray"
font.pixelSize: 12
}
Label {
text: "创建时间: " + model.time
color: "gray"
font.pixelSize: 12
}
}
}
Row {
id: handler
anchors {
right: parent.right
rightMargin: 20
verticalCenter: parent.verticalCenter
}
spacing: 20
Button {
id: qrcode
height: 40
text: "二维码"
onClicked: {
qr_code.source = backend.magnet_qr_code(model.magnet)
qr_code_popup.open()
}
}
Button {
id: download
height: 40
text: "迅雷下载"
onClicked: {
backend.download(model.magnet)
}
}
Button {
id: copy_url
height: 40
text: "复制链接"
onClicked: {
backend.copy_to_clipboard(model.magnet)
message_info.text = "复制成功"
message_timer.start()
}
}
}
}
}
}