Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/main.qml
Context not available. | |||||
19 | 19 | | |||
---|---|---|---|---|---|
20 | import QtQuick 2.5 | 20 | import QtQuick 2.5 | ||
21 | import QtQuick.Layouts 1.1 | 21 | import QtQuick.Layouts 1.1 | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.1 as PlasmaCore | ||
23 | import org.kde.plasma.plasmoid 2.0 | 23 | import org.kde.plasma.plasmoid 2.0 | ||
24 | import org.kde.draganddrop 2.0 as DnD | 24 | import org.kde.draganddrop 2.0 as DnD | ||
25 | import org.kde.kirigami 2.5 as Kirigami | 25 | import org.kde.kirigami 2.5 as Kirigami | ||
Context not available. | |||||
50 | property alias visibleLayout: tasksRow | 50 | property alias visibleLayout: tasksRow | ||
51 | property alias hiddenLayout: expandedRepresentation.hiddenLayout | 51 | property alias hiddenLayout: expandedRepresentation.hiddenLayout | ||
52 | 52 | | |||
53 | property alias statusNotifierModel: statusNotifierModel | | |||
54 | | ||||
55 | // workaround https://bugreports.qt.io/browse/QTBUG-71238 / https://bugreports.qt.io/browse/QTBUG-72004 | | |||
56 | property Component plasmoidItemComponent: Qt.createComponent("items/PlasmoidItem.qml") | | |||
57 | | ||||
58 | Plasmoid.onExpandedChanged: { | 53 | Plasmoid.onExpandedChanged: { | ||
59 | if (!plasmoid.expanded) { | 54 | if (!plasmoid.expanded) { | ||
60 | dialog.visible = plasmoid.expanded; | 55 | dialog.visible = plasmoid.expanded; | ||
Context not available. | |||||
104 | wheel.accepted = true; | 99 | wheel.accepted = true; | ||
105 | } | 100 | } | ||
106 | 101 | | |||
107 | Containment.onAppletAdded: { | | |||
108 | //Allow the plasmoid expander to know in what window it will be | | |||
109 | var plasmoidContainer = plasmoidItemComponent.createObject(invisibleEntriesContainer, {"x": x, "y": y, "applet": applet}); | | |||
110 | | ||||
111 | applet.parent = plasmoidContainer | | |||
112 | applet.anchors.left = plasmoidContainer.left | | |||
113 | applet.anchors.top = plasmoidContainer.top | | |||
114 | applet.anchors.bottom = plasmoidContainer.bottom | | |||
115 | applet.width = plasmoidContainer.height | | |||
116 | applet.visible = true | | |||
117 | plasmoidContainer.visible = true | | |||
118 | | ||||
119 | //This is to make preloading effective, minimizes the scene changes | | |||
120 | if (applet.fullRepresentationItem) { | | |||
121 | applet.fullRepresentationItem.width = expandedRepresentation.width | | |||
122 | applet.fullRepresentationItem.width = expandedRepresentation.height | | |||
123 | applet.fullRepresentationItem.parent = preloadedStorage; | | |||
124 | } else { | | |||
125 | applet.fullRepresentationItemChanged.connect(function() { | | |||
126 | applet.fullRepresentationItem.width = expandedRepresentation.width | | |||
127 | applet.fullRepresentationItem.width = expandedRepresentation.height | | |||
128 | applet.fullRepresentationItem.parent = preloadedStorage; | | |||
129 | }); | | |||
130 | } | | |||
131 | } | | |||
132 | | ||||
133 | //being there forces the items to fully load, and they will be reparented in the popup one by one, this item is *never* visible | 102 | //being there forces the items to fully load, and they will be reparented in the popup one by one, this item is *never* visible | ||
134 | Item { | 103 | Item { | ||
135 | id: preloadedStorage | 104 | id: preloadedStorage | ||
Context not available. | |||||
148 | } | 117 | } | ||
149 | } | 118 | } | ||
150 | 119 | | |||
151 | Connections { | 120 | Connections { | ||
152 | target: plasmoid.configuration | 121 | target: plasmoid.configuration | ||
153 | 122 | | |||
154 | onExtraItemsChanged: plasmoid.nativeInterface.allowedPlasmoids = plasmoid.configuration.extraItems | 123 | onExtraItemsChanged: plasmoid.nativeInterface.allowedPlasmoids = plasmoid.configuration.extraItems | ||
155 | } | 124 | } | ||
156 | 125 | | |||
157 | Component.onCompleted: { | | |||
158 | //script, don't bind | | |||
159 | plasmoid.nativeInterface.allowedPlasmoids = initializePlasmoidList(); | | |||
160 | } | | |||
161 | | ||||
162 | function initializePlasmoidList() { | | |||
163 | var newKnownItems = []; | | |||
164 | var newExtraItems = []; | | |||
165 | | ||||
166 | //NOTE:why this? otherwise the interpreter will execute plasmoid.nativeInterface.defaultPlasmoids() on | | |||
167 | //every access of defaults[], resulting in a very slow iteration | | |||
168 | var defaults = []; | | |||
169 | //defaults = defaults.concat(plasmoid.nativeInterface.defaultPlasmoids); | | |||
170 | defaults = plasmoid.nativeInterface.defaultPlasmoids.slice() | | |||
171 | var candidate; | | |||
172 | | ||||
173 | //Add every plasmoid that is both not enabled explicitly and not already known | | |||
174 | for (var i = 0; i < defaults.length; ++i) { | | |||
175 | candidate = defaults[i]; | | |||
176 | if (plasmoid.configuration.knownItems.indexOf(candidate) === -1) { | | |||
177 | newKnownItems.push(candidate); | | |||
178 | if (plasmoid.configuration.extraItems.indexOf(candidate) === -1) { | | |||
179 | newExtraItems.push(candidate); | | |||
180 | } | | |||
181 | } | | |||
182 | } | | |||
183 | | ||||
184 | if (newExtraItems.length > 0) { | | |||
185 | plasmoid.configuration.extraItems = plasmoid.configuration.extraItems.slice().concat(newExtraItems); | | |||
186 | } | | |||
187 | if (newKnownItems.length > 0) { | | |||
188 | plasmoid.configuration.knownItems = plasmoid.configuration.knownItems.slice().concat(newKnownItems); | | |||
189 | } | | |||
190 | | ||||
191 | return plasmoid.configuration.extraItems; | | |||
192 | } | | |||
193 | | ||||
194 | PlasmaCore.DataSource { | | |||
195 | id: statusNotifierSource | | |||
196 | engine: "statusnotifieritem" | | |||
197 | interval: 0 | | |||
198 | onSourceAdded: { | | |||
199 | connectSource(source) | | |||
200 | } | | |||
201 | Component.onCompleted: { | | |||
202 | connectedSources = sources | | |||
203 | } | | |||
204 | } | | |||
205 | | ||||
206 | | ||||
207 | //due to the magic of property bindings this function will be | 126 | //due to the magic of property bindings this function will be | ||
208 | //re-executed all the times a setting changes | 127 | //re-executed all the times a setting changes | ||
209 | property var shownCategories: { | 128 | property var shownCategories: { | ||
Context not available. | |||||
231 | return array; | 150 | return array; | ||
232 | } | 151 | } | ||
233 | 152 | | |||
234 | PlasmaCore.SortFilterModel { | | |||
235 | id: statusNotifierModel | | |||
236 | sourceModel: PlasmaCore.DataModel { | | |||
237 | dataSource: statusNotifierSource | | |||
238 | } | | |||
239 | } | | |||
240 | | ||||
241 | //This is a dump for items we don't want to be seen or as an incubation, when they are | 153 | //This is a dump for items we don't want to be seen or as an incubation, when they are | ||
242 | //created as a nursery before going in their final place | 154 | //created as a nursery before going in their final place | ||
243 | Item { | 155 | ListView { //Repeater behavies wierdly, messes up with parents of applets | ||
244 | id: invisibleEntriesContainer | 156 | id: invisibleEntriesContainer | ||
245 | visible: false | 157 | visible: false | ||
246 | Repeater { | 158 | height: contentHeight | ||
247 | id: tasksRepeater | | |||
248 | model: statusNotifierModel | | |||
249 | 159 | | |||
250 | delegate: StatusNotifierItem {} | 160 | model: PlasmaCore.SortFilterModel { | ||
161 | id: systemTrayModel | ||||
162 | sourceModel: plasmoid.nativeInterface.systemTrayModel | ||||
163 | filterRole: "canRender" | ||||
164 | filterCallback: function(source_row, value) { return value; } | ||||
165 | } | ||||
166 | delegate: Loader { | ||||
167 | parent: invisibleEntriesContainer | ||||
168 | id: itemLoader | ||||
169 | | ||||
170 | Component.onCompleted: { | ||||
171 | if (model.applet) { | ||||
172 | itemLoader.setSource("items/PlasmoidItem.qml", { | ||||
173 | "parent": invisibleEntriesContainer, | ||||
174 | "applet": model.applet | ||||
175 | }) | ||||
176 | } else if (model.DataEngineSource) { | ||||
177 | itemLoader.setSource("items/StatusNotifierItem.qml", { | ||||
178 | "parent": invisibleEntriesContainer, | ||||
179 | "model": model | ||||
180 | }) | ||||
181 | } | ||||
182 | } | ||||
251 | } | 183 | } | ||
252 | //NOTE: this exists mostly for not causing reference errors | 184 | //NOTE: this exists mostly for not causing reference errors | ||
253 | property QtObject marginHints: QtObject { | 185 | property QtObject marginHints: QtObject { | ||
Context not available. |