NotificationDaemon: add support for resident notifications

Resident notifications don't get removed when they are clicked or
one of their actions is invoked, and are only removed when the app
that created them requests them to be removed or sends another
notification.

Remove the source when a notification associated with it is removed.
Except if the source is a tray icon.

Make sure that we pop down the tray when a notification is clicked
or one of the actions of a non-resident notification is selected.

Based on the initial patch by Jonathan Matthew.

https://bugzilla.gnome.org/show_bug.cgi?id=633412
This commit is contained in:
Marina Zhurakhinskaya
2010-12-16 15:49:47 -05:00
parent 7279cc1db8
commit 2a19d5f143
2 changed files with 57 additions and 14 deletions

View File

@ -291,7 +291,10 @@ NotificationDaemon.prototype = {
function(n) {
delete this._notifications[id];
}));
notification.connect('action-invoked', Lang.bind(this, this._actionInvoked, source, id));
notification.connect('action-invoked', Lang.bind(this,
function(n, actionId) {
this._emitActionInvoked(id, actionId);
}));
} else {
notification.update(summary, body, { icon: iconActor,
bannerMarkup: true,
@ -305,6 +308,7 @@ NotificationDaemon.prototype = {
}
notification.setUrgent(hints.urgency == Urgency.CRITICAL);
notification.setResident(hints.resident == true);
let sourceIconActor = source.useNotificationIcon ? this._iconForNotificationData(icon, hints, source.ICON_SIZE) : null;
source.notify(notification, sourceIconActor);
@ -352,17 +356,13 @@ NotificationDaemon.prototype = {
for (let id in this._sources) {
let source = this._sources[id];
if (source.app == tracker.focus_app) {
source.activated();
if (source.notification && !source.notification.resident)
source.notification.destroy();
return;
}
}
},
_actionInvoked: function(notification, action, source, id) {
source.activated();
this._emitActionInvoked(id, action);
},
_emitNotificationClosed: function(id, reason) {
DBus.session.emit_signal('/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
@ -421,6 +421,9 @@ Source.prototype = {
},
_setApp: function() {
if (this.app)
return;
this.app = Shell.WindowTracker.get_default().get_app_from_pid(this._pid);
if (!this.app)
return;
@ -440,12 +443,10 @@ Source.prototype = {
},
_notificationClicked: function(notification) {
notification.destroy();
this.openApp();
this.activated();
},
activated: function() {
_notificationRemoved: function() {
if (!this._isTrayIcon)
this.destroy();
},