From 34434ff36777ef2cf64a7ec36e63d2280a730680 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 19 Mar 2015 12:11:17 +0100 Subject: [PATCH] make actions work --- .../contents/ui/NotificationStripe.qml | 37 ++++++++++++++++--- applets/notifications/contents/ui/main.qml | 20 ++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/applets/notifications/contents/ui/NotificationStripe.qml b/applets/notifications/contents/ui/NotificationStripe.qml index 5a6374c9..2023446d 100644 --- a/applets/notifications/contents/ui/NotificationStripe.qml +++ b/applets/notifications/contents/ui/NotificationStripe.qml @@ -24,16 +24,18 @@ import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents MouseArea { - id: root + id: notificationItem - height: units.gridUnit * (expanded ? 4 : 2) + background.margins.top + background.margins.bottom + height: units.gridUnit * (expanded ? (actionsLayout.visible ? 6 : 4) : 2) + background.margins.top + background.margins.bottom width: parent.width anchors.bottomMargin: 10 drag.axis: Drag.XAxis - drag.target: root + drag.target: notificationItem property bool expanded: false + property string source: model.source + property var actions: model.actions Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } @@ -61,7 +63,7 @@ MouseArea { imagePath: "widgets/background" anchors { fill: parent - rightMargin: -root.width + rightMargin: -notificationItem.width leftMargin: units.gridUnit } colorGroup: PlasmaCore.ColorScope.colorGroup @@ -95,22 +97,45 @@ MouseArea { anchors { right: icon.left verticalCenter: parent.verticalCenter + rightMargin: units.smallSpacing } horizontalAlignment: Qt.AlignRight verticalAlignment: Qt.AlignVCenter color: PlasmaCore.ColorScope.textColor - text: summary + (root.expanded ? (body ? "\n" + body : '') : + text: summary + (notificationItem.expanded ? (body ? "\n" + body : '') : (body ? '...' : '')) } PlasmaCore.IconItem { id: icon anchors { - right: root.right + right: notificationItem.right verticalCenter: parent.verticalCenter } width: units.iconSizes.medium height: width source: appIcon && appIcon.length > 0 ? appIcon : "im-user" } + RowLayout { + id: actionsLayout + anchors { + right: summaryText.right + top: summaryText.bottom + topMargin: units.smallSpacing + } + opacity: notificationItem.expanded && notificationItem.actions && notificationItem.actions.count > 0 ? 1 : 0 + Behavior on opacity { + NumberAnimation { + duration: units.shortDuration + easing.type: Easing.InOutQuad + } + } + Repeater { + model: notificationItem.actions + delegate: PlasmaComponents.Button { + text: model.text + onClicked: root.executeAction(notificationItem.source, model.id) + } + } + } } diff --git a/applets/notifications/contents/ui/main.qml b/applets/notifications/contents/ui/main.qml index 692c377e..27199ed5 100644 --- a/applets/notifications/contents/ui/main.qml +++ b/applets/notifications/contents/ui/main.qml @@ -64,6 +64,20 @@ Item { } } + function executeAction(source, id) { + //try to use the service + if (source.indexOf("notification") !== -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 (source.indexOf("Job") !== -1) { + Qt.openUrlExternally(id) + } + } + PlasmaCore.DataSource { id: notificationsSource @@ -106,20 +120,26 @@ Item { id: notificationsModel ListElement { + source: "call1Source" appIcon: "call-start" summary: "Missed call from Joe" appName: "Phone" body: "Called at 8:42 from +41 56 373 37 31" + actions: [] } ListElement { + source: "im1Source" appIcon: "im-google" appName: "Message" summary: "July: Hey! Are you around?" + actions: [] } ListElement { + source: "im2Source" appIcon: "im-google" appName: "Message" summary: "July: Hello?" + actions: [] } }