MessageTray: untangle click notifications

Previously, when you clicked on a notification, it would call
this.source.clicked(), which would emit a 'clicked' signal on the
source, and then various other stuff would happen from there. This
used to make a little bit of sense, when clicking on a notification
was supposed to do the same thing as clicking on its source, but makes
less sense now, when clicking on the source itself *doesn't* call
source.clicked()...

Change it so that when you click on a notification, the notification
emits 'clicked' itself, and the source notices that and calls its
notificationClicked() method, and the various source subclasses do
what they need to do with that, and Source no longer has a clicked
method/signal.

https://bugzilla.gnome.org/show_bug.cgi?id=631042
This commit is contained in:
Dan Winship 2010-09-30 16:41:38 -04:00
parent 80f23841e4
commit de16108dff
4 changed files with 16 additions and 25 deletions

View File

@ -116,11 +116,6 @@ Notification.prototype = {
this._capturedEventId = 0; this._capturedEventId = 0;
this._keyPressId = 0; this._keyPressId = 0;
source.connect('clicked', Lang.bind(this,
function() {
this.emit('dismissed');
}));
source.connect('destroy', Lang.bind(this, this.destroy)); source.connect('destroy', Lang.bind(this, this.destroy));
this.actor = new St.Table({ name: 'notification', this.actor = new St.Table({ name: 'notification',
@ -130,7 +125,7 @@ Notification.prototype = {
function (actor, event) { function (actor, event) {
if (!this._actionArea || if (!this._actionArea ||
!this._actionArea.contains(event.get_source())) !this._actionArea.contains(event.get_source()))
this.source.clicked(); this.emit('clicked');
})); }));
// The first line should have the title, followed by the // The first line should have the title, followed by the
@ -665,26 +660,26 @@ Source.prototype = {
}, },
notify: function(notification) { notify: function(notification) {
if (this.notification) if (this.notification) {
this.notification.disconnect(this._notificationClickedId);
this.notification.disconnect(this._notificationDestroyedId); this.notification.disconnect(this._notificationDestroyedId);
}
this.notification = notification; this.notification = notification;
this._notificationClickedId = notification.connect('clicked', Lang.bind(this, this._notificationClicked));
this._notificationDestroyedId = notification.connect('destroy', Lang.bind(this, this._notificationDestroyedId = notification.connect('destroy', Lang.bind(this,
function () { function () {
if (this.notification == notification) { if (this.notification == notification) {
this.notification = null; this.notification = null;
this._notificationDestroyedId = 0; this._notificationDestroyedId = 0;
this._notificationClickedId = 0;
} }
})); }));
this.emit('notify', notification); this.emit('notify', notification);
}, },
clicked: function() {
this.emit('clicked');
},
destroy: function() { destroy: function() {
this.emit('destroy'); this.emit('destroy');
}, },
@ -696,6 +691,10 @@ Source.prototype = {
if (this._iconBin.child) if (this._iconBin.child)
this._iconBin.child.destroy(); this._iconBin.child.destroy();
this._iconBin.child = icon; this._iconBin.child = icon;
},
// Default implementation is to do nothing, but subclass can override
_notificationClicked: function(notification) {
} }
}; };
Signals.addSignalMethods(Source.prototype); Signals.addSignalMethods(Source.prototype);

View File

@ -173,10 +173,6 @@ NotificationDaemon.prototype = {
let source = new Source(title, pid); let source = new Source(title, pid);
this._sources[pid] = source; this._sources[pid] = source;
source.connect('clicked', Lang.bind(this,
function() {
source.destroy();
}));
source.connect('destroy', Lang.bind(this, source.connect('destroy', Lang.bind(this,
function() { function() {
delete this._sources[pid]; delete this._sources[pid];
@ -281,7 +277,7 @@ NotificationDaemon.prototype = {
if (notification == null) { if (notification == null) {
notification = new MessageTray.Notification(source, summary, body, { icon: iconActor }); notification = new MessageTray.Notification(source, summary, body, { icon: iconActor });
ndata.notification = notification; ndata.notification = notification;
notification.connect('dismissed', Lang.bind(this, notification.connect('clicked', Lang.bind(this,
function(n) { function(n) {
this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED); this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED);
})); }));
@ -433,9 +429,9 @@ Source.prototype = {
this.useNotificationIcon = false; this.useNotificationIcon = false;
}, },
clicked: function() { _notificationClicked: function() {
this.openApp(); this.openApp();
MessageTray.Source.prototype.clicked.call(this); this.destroy();
}, },
openApp: function() { openApp: function() {

View File

@ -484,7 +484,7 @@ Source.prototype = {
this.ICON_SIZE); this.ICON_SIZE);
}, },
clicked: function() { _notificationClicked: function(notification) {
channelDispatcher.EnsureChannelRemote(this._accountPath, channelDispatcher.EnsureChannelRemote(this._accountPath,
{ 'org.freedesktop.Telepathy.Channel.ChannelType': Telepathy.CHANNEL_TEXT_NAME, { 'org.freedesktop.Telepathy.Channel.ChannelType': Telepathy.CHANNEL_TEXT_NAME,
'org.freedesktop.Telepathy.Channel.TargetHandle': this._targetHandle, 'org.freedesktop.Telepathy.Channel.TargetHandle': this._targetHandle,
@ -492,8 +492,6 @@ Source.prototype = {
global.get_current_time(), global.get_current_time(),
'', '',
Lang.bind(this, this._gotChannelRequest)); Lang.bind(this, this._gotChannelRequest));
MessageTray.Source.prototype.clicked.call(this);
}, },
_gotChannelRequest: function (chanReqPath, ex) { _gotChannelRequest: function (chanReqPath, ex) {

View File

@ -66,7 +66,6 @@ WindowAttentionHandler.prototype = {
source = new Source(app, window); source = new Source(app, window);
this._sources[appId] = source; this._sources[appId] = source;
Main.messageTray.add(source); Main.messageTray.add(source);
source.connect('clicked', Lang.bind(this, function() { source.destroy(); }));
source.connect('destroy', Lang.bind(this, function() { delete this._sources[appId]; })); source.connect('destroy', Lang.bind(this, function() { delete this._sources[appId]; }));
} }
@ -101,9 +100,8 @@ Source.prototype = {
return this._app.create_icon_texture(this.ICON_SIZE); return this._app.create_icon_texture(this.ICON_SIZE);
}, },
clicked : function() { _notificationClicked : function(notification) {
Main.activateWindow(this._window); Main.activateWindow(this._window);
MessageTray.Source.prototype.clicked.call(this); this.destroy();
} }
}; };