[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:
parent
2915319602
commit
d3031b406a
@ -550,13 +550,12 @@ Notification.prototype = {
|
|||||||
};
|
};
|
||||||
Signals.addSignalMethods(Notification.prototype);
|
Signals.addSignalMethods(Notification.prototype);
|
||||||
|
|
||||||
function Source(id, title, createIcon) {
|
function Source(title, createIcon) {
|
||||||
this._init(id, title, createIcon);
|
this._init(title, createIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
Source.prototype = {
|
Source.prototype = {
|
||||||
_init: function(id, title, createIcon) {
|
_init: function(title, createIcon) {
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
if (createIcon)
|
if (createIcon)
|
||||||
this.createIcon = createIcon;
|
this.createIcon = createIcon;
|
||||||
@ -809,7 +808,7 @@ MessageTray.prototype = {
|
|||||||
this._updateState();
|
this._updateState();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this._summaryItems = {};
|
this._summaryItems = [];
|
||||||
this._longestSummaryItem = null;
|
this._longestSummaryItem = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -827,12 +826,20 @@ MessageTray.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
contains: function(source) {
|
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) {
|
add: function(source) {
|
||||||
if (this.contains(source)) {
|
if (this.contains(source)) {
|
||||||
log('Trying to re-add source ' + source.id);
|
log('Trying to re-add source ' + source.title);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,14 +851,14 @@ MessageTray.prototype = {
|
|||||||
|
|
||||||
let newItemTitleWidth = summaryItem.getTitleNaturalWidth();
|
let newItemTitleWidth = summaryItem.getTitleNaturalWidth();
|
||||||
if (newItemTitleWidth > minTitleWidth) {
|
if (newItemTitleWidth > minTitleWidth) {
|
||||||
for (sourceId in this._summaryItems) {
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
||||||
this._summaryItems[sourceId].setMinTitleWidth(newItemTitleWidth);
|
this._summaryItems[i].setMinTitleWidth(newItemTitleWidth);
|
||||||
}
|
}
|
||||||
summaryItem.setMinTitleWidth(newItemTitleWidth);
|
summaryItem.setMinTitleWidth(newItemTitleWidth);
|
||||||
this._longestSummaryItem = summaryItem;
|
this._longestSummaryItem = summaryItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._summaryItems[source.id] = summaryItem;
|
this._summaryItems.push(summaryItem);
|
||||||
|
|
||||||
source.connect('notify', Lang.bind(this, this._onNotify));
|
source.connect('notify', Lang.bind(this, this._onNotify));
|
||||||
|
|
||||||
@ -872,7 +879,8 @@ MessageTray.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeSource: function(source) {
|
removeSource: function(source) {
|
||||||
if (!this.contains(source))
|
let index = this._getIndexOfSummaryItemForSource(source);
|
||||||
|
if (index == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// remove all notifications with this source from the queue
|
// remove all notifications with this source from the queue
|
||||||
@ -883,26 +891,26 @@ MessageTray.prototype = {
|
|||||||
}
|
}
|
||||||
this._notificationQueue = newNotificationQueue;
|
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)
|
if (this._summary.get_children().length > 0)
|
||||||
this._summaryNeedsToBeShown = true;
|
this._summaryNeedsToBeShown = true;
|
||||||
else
|
else
|
||||||
this._summaryNeedsToBeShown = false;
|
this._summaryNeedsToBeShown = false;
|
||||||
|
|
||||||
delete this._summaryItems[source.id];
|
this._summaryItems.splice(index, 1);
|
||||||
if (this._longestSummaryItem.source == source) {
|
if (this._longestSummaryItem.source == source) {
|
||||||
|
|
||||||
let maxTitleWidth = 0;
|
let maxTitleWidth = 0;
|
||||||
this._longestSummaryItem = null;
|
this._longestSummaryItem = null;
|
||||||
for (sourceId in this._summaryItems) {
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
||||||
let summaryItem = this._summaryItems[sourceId];
|
let summaryItem = this._summaryItems[i];
|
||||||
if (summaryItem.getTitleNaturalWidth() > maxTitleWidth) {
|
if (summaryItem.getTitleNaturalWidth() > maxTitleWidth) {
|
||||||
maxTitleWidth = summaryItem.getTitleNaturalWidth();
|
maxTitleWidth = summaryItem.getTitleNaturalWidth();
|
||||||
this._longestSummaryItem = summaryItem;
|
this._longestSummaryItem = summaryItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (sourceId in this._summaryItems) {
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
||||||
this._summaryItems[sourceId].setMinTitleWidth(maxTitleWidth);
|
this._summaryItems[i].setMinTitleWidth(maxTitleWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,12 +933,6 @@ MessageTray.prototype = {
|
|||||||
this._updateState();
|
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) {
|
removeNotification: function(notification) {
|
||||||
if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
|
if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
|
||||||
if (this._notificationTimeoutId) {
|
if (this._notificationTimeoutId) {
|
||||||
@ -947,12 +949,6 @@ MessageTray.prototype = {
|
|||||||
this._notificationQueue.splice(index, 1);
|
this._notificationQueue.splice(index, 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
getSource: function(id) {
|
|
||||||
if (this._summaryItems[id])
|
|
||||||
return this._summaryItems[id].source;
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
|
|
||||||
_getNotification: function(id, source) {
|
_getNotification: function(id, source) {
|
||||||
if (this._notification && this._notification.id == id)
|
if (this._notification && this._notification.id == id)
|
||||||
return this._notification;
|
return this._notification;
|
||||||
|
@ -107,6 +107,7 @@ NotificationDaemon.prototype = {
|
|||||||
Lang.bind(this, this._acquiredName),
|
Lang.bind(this, this._acquiredName),
|
||||||
Lang.bind(this, this._lostName));
|
Lang.bind(this, this._lostName));
|
||||||
|
|
||||||
|
this._sources = {};
|
||||||
this._currentNotifications = {};
|
this._currentNotifications = {};
|
||||||
|
|
||||||
Shell.WindowTracker.get_default().connect('notify::focus-app',
|
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,
|
Notify: function(appName, replacesId, icon, summary, body,
|
||||||
actions, hints, timeout) {
|
actions, hints, timeout) {
|
||||||
let source = Main.messageTray.getSource(this._sourceId(appName));
|
let source = this._sources[appName];
|
||||||
let id = null;
|
let id = null;
|
||||||
|
|
||||||
// Filter out notifications from Empathy, since we
|
// Filter out notifications from Empathy, since we
|
||||||
@ -167,13 +164,18 @@ NotificationDaemon.prototype = {
|
|||||||
// been acknowledged.
|
// been acknowledged.
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
let title = appNameMap[appName] || appName;
|
let title = appNameMap[appName] || appName;
|
||||||
source = new Source(this._sourceId(appName), title, icon, hints);
|
source = new Source(title, icon, hints);
|
||||||
Main.messageTray.add(source);
|
Main.messageTray.add(source);
|
||||||
|
this._sources[appName] = source;
|
||||||
|
|
||||||
source.connect('clicked', Lang.bind(this,
|
source.connect('clicked', Lang.bind(this,
|
||||||
function() {
|
function() {
|
||||||
source.destroy();
|
source.destroy();
|
||||||
}));
|
}));
|
||||||
|
source.connect('destroy', Lang.bind(this,
|
||||||
|
function() {
|
||||||
|
delete this._sources[appName];
|
||||||
|
}));
|
||||||
|
|
||||||
let sender = DBus.getCurrentMessageContext().sender;
|
let sender = DBus.getCurrentMessageContext().sender;
|
||||||
let busProxy = new Bus();
|
let busProxy = new Bus();
|
||||||
@ -265,8 +267,16 @@ NotificationDaemon.prototype = {
|
|||||||
|
|
||||||
_onFocusAppChanged: function() {
|
_onFocusAppChanged: function() {
|
||||||
let tracker = Shell.WindowTracker.get_default();
|
let tracker = Shell.WindowTracker.get_default();
|
||||||
if (tracker.focus_app)
|
if (!tracker.focus_app)
|
||||||
Main.messageTray.removeSourceByApp(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) {
|
_actionInvoked: function(notification, action, source, id) {
|
||||||
@ -291,15 +301,15 @@ NotificationDaemon.prototype = {
|
|||||||
|
|
||||||
DBus.conformExport(NotificationDaemon.prototype, NotificationDaemonIface);
|
DBus.conformExport(NotificationDaemon.prototype, NotificationDaemonIface);
|
||||||
|
|
||||||
function Source(sourceId, title, icon, hints) {
|
function Source(title, icon, hints) {
|
||||||
this._init(sourceId, title, icon, hints);
|
this._init(title, icon, hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
Source.prototype = {
|
Source.prototype = {
|
||||||
__proto__: MessageTray.Source.prototype,
|
__proto__: MessageTray.Source.prototype,
|
||||||
|
|
||||||
_init: function(sourceId, title, icon, hints) {
|
_init: function(title, icon, hints) {
|
||||||
MessageTray.Source.prototype._init.call(this, sourceId, title);
|
MessageTray.Source.prototype._init.call(this, title);
|
||||||
|
|
||||||
this.app = null;
|
this.app = null;
|
||||||
this._openAppRequested = false;
|
this._openAppRequested = false;
|
||||||
|
@ -445,7 +445,7 @@ Source.prototype = {
|
|||||||
__proto__: MessageTray.Source.prototype,
|
__proto__: MessageTray.Source.prototype,
|
||||||
|
|
||||||
_init: function(accountPath, connPath, channelPath, targetHandle, targetHandleType, targetId) {
|
_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;
|
this._accountPath = accountPath;
|
||||||
|
|
||||||
|
@ -14,10 +14,12 @@ function WindowAttentionHandler() {
|
|||||||
|
|
||||||
WindowAttentionHandler.prototype = {
|
WindowAttentionHandler.prototype = {
|
||||||
_init : function() {
|
_init : function() {
|
||||||
|
this._startupIds = {};
|
||||||
|
this._sources = {};
|
||||||
|
|
||||||
let display = global.screen.get_display();
|
let display = global.screen.get_display();
|
||||||
display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
|
display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
|
||||||
let tracker = Shell.WindowTracker.get_default();
|
let tracker = Shell.WindowTracker.get_default();
|
||||||
this._startupIds = {};
|
|
||||||
tracker.connect('startup-sequence-changed', Lang.bind(this, this._onStartupSequenceChanged));
|
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) {
|
_getTitle : function(app, window) {
|
||||||
if (this._startupIds[window.get_startup_id()])
|
if (this._startupIds[window.get_startup_id()])
|
||||||
return app.get_name();
|
return app.get_name();
|
||||||
@ -61,12 +59,15 @@ WindowAttentionHandler.prototype = {
|
|||||||
|
|
||||||
let tracker = Shell.WindowTracker.get_default();
|
let tracker = Shell.WindowTracker.get_default();
|
||||||
let app = tracker.get_window_app(window);
|
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) {
|
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);
|
Main.messageTray.add(source);
|
||||||
source.connect('clicked', Lang.bind(this, function() { source.destroy(); }));
|
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);
|
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) {
|
function Source(app, window) {
|
||||||
this._init(sourceId, app, window);
|
this._init(app, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
Source.prototype = {
|
Source.prototype = {
|
||||||
__proto__ : MessageTray.Source.prototype,
|
__proto__ : MessageTray.Source.prototype,
|
||||||
|
|
||||||
_init: function(sourceId, app, window) {
|
_init: function(app, window) {
|
||||||
MessageTray.Source.prototype._init.call(this, sourceId, app.get_name());
|
MessageTray.Source.prototype._init.call(this, app.get_name());
|
||||||
this._window = window;
|
this._window = window;
|
||||||
this._app = app;
|
this._app = app;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user