[MessageTray] add support for notification actions

https://bugzilla.gnome.org/show_bug.cgi?id=606979
This commit is contained in:
Dan Winship 2010-02-01 15:41:22 -05:00
parent d20d815b45
commit e40063fc34
3 changed files with 61 additions and 1 deletions

View File

@ -561,6 +561,28 @@ StTooltip {
spacing-columns: 10px; spacing-columns: 10px;
} }
#notification-actions {
spacing: 5px;
}
.notification-button {
border: 2px rgba(0,0,0,0.0);
border-radius: 5px;
padding: 5px;
background: #c0c0c0;
color: black;
font-weight: bold;
}
.notification-button:hover {
border: 2px solid white;
}
.notification-button:active {
border: 2px solid white;
background: #808080;
}
#summary-mode { #summary-mode {
spacing: 10px; spacing: 10px;
padding: 2px 4px; padding: 2px 4px;

View File

@ -103,6 +103,25 @@ Notification.prototype = {
this.actor.add(this._bodyText, { row: 1, this.actor.add(this._bodyText, { row: 1,
col: 1 }); col: 1 });
this.actions = {};
this._buttonBox = null;
},
addAction: function(id, label) {
if (!this._buttonBox) {
this._buttonBox = new St.BoxLayout({ name: 'notification-actions' });
this.actor.add(this._buttonBox, { row: 2,
col: 1,
x_expand: false,
x_fill: false,
x_align: 1.0 });
this._canPopOut = true;
}
let button = new St.Button({ style_class: 'notification-button',
label: label });
this._buttonBox.add(button);
button.connect('clicked', Lang.bind(this, function() { this.emit('action-invoked', id); }));
}, },
_bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) { _bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) {
@ -167,6 +186,7 @@ Notification.prototype = {
return true; return true;
} }
}; };
Signals.addSignalMethods(Notification.prototype);
function Source(id, createIcon) { function Source(id, createIcon) {
this._init(id, createIcon); this._init(id, createIcon);

View File

@ -124,6 +124,12 @@ NotificationDaemon.prototype = {
summary = GLib.markup_escape_text(summary, -1); summary = GLib.markup_escape_text(summary, -1);
let notification = new MessageTray.Notification(source, summary, body); let notification = new MessageTray.Notification(source, summary, body);
if (actions.length) {
for (let i = 0; i < actions.length - 1; i += 2)
notification.addAction(actions[i], actions[i + 1]);
notification.connect('action-invoked', Lang.bind(this, this._actionInvoked, source, id));
}
source.notify(notification); source.notify(notification);
return id; return id;
}, },
@ -137,7 +143,7 @@ NotificationDaemon.prototype = {
GetCapabilities: function() { GetCapabilities: function() {
return [ return [
// 'actions', 'actions',
'body', 'body',
// 'body-hyperlinks', // 'body-hyperlinks',
// 'body-images', // 'body-images',
@ -157,11 +163,23 @@ NotificationDaemon.prototype = {
]; ];
}, },
_actionInvoked: function(notification, action, source, id) {
this._emitActionInvoked(id, action);
source.destroy();
},
_emitNotificationClosed: function(id, reason) { _emitNotificationClosed: function(id, reason) {
DBus.session.emit_signal('/org/freedesktop/Notifications', DBus.session.emit_signal('/org/freedesktop/Notifications',
'org.freedesktop.Notifications', 'org.freedesktop.Notifications',
'NotificationClosed', 'uu', 'NotificationClosed', 'uu',
[id, reason]); [id, reason]);
},
_emitActionInvoked: function(id, action) {
DBus.session.emit_signal('/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
'ActionInvoked', 'us',
[id, action]);
} }
}; };