Start using MessageTray.Source directly instead of having to subclass it

For most subclasses, this is a direct swap -- a lot of the time, the
constructor was a blank class that override createNotificationIcon,
and called _setSummaryIcon in _init.

https://bugzilla.gnome.org/show_bug.cgi?id=661236
This commit is contained in:
Jasper St. Pierre 2011-10-08 18:00:32 -04:00
parent c6fabe504a
commit 9e1a2cfeac
9 changed files with 28 additions and 122 deletions

View File

@ -262,12 +262,11 @@ const AutorunResidentSource = new Lang.Class({
Extends: MessageTray.Source,
_init: function() {
this.parent(_("Removable Devices"));
this.parent(_("Removable Devices"), 'media-removable', St.IconType.FULLCOLOR);
this._mounts = [];
this._notification = new AutorunResidentNotification(this);
this._setSummaryIcon(this.createNotificationIcon());
},
addMount: function(mount, apps) {
@ -310,12 +309,6 @@ const AutorunResidentSource = new Lang.Class({
Main.messageTray.add(this);
this.pushNotification(this._notification);
}
},
createNotificationIcon: function() {
return new St.Icon ({ icon_name: 'media-removable',
icon_type: St.IconType.FULLCOLOR,
icon_size: this.ICON_SIZE });
}
});
@ -500,11 +493,11 @@ const AutorunTransientSource = new Lang.Class({
Extends: MessageTray.Source,
_init: function(mount, apps) {
this.parent(mount.get_name());
this.mount = mount;
this.apps = apps;
this.parent(mount.get_name());
this._notification = new AutorunTransientNotification(this);
this._setSummaryIcon(this.createNotificationIcon());

View File

@ -541,16 +541,8 @@ const KeyboardSource = new Lang.Class({
Extends: MessageTray.Source,
_init: function(keyboard) {
this.parent(_("Keyboard"));
this._keyboard = keyboard;
this._setSummaryIcon(this.createNotificationIcon());
},
createNotificationIcon: function() {
return new St.Icon({ icon_name: 'input-keyboard',
icon_type: St.IconType.SYMBOLIC,
icon_size: this.ICON_SIZE });
this.parent(_("Keyboard"), 'input-keyboard', St.IconType.SYMBOLIC);
},
handleSummaryClick: function() {

View File

@ -2493,15 +2493,7 @@ const SystemNotificationSource = new Lang.Class({
Extends: Source,
_init: function() {
this.parent(_("System Information"));
this._setSummaryIcon(this.createNotificationIcon());
},
createNotificationIcon: function() {
return new St.Icon({ icon_name: 'dialog-information',
icon_type: St.IconType.SYMBOLIC,
icon_size: this.ICON_SIZE });
this.parent(_("System Information"), 'dialog-information', St.IconType.SYMBOLIC);
},
open: function() {

View File

@ -638,5 +638,10 @@ const Source = new Lang.Class({
}
this.parent();
},
createNotificationIcon: function() {
// We set the summary icon ourselves.
return null;
}
});

View File

@ -243,6 +243,7 @@ const ShellMountPasswordSource = new Lang.Class({
this.parent(strings[0]);
this._notification = new ShellMountPasswordNotification(this, strings, icon, reaskPassword);
this._setSummaryIcon(icon);
// add ourselves as a source, and popup the notification
Main.messageTray.add(this);

View File

@ -305,7 +305,7 @@ const Indicator = new Lang.Class({
_ensureSource: function() {
if (!this._source) {
this._source = new Source();
this._source = new MessageTray.Source(_("Bluetooth"), 'bluetooth-active', St.IconType.SYMBOLIC);
Main.messageTray.add(this._source);
}
},
@ -330,35 +330,6 @@ const Indicator = new Lang.Class({
}
});
const Source = new Lang.Class({
Name: 'BluetoothSource',
Extends: MessageTray.Source,
_init: function() {
this.parent(_("Bluetooth"));
this._setSummaryIcon(this.createNotificationIcon());
},
notify: function(notification) {
this._private_destroyId = notification.connect('destroy', Lang.bind(this, function(notification) {
if (this.notification == notification) {
// the destroyed notification is the last for this source
this.notification.disconnect(this._private_destroyId);
this.destroy();
}
}));
this.parent(notification);
},
createNotificationIcon: function() {
return new St.Icon({ icon_name: 'bluetooth-active',
icon_type: St.IconType.SYMBOLIC,
icon_size: this.ICON_SIZE });
}
});
const AuthNotification = new Lang.Class({
Name: 'AuthNotification',
Extends: MessageTray.Notification,

View File

@ -1644,7 +1644,10 @@ const NMApplet = new Lang.Class({
_ensureSource: function() {
if (!this._source) {
this._source = new NMMessageTraySource();
this._source = new MessageTray.Source(_("Network Manager"),
'network-transmit-receive',
St.IconType.SYMBOLIC);
this._source.connect('destroy', Lang.bind(this, function() {
this._source = null;
}));
@ -2100,18 +2103,3 @@ const NMApplet = new Lang.Class({
}
}
});
const NMMessageTraySource = new Lang.Class({
Name: 'NMMessageTraySource',
Extends: MessageTray.Source,
_init: function() {
this.parent(_("Network Manager"));
let icon = new St.Icon({ icon_name: 'network-transmit-receive',
icon_type: St.IconType.SYMBOLIC,
icon_size: this.ICON_SIZE
});
this._setSummaryIcon(icon);
}
});

View File

@ -365,8 +365,9 @@ const Client = new Lang.Class({
_ensureSubscriptionSource: function() {
if (this._subscriptionSource == null) {
this._subscriptionSource = new MultiNotificationSource(
_("Subscription request"), 'gtk-dialog-question');
this._subscriptionSource = new MessageTray.Source(_("Subscription request"),
'gtk-dialog-question',
St.IconType.FULLCOLOR);
Main.messageTray.add(this._subscriptionSource);
this._subscriptionSource.connect('destroy', Lang.bind(this, function () {
this._subscriptionSource = null;
@ -401,8 +402,9 @@ const Client = new Lang.Class({
_ensureAccountSource: function() {
if (this._accountSource == null) {
this._accountSource = new MultiNotificationSource(
_("Connection error"), 'gtk-dialog-error');
this._accountSource = new MessageTray.Source(_("Connection error"),
'gtk-dialog-error',
St.IconType.FULLCOLOR);
Main.messageTray.add(this._accountSource);
this._accountSource.connect('destroy', Lang.bind(this, function () {
this._accountSource = null;
@ -418,14 +420,14 @@ const ChatSource = new Lang.Class({
Extends: MessageTray.Source,
_init: function(account, conn, channel, contact, client) {
this.parent(contact.get_alias());
this.isChat = true;
this._account = account;
this._contact = contact;
this._client = client;
this.parent(contact.get_alias());
this._pendingMessages = [];
this._conn = conn;
@ -446,8 +448,6 @@ const ChatSource = new Lang.Class({
this._receivedId = this._channel.connect('message-received', Lang.bind(this, this._messageReceived));
this._pendingId = this._channel.connect('pending-message-removed', Lang.bind(this, this._pendingRemoved));
this._setSummaryIcon(this.createNotificationIcon());
this._notifyAliasId = this._contact.connect('notify::alias', Lang.bind(this, this._updateAlias));
this._notifyAvatarId = this._contact.connect('notify::avatar-file', Lang.bind(this, this._updateAvatarIcon));
this._presenceChangedId = this._contact.connect('presence-changed', Lang.bind(this, this._presenceChanged));
@ -1002,10 +1002,9 @@ const ApproverSource = new Lang.Class({
Extends: MessageTray.Source,
_init: function(dispatchOp, text, gicon) {
this.parent(text);
this._gicon = gicon;
this._setSummaryIcon(this.createNotificationIcon());
this.parent(text);
this._dispatchOp = dispatchOp;
@ -1028,7 +1027,6 @@ const ApproverSource = new Lang.Class({
createNotificationIcon: function() {
return new St.Icon({ gicon: this._gicon,
icon_type: St.IconType.FULLCOLOR,
icon_size: this.ICON_SIZE });
}
});
@ -1151,40 +1149,6 @@ const FileTransferNotification = new Lang.Class({
}
});
// A notification source that can embed multiple notifications
const MultiNotificationSource = new Lang.Class({
Name: 'MultiNotificationSource',
Extends: MessageTray.Source,
_init: function(title, icon) {
this.parent(title);
this._icon = icon;
this._setSummaryIcon(this.createNotificationIcon());
this._nbNotifications = 0;
},
notify: function(notification) {
this.parent(notification);
this._nbNotifications += 1;
// Display the source while there is at least one notification
notification.connect('destroy', Lang.bind(this, function () {
this._nbNotifications -= 1;
if (this._nbNotifications == 0)
this.destroy();
}));
},
createNotificationIcon: function() {
return new St.Icon({ gicon: Gio.icon_new_for_string(this._icon),
icon_type: St.IconType.FULLCOLOR,
icon_size: this.ICON_SIZE });
}
});
// Subscription request
const SubscriptionRequestNotification = new Lang.Class({
Name: 'SubscriptionRequestNotification',

View File

@ -53,10 +53,10 @@ const Source = new Lang.Class({
Extends: MessageTray.Source,
_init: function(app, window) {
this.parent(app.get_name());
this._window = window;
this._app = app;
this._setSummaryIcon(this.createNotificationIcon());
this.parent(app.get_name());
this.signalIDs = [];
this.signalIDs.push(this._window.connect('notify::demands-attention', Lang.bind(this, function() { this.destroy(); })));