Commit 28d86ab4 authored by Julian Wolff's avatar Julian Wolff

optionally show a history of notifications

Summary:
Bug 378032.
	With these changes, notifications can be configured to always persist in the notifications applet.

	Todo: filter by application, see https://bugs.kde.org/show_bug.cgi?id=378032#c27

Test Plan: Open the notification plasmoid's settings. Check 'Show a history of notifications'. Trigger some notifications. They should show up in the applet.

Reviewers: #plasma, #vdg, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: mart, graesslin, davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7271
parent 4b162496
......@@ -14,6 +14,10 @@
<label>Show the jobs progress</label>
<default>true</default>
</entry>
<entry name="showHistory" type="Bool">
<label>Show a history of notifications</label>
<default>true</default>
</entry>
</group>
</kcfg>
......@@ -27,6 +27,8 @@ import org.kde.kquickcontrolsaddons 2.0
PlasmaComponents.ListItem {
id: notificationItem
width: popupFlickable.width
property ListModel listModel;
opacity: 1-Math.abs(x)/width
......@@ -38,8 +40,8 @@ PlasmaComponents.ListItem {
repeat: false
running: !idleTimeSource.idle
onTriggered: {
if (!notificationsModel.inserting)
notificationsModel.remove(index)
if (!listModel.inserting)
listModel.remove(index)
}
}
......@@ -87,7 +89,7 @@ PlasmaComponents.ListItem {
ScriptAction {
script: {
closeNotification(model.source);
notificationsModel.remove(index);
listModel.remove(index);
}
}
}
......@@ -133,11 +135,11 @@ PlasmaComponents.ListItem {
}
onClose: {
if (notificationsModel.count > 1) {
if (listModel.count > 1) {
removeAnimation.running = true
} else {
closeNotification(model.source)
notificationsModel.remove(index)
listModel.remove(index)
}
}
onConfigure: {
......
......@@ -33,7 +33,7 @@ Item {
svg: notificationSvg
elementId: {
if (totalCount > 0) {
if (activeItemsCount > 0) {
if (jobs && jobs.count > 0) {
return "notification-progress-inactive"
} else {
......@@ -85,7 +85,7 @@ Item {
PlasmaComponents.Label {
id: notificationCountLabel
property int oldTotalCount: 0
property int oldActiveItemsCount: 0
// anchors.fill: parent breaks at small sizes for some reason
anchors.centerIn: parent
......@@ -94,19 +94,19 @@ Item {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: notificationsApplet.totalCount
text: notificationsApplet.activeItemsCount
font.pointSize: 100
fontSizeMode: Text.Fit
minimumPointSize: theme.smallestFont.pointSize
visible: notificationsApplet.totalCount > 0
visible: notificationsApplet.activeItemsCount > 0
Connections {
target: notificationsApplet
onTotalCountChanged: {
if (notificationsApplet.totalCount > notificationCountLabel.oldTotalCount) {
onActiveItemsCountChanged: {
if (notificationsApplet.activeItemsCount > notificationCountLabel.oldActiveItemsCount) {
notificationAnimation.running = true
}
notificationCountLabel.oldTotalCount = notificationsApplet.totalCount
notificationCountLabel.oldActiveItemsCount = notificationsApplet.activeItemsCount
}
}
......
......@@ -20,6 +20,7 @@
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.private.notifications 1.0
......@@ -32,7 +33,16 @@ Column {
}
property alias count: notificationsRepeater.count
property alias historyCount: notificationsHistoryRepeater.count
property bool showHistory
signal popupShown(var popup)
onShowHistoryChanged: {
if(!showHistory)
clearHistory()
}
Component.onCompleted: {
// Create the popup components and pass them to the C++ plugin
......@@ -74,6 +84,28 @@ Column {
notificationsModel.insert(0, notification);
notificationsModel.inserting = false;
}
else if (showHistory) {
notificationsHistoryModel.inserting = true;
//create a copy of the notification.
//Disable actions in this copy as they will stop working once the original notification is closed.
notificationsHistoryModel.insert(0, {
"compact" : notification.compact,
"icon" : notification.icon,
"image" : notification.image,
"summary" : notification.summary,
"body" : notification.body,
"configurable" : false,
"created" : new Date(),
"urls" : notification.urls,
"maximumTextHeight" : notification.maximumTextHeight,
"actions" : null,
"hasDefaultAction" : false,
"hasConfigureAction" : false,
});
notificationsHistoryModel.inserting = false;
}
notificationPositioner.displayNotification(notification);
}
......@@ -129,6 +161,11 @@ Column {
}
notificationsModel.clear()
clearHistory()
}
function clearHistory() {
notificationsHistoryModel.clear()
}
Component {
......@@ -140,6 +177,11 @@ Column {
id: notificationsModel
property bool inserting: false
}
ListModel {
id: notificationsHistoryModel
property bool inserting: false
}
PlasmaCore.DataSource {
id: idleTimeSource
......@@ -220,6 +262,20 @@ Column {
Repeater {
id: notificationsRepeater
model: notificationsModel
delegate: NotificationDelegate {}
delegate: NotificationDelegate { listModel: notificationsModel }
}
PlasmaExtras.Heading {
width: parent.width
level: 3
opacity: 0.6
visible: historyCount > 0
text: i18n("History")
}
Repeater {
id: notificationsHistoryRepeater
model: notificationsHistoryModel
delegate: NotificationDelegate { listModel: notificationsHistoryModel }
}
}
......@@ -35,6 +35,7 @@ Item {
property alias cfg_showNotifications: showNotificationsCheckBox.checked
property alias cfg_showJobs: showJobsCheckBox.checked
property alias cfg_showHistory: showHistoryCheckBox.checked
QtLayouts.ColumnLayout {
anchors.left: parent.left
......@@ -47,6 +48,12 @@ Item {
id: showJobsCheckBox
text: i18n("Track file transfers and other jobs")
}
QtControls.CheckBox {
id: showHistoryCheckBox
text: i18n("Show a history of notifications")
}
QtControls.CheckBox {
id: useCustomPopupPositionCheckBox
text: i18n("Use custom position for the notification popup")
......
......@@ -51,24 +51,25 @@ MouseEventListener {
property Item notifications: notificationsLoader.item
property Item jobs: jobsLoader.item
//notifications + jobs
property int totalCount: (notifications ? notifications.count : 0) + (jobs ? jobs.count : 0)
property int activeItemsCount: (notifications ? notifications.count : 0) + (jobs ? jobs.count : 0)
property int totalCount: activeItemsCount + (notifications ? notifications.historyCount : 0)
Plasmoid.switchWidth: units.gridUnit * 20
Plasmoid.switchHeight: units.gridUnit * 30
Plasmoid.status: totalCount > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus
Plasmoid.status: activeItemsCount > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus
Plasmoid.icon: {
if (jobs && jobs.count) {
return "notification-active"
}
return totalCount ? "notification-inactive" : "notification-disabled"
return activeItemsCount ? "notification-inactive" : "notification-disabled"
}
Plasmoid.toolTipSubText: {
if (totalCount == 0) {
if (activeItemsCount == 0) {
return i18n("No notifications or jobs")
} else if (!notifications || !notifications.count) {
return i18np("%1 running job", "%1 running jobs", jobs.count)
......@@ -83,8 +84,8 @@ MouseEventListener {
hoverEnabled: !UiProperties.touchInput
onTotalCountChanged: {
if (!totalCount) {
onActiveItemsCountChanged: {
if (!activeItemsCount) {
plasmoid.expanded = false;
}
}
......@@ -134,6 +135,9 @@ MouseEventListener {
width: parent.width
source: "Notifications.qml"
active: notificationsApplet.Plasmoid.configuration.showNotifications
onLoaded: {
notificationsLoader.item.showHistory = Qt.binding(function(){ return notificationsApplet.Plasmoid.configuration.showHistory })
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment