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
|
import QtQuick
import QtQuick.Controls
import Quickshell
import qs.Common
import qs.Modals.Common
import qs.Services
import qs.Widgets
FloatingWindow {
id: root
property bool disablePopupTransparency: true
property var allThemes: []
property string searchQuery: ""
property var filteredThemes: []
property int selectedIndex: -1
property bool keyboardNavigationActive: false
property bool isLoading: false
property var parentModal: null
property bool pendingInstallHandled: false
property string pendingApplyThemeId: ""
function updateFilteredThemes() {
var filtered = [];
var query = searchQuery ? searchQuery.toLowerCase() : "";
for (var i = 0; i < allThemes.length; i++) {
var theme = allThemes[i];
if (query.length === 0) {
filtered.push(theme);
continue;
}
var name = theme.name ? theme.name.toLowerCase() : "";
var description = theme.description ? theme.description.toLowerCase() : "";
var author = theme.author ? theme.author.toLowerCase() : "";
if (name.indexOf(query) !== -1 || description.indexOf(query) !== -1 || author.indexOf(query) !== -1)
filtered.push(theme);
}
filteredThemes = filtered;
selectedIndex = -1;
keyboardNavigationActive = false;
}
function selectNext() {
if (filteredThemes.length === 0)
return;
keyboardNavigationActive = true;
selectedIndex = Math.min(selectedIndex + 1, filteredThemes.length - 1);
}
function selectPrevious() {
if (filteredThemes.length === 0)
return;
keyboardNavigationActive = true;
selectedIndex = Math.max(selectedIndex - 1, -1);
if (selectedIndex === -1)
keyboardNavigationActive = false;
}
function installTheme(themeId, themeName, applyAfterInstall) {
ToastService.showInfo(I18n.tr("Installing: %1", "installation progress").arg(themeName));
DMSService.installTheme(themeId, response => {
if (response.error) {
ToastService.showError(I18n.tr("Install failed: %1", "installation error").arg(response.error));
return;
}
ToastService.showInfo(I18n.tr("Installed: %1", "installation success").arg(themeName));
if (applyAfterInstall)
pendingApplyThemeId = themeId;
refreshThemes();
});
}
function applyInstalledTheme(themeId, installedThemes) {
for (var i = 0; i < installedThemes.length; i++) {
var theme = installedThemes[i];
if (theme.id === themeId) {
var sourceDir = theme.sourceDir || theme.id;
var themePath = Quickshell.env("HOME") + "/.config/DankMaterialShell/themes/" + sourceDir + "/theme.json";
SettingsData.set("customThemeFile", themePath);
Theme.switchThemeCategory("registry", "custom");
Theme.switchTheme("custom", true, true);
hide();
return;
}
}
}
function uninstallTheme(themeId, themeName) {
ToastService.showInfo(I18n.tr("Uninstalling: %1", "uninstallation progress").arg(themeName));
DMSService.uninstallTheme(themeId, response => {
if (response.error) {
ToastService.showError(I18n.tr("Uninstall failed: %1", "uninstallation error").arg(response.error));
return;
}
ToastService.showInfo(I18n.tr("Uninstalled: %1", "uninstallation success").arg(themeName));
refreshThemes();
});
}
function refreshThemes() {
isLoading = true;
DMSService.listThemes();
DMSService.listInstalledThemes();
}
function checkPendingInstall() {
if (!PopoutService.pendingThemeInstall || pendingInstallHandled)
return;
pendingInstallHandled = true;
var themeId = PopoutService.pendingThemeInstall;
PopoutService.pendingThemeInstall = "";
urlInstallConfirm.showWithOptions({
"title": I18n.tr("Install Theme", "theme installation dialog title"),
"message": I18n.tr("Install theme '%1' from the DMS registry?", "theme installation confirmation").arg(themeId),
"confirmText": I18n.tr("Install", "install action button"),
"cancelText": I18n.tr("Cancel"),
"onConfirm": () => installTheme(themeId, themeId, true),
"onCancel": () => hide()
});
}
function show() {
if (parentModal)
parentModal.shouldHaveFocus = false;
visible = true;
Qt.callLater(() => browserSearchField.forceActiveFocus());
}
function hide() {
visible = false;
if (!parentModal)
return;
parentModal.shouldHaveFocus = Qt.binding(() => parentModal.shouldBeVisible);
Qt.callLater(() => {
if (parentModal.modalFocusScope)
parentModal.modalFocusScope.forceActiveFocus();
});
}
objectName: "themeBrowser"
title: I18n.tr("Browse Themes", "theme browser window title")
minimumSize: Qt.size(550, 450)
implicitWidth: 700
implicitHeight: 700
color: Theme.surfaceContainer
visible: false
onVisibleChanged: {
if (visible) {
pendingInstallHandled = false;
refreshThemes();
Qt.callLater(() => {
browserSearchField.forceActiveFocus();
checkPendingInstall();
});
return;
}
allThemes = [];
searchQuery = "";
filteredThemes = [];
selectedIndex = -1;
keyboardNavigationActive = false;
isLoading = false;
}
ConfirmModal {
id: urlInstallConfirm
}
Connections {
target: DMSService
function onThemesListReceived(themes) {
isLoading = false;
allThemes = themes;
updateFilteredThemes();
}
function onInstalledThemesReceived(themes) {
if (!pendingApplyThemeId)
return;
var themeId = pendingApplyThemeId;
pendingApplyThemeId = "";
applyInstalledTheme(themeId, themes);
}
}
FocusScope {
id: browserKeyHandler
anchors.fill: parent
focus: true
Keys.onPressed: event => {
switch (event.key) {
case Qt.Key_Escape:
root.hide();
event.accepted = true;
return;
case Qt.Key_Down:
root.selectNext();
event.accepted = true;
return;
case Qt.Key_Up:
root.selectPrevious();
event.accepted = true;
return;
}
}
Item {
id: browserContent
anchors.fill: parent
anchors.margins: Theme.spacingL
Item {
id: headerArea
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
height: Math.max(headerIcon.height, headerText.height, refreshButton.height, closeButton.height)
MouseArea {
anchors.fill: parent
onPressed: windowControls.tryStartMove()
onDoubleClicked: windowControls.tryToggleMaximize()
}
DankIcon {
id: headerIcon
name: "palette"
size: Theme.iconSize
color: Theme.primary
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
id: headerText
text: I18n.tr("Browse Themes", "theme browser header")
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Medium
color: Theme.surfaceText
anchors.left: headerIcon.right
anchors.leftMargin: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter
}
Row {
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingXS
DankActionButton {
id: refreshButton
iconName: "refresh"
iconSize: 18
iconColor: Theme.primary
visible: !root.isLoading
onClicked: root.refreshThemes()
}
DankActionButton {
visible: windowControls.supported
iconName: root.maximized ? "fullscreen_exit" : "fullscreen"
iconSize: Theme.iconSize - 2
iconColor: Theme.outline
onClicked: windowControls.tryToggleMaximize()
}
DankActionButton {
id: closeButton
iconName: "close"
iconSize: Theme.iconSize - 2
iconColor: Theme.outline
onClicked: root.hide()
}
}
}
StyledText {
id: descriptionText
anchors.left: parent.left
anchors.right: parent.right
anchors.top: headerArea.bottom
anchors.topMargin: Theme.spacingM
text: I18n.tr("Install color themes from the DMS theme registry", "theme browser description")
font.pixelSize: Theme.fontSizeSmall
color: Theme.outline
wrapMode: Text.WordWrap
}
DankTextField {
id: browserSearchField
anchors.left: parent.left
anchors.right: parent.right
anchors.top: descriptionText.bottom
anchors.topMargin: Theme.spacingM
height: 48
cornerRadius: Theme.cornerRadius
backgroundColor: Theme.surfaceContainerHigh
normalBorderColor: Theme.outlineMedium
focusedBorderColor: Theme.primary
leftIconName: "search"
leftIconSize: Theme.iconSize
leftIconColor: Theme.surfaceVariantText
leftIconFocusedColor: Theme.primary
showClearButton: true
textColor: Theme.surfaceText
font.pixelSize: Theme.fontSizeMedium
placeholderText: I18n.tr("Search themes...", "theme search placeholder")
text: root.searchQuery
focus: true
ignoreLeftRightKeys: true
keyForwardTargets: [browserKeyHandler]
onTextEdited: {
root.searchQuery = text;
root.updateFilteredThemes();
}
}
Item {
id: listArea
anchors.left: parent.left
anchors.right: parent.right
anchors.top: browserSearchField.bottom
anchors.topMargin: Theme.spacingM
anchors.bottom: parent.bottom
Item {
anchors.fill: parent
visible: root.isLoading
Column {
anchors.centerIn: parent
spacing: Theme.spacingM
DankIcon {
name: "sync"
size: 48
color: Theme.primary
anchors.horizontalCenter: parent.horizontalCenter
RotationAnimator on rotation {
from: 0
to: 360
duration: 1000
loops: Animation.Infinite
running: root.isLoading
}
}
StyledText {
text: I18n.tr("Loading...", "loading indicator")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
DankListView {
id: themeBrowserList
anchors.fill: parent
spacing: Theme.spacingS
model: ScriptModel {
values: root.filteredThemes
}
clip: true
visible: !root.isLoading
ScrollBar.vertical: DankScrollbar {
id: browserScrollbar
}
delegate: Rectangle {
id: themeDelegate
width: themeBrowserList.width
height: hasPreview ? 140 : themeDelegateContent.implicitHeight + Theme.spacingM * 2
radius: Theme.cornerRadius
property bool isSelected: root.keyboardNavigationActive && index === root.selectedIndex
property bool isInstalled: modelData.installed || false
property bool isFirstParty: modelData.firstParty || false
property bool hasVariants: modelData.hasVariants || false
property var variants: modelData.variants || null
property string selectedVariantId: {
if (!hasVariants || !variants)
return "";
if (variants.type === "multi") {
const mode = Theme.isLightMode ? "light" : "dark";
const defaults = variants.defaults?.[mode] || variants.defaults?.dark || {};
return (defaults.flavor || "") + (defaults.accent ? "-" + defaults.accent : "");
}
return variants.default || (variants.options?.[0]?.id ?? "");
}
property string previewPath: {
const baseDir = "/tmp/dankdots-plugin-registry/themes/" + (modelData.sourceDir || modelData.id);
const mode = Theme.isLightMode ? "light" : "dark";
if (hasVariants && selectedVariantId) {
if (variants?.type === "multi")
return baseDir + "/preview-" + selectedVariantId + ".svg";
return baseDir + "/preview-" + selectedVariantId + "-" + mode + ".svg";
}
return baseDir + "/preview-" + mode + ".svg";
}
property bool hasPreview: previewImage.status === Image.Ready
color: isSelected ? Theme.primarySelected : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
border.color: isSelected ? Theme.primary : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
border.width: isSelected ? 2 : 1
Row {
id: themeDelegateContent
anchors.fill: parent
anchors.margins: Theme.spacingM
spacing: Theme.spacingM
Rectangle {
width: hasPreview ? 180 : 0
height: parent.height
radius: Theme.cornerRadius - 2
color: Theme.surfaceContainerHigh
visible: hasPreview
Image {
id: previewImage
anchors.fill: parent
anchors.margins: 2
source: "file://" + previewPath
fillMode: Image.PreserveAspectFit
smooth: true
mipmap: true
}
}
DankIcon {
name: "palette"
size: 48
color: Theme.primary
anchors.verticalCenter: parent.verticalCenter
visible: !hasPreview
}
Column {
width: parent.width - (hasPreview ? 180 : 48) - Theme.spacingM - installButton.width - Theme.spacingM
spacing: 6
anchors.verticalCenter: parent.verticalCenter
Row {
spacing: Theme.spacingXS
width: parent.width
StyledText {
text: modelData.name
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Medium
color: Theme.surfaceText
elide: Text.ElideRight
anchors.verticalCenter: parent.verticalCenter
}
Rectangle {
height: 18
width: versionText.implicitWidth + Theme.spacingS
radius: 9
color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.15)
anchors.verticalCenter: parent.verticalCenter
StyledText {
id: versionText
anchors.centerIn: parent
text: modelData.version || "1.0.0"
font.pixelSize: Theme.fontSizeSmall
color: Theme.outline
}
}
Rectangle {
height: 18
width: firstPartyText.implicitWidth + Theme.spacingS
radius: 9
color: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.15)
border.color: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.4)
border.width: 1
visible: isFirstParty
anchors.verticalCenter: parent.verticalCenter
StyledText {
id: firstPartyText
anchors.centerIn: parent
text: I18n.tr("official")
font.pixelSize: Theme.fontSizeSmall
color: Theme.primary
font.weight: Font.Medium
}
}
Rectangle {
height: 18
width: variantsText.implicitWidth + Theme.spacingS
radius: 9
color: Qt.rgba(Theme.secondary.r, Theme.secondary.g, Theme.secondary.b, 0.15)
border.color: Qt.rgba(Theme.secondary.r, Theme.secondary.g, Theme.secondary.b, 0.4)
border.width: 1
visible: themeDelegate.hasVariants
anchors.verticalCenter: parent.verticalCenter
StyledText {
id: variantsText
anchors.centerIn: parent
text: {
if (themeDelegate.variants?.type === "multi")
return I18n.tr("%1 variants").arg(themeDelegate.variants?.accents?.length ?? 0);
return I18n.tr("%1 variants").arg(themeDelegate.variants?.options?.length ?? 0);
}
font.pixelSize: Theme.fontSizeSmall
color: Theme.secondary
font.weight: Font.Medium
}
}
}
StyledText {
text: I18n.tr("by %1", "author attribution").arg(modelData.author || I18n.tr("Unknown", "unknown author"))
font.pixelSize: Theme.fontSizeMedium
color: Theme.outline
elide: Text.ElideRight
width: parent.width
}
StyledText {
text: modelData.description || ""
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
width: parent.width
wrapMode: Text.WordWrap
maximumLineCount: themeDelegate.hasVariants ? 2 : 3
elide: Text.ElideRight
visible: modelData.description && modelData.description.length > 0
}
Flow {
width: parent.width
spacing: Theme.spacingXS
visible: themeDelegate.hasVariants && themeDelegate.variants?.type !== "multi"
Repeater {
model: themeDelegate.variants?.options ?? []
Rectangle {
property bool isActive: themeDelegate.selectedVariantId === modelData.id
height: 22
width: variantChipText.implicitWidth + Theme.spacingS * 2
radius: 11
color: isActive ? Theme.primary : Theme.surfaceContainerHigh
border.color: isActive ? Theme.primary : Theme.outline
border.width: 1
StyledText {
id: variantChipText
anchors.centerIn: parent
text: modelData.name
font.pixelSize: Theme.fontSizeSmall
color: isActive ? Theme.primaryText : Theme.surfaceText
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: themeDelegate.selectedVariantId = modelData.id
}
}
}
}
Flow {
width: parent.width
spacing: Theme.spacingXS
visible: themeDelegate.hasVariants && themeDelegate.variants?.type === "multi"
Repeater {
model: themeDelegate.variants?.accents ?? []
Rectangle {
width: 18
height: 18
radius: 9
color: modelData.color || Theme.primary
border.color: Theme.outline
border.width: 1
DankTooltipV2 {
id: accentTooltip
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: accentTooltip.show(modelData.name || modelData.id, parent, 0, 0, "top")
onExited: accentTooltip.hide()
}
}
}
}
}
Rectangle {
id: installButton
width: 90
height: 36
radius: Theme.cornerRadius
anchors.verticalCenter: parent.verticalCenter
color: isInstalled ? (uninstallMouseArea.containsMouse ? Theme.error : Theme.surfaceVariant) : Theme.primary
opacity: installMouseArea.containsMouse || uninstallMouseArea.containsMouse ? 0.9 : 1
border.width: isInstalled ? 1 : 0
border.color: isInstalled ? (uninstallMouseArea.containsMouse ? Theme.error : Theme.outline) : "transparent"
Behavior on opacity {
NumberAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
Behavior on color {
ColorAnimation {
duration: Theme.shortDuration
}
}
Row {
anchors.centerIn: parent
spacing: Theme.spacingXS
DankIcon {
name: isInstalled ? (uninstallMouseArea.containsMouse ? "delete" : "check") : "download"
size: 16
color: isInstalled ? (uninstallMouseArea.containsMouse ? "white" : Theme.surfaceText) : Theme.surface
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: {
if (!isInstalled)
return I18n.tr("Install", "install action button");
if (uninstallMouseArea.containsMouse)
return I18n.tr("Uninstall", "uninstall action button");
return I18n.tr("Installed", "installed status");
}
font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Medium
color: isInstalled ? (uninstallMouseArea.containsMouse ? "white" : Theme.surfaceText) : Theme.surface
anchors.verticalCenter: parent.verticalCenter
}
}
MouseArea {
id: installMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
visible: !isInstalled
onClicked: root.installTheme(modelData.id, modelData.name, false)
}
MouseArea {
id: uninstallMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
visible: isInstalled
onClicked: root.uninstallTheme(modelData.id, modelData.name)
}
}
}
}
}
StyledText {
anchors.centerIn: listArea
text: I18n.tr("No themes found", "empty theme list")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
visible: !root.isLoading && root.filteredThemes.length === 0
}
}
}
}
FloatingWindowControls {
id: windowControls
targetWindow: root
}
}
|