Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2016 Marco Martin <mart@kde.org> | 2 | * Copyright 2016 Marco Martin <mart@kde.org> | ||
3 | * Copyright 2019 ivan tkachenko <ratijastk@kde.org> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Library General Public License as | 6 | * it under the terms of the GNU Library General Public License as | ||
6 | * published by the Free Software Foundation; either version 2, or | 7 | * published by the Free Software Foundation; either version 2, or | ||
7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 28 Lines | 36 | status: { | |||
39 | case "NeedsAttention": | 40 | case "NeedsAttention": | ||
40 | return PlasmaCore.Types.NeedsAttentionStatus; | 41 | return PlasmaCore.Types.NeedsAttentionStatus; | ||
41 | //just assume passive | 42 | //just assume passive | ||
42 | default: | 43 | default: | ||
43 | return PlasmaCore.Types.PassiveStatus; | 44 | return PlasmaCore.Types.PassiveStatus; | ||
44 | } | 45 | } | ||
45 | } | 46 | } | ||
46 | 47 | | |||
47 | iconItem: iconItem | 48 | iconItem: PlasmaCore.IconItem { | ||
48 | | ||||
49 | PlasmaCore.IconItem { | | |||
50 | id: iconItem | | |||
51 | source: Icon ? Icon : IconName | 49 | source: Icon ? Icon : IconName | ||
52 | width: Math.min(parent.width, parent.height) | | |||
53 | height: width | | |||
54 | active: taskIcon.containsMouse | 50 | active: taskIcon.containsMouse | ||
55 | | ||||
56 | anchors { | | |||
57 | left: parent.left | | |||
58 | verticalCenter: parent.verticalCenter | | |||
59 | } | | |||
60 | } | 51 | } | ||
61 | 52 | | |||
62 | onContextMenu: { | 53 | onContextMenu: { | ||
63 | openContextMenu(plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y)) | 54 | openContextMenu(plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y)) | ||
64 | } | 55 | } | ||
65 | 56 | | |||
66 | onClicked: { | 57 | onClicked: { | ||
67 | var pos = plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y); | 58 | var pos = plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y); | ||
68 | 59 | | |||
69 | switch (mouse.button) { | 60 | switch (mouse.button) { | ||
70 | case Qt.LeftButton: { | 61 | case Qt.LeftButton: { | ||
71 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 62 | var service = statusNotifierModel.source.serviceForSource(DataEngineSource); | ||
72 | var operation = service.operationDescription("Activate"); | 63 | var operation = service.operationDescription("Activate"); | ||
73 | operation.x = pos.x; | 64 | operation.x = pos.x; | ||
74 | operation.y = pos.y; | 65 | operation.y = pos.y; | ||
75 | var job = service.startOperationCall(operation); | 66 | var job = service.startOperationCall(operation); | ||
76 | job.finished.connect(function () { | 67 | job.finished.connect(function () { | ||
77 | if (!job.result) { | 68 | if (!job.result) { | ||
78 | // On error try to invoke the context menu. | 69 | // On error try to invoke the context menu. | ||
79 | // Workaround primarily for apps using libappindicator. | 70 | // Workaround primarily for apps using libappindicator. | ||
80 | openContextMenu(pos); | 71 | openContextMenu(pos); | ||
81 | } | 72 | } | ||
82 | }); | 73 | }); | ||
83 | break; | 74 | break; | ||
84 | } | 75 | } | ||
85 | case Qt.RightButton: | 76 | case Qt.RightButton: | ||
86 | openContextMenu(pos); | 77 | openContextMenu(pos); | ||
87 | break; | 78 | break; | ||
88 | 79 | | |||
89 | case Qt.MiddleButton: | 80 | case Qt.MiddleButton: | ||
90 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 81 | var service = statusNotifierModel.source.serviceForSource(DataEngineSource); | ||
91 | var operation = service.operationDescription("SecondaryActivate"); | 82 | var operation = service.operationDescription("SecondaryActivate"); | ||
92 | operation.x = pos.x; | 83 | operation.x = pos.x; | ||
93 | 84 | | |||
94 | operation.y = pos.y; | 85 | operation.y = pos.y; | ||
95 | service.startOperationCall(operation); | 86 | service.startOperationCall(operation); | ||
96 | break; | 87 | break; | ||
97 | } | 88 | } | ||
98 | } | 89 | } | ||
99 | 90 | | |||
100 | function openContextMenu(pos) { | 91 | function openContextMenu(pos) { | ||
101 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 92 | var service = statusNotifierModel.source.serviceForSource(DataEngineSource); | ||
102 | var operation = service.operationDescription("ContextMenu"); | 93 | var operation = service.operationDescription("ContextMenu"); | ||
103 | operation.x = pos.x; | 94 | operation.x = pos.x; | ||
104 | operation.y = pos.y; | 95 | operation.y = pos.y; | ||
105 | 96 | | |||
106 | var job = service.startOperationCall(operation); | 97 | var job = service.startOperationCall(operation); | ||
107 | job.finished.connect(function () { | 98 | job.finished.connect(function () { | ||
108 | plasmoid.nativeInterface.showStatusNotifierContextMenu(job, taskIcon); | 99 | plasmoid.nativeInterface.showStatusNotifierContextMenu(job, taskIcon); | ||
109 | }); | 100 | }); | ||
110 | } | 101 | } | ||
111 | 102 | | |||
112 | onWheel: { | 103 | onWheel: { | ||
113 | //don't send activateVertScroll with a delta of 0, some clients seem to break (kmix) | 104 | //don't send activateVertScroll with a delta of 0, some clients seem to break (kmix) | ||
114 | if (wheel.angleDelta.y !== 0) { | 105 | if (wheel.angleDelta.y !== 0) { | ||
115 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 106 | var service = statusNotifierModel.source.serviceForSource(DataEngineSource); | ||
116 | var operation = service.operationDescription("Scroll"); | 107 | var operation = service.operationDescription("Scroll"); | ||
117 | operation.delta =wheel.angleDelta.y; | 108 | operation.delta =wheel.angleDelta.y; | ||
118 | operation.direction = "Vertical"; | 109 | operation.direction = "Vertical"; | ||
119 | service.startOperationCall(operation); | 110 | service.startOperationCall(operation); | ||
120 | } | 111 | } | ||
121 | if (wheel.angleDelta.x !== 0) { | 112 | if (wheel.angleDelta.x !== 0) { | ||
122 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 113 | var service = statusNotifierModel.source.serviceForSource(DataEngineSource); | ||
123 | var operation = service.operationDescription("Scroll"); | 114 | var operation = service.operationDescription("Scroll"); | ||
124 | operation.delta =wheel.angleDelta.x; | 115 | operation.delta =wheel.angleDelta.x; | ||
125 | operation.direction = "Horizontal"; | 116 | operation.direction = "Horizontal"; | ||
126 | service.startOperationCall(operation); | 117 | service.startOperationCall(operation); | ||
127 | } | 118 | } | ||
128 | } | 119 | } | ||
129 | } | 120 | } |