Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/main.qml
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 28 | MouseArea { | |||
---|---|---|---|---|---|
45 | property Item activeApplet | 45 | property Item activeApplet | ||
46 | property int status: dialog.visible ? PlasmaCore.Types.RequiresAttentionStatus : PlasmaCore.Types.PassiveStatus | 46 | property int status: dialog.visible ? PlasmaCore.Types.RequiresAttentionStatus : PlasmaCore.Types.PassiveStatus | ||
47 | 47 | | |||
48 | property alias visibleLayout: tasksRow | 48 | property alias visibleLayout: tasksRow | ||
49 | property alias hiddenLayout: expandedRepresentation.hiddenLayout | 49 | property alias hiddenLayout: expandedRepresentation.hiddenLayout | ||
50 | 50 | | |||
51 | property alias statusNotifierModel: statusNotifierModel | 51 | property alias statusNotifierModel: statusNotifierModel | ||
52 | 52 | | |||
53 | property int creationIdCounter: 0 | ||||
54 | | ||||
53 | property Component plasmoidItemComponent | 55 | property Component plasmoidItemComponent | ||
54 | 56 | | |||
55 | Plasmoid.onExpandedChanged: { | 57 | Plasmoid.onExpandedChanged: { | ||
56 | if (!plasmoid.expanded) { | 58 | if (!plasmoid.expanded) { | ||
57 | dialog.visible = plasmoid.expanded; | 59 | dialog.visible = plasmoid.expanded; | ||
58 | } | 60 | } | ||
59 | } | 61 | } | ||
60 | 62 | | |||
63 | // temporary hack to fix known broken categories | ||||
64 | // should go away as soon as fixes are merged | ||||
65 | readonly property var categoryOverride: { | ||||
66 | "org.kde.discovernotifier": "SystemServices", | ||||
67 | "org.kde.plasma.networkmanagement": "Hardware", | ||||
mart: as convention we usually don't have getFoo as names (and this is not getting a property… | |||||
What about indexForItemCategory? I need to pass in item not category because of special treatment of notifications. Also I'll rename itemCompare to compareItems. Pitel: What about `indexForItemCategory`? I need to pass in item not category because of special… | |||||
68 | "org.kde.kdeconnect": "Hardware", | ||||
69 | "org.kde.plasma.keyboardindicator": "Hardware", | ||||
70 | "touchpad": "Hardware" | ||||
71 | } | ||||
72 | | ||||
73 | readonly property var categoryOrder: [ | ||||
74 | "UnknownCategory", "ApplicationStatus", "Communications", | ||||
75 | "SystemServices", "Hardware" | ||||
76 | ] | ||||
77 | function indexForItemCategory(item) { | ||||
78 | if (item.itemId == "org.kde.plasma.notifications") { | ||||
79 | return -1 | ||||
80 | } | ||||
81 | var i = categoryOrder.indexOf(categoryOverride[item.itemId] || item.category) | ||||
mart: i like the logic, but add some comments on what is doing | |||||
82 | return i == -1 ? categoryOrder.indexOf("UnknownCategory") : i | ||||
83 | } | ||||
84 | | ||||
85 | // return negative integer if a < b, 0 if a === b, and positive otherwise | ||||
86 | function compareItems(a, b) { | ||||
87 | var categoryDiff = indexForItemCategory(a) - indexForItemCategory(b) | ||||
88 | var textDiff = (categoryDiff != 0 ? categoryDiff : a.text.localeCompare(b.text)) | ||||
89 | return textDiff != 0 ? textDiff : b.creationId - a.creationId | ||||
90 | } | ||||
91 | | ||||
92 | function moveItemAt(item, container, index) { | ||||
93 | if (container.children.length == 0) { | ||||
94 | item.parent = container | ||||
95 | } else { | ||||
96 | if (index == container.children.length) { | ||||
97 | var other = container.children[index - 1] | ||||
98 | if (item != other) { | ||||
99 | plasmoid.nativeInterface.reorderItemAfter(item, other) | ||||
100 | } | ||||
101 | } else { | ||||
102 | var other = container.children[index] | ||||
103 | if (item != other) { | ||||
104 | plasmoid.nativeInterface.reorderItemBefore(item, other) | ||||
105 | } | ||||
106 | } | ||||
107 | } | ||||
108 | } | ||||
109 | | ||||
110 | function reorderItem(item, container) { | ||||
111 | var i = 0; | ||||
112 | while (i < container.children.length && | ||||
113 | compareItems(container.children[i], item) <= 0) { | ||||
114 | i++ | ||||
115 | } | ||||
116 | moveItemAt(item, container, i) | ||||
117 | } | ||||
118 | | ||||
61 | function updateItemVisibility(item) { | 119 | function updateItemVisibility(item) { | ||
62 | switch (item.effectiveStatus) { | 120 | switch (item.effectiveStatus) { | ||
63 | case PlasmaCore.Types.HiddenStatus: | 121 | case PlasmaCore.Types.HiddenStatus: | ||
64 | if (item.parent == invisibleEntriesContainer) { | 122 | if (item.parent != invisibleEntriesContainer) { | ||
65 | return; | | |||
66 | } | | |||
67 | | ||||
68 | item.parent = invisibleEntriesContainer; | 123 | item.parent = invisibleEntriesContainer; | ||
124 | } | ||||
69 | break; | 125 | break; | ||
70 | 126 | | |||
71 | case PlasmaCore.Types.ActiveStatus: | 127 | case PlasmaCore.Types.ActiveStatus: | ||
72 | if (visibleLayout.children.length == 0) { | 128 | reorderItem(item, visibleLayout) | ||
73 | item.parent = visibleLayout; | | |||
74 | //notifications is always the first | | |||
75 | } else if (visibleLayout.children[0].itemId == "org.kde.plasma.notifications" && | | |||
76 | item.itemId != "org.kde.plasma.notifications") { | | |||
77 | plasmoid.nativeInterface.reorderItemAfter(item, visibleLayout.children[0]); | | |||
78 | } else if (visibleLayout.children[0] != item) { | | |||
79 | plasmoid.nativeInterface.reorderItemBefore(item, visibleLayout.children[0]); | | |||
80 | } | | |||
81 | break; | 129 | break; | ||
82 | 130 | | |||
83 | case PlasmaCore.Types.PassiveStatus: | 131 | case PlasmaCore.Types.PassiveStatus: | ||
84 | 132 | reorderItem(item, hiddenLayout) | |||
85 | if (hiddenLayout.children.length == 0) { | | |||
86 | item.parent = hiddenLayout; | | |||
87 | //notifications is always the first | | |||
88 | } else if (hiddenLayout.children[0].itemId == "org.kde.plasma.notifications" && | | |||
89 | item.itemId != "org.kde.plasma.notifications") { | | |||
90 | plasmoid.nativeInterface.reorderItemAfter(item, hiddenLayout.children[0]); | | |||
91 | } else if (hiddenLayout.children[0] != item) { | | |||
92 | plasmoid.nativeInterface.reorderItemBefore(item, hiddenLayout.children[0]); | | |||
93 | } | | |||
94 | item.x = 0; | 133 | item.x = 0; | ||
95 | break; | 134 | break; | ||
96 | } | 135 | } | ||
97 | } | 136 | } | ||
98 | 137 | | |||
99 | onWheel: { | 138 | onWheel: { | ||
100 | // Don't propagate unhandled wheel events | 139 | // Don't propagate unhandled wheel events | ||
101 | wheel.accepted = true; | 140 | wheel.accepted = true; | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |
as convention we usually don't have getFoo as names (and this is not getting a property anyways)
i would like a more descriptive name like indexForCategory and have the category as parameter instead of the item