-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.qml
712 lines (570 loc) · 21.5 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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
/*
Copyright (c) 2016 - 2017 Sylvia van Os <sylvia@hackerchick.me>
This file is part of Pext
Pext is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.0
import QtQuick.Window 2.0
ApplicationWindow {
id: applicationWindow
property string version: applicationVersion
property string platform: systemPlatform
property int margin: 10
width: Screen.width
height: 300
flags: Qt.Window
SystemPalette { id: palette; colorGroup: SystemPalette.Active }
function getActiveList() {
var tab = tabs.getTab(tabs.currentIndex);
if (typeof tab === "undefined")
return;
if (tab.item.children[0].children[0].visible) {
return tab.item.children[0].children[0].contentItem;
} else {
return tab.item.children[0].children[2].contentItem;
}
}
function isContextMenuVisible() {
var tab = tabs.getTab(tabs.currentIndex);
if (typeof tab === "undefined")
return;
return tab.item.children[0].children[0].visible;
}
function openBaseMenu() {
var tab = tabs.getTab(tabs.currentIndex);
if (typeof tab === "undefined")
return;
tab.item.children[0].children[2].contentItem.openBaseMenu();
}
function openContextMenu() {
var tab = tabs.getTab(tabs.currentIndex);
if (typeof tab === "undefined")
return;
tab.item.children[0].children[2].contentItem.openContextMenu();
}
function moveUp() {
getActiveList().decrementCurrentIndex();
}
function moveDown() {
getActiveList().incrementCurrentIndex();
}
function pageUp() {
var listView = getActiveList();
var newIndex = listView.currentIndex - (listView.height / listView.currentItem.height) + 1;
if (newIndex < 0)
listView.currentIndex = 0;
else
listView.currentIndex = newIndex;
listView.positionViewAtIndex(listView.currentIndex, ListView.Beginning);
}
function pageDown() {
var listView = getActiveList();
var newIndex = listView.currentIndex + (listView.height / listView.currentItem.height);
var maxIndex = listView.count - 1;
if (newIndex > maxIndex)
listView.currentIndex = maxIndex;
else
listView.currentIndex = newIndex;
listView.positionViewAtIndex(listView.currentIndex, ListView.Beginning);
}
function nextTab() {
if (tabs.currentIndex < tabs.count - 1)
tabs.currentIndex += 1;
else
tabs.currentIndex = 0;
}
function prevTab() {
if (tabs.currentIndex > 0)
tabs.currentIndex -= 1;
else
tabs.currentIndex = tabs.count - 1;
}
function switchTab(id) {
if (tabs.count - 1 >= id)
tabs.currentIndex = id;
}
Shortcut {
objectName: "escapeShortcut"
sequence: "Escape"
}
Shortcut {
objectName: "tabShortcut"
sequence: "Tab"
}
Shortcut {
sequence: "Ctrl+Shift+."
onActivated: openBaseMenu();
}
Shortcut {
sequence: "Ctrl+."
onActivated: openContextMenu();
}
Shortcut {
sequence: StandardKey.MoveToPreviousLine
onActivated: moveUp();
}
Shortcut {
sequence: "Ctrl+K"
onActivated: moveUp();
}
Shortcut {
sequence: StandardKey.MoveToNextLine
onActivated: moveDown();
}
Shortcut {
sequence: "Ctrl+J"
onActivated: moveDown();
}
Shortcut {
sequence: StandardKey.MoveToPreviousPage
onActivated: pageUp()
}
Shortcut {
sequence: "Ctrl+B"
onActivated: pageUp()
}
Shortcut {
sequence: StandardKey.MoveToNextPage
onActivated: pageDown()
}
Shortcut {
sequence: "Ctrl+F"
onActivated: pageDown()
}
Shortcut {
sequence: "Ctrl+Tab"
onActivated: nextTab()
}
Shortcut {
sequence: "Ctrl+Shift+Tab" // StandardKey.PreviousChild does not work on my machine
onActivated: prevTab()
}
Shortcut {
sequence: "Alt+1"
onActivated: switchTab(0)
}
Shortcut {
sequence: "Alt+2"
onActivated: switchTab(1)
}
Shortcut {
sequence: "Alt+3"
onActivated: switchTab(2)
}
Shortcut {
sequence: "Alt+4"
onActivated: switchTab(3)
}
Shortcut {
sequence: "Alt+5"
onActivated: switchTab(4)
}
Shortcut {
sequence: "Alt+6"
onActivated: switchTab(5)
}
Shortcut {
sequence: "Alt+7"
onActivated: switchTab(6)
}
Shortcut {
sequence: "Alt+8"
onActivated: switchTab(7)
}
Shortcut {
sequence: "Alt+9"
onActivated: switchTab(8)
}
Shortcut {
sequence: "Alt+0"
onActivated: switchTab(9)
}
menuBar: MenuBar {
Menu {
title: "&Pext"
MenuItem {
objectName: "menuRestart"
text: qsTr("Restart")
}
MenuItem {
objectName: "menuQuit"
text: qsTr("Quit")
shortcut: StandardKey.Quit
}
MenuItem {
objectName: "menuQuitWithoutSaving"
text: qsTr("Quit without saving")
}
}
Menu {
title: qsTr("&Module")
MenuItem {
objectName: "menuReloadActiveModule"
text: qsTr("Reload active module")
shortcut: StandardKey.Refresh
}
MenuItem {
id: menuCloseActiveModule
objectName: "menuCloseActiveModule"
text: qsTr("Close active module")
shortcut: StandardKey.Close
}
MenuSeparator { }
MenuItem {
id: menuLoadModule
objectName: "menuLoadModule"
signal loadModuleRequest(string name, string settings)
text: qsTr("Load module")
shortcut: StandardKey.AddTab
onTriggered: {
if (Object.keys(modules).length == 0) {
var noModulesInstalledDialog = Qt.createComponent("NoModulesInstalledDialog.qml");
noModulesInstalledDialog.createObject(applicationWindow);
} else {
var loadModuleDialog = Qt.createComponent("LoadModuleDialog.qml");
loadModuleDialog.createObject(applicationWindow,
{"modules": Object.keys(modules).sort(),
"loadRequest": loadModuleRequest,
"modulesPath": modulesPath});
}
}
}
MenuItem {
id: menuManageModules
objectName: "menuManageModules"
text: qsTr("Manage modules")
signal updateModuleRequest(string name)
signal uninstallModuleRequest(string name)
onTriggered: {
if (Object.keys(modules).length == 0) {
var noModulesInstalledDialog = Qt.createComponent("NoModulesInstalledDialog.qml");
noModulesInstalledDialog.createObject(applicationWindow);
} else {
var manageDialog = Qt.createComponent("ManageDialog.qml");
manageDialog.createObject(applicationWindow,
{"manageableObjects": modules,
"updateRequest": updateModuleRequest,
"uninstallRequest": uninstallModuleRequest});
}
}
}
Menu {
id: menuInstallModule
objectName: "menuInstallModule"
title: qsTr("Install module")
signal installModuleRequest(string url)
MenuItem {
text: qsTr("From online module list")
property var repositories:
[{
"name": "Pext team",
"url": "https://pext.hackerchick.me/modules_v2.json"
}, {
"name": "Other developers",
"url": "https://pext.hackerchick.me/third_party_modules_v2.json"
}]
onTriggered: {
var installModuleFromRepositoryDialog = Qt.createComponent("InstallModuleFromRepositoryDialog.qml");
installModuleFromRepositoryDialog.createObject(applicationWindow,
{"applicationWindow": applicationWindow,
"installRequest": menuInstallModule.installModuleRequest,
"repositories": repositories})
}
}
MenuItem {
text: qsTr("From URL")
onTriggered: {
var installModuleFromURLDialog = Qt.createComponent("InstallModuleFromURLDialog.qml");
installModuleFromURLDialog.createObject(applicationWindow,
{"installRequest": menuInstallModule.installRequest});
}
}
}
MenuItem {
objectName: "menuUpdateAllModules"
text: qsTr("Update all modules")
signal updateAllModulesRequest()
onTriggered: {
updateAllModulesRequest()
}
}
}
Menu {
title: qsTr("&Theme")
MenuItem {
id: menuLoadTheme
objectName: "menuLoadTheme"
signal loadThemeRequest(string name)
text: qsTr("Switch theme")
onTriggered: {
if (Object.keys(themes).length == 0) {
var noThemesInstalledDialog = Qt.createComponent("NoThemesInstalledDialog.qml");
noThemesInstalledDialog.createObject(applicationWindow);
} else {
var loadThemeDialog = Qt.createComponent("LoadThemeDialog.qml");
loadThemeDialog.createObject(applicationWindow,
{"themes": Object.keys(themes).sort(),
"loadRequest": loadThemeRequest,
"themesPath": themesPath});
}
}
}
MenuItem {
id: menuManageThemes
objectName: "menuManageThemes"
text: qsTr("Manage themes")
signal updateThemeRequest(string name)
signal uninstallThemeRequest(string name)
onTriggered: {
if (Object.keys(themes).length == 0) {
var noThemesInstalledDialog = Qt.createComponent("NoThemesInstalledDialog.qml");
noThemesInstalledDialog.createObject(applicationWindow);
} else {
var manageDialog = Qt.createComponent("ManageDialog.qml");
manageDialog.createObject(applicationWindow,
{"manageableObjects": themes,
"updateRequest": updateThemeRequest,
"uninstallRequest": uninstallThemeRequest});
}
}
}
Menu {
id: menuInstallTheme
objectName: "menuInstallTheme"
title: qsTr("Install theme")
signal installThemeRequest(string url)
MenuItem {
text: qsTr("From online theme list")
property var repositories:
[{
"name": "Pext team",
"url": "https://pext.hackerchick.me/themes_v2.json"
}, {
"name": "Other developers",
"url": "https://pext.hackerchick.me/third_party_themes_v2.json"
}]
onTriggered: {
var installThemeFromRepositoryDialog = Qt.createComponent("InstallThemeFromRepositoryDialog.qml");
installThemeFromRepositoryDialog.createObject(applicationWindow,
{"applicationWindow": applicationWindow,
"installRequest": menuInstallTheme.installThemeRequest,
"repositories": repositories})
}
}
MenuItem {
text: qsTr("From URL")
onTriggered: {
var installThemeFromURLDialog = Qt.createComponent("InstallThemeFromURLDialog.qml");
installThemeFromURLDialog.createObject(applicationWindow,
{"installRequest": menuInstallTheme.installThemeRequest});
}
}
}
MenuItem {
objectName: "menuUpdateAllThemes"
text: qsTr("Update all themes")
signal updateAllThemesRequest()
onTriggered: {
updateAllThemesRequest()
}
}
}
Menu {
title: qsTr("&Settings")
ExclusiveGroup {
id: menuSortGroup
objectName: "menuSortGroup"
}
MenuItem {
objectName: "menuSortModule"
text: qsTr("Sort by module choice")
checkable: true
exclusiveGroup: menuSortGroup
}
MenuItem {
objectName: "menuSortAscending"
text: qsTr("Sort ascending")
checkable: true
exclusiveGroup: menuSortGroup
}
MenuItem {
objectName: "menuSortDescending"
text: qsTr("Sort descending")
checkable: true
exclusiveGroup: menuSortGroup
}
MenuSeparator { }
ExclusiveGroup {
id: menuMinimizeGroup
objectName: "menuMinimizeGroup"
}
MenuItem {
objectName: "menuMinimizeNormally"
text: qsTr("Minimize normally")
checkable: true
exclusiveGroup: menuMinimizeGroup
}
MenuItem {
objectName: "menuMinimizeToTray"
text: qsTr("Minimize to tray")
checkable: true
exclusiveGroup: menuMinimizeGroup
}
MenuItem {
objectName: "menuMinimizeNormallyManually"
text: qsTr("Manual only: Minimize normally")
checkable: true
exclusiveGroup: menuMinimizeGroup
}
MenuItem {
objectName: "menuMinimizeToTrayManually"
text: qsTr("Manual only: Minimize to tray")
checkable: true
exclusiveGroup: menuMinimizeGroup
}
MenuSeparator { }
MenuItem {
objectName: "menuShowTrayIcon"
text: qsTr("Show tray icon")
checkable: true
}
MenuSeparator { }
MenuItem {
objectName: "menuEnableUpdateCheck"
text: qsTr("Automatically check for updates")
checkable: true
}
}
Menu {
title: qsTr("&Help")
MenuItem {
objectName: "menuAbout"
text: qsTr("About")
onTriggered: {
var aboutDialog = Qt.createComponent("AboutDialog.qml");
aboutDialog.createObject(applicationWindow);
}
}
MenuItem {
objectName: "menuCheckForUpdates"
text: qsTr("Check for updates")
}
MenuItem {
objectName: "menuHomepage"
text: qsTr("Visit homepage")
}
}
}
ColumnLayout {
anchors.fill: parent
anchors.margins: margin
GridLayout {
Layout.minimumHeight: 30
Layout.fillHeight: true
Button {
anchors.top: parent.top
anchors.bottom: parent.bottom
enabled: tabs.getTab(tabs.currentIndex) != null && tabs.count > 0 && (searchInput.length > 0 || tabs.getTab(tabs.currentIndex).item.children[0].children[2].contentItem.depth > 0 || tabs.getTab(tabs.currentIndex).item.children[0].children[0].visible)
width: 60
text: searchInput.length > 0 ? qsTr("Clear") : qsTr("Back")
objectName: "backButton"
}
TextField {
anchors.top: parent.top
anchors.bottom: parent.bottom
enabled: tabs.count > 0
placeholderText: tabs.count > 0 ? qsTr("Type to search") : ""
id: searchInput
objectName: "searchInputModel"
focus: true
onFocusChanged: {
focus = true
}
Layout.fillWidth: true
}
}
TabView {
visible: tabs.count > 0
id: tabs
objectName: "tabs"
Layout.fillHeight: true
Layout.fillWidth: true
}
GridLayout {
flow: applicationWindow.width > 700 ? GridLayout.LeftToRight : GridLayout.TopToBottom
visible: tabs.count == 0
TextEdit {
text: "<h2>" + qsTr("Design philosophy") + "</h2>" +
"<p>" + qsTr("Pext is designed to stay out of your way. As soon as a module deems you are done using it, Pext will hide itself to the system tray. If you need to reach Pext again after it hid itself, just start it again or open it from the system tray.") + "</p>"
color: palette.text
textFormat: TextEdit.RichText
readOnly: true
selectByMouse: false
wrapMode: TextEdit.Wrap
horizontalAlignment: TextEdit.AlignHCenter
verticalAlignment: TextEdit.AlignVCenter
Layout.fillHeight: true
Layout.fillWidth: true
}
Image {
visible: applicationWindow.width > 900
asynchronous: true
source: "../images/scalable/logo.svg"
fillMode: Image.Pad
horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter
Layout.fillHeight: true
Layout.fillWidth: true
Layout.minimumWidth: sourceSize.width + 50
anchors.leftMargin: 30
anchors.rightMargin: 30
}
TextEdit {
objectName: "introScreen"
property int modulesInstalledCount
text: "<h2>" + qsTr("Getting started") + "</h2>" +
"<p>" + qsTr("To get started, press <kbd>%1</kbd> to open a new tab. When you are done with a tab, you can always close it by pressing <kbd>%2</kbd>. You currently have %n module(s) installed. You can manage modules in the Module menu.", "", modulesInstalledCount).arg(menuLoadModule.shortcut).arg(menuCloseActiveModule.shortcut) + "</p>"
color: palette.text
textFormat: TextEdit.RichText
readOnly: true
selectByMouse: false
wrapMode: TextEdit.Wrap
horizontalAlignment: TextEdit.AlignHCenter
verticalAlignment: TextEdit.AlignVCenter
Layout.fillHeight: true
Layout.fillWidth: true
}
}
}
statusBar: StatusBar {
RowLayout {
width: parent.width
Label {
objectName: "statusText"
Layout.fillWidth: true
}
Label {
objectName: "statusQueue"
property var entriesLeftForeground
property var entriesLeftBackground
anchors.right: parent.right
text: entriesLeftForeground || entriesLeftBackground ?
qsTr("Processing: %1 (%2)").arg(entriesLeftForeground).arg(entriesLeftBackground) :
tabs.getTab(tabs.currentIndex) != null && !tabs.getTab(tabs.currentIndex).item.children[0].children[2].contentItem.hasEntries ?
qsTr("Waiting") : qsTr("Ready")
}
}
}
}