[polari/wip/bastianilso/error-handling: 4/7] MainWindow: Display error messages



commit 91b97a96a1ddde6cd93395d0207135583d05d89c
Author: Bastian Ilsø <bastianilso src gnome org>
Date:   Thu Jul 16 15:28:44 2015 +0200

    MainWindow: Display error messages
    
    GNOME Shell no longer handles error messages from telepathy,
    so display them error messages as in-app notifications within
    Polari instead.

 src/appNotifications.js |   68 +++++++++++++++++++++++++++++++++++++++++++++++
 src/connections.js      |    5 +++
 src/mainWindow.js       |   27 +++++++++++++++---
 src/roomList.js         |    8 +++---
 4 files changed, 99 insertions(+), 9 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 694c422..5e74a14 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -3,6 +3,7 @@ const Tp = imports.gi.TelepathyGLib;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const Connections = imports.connections;
 
 const COMMAND_OUTPUT_REVEAL_TIME = 3;
 
@@ -123,6 +124,73 @@ const ConnectingNotification = new Lang.Class({
     }
 });
 
+const ErrorNotification = new Lang.Class({
+    Name: 'ErrorNotification',
+    Extends: AppNotification,
+
+    _init: function(account, window) {
+        this.parent();
+        this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
+                                    column_spacing: 12 });
+
+        this._grid.add(new Gtk.Image({icon_name: 'dialog-error-symbolic' }));
+
+        let button = new Gtk.Button({label: "Edit Account"});
+        button.connect('clicked', Lang.bind(this, function() {
+            log('clicked');
+            account.error = this._getMessage(account.connection_error);
+            let dialog = new Connections.ConnectionDetailsDialog(account);
+            //  put a red outline around the the Address field. add .error?
+            dialog.widget.transient_for = window;
+            dialog.widget.show();
+            this.close();
+            dialog.widget.connect('response',
+            function(w, response) {
+                // should try to connect again but
+                // we already try again when account info is updated in SSL patch
+                dialog.widget.destroy();
+            });
+            }));
+
+        // Not sure if it is necessary to support all types of error messages.
+        this._connectionErrorMessages = {};
+        this._connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.NETWORK_ERROR)]
+          = _("Network error");
+        this._connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.AUTHENTICATION_FAILED)]
+          = _("Authentication failed");
+
+        let text = _("Unable to connect to %s").format(account.display_name);
+        let label = new Gtk.Label({ label: text });
+        //let error = new Gtk.Label({ label: this._getMessage(account.connection_error) });
+        this._grid.add(label);
+        this._grid.add(button);
+        this.widget.add(this._grid);
+        this.widget.show_all();
+        let id = account.connect('notify::connection-status',
+                                 Lang.bind(this, this._onConnectionStatusChanged));
+        this.widget.connect('destroy',
+            function() {
+                account.disconnect(id);
+            });
+    },
+
+    _getMessage: function(connectionError) {
+        let message;
+        if (connectionError in this._connectionErrorMessages) {
+            message = this._connectionErrorMessages[connectionError];
+        } else {
+            message = _("Unknown reason");
+        }
+        return message;
+    },
+
+    _onConnectionStatusChanged: function(account) {
+        if (account.connection_status == Tp.ConnectionStatus.CONNECTING)
+            return;
+        this.close();
+    }
+});
+
 const NotificationQueue = new Lang.Class({
     Name: 'NotificationQueue',
 
diff --git a/src/connections.js b/src/connections.js
index b7fc45c..216a5f1 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -247,6 +247,11 @@ const ConnectionDetails = new Lang.Class({
 
         if (server != account.display_name)
             this._descEntry.text = account.display_name;
+
+        if (!account.error)
+            return;
+        log('account has error');
+        this._serverEntry.get_style_context().add_class('error');
     },
 
     get can_confirm() {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 6e6ad86..2459fbe 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -120,22 +120,39 @@ const MainWindow = new Lang.Class({
     },
 
     _onAccountChanged: function(am, account) {
-        if (account.connection_status != Tp.ConnectionStatus.CONNECTING)
+        let notification, reason = null;
+        if (account.connection_status == Tp.ConnectionStatus.CONNECTING) {
+            log(account.display_name + ': we are connecting to the server');
+            notification = new AppNotifications.ConnectingNotification(account);
+
+        } else if (account.connection_status == Tp.ConnectionStatus.DISCONNECTED) {
+            log(account.display_name + ': disconnected');
+            if (!account.connection_status_reason)
+                return;
+            reason = account.connection_status_reason;
+            if (reason == Tp.ConnectionStatusReason.REQUESTED)
+                return;
+
+            notification = new AppNotifications.ErrorNotification(account, this.window);
+            log(account.display_name + ': we are disconnected due to error');
+            log(account.connection_status_reason);
+        }
+        if (!notification)
             return;
 
-        if (account._connectingNotification)
+        if (account._notification)
             return;
 
         let app = Gio.Application.get_default();
-        let notification = new AppNotifications.ConnectingNotification(account);
+
         app.notificationQueue.addNotification(notification);
         app.mark_busy();
 
-        account._connectingNotification = notification;
+        account._notification = notification;
         notification.widget.connect('destroy',
             function() {
                 app.unmark_busy();
-                delete account._connectingNotification;
+                delete account._notification;
             });
     },
 
diff --git a/src/roomList.js b/src/roomList.js
index 49174c9..9d21020 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -299,14 +299,14 @@ const RoomList = new Lang.Class({
         let displayStatus = function(binding) {
             let child = 'none';
             let status = binding.source.connection_status;
-            log('transformTo called');
+            //log('transformTo called');
             if (status == Tp.ConnectionStatus.CONNECTING) {
                 child = 'connecting';
-                log('child set to connecting');
+                //log('child set to connecting');
             } else if (status == Tp.ConnectionStatus.DISCONNECTED) {
-                log('connection_status_reason: ' + binding.source.connection_status_reason)
+                //log('connection_status_reason: ' + binding.source.connection_status_reason)
                 child = 'error';
-                log('child set to error');
+                //log('child set to error');
             }
             binding.target.visible_child_name = child;
         }


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