[MessageTray] remove Source IDs

The tray itself does not actually need them, and to make status icon
sources work correctly the NotificationDaemon will need to be tracking
its sources by two separate IDs, so the existing system won't work.

Also remove MessageTray.removeSourceByApp(), which is
NotificationDaemon-specific, and implement the functionality in
notificationDaemon.js instead.

https://bugzilla.gnome.org/show_bug.cgi?id=627303
This commit is contained in:
Dan Winship 2010-08-09 13:18:15 -04:00
parent 2915319602
commit d3031b406a
4 changed files with 60 additions and 53 deletions

View File

@ -550,13 +550,12 @@ Notification.prototype = {
};
Signals.addSignalMethods(Notification.prototype);
function Source(id, title, createIcon) {
this._init(id, title, createIcon);
function Source(title, createIcon) {
this._init(title, createIcon);
}
Source.prototype = {
_init: function(id, title, createIcon) {
this.id = id;
_init: function(title, createIcon) {
this.title = title;
if (createIcon)
this.createIcon = createIcon;
@ -809,7 +808,7 @@ MessageTray.prototype = {
this._updateState();
}));
this._summaryItems = {};
this._summaryItems = [];
this._longestSummaryItem = null;
},
@ -827,12 +826,20 @@ MessageTray.prototype = {
},
contains: function(source) {
return this._summaryItems.hasOwnProperty(source.id);
return this._getIndexOfSummaryItemForSource(source) >= 0;
},
_getIndexOfSummaryItemForSource: function(source) {
for (let i = 0; i < this._summaryItems.length; i++) {
if (this._summaryItems[i].source == source)
return i;
}
return -1;
},
add: function(source) {
if (this.contains(source)) {
log('Trying to re-add source ' + source.id);
log('Trying to re-add source ' + source.title);
return;
}
@ -844,14 +851,14 @@ MessageTray.prototype = {
let newItemTitleWidth = summaryItem.getTitleNaturalWidth();
if (newItemTitleWidth > minTitleWidth) {
for (sourceId in this._summaryItems) {
this._summaryItems[sourceId].setMinTitleWidth(newItemTitleWidth);
for (let i = 0; i < this._summaryItems.length; i++) {
this._summaryItems[i].setMinTitleWidth(newItemTitleWidth);
}
summaryItem.setMinTitleWidth(newItemTitleWidth);
this._longestSummaryItem = summaryItem;
}
this._summaryItems[source.id] = summaryItem;
this._summaryItems.push(summaryItem);
source.connect('notify', Lang.bind(this, this._onNotify));
@ -872,7 +879,8 @@ MessageTray.prototype = {
},
removeSource: function(source) {
if (!this.contains(source))
let index = this._getIndexOfSummaryItemForSource(source);
if (index == -1)
return;
// remove all notifications with this source from the queue
@ -883,26 +891,26 @@ MessageTray.prototype = {
}
this._notificationQueue = newNotificationQueue;
this._summary.remove_actor(this._summaryItems[source.id].actor);
this._summary.remove_actor(this._summaryItems[index].actor);
if (this._summary.get_children().length > 0)
this._summaryNeedsToBeShown = true;
else
this._summaryNeedsToBeShown = false;
delete this._summaryItems[source.id];
this._summaryItems.splice(index, 1);
if (this._longestSummaryItem.source == source) {
let maxTitleWidth = 0;
this._longestSummaryItem = null;
for (sourceId in this._summaryItems) {
let summaryItem = this._summaryItems[sourceId];
for (let i = 0; i < this._summaryItems.length; i++) {
let summaryItem = this._summaryItems[i];
if (summaryItem.getTitleNaturalWidth() > maxTitleWidth) {
maxTitleWidth = summaryItem.getTitleNaturalWidth();
this._longestSummaryItem = summaryItem;
}
}
for (sourceId in this._summaryItems) {
this._summaryItems[sourceId].setMinTitleWidth(maxTitleWidth);
for (let i = 0; i < this._summaryItems.length; i++) {
this._summaryItems[i].setMinTitleWidth(maxTitleWidth);
}
}
@ -925,12 +933,6 @@ MessageTray.prototype = {
this._updateState();
},
removeSourceByApp: function(app) {
for (let sourceId in this._summaryItems)
if (this._summaryItems[sourceId].source.app == app)
this.removeSource(this._summaryItems[sourceId].source);
},
removeNotification: function(notification) {
if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
if (this._notificationTimeoutId) {
@ -947,12 +949,6 @@ MessageTray.prototype = {
this._notificationQueue.splice(index, 1);
},
getSource: function(id) {
if (this._summaryItems[id])
return this._summaryItems[id].source;
return null;
},
_getNotification: function(id, source) {
if (this._notification && this._notification.id == id)
return this._notification;

View File

@ -107,6 +107,7 @@ NotificationDaemon.prototype = {
Lang.bind(this, this._acquiredName),
Lang.bind(this, this._lostName));
this._sources = {};
this._currentNotifications = {};
Shell.WindowTracker.get_default().connect('notify::focus-app',
@ -140,13 +141,9 @@ NotificationDaemon.prototype = {
}
},
_sourceId: function(id) {
return 'source-' + id;
},
Notify: function(appName, replacesId, icon, summary, body,
actions, hints, timeout) {
let source = Main.messageTray.getSource(this._sourceId(appName));
let source = this._sources[appName];
let id = null;
// Filter out notifications from Empathy, since we
@ -167,13 +164,18 @@ NotificationDaemon.prototype = {
// been acknowledged.
if (source == null) {
let title = appNameMap[appName] || appName;
source = new Source(this._sourceId(appName), title, icon, hints);
source = new Source(title, icon, hints);
Main.messageTray.add(source);
this._sources[appName] = source;
source.connect('clicked', Lang.bind(this,
function() {
source.destroy();
}));
source.connect('destroy', Lang.bind(this,
function() {
delete this._sources[appName];
}));
let sender = DBus.getCurrentMessageContext().sender;
let busProxy = new Bus();
@ -265,8 +267,16 @@ NotificationDaemon.prototype = {
_onFocusAppChanged: function() {
let tracker = Shell.WindowTracker.get_default();
if (tracker.focus_app)
Main.messageTray.removeSourceByApp(tracker.focus_app);
if (!tracker.focus_app)
return;
for (let id in this._sources) {
let source = this._sources[id];
if (source.app == tracker.focus_app) {
source.destroy();
return;
}
}
},
_actionInvoked: function(notification, action, source, id) {
@ -291,15 +301,15 @@ NotificationDaemon.prototype = {
DBus.conformExport(NotificationDaemon.prototype, NotificationDaemonIface);
function Source(sourceId, title, icon, hints) {
this._init(sourceId, title, icon, hints);
function Source(title, icon, hints) {
this._init(title, icon, hints);
}
Source.prototype = {
__proto__: MessageTray.Source.prototype,
_init: function(sourceId, title, icon, hints) {
MessageTray.Source.prototype._init.call(this, sourceId, title);
_init: function(title, icon, hints) {
MessageTray.Source.prototype._init.call(this, title);
this.app = null;
this._openAppRequested = false;

View File

@ -445,7 +445,7 @@ Source.prototype = {
__proto__: MessageTray.Source.prototype,
_init: function(accountPath, connPath, channelPath, targetHandle, targetHandleType, targetId) {
MessageTray.Source.prototype._init.call(this, targetId, targetId);
MessageTray.Source.prototype._init.call(this, targetId);
this._accountPath = accountPath;

View File

@ -14,10 +14,12 @@ function WindowAttentionHandler() {
WindowAttentionHandler.prototype = {
_init : function() {
this._startupIds = {};
this._sources = {};
let display = global.screen.get_display();
display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
let tracker = Shell.WindowTracker.get_default();
this._startupIds = {};
tracker.connect('startup-sequence-changed', Lang.bind(this, this._onStartupSequenceChanged));
},
@ -29,10 +31,6 @@ WindowAttentionHandler.prototype = {
}
},
_sourceId : function(appId) {
return 'attention-' + appId;
},
_getTitle : function(app, window) {
if (this._startupIds[window.get_startup_id()])
return app.get_name();
@ -61,12 +59,15 @@ WindowAttentionHandler.prototype = {
let tracker = Shell.WindowTracker.get_default();
let app = tracker.get_window_app(window);
let appId = app.get_id();
let source = Main.messageTray.getSource(this._sourceId(app.get_id()));
let source = this._sources[appId];
if (source == null) {
source = new Source(this._sourceId(app.get_id()), app, window);
source = new Source(app, window);
this._sources[appId] = 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]; }));
}
let notification = new MessageTray.Notification(window.get_startup_id(), source, this._getTitle(app, window), this._getBanner(app, window), true);
@ -82,15 +83,15 @@ WindowAttentionHandler.prototype = {
}
};
function Source(sourceId, app, window) {
this._init(sourceId, app, window);
function Source(app, window) {
this._init(app, window);
}
Source.prototype = {
__proto__ : MessageTray.Source.prototype,
_init: function(sourceId, app, window) {
MessageTray.Source.prototype._init.call(this, sourceId, app.get_name());
_init: function(app, window) {
MessageTray.Source.prototype._init.call(this, app.get_name());
this._window = window;
this._app = app;
},