[polari/wip/bastianilso/error-handling2: 1/3] fix open and close transitions, almost at least



commit 060596e667e3a56a598db7378d73da404fd0c8e7
Author: Bastian Ilsø <bastianilso src gnome org>
Date:   Thu Jul 30 16:07:29 2015 +0200

    fix open and close transitions, almost at least

 src/appNotifications.js |  113 ++++++++++++++++++++---------------------------
 1 files changed, 48 insertions(+), 65 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 0563676..53e88a6 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -17,12 +17,20 @@ const AppNotification = new Lang.Class({
     _init: function() {
         this.widget = new Gtk.Revealer({ reveal_child: false });
         this.widget.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
+
+        this.widget.connect('notify::child-revealed',
+                            Lang.bind(this, this._onChildRevealed));
     },
 
     close: function() {
         this.widget.reveal_child = false;
-        this.widget.destroy();
-        this.widget = null;
+    },
+
+    _onChildRevealed: function() {
+        if (!this.widget.child_revealed) {
+            this.widget.destroy();
+            this.widget = null;
+        }
     },
 
     open: function() {
@@ -125,7 +133,8 @@ const ErrorNotification = new Lang.Class({
         if (error == Tp.error_get_dbus_name(Tp.Error.NETWORK_ERROR)) {
             // Network Error is given
             // - when the server adress is misspelled
-            // - when you disconnect while connecting and reconnect (then you disconnect temporarily again 
with this error and reconnect shortly after)
+            // - inconsistenly when turning your internet on and off
+            // - if you are on an internet connection and the DNS is down
             // - when you try to connect to a port that only supports SSL, but didn't check off "use-ssl" 
(fx by specifying a wrong port number).
             this._label.label = _("Unable to connect to %s").format(this._account.display_name);
             let details = _("Polari disconnected due to a network error. Please check if the address field 
is correct.");
@@ -170,7 +179,7 @@ const ErrorNotification = new Lang.Class({
             // Show "Unlocked" symbol instead of error icon? or show world icon.
             // "Everyone can see what you read and write on this connection." Subtitle?
             this._label.label = _("The connection to %s is not safe.").format(this._account.display_name);
-            // More like "For this connection it's okay." or "For this connection I don't care" button.
+            // More like a "For this connection it's okay." or "For this connection I don't care" button.
             this._button.label =  _("Continue Anyway");
             this._button.connect('clicked', Lang.bind(this, this._reconnectNoEncryption));
         } else {
@@ -253,85 +262,59 @@ const NotificationQueue = new Lang.Class({
 
     setNotification: function(params) {
         this._notifications[params.identifier] = params;
-        //log('checking if ' + params.identifier + ' is active..');
-        //log('this._activeNotifications[' + params.type + '].identifier: ' + 
this._activeNotifications[params.type].identifier)
-        if (this._activeNotifications[params.type].identifier != params.identifier)
-            return;
-        if (this._activeNotifications[params.type].notification == params.notification)
+
+        if (this._activeNotifications[params.type].identifier != params.identifier ||
+            this._activeNotifications[params.type].notification == params.notification)
             return;
-        //log('..true. calling displayNotification.');
+
         this._displayNotification(params);
     },
 
     loadNotifications: function(identifier, type) {
-        //log('current notice is ' + this._activeNotifications[type].notification
-        //    + ' and is loaded for: ' + this._activeNotifications[type].identifier);
-        // We only perform this check if activeNotification has already been initialized.
-        // Otherwise we'll never be able to load notifications from this._activeNotifications.
-        if (this._activeNotifications[type]) {
-            //log('loadNotifications: checking archived notification == displayed notification..');
-            //log('activeNotification for ' + type + ': ' + this._activeNotifications[type]);
-            /*log('this._notifications[identifier] for ' + identifier + ': ' + 
this._notifications[identifier]);
-            if (this._notifications[identifier]) {
-                log('.notification for ' + identifier + ': ' + this._notifications[identifier].notification);
-                if (this._notifications[identifier].notification)
-                    log('.notification.widget for ' + identifier + ': ' + 
this._notifications[identifier].notification.widget);
-            }*/
-            if (this._activeNotifications[type] == this._notifications[identifier]) {
-                //log('match between active notification and current notification!');
-                return;
-            }
-            //log('loadNotifications: notifications did not match');
-        }
+        if (this._activeNotifications[type] == this._notifications[identifier])
+            return;
+
+        let notification = this._notifications[identifier] ?
+                           this._notifications[identifier].notification
+                           : null;
 
-        let notification = this._notifications[identifier] ? this._notifications[identifier].notification : 
null;
-        let params = { notification: notification,
-                       type: type, identifier: identifier };
+        let params = { notification: notification, type: type,
+                       identifier: identifier };
 
         this._displayNotification(params);
     },
 
     _displayNotification: function(params) {
-        //log('now displaying ' + params.notification + ' for: ' + params.identifier);
-
-        //log('_displayNotification: checking if any notifications of that type is visible..');
-        if (this._activeNotifications[params.type].notification) {
-            //log('_displayNotification: true. removing visible notification');
-            //this._activeNotifications[params.type].notification.close();
-            //log('grid children: ' + this._grid.get_children().length);
-            if (this._activeNotifications[params.type].notification.widget) {
-            //log('removing ' + this._activeNotifications[params.type].notification);
-                // If the next notification is null and we're still displaying for the same room.
-                // Then we should just make the active notification null.
-                if (!params.notification && params.identifier == 
this._activeNotifications[params.type].identifier) {
-                    this._activeNotifications[params.type].notification.close();
-                } else {
-                    this._grid.remove(this._activeNotifications[params.type].notification.widget);
-                }
-            }
+        let isNotification = this._activeNotifications[params.type].notification &&
+                             this._activeNotifications[params.type].notification.widget;
+
+        if (isNotification) {
+            if (!params.notification && params.identifier == 
this._activeNotifications[params.type].identifier)
+                this._activeNotifications[params.type].notification.close();
+            else
+                this._grid.remove(this._activeNotifications[params.type].notification.widget);
         }
-        //log('storing parameters inside this._activeNotifications[' + params.type + ']..');
-        this._activeNotifications[params.type] = params;
-        //log('_displayNotification: checking if our notification is empty...');
-        if (!params.notification) {
-            //log('_displayNotification: notification is empty, returning..');
-            this._updateVisibility();
-            return;
+
+        if (params.notification) {
+            if (isNotification)
+                params.notification.widget.transition_type = Gtk.RevealerTransitionType.NONE;
+
+            this._grid.add(params.notification.widget);
+            params.notification.open();
+            params.notification.widget.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
+            params.notification.widget.connect('destroy',
+                                        Lang.bind(this, this._updateVisibility));
         }
 
-        this._grid.add(params.notification.widget);
-        params.notification.open();
-        params.notification.widget.connect('destroy',
-                                    Lang.bind(this, this._updateVisibility));
-        this.widget.show();
+        this._activeNotifications[params.type] = params;
+        this._updateVisibility();
     },
 
     _updateVisibility: function() {
-        //log('amount of children in tree: ' + this._grid.get_children().length);
-        if (this._grid.get_children().length == 0) {
-            //log('hiding widget..');
+        if (this._grid.get_children().length == 0)
            this.widget.hide();
-        }
+        else
+           this.widget.show();
     }
 });
 


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