diff --git a/applets/notifications/package/contents/tests/test.qml b/applets/notifications/package/contents/tests/test.qml new file mode 100644 --- /dev/null +++ b/applets/notifications/package/contents/tests/test.qml @@ -0,0 +1,74 @@ +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.plasmoid 2.0 + +Item { + id: root + property QtObject plasmoidItem: null + onPlasmoidItemChanged: { + if (plasmoidItem && !root.plasmoidItem.rootItem) { + discardTimer.running = true + return + } + + showNotification("testing test") + console.log("sent notification", root.plasmoidItem, root.plasmoidItem.rootItem) + } + Timer { + id: discardTimer + interval: 0 + running: false + onTriggered: { + notificationShown = notificationClosed = true + root.done(); + } + } + + PlasmaCore.DataSource { + id: notificationSource + engine: "notifications" + connectedSources: "org.freedesktop.Notifications" + } + + function showNotification(summary, icon, appname, body, timeout) { + if(!icon) icon = "debug-run" + if(!appname) appname="test" + if(!body) body="" + if(!timeout) timeout=2000 + + var service = notificationSource.serviceForSource("notification"); + var operation = service.operationDescription("createNotification"); + operation["appName"] = appname; + operation["appIcon"] = icon; + operation["summary"] = summary; + operation["body"] = body; + operation["timeout"] = timeout; + + service.startOperationCall(operation); + } + + Connections { + target: root.plasmoidItem.rootItem ? root.plasmoidItem.rootItem.notifications : null + onPopupShown: { + root.notificationShown = true + popupConnections.target = popup + } + } + + Connections { + id: popupConnections + onVisibleChanged: { + if (target.visible) { + popupConnections.target.mainItem.close() + } else { + root.notificationClosed = true + root.done() + } + } + } + + property bool notificationShown: false + property bool notificationClosed: false + signal done() + readonly property bool failed: !notificationShown || !notificationClosed +} diff --git a/applets/notifications/package/contents/ui/Notifications.qml b/applets/notifications/package/contents/ui/Notifications.qml --- a/applets/notifications/package/contents/ui/Notifications.qml +++ b/applets/notifications/package/contents/ui/Notifications.qml @@ -31,8 +31,8 @@ right: parent.right } - property QtObject notificationPopup property alias count: notificationsRepeater.count + signal popupShown(var popup) Component.onCompleted: { // Create the popup components and pass them to the C++ plugin @@ -214,6 +214,7 @@ Component.onCompleted: { notificationPositioner.setPlasmoidScreenGeometry(plasmoid.nativeInterface.availableScreenRect); } + onPopupShown: notificationsRoot.popupShown(popup) } Repeater { diff --git a/applets/notifications/plugin/notificationshelper.h b/applets/notifications/plugin/notificationshelper.h --- a/applets/notifications/plugin/notificationshelper.h +++ b/applets/notifications/plugin/notificationshelper.h @@ -67,6 +67,7 @@ Q_SIGNALS: void popupLocationChanged(); + void popupShown(QQuickWindow* popup); // void plasmoidScreenChanged(); private Q_SLOTS: diff --git a/applets/notifications/plugin/notificationshelper.cpp b/applets/notifications/plugin/notificationshelper.cpp --- a/applets/notifications/plugin/notificationshelper.cpp +++ b/applets/notifications/plugin/notificationshelper.cpp @@ -149,6 +149,7 @@ // Populate the popup with data, this is the component's own QML method QMetaObject::invokeMethod(popup, "populatePopup", Qt::DirectConnection, Q_ARG(QVariant, notificationData)); + Q_EMIT popupShown(popup); QTimer::singleShot(300, popup, &QWindow::show);