[gnome-shell/wip/gtk-notification: 15/22] messageTray: Don't always open the source when clicking on the notification



commit 255b935ec3e924d002f76970403256a026aa95ea
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Oct 13 23:20:50 2013 -0400

    messageTray: Don't always open the source when clicking on the notification
    
    Some consumers may not always want to open the app, so make clients that
    want to do this explicitly connect to the 'clicked' signal.

 js/ui/components/telepathyClient.js |   28 ++++++++++++++--------------
 js/ui/messageTray.js                |    2 --
 js/ui/notificationDaemon.js         |   11 ++++++-----
 js/ui/windowAttentionHandler.js     |    5 ++++-
 4 files changed, 24 insertions(+), 22 deletions(-)
---
diff --git a/js/ui/components/telepathyClient.js b/js/ui/components/telepathyClient.js
index 1522be6..28a87cd 100644
--- a/js/ui/components/telepathyClient.js
+++ b/js/ui/components/telepathyClient.js
@@ -446,6 +446,7 @@ const ChatSource = new Lang.Class({
         this._closedId = this._channel.connect('invalidated', Lang.bind(this, this._channelClosed));
 
         this._notification = new ChatNotification(this);
+        this._notification.connect('clicked', Lang.bind(this, this.open));
         this._notification.setUrgency(MessageTray.Urgency.HIGH);
         this._notifyTimeoutId = 0;
 
@@ -544,20 +545,19 @@ const ChatSource = new Lang.Class({
         this._notification.update(this._notification.title, null, { customContent: true });
     },
 
-    open: function(notification) {
-          if (this._client.is_handling_channel(this._channel)) {
-              // We are handling the channel, try to pass it to Empathy
-              this._client.delegate_channels_async([this._channel],
-                  global.get_current_time(),
-                  'org.freedesktop.Telepathy.Client.Empathy.Chat', null);
-          }
-          else {
-              // We are not the handler, just ask to present the channel
-              let dbus = Tp.DBusDaemon.dup();
-              let cd = Tp.ChannelDispatcher.new(dbus);
-
-              cd.present_channel_async(this._channel, global.get_current_time(), null);
-          }
+    open: function() {
+        if (this._client.is_handling_channel(this._channel)) {
+            // We are handling the channel, try to pass it to Empathy
+            this._client.delegate_channels_async([this._channel],
+                                                 global.get_current_time(),
+                                                 'org.freedesktop.Telepathy.Client.Empathy.Chat', null);
+        } else {
+            // We are not the handler, just ask to present the channel
+            let dbus = Tp.DBusDaemon.dup();
+            let cd = Tp.ChannelDispatcher.new(dbus);
+
+            cd.present_channel_async(this._channel, global.get_current_time(), null);
+        }
     },
 
     _getLogMessages: function() {
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index d2fe70c..2e26b16 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1380,9 +1380,7 @@ const Source = new Lang.Class({
         if (this.notifications.indexOf(notification) >= 0)
             return;
 
-        notification.connect('clicked', Lang.bind(this, this.open));
         notification.connect('destroy', Lang.bind(this, this._onNotificationDestroy));
-
         this.notifications.push(notification);
         this.emit('notification-added', notification);
 
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 8960b49..51d18c3 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -404,11 +404,7 @@ const NotificationDaemon = new Lang.Class({
             for (let i = 0; i < actions.length - 1; i += 2) {
                 let [actionId, title] = [actions[i], actions[i+1]];
 
-                if (actionId == 'default') {
-                    notification.connect('clicked', Lang.bind(this, function() {
-                        this._emitActionInvoked(ndata.id, "default");
-                    }));
-                } else {
+                if (actionId != 'default') {
                     notification.addButtonFull(this._makeButton(id, label, useActionIcons), Lang.bind(this, 
function() {
                         this._emitActionInvoked(ndata.id, actionId);
                     }));
@@ -431,6 +427,11 @@ const NotificationDaemon = new Lang.Class({
         // of the 'transient' hint with hints['transient'] rather than hints.transient
         notification.setTransient(hints['transient'] == true);
 
+        notification.connect('clicked', Lang.bind(this, function() {
+            this.open();
+            this._emitActionInvoked(ndata.id, 'default');
+        }));
+
         let sourceGIcon = source.useNotificationIcon ? gicon : null;
         source.processNotification(notification, sourceGIcon);
     },
diff --git a/js/ui/windowAttentionHandler.js b/js/ui/windowAttentionHandler.js
index 78e2061..599eee9 100644
--- a/js/ui/windowAttentionHandler.js
+++ b/js/ui/windowAttentionHandler.js
@@ -39,6 +39,9 @@ const WindowAttentionHandler = new Lang.Class({
         let [title, banner] = this._getTitleAndBanner(app, window);
 
         let notification = new MessageTray.Notification(source, title, banner);
+        notification.connect('clicked', function() {
+            source.open();
+        });
         notification.setForFeedback(true);
 
         source.notify(notification);
@@ -79,7 +82,7 @@ const Source = new Lang.Class({
         return this._app.create_icon_texture(size);
     },
 
-    open : function(notification) {
+    open: function() {
         Main.activateWindow(this._window);
         this.destroy();
     }


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