Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/tests/test.qml
- This file was added.
1 | import QtQuick 2.0 | ||||
---|---|---|---|---|---|
2 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
3 | import org.kde.plasma.plasmoid 2.0 | ||||
4 | | ||||
5 | Item { | ||||
6 | id: root | ||||
7 | property QtObject plasmoidItem: null | ||||
8 | onPlasmoidItemChanged: { | ||||
9 | if (plasmoidItem && !root.plasmoidItem.rootItem) { | ||||
10 | discardTimer.running = true | ||||
11 | return | ||||
12 | } | ||||
13 | | ||||
14 | showNotification("testing test") | ||||
15 | console.log("sent notification", root.plasmoidItem, root.plasmoidItem.rootItem) | ||||
16 | } | ||||
17 | Timer { | ||||
18 | id: discardTimer | ||||
19 | interval: 0 | ||||
20 | running: false | ||||
21 | onTriggered: { | ||||
22 | notificationShown = notificationClosed = true | ||||
23 | root.done(); | ||||
24 | } | ||||
25 | } | ||||
26 | | ||||
27 | PlasmaCore.DataSource { | ||||
28 | id: notificationSource | ||||
29 | engine: "notifications" | ||||
30 | connectedSources: "org.freedesktop.Notifications" | ||||
31 | } | ||||
32 | | ||||
33 | function showNotification(summary, icon, appname, body, timeout) { | ||||
34 | if(!icon) icon = "debug-run" | ||||
35 | if(!appname) appname="test" | ||||
36 | if(!body) body="" | ||||
37 | if(!timeout) timeout=2000 | ||||
38 | | ||||
39 | var service = notificationSource.serviceForSource("notification"); | ||||
40 | var operation = service.operationDescription("createNotification"); | ||||
41 | operation["appName"] = appname; | ||||
42 | operation["appIcon"] = icon; | ||||
43 | operation["summary"] = summary; | ||||
44 | operation["body"] = body; | ||||
45 | operation["timeout"] = timeout; | ||||
46 | | ||||
47 | service.startOperationCall(operation); | ||||
48 | } | ||||
49 | | ||||
50 | Connections { | ||||
51 | target: root.plasmoidItem.rootItem ? root.plasmoidItem.rootItem.notifications : null | ||||
52 | onPopupShown: { | ||||
53 | root.notificationShown = true | ||||
54 | popupConnections.target = popup | ||||
55 | } | ||||
56 | } | ||||
57 | | ||||
58 | Connections { | ||||
59 | id: popupConnections | ||||
60 | onVisibleChanged: { | ||||
61 | if (target.visible) { | ||||
62 | popupConnections.target.mainItem.clicked(null) | ||||
63 | } else { | ||||
64 | root.notificationClosed = true | ||||
65 | root.done() | ||||
66 | } | ||||
67 | } | ||||
68 | } | ||||
69 | | ||||
70 | property bool notificationShown: false | ||||
71 | property bool notificationClosed: false | ||||
72 | signal done() | ||||
73 | readonly property bool failed: notificationShown && notificationClosed | ||||
74 | } |