[gnome-shell] Start using MessageTray.Source directly instead of having to subclass it



commit 9e1a2cfeacec412c7a97b2a454513764e070af95
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Oct 8 18:00:32 2011 -0400

    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

 js/ui/autorunManager.js         |   13 ++-------
 js/ui/keyboard.js               |   10 +------
 js/ui/messageTray.js            |   10 +------
 js/ui/notificationDaemon.js     |    5 +++
 js/ui/shellMountOperation.js    |    1 +
 js/ui/status/bluetooth.js       |   31 +---------------------
 js/ui/status/network.js         |   20 +++-----------
 js/ui/telepathyClient.js        |   56 +++++++--------------------------------
 js/ui/windowAttentionHandler.js |    4 +-
 9 files changed, 28 insertions(+), 122 deletions(-)
---
diff --git a/js/ui/autorunManager.js b/js/ui/autorunManager.js
index 27d89e8..9fbb26e 100644
--- a/js/ui/autorunManager.js
+++ b/js/ui/autorunManager.js
@@ -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());
 
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 1340e7b..a5cd199 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -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() {
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index b3da8c7..c7e3410 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -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() {
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 5a20e7c..4d9035d 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -638,5 +638,10 @@ const Source = new Lang.Class({
         }
 
         this.parent();
+    },
+
+    createNotificationIcon: function() {
+        // We set the summary icon ourselves.
+        return null;
     }
 });
diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js
index 93f9d9c..6a44a24 100644
--- a/js/ui/shellMountOperation.js
+++ b/js/ui/shellMountOperation.js
@@ -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);
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index c671e6b..8342ab1 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -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,
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index dedd4a4..46e9da9 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -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);
-    }
-});
diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js
index b705c7a..c38b3f7 100644
--- a/js/ui/telepathyClient.js
+++ b/js/ui/telepathyClient.js
@@ -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',
diff --git a/js/ui/windowAttentionHandler.js b/js/ui/windowAttentionHandler.js
index e503de4..9a2dd73 100644
--- a/js/ui/windowAttentionHandler.js
+++ b/js/ui/windowAttentionHandler.js
@@ -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(); })));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]