[polari/wip/fmuellner/disconnect-accounts: 4/5] Use PolariAccount:visible instead of :enabled



commit aab8fd11aaa11c2bb9a97cc7bf739bc008a9b5c7
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Nov 9 03:29:26 2017 +0100

    Use PolariAccount:visible instead of :enabled
    
    Return to showing disabled accounts in the UI by switching to the
    :visible property to control an account's visibility. In a next
    step, we will also expose enable and disable in the UI again.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771889

 src/accountsMonitor.js   | 13 +++++++++++--
 src/application.js       | 11 +++++------
 src/joinDialog.js        |  2 +-
 src/mainWindow.js        |  4 ++--
 src/roomList.js          |  6 +++---
 src/roomManager.js       |  6 +++---
 src/serverRoomManager.js |  2 +-
 src/telepathyClient.js   |  9 ++++++---
 8 files changed, 32 insertions(+), 21 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index 5dce4d2..858eafa 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -35,8 +35,8 @@ var AccountsMonitor = class {
         return [...this._accounts.values()];
     }
 
-    get enabledAccounts() {
-        return [...this._accounts.values()].filter(a => a.enabled);
+    get visibleAccounts() {
+        return [...this._accounts.values()].filter(a => a.visible);
     }
 
     get accountManager() {
@@ -121,6 +121,12 @@ var AccountsMonitor = class {
             account.connect('notify::connection-status', () => {
                 this.emit('account-status-changed', account);
             });
+        account._visibleNotifyId =
+            account.connect('notify::visible', () => {
+                this.emit(account.visible ? 'account-shown'
+                                          : 'account-hidden', account);
+                this.emit('accounts-changed');
+            });
         this._accounts.set(account.object_path, account);
 
         this.emit('account-added', account);
@@ -134,6 +140,9 @@ var AccountsMonitor = class {
         account.disconnect(account._statusNotifyId);
         delete account._statusNotifyId;
 
+        account.disconnect(account._visibleNotifyId);
+        delete account._visibleNotifyId;
+
         this.emit('account-removed', account);
         this.emit('accounts-changed');
     }
diff --git a/src/application.js b/src/application.js
index 66aa6c0..01c7d2a 100644
--- a/src/application.js
+++ b/src/application.js
@@ -343,7 +343,7 @@ var Application = GObject.registerClass({
     _openURIs(uris, time) {
         let map = {};
 
-        this._accountsMonitor.enabledAccounts.forEach(a => {
+        this._accountsMonitor.visibleAccounts.forEach(a => {
             let params = a.dup_parameters_vardict().deep_unpack();
             map[a.get_object_path()] = {
                 server: params.server.deep_unpack(),
@@ -656,10 +656,11 @@ var Application = GObject.registerClass({
         action.change_state(GLib.Variant.new('b', !state.get_boolean()));
     }
 
-    _onRemoveConnection(action, parameter){
+    _onRemoveConnection(action, parameter) {
         let accountPath = parameter.deep_unpack();
         let account = this._accountsMonitor.lookupAccount(accountPath);
-        account.set_enabled_async(false, () => {
+
+        account.setVisible(false, () => {
             let label = _("%s removed.").format(account.display_name);
             let n = new AppNotifications.UndoNotification(label);
             this.notificationQueue.addNotification(n);
@@ -670,9 +671,7 @@ var Application = GObject.registerClass({
                 });
             });
             n.connect('undo', () => {
-                account.set_enabled_async(true, (a, res) => {
-                    a.set_enabled_finish(res); // TODO: Check for errors
-                });
+                account.setVisible(true, () => {});
             });
         });
     }
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 7686ce9..6da6c4b 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -53,7 +53,7 @@ var JoinDialog = GObject.registerClass({
         this._accountsMonitor = AccountsMonitor.getDefault();
 
         this._accounts = new Map();
-        this._accountsMonitor.enabledAccounts.forEach(a => {
+        this._accountsMonitor.visibleAccounts.forEach(a => {
             this._accounts.set(a.display_name, a);
         });
         this._accountAddedId =
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 38bdf4d..cc1f586 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -271,7 +271,7 @@ var MainWindow = GObject.registerClass({
     }
 
     _onAccountsChanged(am) {
-        let hasAccounts = this._accountsMonitor.enabledAccounts.length > 0;
+        let hasAccounts = this._accountsMonitor.visibleAccounts.length > 0;
         this._roomListRevealer.reveal_child = hasAccounts;
     }
 
@@ -349,7 +349,7 @@ var MainWindow = GObject.registerClass({
         let roomId = null;
         let account = this._accountsMonitor.lookupAccount(selectedRoom.account);
         let channelName = selectedRoom.channel;
-        if (account && account.enabled && channelName)
+        if (account && account.visible && channelName)
             roomId = Polari.create_room_id(account, channelName, Tp.HandleType.ROOM);
 
         this.active_room = this._roomManager.lookupRoom(roomId) ||
diff --git a/src/roomList.js b/src/roomList.js
index d5c8cc0..cdf034a 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -356,10 +356,10 @@ class RoomList extends Gtk.ListBox {
                                       this._accountAdded.bind(this));
         this._accountsMonitor.connect('account-removed',
                                       this._accountRemoved.bind(this));
-        this._accountsMonitor.connect('account-enabled', (mon, account) => {
+        this._accountsMonitor.connect('account-shown', (mon, account) => {
             this._updatePlaceholderVisibility(account);
         });
-        this._accountsMonitor.connect('account-disabled', (mon, account) => {
+        this._accountsMonitor.connect('account-hidden', (mon, account) => {
             this._updatePlaceholderVisibility(account);
         });
         this._accountsMonitor.prepare(() => {
@@ -540,7 +540,7 @@ class RoomList extends Gtk.ListBox {
     }
 
     _updatePlaceholderVisibility(account) {
-        if (!account.enabled) {
+        if (!account.visible) {
             this._placeholders.get(account).hide();
             return;
         }
diff --git a/src/roomManager.js b/src/roomManager.js
index 7344b07..9daeb4e 100644
--- a/src/roomManager.js
+++ b/src/roomManager.js
@@ -36,10 +36,10 @@ var RoomManager = class {
                 this._app.lookup_action(a.name).connect('activate', a.handler);
         });
 
-        this._accountsMonitor.connect('account-enabled', (mon, account) => {
+        this._accountsMonitor.connect('account-shown', (mon, account) => {
             this._restoreRooms(account.object_path);
         });
-        this._accountsMonitor.connect('account-disabled', (mon, account) => {
+        this._accountsMonitor.connect('account-hidden', (mon, account) => {
             this._removeRooms(account.object_path);
         });
         this._accountsMonitor.connect('account-removed', (mon, account) => {
@@ -164,7 +164,7 @@ var RoomManager = class {
             return null;
         }
 
-        if (!account.enabled)
+        if (!account.visible)
             return null;
 
         let id = Polari.create_room_id(account, channelName, type);
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index c0d7656..734a148 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -29,7 +29,7 @@ var ServerRoomManager = class {
         this._accountsMonitor.connect('account-removed',
                                       this._onAccountRemoved.bind(this));
         this._accountsMonitor.prepare(() => {
-            this._accountsMonitor.enabledAccounts.forEach(a => {
+            this._accountsMonitor.visibleAccounts.forEach(a => {
                 this._onAccountStatusChanged(this._accountsMonitor, a);
             });
         });
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index f62b3b4..1f0f020 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -184,10 +184,10 @@ class TelepathyClient extends Tp.BaseClient {
         this._accountsMonitor.connect('account-added', (mon, account) => {
             this._connectAccount(account);
         });
-        this._accountsMonitor.connect('account-enabled', (mon, account) => {
+        this._accountsMonitor.connect('account-shown', (mon, account) => {
             this._connectAccount(account);
         });
-        this._accountsMonitor.enabledAccounts.forEach(a => {
+        this._accountsMonitor.visibleAccounts.forEach(a => {
             this._onAccountStatusChanged(this._accountsMonitor, a);
         });
 
@@ -203,7 +203,7 @@ class TelepathyClient extends Tp.BaseClient {
         debug('Network changed to %s'.format(connected ? 'available'
                                                        : 'unavailable'));
 
-        this._accountsMonitor.enabledAccounts.forEach(a => {
+        this._accountsMonitor.visibleAccounts.forEach(a => {
             this._setAccountPresence(a, presence);
         });
     }
@@ -225,6 +225,9 @@ class TelepathyClient extends Tp.BaseClient {
     }
 
     _setAccountPresence(account, presence) {
+        if (!account.enabled)
+            return;
+
         let statuses = Object.keys(Tp.ConnectionPresenceType).map(s =>
             s.replace(/_/g, '-').toLowerCase()
         );


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