-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.qml
More file actions
1785 lines (1713 loc) · 63.8 KB
/
Copy pathPanel.qml
File metadata and controls
1785 lines (1713 loc) · 63.8 KB
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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick
import QtQuick.Controls
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui
import "Model.js" as Model
Panel {
id: root
moduleName: "gotar.omarchy-themes"
manageIpc: false
property var anchorItem: null
property var hostWidget: null
// shell-theme-aware palette
readonly property color fg: barForeground
readonly property color dim: Qt.darker(fg, 1.5)
readonly property color faint: Qt.darker(fg, 2.2)
readonly property color okC: "#8fd08a"
readonly property color errC: "#e74c5b"
readonly property string mono: Style.font.family
// ---- data
property var db: null // { base, fetchedAt, count, entries: [...] }
property var filtered: [] // indexes into db.entries passing the filters
property var facets: ({ tone: {}, color: {}, resMin: {}, resMax: {} })
property string q: ""
property string tone: ""
property string color: ""
property string resMin: ""
property string resMax: ""
property var crumbs: []
property int phase: 0 // 0 loading, 1 ready, 2 error
property string phaseMsg: ""
property string currentTheme: ""
// ---- detail (variant picker)
property int detailIdx: -1
property string detailPath: ""
property int detailVariant: 0
property var detailVariants: []
property int applyPhase: 0 // 0 none, 1 installing, 2 setting, 3 done, 4 error
property string applySlug: ""
property string applyMsg: ""
property int cursorIdx: 0
// ---- single-flight operation state ----
// Only one apply/wallpaper operation may run at a time; UI entry points are
// gated on operationBusy so a fast user can never start a second install
// while one is in flight (which used to let an unstable slug win).
readonly property bool operationBusy:
applyProc.running || wallpaperProc.running || themeSetProc.running
|| root.themeSetCycleActive || root.activationPending
property string operationKind: "" // "" | "theme" | "wallpaper"
property bool pendingForce: false
property bool fetchExitSeen: false
property bool fetchStreamSeen: false
property bool fetchExpectedStop: false
readonly property bool fetchSettling:
root.fetchExitSeen !== root.fetchStreamSeen
|| (root.fetchExpectedStop && (!root.fetchExitSeen || !root.fetchStreamSeen))
property string applyWarn: ""
property string themeSetError: ""
property bool themeSetCycleActive: false
property bool themeSetExitSeen: false
property bool themeSetStderrSeen: false
property int themeSetExitCode: -1
property bool activationPending: false
property int activateCheckCount: 0
readonly property bool hasActiveFilters:
q !== "" || tone !== "" || color !== "" || resMin !== "" || resMax !== ""
// ---- auto random + wallpaper-only
property bool wallpaperOnly: false
property int autoIntervalSec: 0 // 0=Off, 300=5m, 900=15m, 1800=30m, 3600=60m
readonly property var autoOptions: [0, 300, 900, 1800, 3600]
readonly property var autoLabels: ["Off", "5m", "15m", "30m", "60m"]
readonly property string modeLabel:
applyPhase > 0 ? "APPLY" :
detailPath !== "" ? "VIEW" : "BROWSE"
readonly property int gridCols: 4
function scriptPath(name) {
var u = String(Qt.resolvedUrl("bin/" + name))
if (u.startsWith("file://")) return u.substring(7)
return u
}
function baseOf() { return db ? String(db.base || "") : "" }
// Builds a media URL. Both parts are validate-it-early: `base` comes from
// the manifest (https + allowlisted host) and rel must be a safe relative
// path — anything else yields "" so Image/Process never see it.
function safeRel(rel) {
// Mirrors _sec.safe_relpath: '..' and '.' are rejected as path components,
// not substrings, so file names like "img..jpg" still load. Trailing slash
// and "//" are also rejected (would make Image/Process hit a directory).
var s = String(rel || "")
return s.length <= 512 && /^[A-Za-z0-9_./+@=~-]+$/.test(s)
&& !s.startsWith("/") && !s.startsWith("\\")
&& s.split("/").indexOf("..") === -1 && s.split("/").indexOf(".") === -1
&& s.indexOf(":") === -1 && !s.endsWith("/") && s.indexOf("//") === -1
}
function url(rel) {
var b = baseOf()
if (!b || !/^https:\/\/[A-Za-z0-9.-]+\//.test(b + "/")) return ""
if (!root.safeRel(rel)) return ""
return b + "/" + String(rel).replace(/^\/+/, "")
}
function entryAt(i) { return db && db.entries ? db.entries[i] : null }
function setQuery(text) {
root.q = String(text || "")
qTimer.restart()
}
function buildCrumbs() {
var c = []
if (root.q) c.push({ key: "search", label: "q:\u0022" + root.q + "\u0022" })
if (root.tone) c.push({ key: "tone", label: "tone:" + root.tone })
if (root.color) c.push({ key: "color", label: "color:" + root.color })
if (root.resMin || root.resMax) {
var v
if (root.resMin && root.resMax) v = "res:" + root.resMin + ".." + root.resMax
else if (root.resMin) v = "res:\u2265" + root.resMin
else v = "res:\u2264" + root.resMax
c.push({ key: "res", label: v })
}
root.crumbs = c
}
function refreshFilters() {
if (!root.db) return
var res = Model.apply(root.db.entries, root.q, root.tone, root.color,
root.resMin, root.resMax)
root.filtered = res.filtered
root.facets = res.facets
if (root.cursorIdx >= res.filtered.length)
root.cursorIdx = Math.max(0, res.filtered.length - 1)
root.buildCrumbs()
}
function toggleFacet(key, value) {
if (key === "tone") root.tone = (root.tone === value) ? "" : value
else if (key === "color") root.color = (root.color === value) ? "" : value
else if (key === "res-min") root.resMin = (root.resMin === value) ? "" : value
else if (key === "res-max") root.resMax = (root.resMax === value) ? "" : value
root.refreshFilters()
}
function clearCrumb(key) {
if (key === "search") { root.q = ""; searchField.text = "" }
else if (key === "tone") root.tone = ""
else if (key === "color") root.color = ""
else if (key === "res") { root.resMin = ""; root.resMax = "" }
root.refreshFilters()
}
function resetFilters() {
root.tone = ""
root.color = ""
root.resMin = ""
root.resMax = ""
root.q = ""
searchField.text = ""
root.refreshFilters()
}
function startLoad(force) {
if (fetchProc.running || root.fetchSettling) {
// Queue the forced replacement, but never reuse the Process until both
// exit and buffered-stream completion from the old generation arrived.
if (force) root.pendingForce = true
return
}
root.fetchExitSeen = false
root.fetchStreamSeen = false
root.fetchExpectedStop = false
root.phase = 0
root.phaseMsg = force ? "re-fetching index (35 MB)\u2026" : "loading index\u2026"
var sc=root.scriptPath("fetch-manifest.py")
fetchProc.command = ["python3", sc].concat(force ? ["--force"] : [])
fetchWatchdog.start()
fetchProc.running = true
}
function finishFetchCycle() {
if (!root.fetchExitSeen || !root.fetchStreamSeen) return
root.fetchExpectedStop = false
if (root.pendingForce) {
root.pendingForce = false
root.startLoad(true)
}
}
function handleFetchOutput(text) {
fetchWatchdog.stop()
root.fetchStreamSeen = true
if (root.fetchExpectedStop) {
root.finishFetchCycle()
return
}
var j = null
try { j = JSON.parse(text) } catch (e) { j = null }
if (!j || j.error || !j.entries) {
root.phase = 2
root.phaseMsg = (j && j.error) ? String(j.error) : "bad manifest"
root.finishFetchCycle()
return
}
root.db = j
Model.prep(j.entries)
root.phase = 1
root.phaseMsg = ""
root.cursorIdx = 0
root.refreshFilters()
root.loadCurrentTheme()
root.finishFetchCycle()
}
function loadCurrentTheme() {
if (themeCurProc.running) return
themeCurProc.command = ["omarchy", "theme", "current"]
themeCurProc.running = true
}
function currentThemeSlug() {
return Model.slugFromThemeCurrent(root.currentTheme)
}
function moveCursor(dx, dy) {
var n = root.filtered.length
if (!root.db || !n) return
if (root.cursorIdx < 0) root.cursorIdx = 0
if (root.cursorIdx >= n) root.cursorIdx = n - 1
var cols = root.gridCols
var row = Math.floor(root.cursorIdx / cols)
var col = root.cursorIdx % cols
var lastRow = Math.floor((n - 1) / cols)
if (dy > 0) {
row = Math.min(lastRow, row + 1)
col = Math.min(col, (n - 1) - row * cols)
} else if (dy < 0) {
row = Math.max(0, row - 1)
col = Math.min(col, (n - 1) - row * cols)
} else if (dx > 0) {
col = Math.min(cols - 1, col + 1)
} else if (dx < 0) {
col = Math.max(0, col - 1)
}
root.cursorIdx = Math.max(0, Math.min(n - 1, row * cols + col))
gridView.positionViewAtIndex(root.cursorIdx, GridView.Contain)
}
function openDetailAt(pos) {
if (!root.db || !root.filtered.length) return
pos = Math.max(0, Math.min(root.filtered.length - 1, Math.max(0, pos)))
var full = root.filtered[pos]
var e = root.db.entries[full]
root.detailIdx = full
root.detailPath = e.p
root.detailVariants = Model.variantsOf(e)
root.detailVariant = 0
// Only reset the apply feedback when nothing is in flight.
if (!root.operationBusy) {
root.applyPhase = 0
root.applyMsg = ""
root.applyWarn = ""
}
}
function closeDetail() {
root.detailIdx = -1
root.detailPath = ""
root.detailVariants = []
// Keep an in-flight operation's state visible so closing the detail view
// cannot make a running apply look like it was cancelled.
if (!root.operationBusy) {
root.applyPhase = 0
root.applyMsg = ""
root.applyWarn = ""
}
}
function detailNav(delta) {
if (!root.db || !root.filtered.length) return
var pos = root.filtered.indexOf(root.detailIdx)
if (pos < 0) pos = 0
pos = (pos + delta + root.filtered.length) % root.filtered.length
root.openDetailAt(pos)
}
function cycleVariant(d) {
var n = root.detailVariants.length
if (!n) return
root.detailVariant = ((root.detailVariant + d) % n + n) % n
}
function applySelected() {
if (root.operationBusy || root.applyPhase === 1 || root.applyPhase === 2) return
var vs = root.detailVariants
if (!vs.length) return
var v = vs[root.detailVariant % vs.length]
if (!v.n || !root.baseOf() || (!root.wallpaperOnly && !v.ct)) {
root.applyPhase = 4
root.applyMsg = "missing apply data in index"
return
}
if (!root.safeSlug(v.n)) {
root.applyPhase = 4
root.applyMsg = "theme name is not a safe slug"
return
}
root.applySlug = v.n
root.applyWarn = ""
root.applyPhase = 1
root.applyMsg = "downloading " + v.n
var e = (root.db && root.detailIdx >= 0) ? root.db.entries[root.detailIdx] : null
// Full-res original as the fallback background (med is a downscaled copy).
var fallbackP = e ? (e.p || "") : ""
// wallpaper-only: set image directly, no theme
if (root.wallpaperOnly) {
var rel = e ? (e.med || e.p || v.bg || "") : (v.bg || "")
if (!rel) { root.applyPhase = 4; root.applyMsg = "missing wallpaper"; return }
root.applySlug = v.n
root.applyPhase = 1
root.applyMsg = "setting wallpaper…"
root.operationKind = "wallpaper"
wallpaperProc.command = ["timeout", "340", "python3", root.scriptPath("set-wallpaper.py"), root.baseOf(), rel]
wallpaperProc.running = true
return
}
root.operationKind = "theme"
applyProc.command = ["timeout", "700", "python3", root.scriptPath("apply-theme.py"),
v.n, root.baseOf(), v.ct, v.bg, fallbackP].slice()
applyProc.running = true
}
function applicableThemeVariants(entry) {
var all = Model.variantsOf(entry)
var out = []
for (var i = 0; i < all.length; i++) {
if (all[i].n && all[i].ct && root.safeSlug(all[i].n)) out.push(all[i])
}
return out
}
function applyRandom() {
if (!db || !filtered.length) return
if (root.operationBusy) return
// Pick a wallpaper that can actually be applied so shuffle/AUTO never
// silently no-ops on an entry that lacks a variant or media path.
var cands = []
if (wallpaperOnly) {
for (var i = 0; i < filtered.length; i++) {
var e = db.entries[filtered[i]]
if (e && (e.med || e.p)) cands.push(filtered[i])
}
if (!cands.length) {
applyPhase = 4; applyMsg = "no wallpaper available in current filter"
return
}
var full = cands[Math.floor(Math.random() * cands.length)]
var ee = db.entries[full]
var rel = ee.med || ee.p
// show in detail briefly then apply
detailIdx = full; detailPath = ee.p; detailVariants = Model.variantsOf(ee); detailVariant = 0
applyWallpaper(rel)
} else {
for (var j = 0; j < filtered.length; j++) {
var ej = db.entries[filtered[j]]
if (ej && root.applicableThemeVariants(ej).length) cands.push(filtered[j])
}
if (!cands.length) {
applyPhase = 4; applyMsg = "no theme variants in current filter"
return
}
var f2 = cands[Math.floor(Math.random() * cands.length)]
var e2 = db.entries[f2]
var vs2 = root.applicableThemeVariants(e2)
var v2 = vs2[Math.floor(Math.random() * vs2.length)]
detailIdx = f2; detailPath = e2.p; detailVariants = vs2; detailVariant = vs2.indexOf(v2)
applySelected()
}
}
function applyWallpaper(rel) {
if (!rel || !baseOf()) return
if (root.operationBusy) return
applyPhase = 1; applyMsg = "setting wallpaper…"; applyWarn = ""
root.operationKind = "wallpaper"
wallpaperProc.command = ["timeout", "340", "python3", root.scriptPath("set-wallpaper.py"), baseOf(), rel]
wallpaperProc.running = true
}
function setAutoInterval(sec) { autoIntervalSec = sec }
// Label of the currently selected AUTO step ("Off"/"5m"/…), from the
// parallel autoOptions/autoLabels arrays.
function autoSelLabel() {
var i = root.autoOptions.indexOf(root.autoIntervalSec)
return i >= 0 ? root.autoLabels[i] : "Off"
}
// Slug validation: theme names come from the remote index and are passed as
// argv to `omarchy theme set`. Only lowercase slugs with [a-z0-9._-] are
// allowed; '..' is rejected as a substring (mirrors _sec.safe_slug).
function safeSlug(s) {
s = String(s || "")
return /^[a-z0-9][a-z0-9._-]*$/.test(s) && s.indexOf("..") === -1 && s.length <= 256
}
onOpenedChanged: {
if (opened) {
root.startLoad(false)
root.loadCurrentTheme()
}
}
IpcHandler {
target: "gotar.omarchy-themes"
function open(): string { root.open(); return "ok" }
function close(): string { root.close(); return "ok" }
function toggle(): string { root.toggle(); return "ok" }
}
Component.onCompleted: {
if (opened) {
root.startLoad(false)
root.loadCurrentTheme()
}
}
// ---- processes ----------------------------------------------------------
Process {
id: fetchProc
running: false
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: root.handleFetchOutput(String(text || ""))
}
onExited: function(exitCode) {
root.fetchExitSeen = true
if (!root.fetchExpectedStop && exitCode !== 0 && root.phase === 0) {
root.phase = 2
root.phaseMsg = "index fetch failed (exit " + exitCode + ")"
}
root.finishFetchCycle()
}
}
Timer {
id: fetchWatchdog
interval: 180000
repeat: false
onTriggered: {
if (root.phase === 0) {
// Ignore buffered output from the canceled generation and keep retries
// queued until both exit and stream-finished callbacks have settled.
root.fetchExpectedStop = true
fetchProc.running = false
root.phase = 2
root.phaseMsg = "fetch timed out \u2014 the 35 MB index is unreachable"
}
}
}
Timer {
id: qTimer
interval: 150
repeat: false
onTriggered: root.refreshFilters()
}
Timer {
id: autoTimer
interval: root.autoIntervalSec * 1000
repeat: true
running: root.autoIntervalSec > 0 && root.db !== null && root.filtered.length > 0
onTriggered: root.applyRandom()
}
function finishThemeSetCycle() {
if (!root.themeSetCycleActive || !root.themeSetExitSeen || !root.themeSetStderrSeen) return
root.themeSetCycleActive = false
if (root.themeSetExitCode === 0) {
root.activationPending = true
root.activateCheckCount = 0
root.activateCheckTimer.start()
} else {
root.applyPhase = 4
root.applyMsg = "theme activation failed (exit " + root.themeSetExitCode + ")"
+ (root.themeSetError ? ": " + root.themeSetError : "")
root.operationKind = ""
}
}
// Activate-state confirmation: after an observable successful
// `omarchy theme set`, poll the canonical current slug.
function evalActivation() {
if (root.currentThemeSlug() === root.applySlug.toLowerCase()) {
root.activationPending = false
root.activateCheckTimer.stop()
root.applyPhase = 3
root.applyMsg = "\u2713 " + root.applySlug + (root.applyWarn ? " — background failed: " + root.applyWarn : "")
root.operationKind = ""
} else {
root.activateCheckCount += 1
if (root.activateCheckCount > 5) {
root.activationPending = false
root.activateCheckTimer.stop()
root.applyPhase = 4
root.applyMsg = "installed, but activation not confirmed (current: " + root.currentTheme + ")" + (root.applyWarn ? " — background failed: " + root.applyWarn : "")
root.operationKind = ""
} else {
root.activateCheckTimer.start()
}
}
}
Process {
id: themeCurProc
running: false
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: {
root.currentTheme = String(text || "").trim()
if (root.activationPending) root.evalActivation()
}
}
}
Process {
id: applyProc
running: false
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: function(text) {
try {
var j = JSON.parse(String(text || "{}"))
if (j && j.error) root.applyMsg = String(j.error)
else if (j && j.warning) {
root.applyWarn = String(j.warning)
root.applyMsg = "colors ok, background failed: " + root.applyWarn
}
} catch (e) {}
}
}
onExited: function(exitCode) {
if (exitCode === 0) {
if (!root.safeSlug(root.applySlug)) {
root.applyPhase = 4
root.applyMsg = "theme name is not a safe slug"
root.operationKind = ""
return
}
root.applyPhase = 2
root.applyMsg = "activating " + root.applySlug + (root.applyWarn ? " (background failed)" : "") + "…"
root.close()
root.themeSetError = ""
root.themeSetExitSeen = false
root.themeSetStderrSeen = false
root.themeSetExitCode = -1
root.themeSetCycleActive = true
themeSetProc.command = ["timeout", "180", "omarchy", "theme", "set", root.applySlug]
themeSetProc.running = true
} else {
root.applyPhase = 4
if (!root.applyMsg || root.applyMsg.startsWith("downloading")) root.applyMsg = "install failed" + (root.applyMsg ? ": " + root.applyMsg : "")
root.operationKind = ""
}
}
}
Process {
id: themeSetProc
running: false
stderr: StdioCollector {
waitForEnd: true
onStreamFinished: {
root.themeSetError = String(text || "").trim()
root.themeSetStderrSeen = true
root.finishThemeSetCycle()
}
}
onExited: function(exitCode) {
root.themeSetExitCode = exitCode
root.themeSetExitSeen = true
root.finishThemeSetCycle()
}
}
Process {
id: wallpaperProc
running: false
stdout: StdioCollector { waitForEnd: true; onStreamFinished: function(text) { try { var j=JSON.parse(String(text||"{}")); if(j&&j.error) root.applyMsg=String(j.error) } catch(e) {} } }
onExited: function(exitCode) {
root.operationKind = ""
if (exitCode === 0) { root.applyPhase = 3; root.applyMsg = "\u2713 wallpaper set"; root.close() }
else { root.applyPhase = 4; if(!root.applyMsg || root.applyMsg.startsWith("setting")) root.applyMsg = "wallpaper failed (exit " + exitCode + ")" }
}
}
Timer {
id: activateCheckTimer
interval: 2000
repeat: false
onTriggered: root.loadCurrentTheme()
}
// ---- UI ------------------------------------------------------------------
KeyboardPanel {
id: panel
anchorItem: root.anchorItem
owner: root.hostWidget || root
bar: root.bar
open: root.opened
focusTarget: keyCatcher
contentWidth: panel.fittedContentWidth(Style.space(1020))
contentHeight: panel.fittedContentHeight(Style.space(720))
PanelKeyCatcher {
id: keyCatcher
anchors.fill: parent
blocked: searchField.activeFocus
onCloseRequested: {
if (root.detailPath !== "") root.closeDetail()
else root.close()
}
onTabRequested: function(direction) { root.switchPanel(direction) }
onMoveRequested: function(dx, dy) {
if (root.detailPath !== "") {
if (dx !== 0) root.detailNav(dx > 0 ? 1 : -1)
else if (dy !== 0) root.cycleVariant(dy > 0 ? 1 : -1)
} else if (root.phase === 1) {
root.moveCursor(dx, dy)
}
}
onActivateRequested: {
if (root.detailPath !== "") root.applySelected()
else if (root.phase === 1) root.openDetailAt(root.cursorIdx)
}
onDeleteRequested: root.resetFilters()
onTextKey: function(t) {
if (t === "/" && root.detailPath === "") searchField.forceActiveFocus()
else if ((t === "r" || t === "R") && root.detailPath === "") root.startLoad(true)
}
// ============================ main browse view =======================
Item {
id: content
anchors.fill: parent
visible: root.phase === 1
Item {
id: headerRow
anchors.left: parent.left
anchors.leftMargin: Style.spacing.md
anchors.top: parent.top
anchors.topMargin: Style.spacing.md
anchors.right: parent.right
anchors.rightMargin: Style.spacing.md
height: Style.space(30)
Text {
id: slashText
text: "/"
color: root.dim
font.family: root.mono
font.pointSize: Style.font.body
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
Item {
id: shuffleBtn
width: 24
height: 24
enabled: !root.operationBusy
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
Text {
anchors.centerIn: parent
text: "\uF074"
color: root.faint
font.pointSize: Style.font.caption
font.bold: true
}
MouseArea {
id: shuffleHover
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.applyRandom()
}
PanelToolTip {
visible: shuffleHover.containsMouse
text: "Apply a random wallpaper / theme"
}
}
Item {
id: refreshBtn
width: 24
height: 24
anchors.right: shuffleBtn.left
anchors.rightMargin: Style.spacing.xs
anchors.verticalCenter: parent.verticalCenter
Text {
anchors.centerIn: parent
text: "R"
color: root.faint
font.pointSize: Style.font.caption
font.bold: true
}
MouseArea {
id: refreshHover
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.startLoad(true)
}
PanelToolTip {
visible: refreshHover.containsMouse
text: "Re-fetch the index (35 MB)"
}
}
Item {
id: resetBtn
width: 24
height: 24
visible: root.hasActiveFilters
anchors.right: refreshBtn.left
anchors.rightMargin: Style.spacing.sm
anchors.verticalCenter: parent.verticalCenter
Text {
anchors.centerIn: parent
text: "\u00d7"
color: root.dim
font.pointSize: Style.font.body
}
MouseArea {
id: resetHover
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.resetFilters()
}
PanelToolTip {
visible: resetHover.containsMouse
text: "Reset all filters"
}
}
Text {
id: countText
text: root.filtered.length + " / " + (root.db ? root.db.count : 0)
color: root.dim
font.family: root.mono
font.pointSize: Style.font.caption
anchors.right: resetBtn.left
anchors.rightMargin: Style.spacing.sm
anchors.verticalCenter: parent.verticalCenter
}
TextField {
id: searchField
anchors.left: slashText.right
anchors.leftMargin: Style.spacing.sm
anchors.right: countText.left
anchors.rightMargin: Style.spacing.sm
anchors.verticalCenter: parent.verticalCenter
leftPadding: 8
rightPadding: 8
topPadding: 4
bottomPadding: 4
color: root.fg
font.family: root.mono
font.pointSize: Style.font.body
placeholderText: "search themes, palettes, tags\u2026"
placeholderTextColor: root.faint
background: BorderSurface {
radius: 6
color: searchField.activeFocus ? Qt.alpha(Color.background, 0.55) : Qt.alpha(Color.background, 0.32)
borderSpec: searchField.activeFocus
? Border.flat(root.dim, 1)
: Border.flat(Qt.alpha(root.fg, 0.12), 1)
}
onTextChanged: root.setQuery(text)
onAccepted: {
// Flush the debounced search before opening, or Enter within the
// 150 ms window would open the result from the previous query.
qTimer.stop()
root.refreshFilters()
root.openDetailAt(root.cursorIdx)
searchField.focus = false
keyCatcher.forceActiveFocus()
}
Keys.onEscapePressed: {
searchField.text = ""
root.setQuery("")
searchField.focus = false
keyCatcher.forceActiveFocus()
}
}
}
// ----------------------- mode / auto bar -------------------------
Row {
id: modeRow
anchors.left: parent.left
anchors.leftMargin: Style.spacing.md
anchors.right: parent.right
anchors.rightMargin: Style.spacing.md
anchors.top: headerRow.bottom
anchors.topMargin: Style.spacing.md
height: 28
spacing: Style.space(32)
Row {
id: modeGroup
spacing: Style.spacing.md
anchors.verticalCenter: parent.verticalCenter
Text {
text: "MODE"
color: root.faint
font.family: root.mono
font.pointSize: Style.font.caption
font.bold: true
anchors.verticalCenter: parent.verticalCenter
}
Item {
id: modeBtns
width: Style.space(150)
height: 22
anchors.verticalCenter: parent.verticalCenter
Row {
width: parent.width
spacing: Style.spacing.xs
Rectangle {
width: modeBtns.width/2 - 2; height: 22; radius: 4
color: !root.wallpaperOnly ? Style.selectedFill : Style.hoverFill
activeFocusOnTab: true
Text { anchors.centerIn: parent; text: "Theme"; color: !root.wallpaperOnly ? root.fg : root.dim; font.family: root.mono; font.pointSize: Style.font.caption }
MouseArea {
id: themeHover
anchors.fill: parent; hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.wallpaperOnly = false
}
Keys.onReturnPressed: root.wallpaperOnly = false
Keys.onSpacePressed: root.wallpaperOnly = false
Accessible.role: Accessible.Button
Accessible.name: "Theme mode"
Accessible.checked: !root.wallpaperOnly
Accessible.onPressAction: root.wallpaperOnly = false
PanelToolTip {
visible: themeHover.containsMouse
text: "Theme mode: apply one-click theme variants"
}
}
Rectangle {
width: modeBtns.width/2 - 2; height: 22; radius: 4
color: root.wallpaperOnly ? Style.selectedFill : Style.hoverFill
activeFocusOnTab: true
Text { anchors.centerIn: parent; text: "Wallpaper"; color: root.wallpaperOnly ? root.fg : root.dim; font.family: root.mono; font.pointSize: Style.font.caption }
MouseArea {
id: wallpaperHover
anchors.fill: parent; hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.wallpaperOnly = true
}
Keys.onReturnPressed: root.wallpaperOnly = true
Keys.onSpacePressed: root.wallpaperOnly = true
Accessible.role: Accessible.Button
Accessible.name: "Wallpaper mode"
Accessible.checked: root.wallpaperOnly
Accessible.onPressAction: root.wallpaperOnly = true
PanelToolTip {
visible: wallpaperHover.containsMouse
text: "Wallpaper mode: set the image directly"
}
}
}
}
}
Row {
id: autoGroup
spacing: Style.spacing.md
anchors.verticalCenter: parent.verticalCenter
Text {
text: "AUTO"
color: root.faint
font.family: root.mono
font.pointSize: Style.font.caption
font.bold: true
anchors.verticalCenter: parent.verticalCenter
}
Item {
id: autoBtns
width: Style.space(135)
height: 20
anchors.verticalCenter: parent.verticalCenter
Row {
width: parent.width
spacing: 2
Repeater {
model: root.autoLabels
delegate: Rectangle {
width: (autoBtns.width - 8)/5; height: 20; radius: 4
color: root.autoLabels[index] === root.autoSelLabel() ? Style.selectedFill : Style.hoverFill
activeFocusOnTab: true
Text { anchors.centerIn: parent; text: modelData; color: root.autoLabels[index] === root.autoSelLabel() ? root.fg : root.dim; font.family: root.mono; font.pointSize: 9 }
MouseArea {
id: autoBtnHover
anchors.fill: parent; hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: { var sec=root.autoOptions[index]; root.autoIntervalSec=sec }
}
Keys.onReturnPressed: { root.autoIntervalSec=root.autoOptions[index] }
Keys.onSpacePressed: { root.autoIntervalSec=root.autoOptions[index] }
Accessible.role: Accessible.Button
Accessible.name: "AUTO " + modelData
Accessible.checked: root.autoSelLabel() === modelData
Accessible.onPressAction: { root.autoIntervalSec=root.autoOptions[index] }
PanelToolTip {
visible: autoBtnHover.containsMouse
text: root.autoOptions[index] === 0
? "Auto-random: off"
: "Auto-apply a random wallpaper every " + root.autoLabels[index]
}
}
}
}
}
Text {
text: root.autoIntervalSec > 0 ? "every " + root.autoSelLabel() : "off"
color: root.faint
font.family: root.mono
font.pointSize: Style.font.caption
anchors.verticalCenter: parent.verticalCenter
}
Item {
id: nowBtn
width: nowText.implicitWidth + 6
height: 20
enabled: !root.operationBusy
anchors.verticalCenter: parent.verticalCenter
Text {
id: nowText
text: "↻ now"
color: root.dim
font.family: root.mono
font.pointSize: Style.font.caption
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
MouseArea {
id: nowHover
anchors.fill: parent; hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.applyRandom()
}
PanelToolTip {
visible: nowHover.containsMouse
text: "Apply a random wallpaper now"
}
}
}
}
Item {
id: bodyRow
anchors.left: parent.left
anchors.leftMargin: Style.spacing.md
anchors.right: parent.right
anchors.rightMargin: Style.spacing.md
anchors.top: modeRow.bottom
anchors.topMargin: Style.spacing.md
anchors.bottom: statusRow.top
anchors.bottomMargin: Style.spacing.md
// ----------------------- filter rail ---------------------------
Column {
id: filterCol
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: Style.space(150)
spacing: Style.spacing.md
Text {
text: "TONE"
color: root.faint
font.family: root.mono
font.pointSize: Style.font.caption
font.bold: true
}
Repeater {
model: Model.TONES
delegate: Item {
id: toneRow
width: filterCol.width
height: 22
property string val: modelData