mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-01 01:07:33 +00:00
make actions work
This commit is contained in:
parent
f1ce156ce9
commit
34434ff367
2 changed files with 51 additions and 6 deletions
|
|
@ -24,16 +24,18 @@ import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||||
|
|
||||||
MouseArea {
|
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
|
width: parent.width
|
||||||
anchors.bottomMargin: 10
|
anchors.bottomMargin: 10
|
||||||
drag.axis: Drag.XAxis
|
drag.axis: Drag.XAxis
|
||||||
drag.target: root
|
drag.target: notificationItem
|
||||||
|
|
||||||
property bool expanded: false
|
property bool expanded: false
|
||||||
|
property string source: model.source
|
||||||
|
property var actions: model.actions
|
||||||
|
|
||||||
Behavior on x {
|
Behavior on x {
|
||||||
SpringAnimation { spring: 2; damping: 0.2 }
|
SpringAnimation { spring: 2; damping: 0.2 }
|
||||||
|
|
@ -61,7 +63,7 @@ MouseArea {
|
||||||
imagePath: "widgets/background"
|
imagePath: "widgets/background"
|
||||||
anchors {
|
anchors {
|
||||||
fill: parent
|
fill: parent
|
||||||
rightMargin: -root.width
|
rightMargin: -notificationItem.width
|
||||||
leftMargin: units.gridUnit
|
leftMargin: units.gridUnit
|
||||||
}
|
}
|
||||||
colorGroup: PlasmaCore.ColorScope.colorGroup
|
colorGroup: PlasmaCore.ColorScope.colorGroup
|
||||||
|
|
@ -95,22 +97,45 @@ MouseArea {
|
||||||
anchors {
|
anchors {
|
||||||
right: icon.left
|
right: icon.left
|
||||||
verticalCenter: parent.verticalCenter
|
verticalCenter: parent.verticalCenter
|
||||||
|
rightMargin: units.smallSpacing
|
||||||
}
|
}
|
||||||
horizontalAlignment: Qt.AlignRight
|
horizontalAlignment: Qt.AlignRight
|
||||||
verticalAlignment: Qt.AlignVCenter
|
verticalAlignment: Qt.AlignVCenter
|
||||||
color: PlasmaCore.ColorScope.textColor
|
color: PlasmaCore.ColorScope.textColor
|
||||||
text: summary + (root.expanded ? (body ? "\n" + body : '') :
|
text: summary + (notificationItem.expanded ? (body ? "\n" + body : '') :
|
||||||
(body ? '...' : ''))
|
(body ? '...' : ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
PlasmaCore.IconItem {
|
PlasmaCore.IconItem {
|
||||||
id: icon
|
id: icon
|
||||||
anchors {
|
anchors {
|
||||||
right: root.right
|
right: notificationItem.right
|
||||||
verticalCenter: parent.verticalCenter
|
verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
width: units.iconSizes.medium
|
width: units.iconSizes.medium
|
||||||
height: width
|
height: width
|
||||||
source: appIcon && appIcon.length > 0 ? appIcon : "im-user"
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
PlasmaCore.DataSource {
|
||||||
id: notificationsSource
|
id: notificationsSource
|
||||||
|
|
||||||
|
|
@ -106,20 +120,26 @@ Item {
|
||||||
id: notificationsModel
|
id: notificationsModel
|
||||||
|
|
||||||
ListElement {
|
ListElement {
|
||||||
|
source: "call1Source"
|
||||||
appIcon: "call-start"
|
appIcon: "call-start"
|
||||||
summary: "Missed call from Joe"
|
summary: "Missed call from Joe"
|
||||||
appName: "Phone"
|
appName: "Phone"
|
||||||
body: "Called at 8:42 from +41 56 373 37 31"
|
body: "Called at 8:42 from +41 56 373 37 31"
|
||||||
|
actions: []
|
||||||
}
|
}
|
||||||
ListElement {
|
ListElement {
|
||||||
|
source: "im1Source"
|
||||||
appIcon: "im-google"
|
appIcon: "im-google"
|
||||||
appName: "Message"
|
appName: "Message"
|
||||||
summary: "July: Hey! Are you around?"
|
summary: "July: Hey! Are you around?"
|
||||||
|
actions: []
|
||||||
}
|
}
|
||||||
ListElement {
|
ListElement {
|
||||||
|
source: "im2Source"
|
||||||
appIcon: "im-google"
|
appIcon: "im-google"
|
||||||
appName: "Message"
|
appName: "Message"
|
||||||
summary: "July: Hello?"
|
summary: "July: Hello?"
|
||||||
|
actions: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue