..
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 | /*
* Copyright 2012 Marco Martin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.0
import QtQuick.Window 2.2
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.private.notifications 1.0
Item {
id: notificationsRoot
property QtObject notificationPopup
property alias count: notificationsModel.count
Component.onCompleted: {
// Create the popup components and pass them to the C++ plugin
for (var i = 0; i < 3; i++) {
var popup = notificationPopupComponent.createObject();
notificationPositioner.addNotificationPopup(popup);
}
}
function addNotification(notification) {
// Do not show duplicated notifications
for (var i = 0; i < notificationsModel.count; ++i) {
if (notificationsModel.get(i).source == notification.source &&
notificationsModel.get(i).appName == notification.appName &&
notificationsModel.get(i).summary == notification.summary &&
notificationsModel.get(i).body == notification.body) {
return
}
}
for (var i = 0; i < notificationsModel.count; ++i) {
if (notificationsModel.get(i).source == notification.source ||
(notificationsModel.get(i).appName == notification.appName &&
notificationsModel.get(i).summary == notification.summary &&
notificationsModel.get(i).body == notification.body)) {
notificationsModel.remove(i)
break
}
}
/* Stacking limit disable
if (notificationsModel.count > 20) {
notificationsModel.remove(notificationsModel.count-1)
}*/
if (notification.isPersistent || plasmoid.configuration.stackAll) {
// Group notifications by app name
var position = 0;
while (position < notificationsModel.count &&
notificationsModel.get(position).appName != notification.appName)
position ++;
notification.created = new Date();
notificationsModel.inserting = true;
notificationsModel.insert(position, notification);
notificationsModel.inserting = false;
}
notificationPositioner.displayNotification(notification);
}
function executeAction(source, id) {
//try to use the service
if (id.indexOf("jobUrl#") === -1) {
var service = notificationsSource.serviceForSource(source)
var op = service.operationDescription("invokeAction")
op["actionId"] = id
service.startOperationCall(op)
//try to open the id as url
} else if (id.indexOf("jobUrl#") !== -1) {
Qt.openUrlExternally(id.slice(7));
notificationPositioner.closePopup(source);
}
}
function configureNotification(appRealName) {
var service = notificationsSource.serviceForSource("notification")
var op = service.operationDescription("configureNotification")
op["appRealName"] = appRealName;
service.startOperationCall(op)
}
function createNotification(data) {
var service = notificationsSource.serviceForSource("notification");
var op = service.operationDescription("createNotification");
// add everything from "data" to "op"
for (var attrname in data) { op[attrname] = data[attrname]; }
service.startOperationCall(op);
}
function closeNotification(source) {
var service = notificationsSource.serviceForSource(source)
var op = service.operationDescription("userClosed")
service.startOperationCall(op)
}
function expireNotification(source) {
var service = notificationsSource.serviceForSource(source)
var op = service.operationDescription("expireNotification")
service.startOperationCall(op)
}
function clearAll() {
for (var i = 0; i < notificationsModel.count; i ++) {
var notificationProperties = notificationsModel.get(i)
closeNotification(notificationProperties.source)
}
// notificationsModel.clear();
}
Component {
id: notificationPopupComponent
NotificationPopup { }
}
property ListModel model : ListModel {
id: notificationsModel
property bool inserting: false
}
property QtObject idleTimeSource: PlasmaCore.DataSource {
id: idleTimeSource
property bool idle: data["UserActivity"]["IdleTime"] > 300000
engine: "powermanagement"
interval: 30000
connectedSources: ["UserActivity"]
//Idle with more than 5 minutes of user inactivity
}
PlasmaCore.DataSource {
id: notificationsSource
engine: "notifications"
interval: 0
onSourceAdded: {
connectSource(source);
}
onSourceRemoved: {
notificationPositioner.closePopup(source);
for (var i = 0; i < notificationsModel.count; ++i) {
if (notificationsModel.get(i).source == source) {
notificationsModel.remove(i)
break
}
}
}
onNewData: {
var _data = data; // Temp copy to avoid lots of context switching
var actions = []
if (data["actions"] && data["actions"].length % 2 == 0) {
for (var i = 0; i < data["actions"].length; i += 2) {
actions.push({
id: data["actions"][i],
text: data["actions"][i+1]
})
}
}
_data["source"] = sourceName
_data["actions"] = actions
notificationsRoot.addNotification(_data)
}
}
}
|
|