[polari] Move users of AccountManager to AccountsMonitor



commit fb294f2a3ecd9750c5003c74a18ddc569962720e
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 25 01:04:50 2013 +0200

    Move users of AccountManager to AccountsMonitor
    
    In particular this puts our filtering of non-irc accounts in one
    place.

 src/application.js |   23 ++++-------------------
 src/connections.js |   49 +++++++++++++++++++------------------------------
 src/joinDialog.js  |   43 +++++++++++++++++++++----------------------
 3 files changed, 44 insertions(+), 71 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 03925fe..a583428 100644
--- a/src/application.js
+++ b/src/application.js
@@ -3,6 +3,7 @@ const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 const Tp = imports.gi.TelepathyGLib;
 
+const AccountsMonitor = imports.accountsMonitor;
 const AppNotifications = imports.appNotifications;
 const ChatroomManager = imports.chatroomManager;
 const Config = imports.config;
@@ -37,7 +38,7 @@ const Application = new Lang.Class({
         resource._register();
 
         this._chatroomManager = ChatroomManager.getDefault();
-        this._accountManager = Tp.AccountManager.dup();
+        this._accountsMonitor = AccountsMonitor.getDefault();
 
         this.notificationQueue = new AppNotifications.NotificationQueue();
         this.commandOutputQueue = new AppNotifications.CommandOutputQueue();
@@ -119,30 +120,14 @@ const Application = new Lang.Class({
     },
 
     _updateAccountAction: function(action) {
-        action.enabled = this._accountManager.dup_valid_accounts().filter(
+        action.enabled = this._accountsMonitor.dupAccounts().filter(
             function(a) {
                 return a.enabled;
             }).length > 0;
     },
 
     _accountActionsCreateHook: function(action) {
-        this._accountManager.connect('account-enabled', Lang.bind(this,
-            function() {
-                this._updateAccountAction(action);
-            }));
-        this._accountManager.connect('account-disabled', Lang.bind(this,
-            function() {
-                this._updateAccountAction(action);
-            }));
-        this._accountManager.connect('account-validity-changed', Lang.bind(this,
-            function() {
-                this._updateAccountAction(action);
-            }));
-        this._accountManager.connect('account-removed', Lang.bind(this,
-            function() {
-                this._updateAccountAction(action);
-            }));
-        this._accountManager.prepare_async(null, Lang.bind(this,
+        this._accountsMonitor.connect('accounts-changed', Lang.bind(this,
             function() {
                 this._updateAccountAction(action);
             }));
diff --git a/src/connections.js b/src/connections.js
index d63e7db..79456d4 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -4,6 +4,7 @@ const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const Tp = imports.gi.TelepathyGLib;
 
+const AccountsMonitor = imports.accountsMonitor;
 const Lang = imports.lang;
 
 const ConnectionsDialog = new Lang.Class({
@@ -11,7 +12,20 @@ const ConnectionsDialog = new Lang.Class({
 
     _init: function() {
         this._createWindow();
-        this._prepareAccountManager();
+
+        this._accountsMonitor = AccountsMonitor.getDefault();
+
+        this._accountAddedId =
+            this._accountsMonitor.connect('account-added', Lang.bind(this,
+                function(am, account) {
+                    this._addAccount(account);
+                }));
+        this._accountRemovedId =
+            this._accountsMonitor.connect('account-removed', Lang.bind(this,
+                function(am, account) {
+                    this._removeAccount(account);
+                }));
+        this._accountsMonitor.dupAccounts().forEach(Lang.bind(this, this._addAccount));
     },
 
     _createWindow: function() {
@@ -49,32 +63,6 @@ const ConnectionsDialog = new Lang.Class({
         this.widget.connect('destroy', Lang.bind(this, this._onDestroy));
     },
 
-    _prepareAccountManager: function() {
-        this._accountMgr = Tp.AccountManager.dup();
-
-        this._accountValidityChangedId =
-            this._accountMgr.connect('account-validity-changed', Lang.bind(this,
-                function(am, account, valid) {
-                    if (valid)
-                        this._addAccount(account);
-                    else
-                        this._removeAccount(account);
-                }));
-        this._accountRemovedId =
-            this._accountMgr.connect('account-removed', Lang.bind(this,
-                function(am, account) {
-                    this._removeAccount(account);
-                }));
-
-        this._accountMgr.prepare_async(null, Lang.bind(this,
-            function(am) {
-                am.dup_valid_accounts().filter(
-                    function(a) {
-                        return a.protocol_name == 'irc';
-                }).forEach(Lang.bind(this, this._addAccount));
-            }));
-    },
-
     _addAccount: function(account) {
         let row = new Gtk.ListBoxRow();
         row._account = account;
@@ -142,7 +130,8 @@ const ConnectionsDialog = new Lang.Class({
     },
 
     _createAccount: function(params) {
-        let req = new Tp.AccountRequest({ account_manager: this._accountMgr,
+        let accountManager = Tp.AccountManager.dup();
+        let req = new Tp.AccountRequest({ account_manager: accountManager,
                                           connection_manager: 'idle',
                                           protocol: 'irc',
                                           display_name: params.name });
@@ -204,8 +193,8 @@ const ConnectionsDialog = new Lang.Class({
     },
 
     _onDestroy: function() {
-        this._accountMgr.disconnect(this._accountValidityChangedId);
-        this._accountMgr.disconnect(this._accountRemovedId);
+        this._accountsMonitor.disconnect(this._accountAddedId);
+        this._accountsMonitor.disconnect(this._accountRemovedId);
     }
 });
 
diff --git a/src/joinDialog.js b/src/joinDialog.js
index e32baa7..29ac41b 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -3,6 +3,7 @@ const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 const Tp = imports.gi.TelepathyGLib;
 
+const AccountsMonitor = imports.accountsMonitor;
 const Lang = imports.lang;
 
 const MAX_RETRIES = 3;
@@ -14,11 +15,28 @@ const JoinDialog = new Lang.Class({
     Name: 'JoinDialog',
 
     _init: function() {
-        this._accountManager = Tp.AccountManager.dup();
-        this._accountManager.prepare_async(null,
-                                           Lang.bind(this, this._onPrepared));
+        this._createWidget();
+
         this._accounts = {};
+        AccountsMonitor.getDefault().dupAccounts().forEach(Lang.bind(this,
+            function(a) {
+                if (!a.enabled)
+                    return;
+                this._accounts[a.display_name] = a;
+            }));
+        let names = Object.keys(this._accounts).sort(
+            function(a, b) {
+                // TODO: figure out combo box sorting
+                return (a < b) ? -1 : ((a > b) ? 1 : 0);
+            });
+        for (let i = 0; i < names.length; i++)
+            this._connectionCombo.append_text(names[i]);
+        this._connectionCombo.set_active(0);
+        this._connectionCombo.sensitive = names.length > 1;
+        this._updateCanConfirm();
+    },
 
+    _createWidget: function() {
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/polari/join-room-dialog.ui');
 
@@ -37,25 +55,6 @@ const JoinDialog = new Lang.Class({
                                 Lang.bind(this, this._updateCanConfirm));
     },
 
-    _onPrepared: function() {
-        this._accountManager.dup_valid_accounts().forEach(Lang.bind(this,
-            function(a) {
-                if (!a.enabled || a.protocol_name != 'irc')
-                    return;
-                this._accounts[a.display_name] = a;
-            }));
-        let names = Object.keys(this._accounts).sort(
-            function(a, b) {
-                // TODO: figure out combo box sorting
-                return (a < b) ? -1 : ((a > b) ? 1 : 0);
-            });
-        for (let i = 0; i < names.length; i++)
-            this._connectionCombo.append_text(names[i]);
-        this._connectionCombo.set_active(0);
-        this._connectionCombo.sensitive = names.length > 1;
-        this._updateCanConfirm();
-    },
-
     _onJoinClicked: function() {
         this.widget.hide();
 


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