Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.1 | 20 | import QtQuick 2.1 | ||
21 | import org.kde.plasma.core 2.0 as PlasmaCore | 21 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
22 | 22 | | |||
23 | AbstractItem { | 23 | AbstractItem { | ||
24 | id: taskIcon | 24 | id: taskIcon | ||
25 | 25 | | |||
26 | itemId: Id | 26 | property var model | ||
27 | text: Title | 27 | | ||
28 | mainText: ToolTipTitle != "" ? ToolTipTitle : Title | 28 | itemId: model.Id | ||
29 | subText: ToolTipSubTitle | 29 | text: model.Title | ||
30 | icon: ToolTipIcon != "" ? ToolTipIcon : Icon ? Icon : IconName | 30 | mainText: model.ToolTipTitle !== "" ? model.ToolTipTitle : model.Title | ||
31 | subText: model.ToolTipSubTitle | ||||
32 | icon: model.ToolTipIcon !== "" ? model.ToolTipIcon : model.Icon ? model.Icon : model.IconName | ||||
31 | textFormat: Text.AutoText | 33 | textFormat: Text.AutoText | ||
32 | category: Category | | |||
33 | 34 | | |||
34 | status: { | 35 | status: model.status | ||
35 | switch (Status) { | | |||
36 | case "Active": | | |||
37 | return PlasmaCore.Types.ActiveStatus; | | |||
38 | case "NeedsAttention": | | |||
39 | return PlasmaCore.Types.NeedsAttentionStatus; | | |||
40 | //just assume passive | | |||
41 | default: | | |||
42 | return PlasmaCore.Types.PassiveStatus; | | |||
43 | } | | |||
44 | } | | |||
45 | 36 | | |||
46 | iconItem: iconItem | 37 | iconItem: iconItem | ||
47 | 38 | | |||
48 | PlasmaCore.IconItem { | 39 | PlasmaCore.IconItem { | ||
49 | id: iconItem | 40 | id: iconItem | ||
50 | source: { | 41 | source: { | ||
51 | if (taskIcon.status === PlasmaCore.Types.NeedsAttentionStatus) { | 42 | if (model.status === PlasmaCore.Types.NeedsAttentionStatus) { | ||
52 | if (AttentionIcon) { | 43 | if (model.AttentionIcon) { | ||
53 | return AttentionIcon | 44 | return model.AttentionIcon | ||
54 | } | 45 | } | ||
55 | if (AttentionIconName) { | 46 | if (model.AttentionIconName) { | ||
56 | return AttentionIconName | 47 | return model.AttentionIconName | ||
57 | } | 48 | } | ||
58 | } | 49 | } | ||
59 | return Icon ? Icon : IconName | 50 | return model.Icon ? model.Icon : model.IconName | ||
60 | } | 51 | } | ||
61 | 52 | | |||
62 | width: Math.min(parent.width, parent.height) | 53 | width: Math.min(parent.width, parent.height) | ||
63 | height: width | 54 | height: width | ||
64 | active: taskIcon.containsMouse | 55 | active: taskIcon.containsMouse | ||
65 | 56 | | |||
66 | anchors { | 57 | anchors { | ||
67 | left: parent.left | 58 | left: parent.left | ||
68 | verticalCenter: parent.verticalCenter | 59 | verticalCenter: parent.verticalCenter | ||
69 | } | 60 | } | ||
70 | } | 61 | } | ||
71 | 62 | | |||
72 | onContextMenu: { | 63 | onContextMenu: { | ||
73 | openContextMenu(plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y)) | 64 | openContextMenu(plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y)) | ||
74 | } | 65 | } | ||
75 | 66 | | |||
76 | onClicked: { | 67 | onClicked: { | ||
77 | var pos = plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y); | 68 | var pos = plasmoid.nativeInterface.popupPosition(taskIcon, mouse.x, mouse.y); | ||
78 | 69 | | |||
79 | switch (mouse.button) { | 70 | switch (mouse.button) { | ||
80 | case Qt.LeftButton: | 71 | case Qt.LeftButton: | ||
81 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 72 | var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); | ||
82 | var operation = service.operationDescription("Activate"); | 73 | var operation = service.operationDescription("Activate"); | ||
83 | operation.x = pos.x; | 74 | operation.x = pos.x; | ||
84 | operation.y = pos.y; | 75 | operation.y = pos.y; | ||
85 | var job = service.startOperationCall(operation); | 76 | var job = service.startOperationCall(operation); | ||
86 | job.finished.connect(function () { | 77 | job.finished.connect(function () { | ||
87 | if (!job.result) { | 78 | if (!job.result) { | ||
88 | // On error try to invoke the context menu. | 79 | // On error try to invoke the context menu. | ||
89 | // Workaround primarily for apps using libappindicator. | 80 | // Workaround primarily for apps using libappindicator. | ||
90 | openContextMenu(pos); | 81 | openContextMenu(pos); | ||
91 | } | 82 | } | ||
92 | }); | 83 | }); | ||
93 | taskIcon.activated() | 84 | taskIcon.activated() | ||
94 | break; | 85 | break; | ||
95 | case Qt.RightButton: | 86 | case Qt.RightButton: | ||
96 | openContextMenu(pos); | 87 | openContextMenu(pos); | ||
97 | break; | 88 | break; | ||
98 | 89 | | |||
99 | case Qt.MiddleButton: | 90 | case Qt.MiddleButton: | ||
100 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 91 | var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); | ||
101 | var operation = service.operationDescription("SecondaryActivate"); | 92 | var operation = service.operationDescription("SecondaryActivate"); | ||
102 | operation.x = pos.x; | 93 | operation.x = pos.x; | ||
103 | 94 | | |||
104 | operation.y = pos.y; | 95 | operation.y = pos.y; | ||
105 | service.startOperationCall(operation); | 96 | service.startOperationCall(operation); | ||
106 | taskIcon.activated() | 97 | taskIcon.activated() | ||
107 | break; | 98 | break; | ||
108 | } | 99 | } | ||
109 | } | 100 | } | ||
110 | 101 | | |||
111 | function openContextMenu(pos) { | 102 | function openContextMenu(pos) { | ||
112 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 103 | var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); | ||
113 | var operation = service.operationDescription("ContextMenu"); | 104 | var operation = service.operationDescription("ContextMenu"); | ||
114 | operation.x = pos.x; | 105 | operation.x = pos.x; | ||
115 | operation.y = pos.y; | 106 | operation.y = pos.y; | ||
116 | 107 | | |||
117 | var job = service.startOperationCall(operation); | 108 | var job = service.startOperationCall(operation); | ||
118 | job.finished.connect(function () { | 109 | job.finished.connect(function () { | ||
119 | plasmoid.nativeInterface.showStatusNotifierContextMenu(job, taskIcon); | 110 | plasmoid.nativeInterface.showStatusNotifierContextMenu(job, taskIcon); | ||
120 | }); | 111 | }); | ||
121 | } | 112 | } | ||
122 | 113 | | |||
123 | onWheel: { | 114 | onWheel: { | ||
124 | //don't send activateVertScroll with a delta of 0, some clients seem to break (kmix) | 115 | //don't send activateVertScroll with a delta of 0, some clients seem to break (kmix) | ||
125 | if (wheel.angleDelta.y !== 0) { | 116 | if (wheel.angleDelta.y !== 0) { | ||
126 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 117 | var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); | ||
127 | var operation = service.operationDescription("Scroll"); | 118 | var operation = service.operationDescription("Scroll"); | ||
128 | operation.delta =wheel.angleDelta.y; | 119 | operation.delta =wheel.angleDelta.y; | ||
129 | operation.direction = "Vertical"; | 120 | operation.direction = "Vertical"; | ||
130 | service.startOperationCall(operation); | 121 | service.startOperationCall(operation); | ||
131 | } | 122 | } | ||
132 | if (wheel.angleDelta.x !== 0) { | 123 | if (wheel.angleDelta.x !== 0) { | ||
133 | var service = statusNotifierSource.serviceForSource(DataEngineSource); | 124 | var service = plasmoid.nativeInterface.serviceForSource(model.DataEngineSource); | ||
134 | var operation = service.operationDescription("Scroll"); | 125 | var operation = service.operationDescription("Scroll"); | ||
135 | operation.delta =wheel.angleDelta.x; | 126 | operation.delta =wheel.angleDelta.x; | ||
136 | operation.direction = "Horizontal"; | 127 | operation.direction = "Horizontal"; | ||
137 | service.startOperationCall(operation); | 128 | service.startOperationCall(operation); | ||
138 | } | 129 | } | ||
139 | } | 130 | } | ||
140 | } | 131 | } |