[polari/wip/bastianilso/error-handling: 3/7] roomList: Status icon in header when connecting or on error



commit 287dcd6a7349d8e682b5314c9080819287ef4c03
Author: Bastian Ilsø <bastianilso src gnome org>
Date:   Wed Jul 15 13:55:19 2015 +0200

    roomList: Status icon in header when connecting or on error
    
    When an account is connecting to a server, a spinner should
    be displayed next to the server in the room list. If the
    connection fails, we should show an icon indicating error.

 src/roomList.js |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index f7ee09f..49174c9 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -281,14 +281,41 @@ const RoomList = new Lang.Class({
         if (row.get_header())
             return;
 
-        let label = new Gtk.Label({ margin_bottom: 4, xalign: 0,
+        let hbox = new Gtk.Box({ margin_bottom: 4, spacing: 2, hexpand: true,
+                                orientation: Gtk.Orientation.HORIZONTAL, visible: true });
+        hbox.get_style_context().add_class('room-list-header');
+
+        let label = new Gtk.Label({ xalign: 0, margin: 4,
                                     max_width_chars: 15,
                                     ellipsize: Pango.EllipsizeMode.END });
-        label.get_style_context().add_class('room-list-header');
-
         account.bind_property('display-name', label, 'label',
                               GObject.BindingFlags.SYNC_CREATE);
-        row.set_header(label);
+        hbox.add(label);
+
+        let icon = new Gtk.Stack({ hhomogeneous: true });
+        icon.add_named(new Gtk.Image({icon_name: 'dialog-error-symbolic' }), 'error');
+        icon.add_named(new Gtk.Spinner({active: true}), 'connecting');
+        icon.add_named(new Gtk.Box({visible: false}), 'none');
+        let displayStatus = function(binding) {
+            let child = 'none';
+            let status = binding.source.connection_status;
+            log('transformTo called');
+            if (status == Tp.ConnectionStatus.CONNECTING) {
+                child = 'connecting';
+                log('child set to connecting');
+            } else if (status == Tp.ConnectionStatus.DISCONNECTED) {
+                log('connection_status_reason: ' + binding.source.connection_status_reason)
+                child = 'error';
+                log('child set to error');
+            }
+            binding.target.visible_child_name = child;
+        }
+        account.bind_property_full('connection-status', icon, 'visible-child-name',
+                                    GObject.BindingFlags.DEFAULT, displayStatus, function(){});
+        hbox.add(icon);
+
+        hbox.show_all();
+        row.set_header(hbox);
     },
 
     _sort: function(row1, row2) {


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