[gnome-shell] TelepathyClient: track added/removed accounts



commit fdd819e9f6abbdb571a6f51a3b00f8b85ca5b527
Author: Dan Winship <danw gnome org>
Date:   Tue May 11 13:00:55 2010 -0400

    TelepathyClient: track added/removed accounts
    
    (prep work for presence tracking)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=611613

 js/misc/telepathy.js     |    4 +++
 js/ui/telepathyClient.js |   65 ++++++++++++++++++++++++++++-----------------
 2 files changed, 44 insertions(+), 25 deletions(-)
---
diff --git a/js/misc/telepathy.js b/js/misc/telepathy.js
index ea411c8..b53318c 100644
--- a/js/misc/telepathy.js
+++ b/js/misc/telepathy.js
@@ -262,6 +262,10 @@ const AccountManagerIface = {
         { name: 'ValidAccounts',
           signature: 'ao',
           access: 'read' }
+    ],
+    signals: [
+        { name: 'AccountValidityChanged',
+          inSignature: 'ob' }
     ]
 };
 let AccountManager = makeProxyClass(AccountManagerIface);
diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js
index 405ad53..8b1f1c5 100644
--- a/js/ui/telepathyClient.js
+++ b/js/ui/telepathyClient.js
@@ -52,6 +52,7 @@ Client.prototype = {
                                   function (name) { /* FIXME: acquired */ },
                                   function (name) { /* FIXME: lost */ });
 
+        this._accounts = {};
         this._channels = {};
 
         contactManager = new ContactManager();
@@ -65,33 +66,47 @@ Client.prototype = {
         let accountManager = new Telepathy.AccountManager(DBus.session,
                                                           Telepathy.ACCOUNT_MANAGER_NAME,
                                                           Telepathy.nameToPath(Telepathy.ACCOUNT_MANAGER_NAME));
-        accountManager.GetRemote('ValidAccounts', Lang.bind(this, this._gotValidAccounts));
+        accountManager.GetRemote('ValidAccounts', Lang.bind(this,
+            function (accounts, err) {
+                if (!accounts)
+                    return;
+
+                for (let i = 0; i < accounts.length; i++)
+                    this._gotAccount(accounts[i]);
+            }));
+        accountManager.connect('AccountValidityChanged', Lang.bind(this, this._accountValidityChanged));
     },
 
-    _gotValidAccounts: function(accounts, err) {
-        if (!accounts)
-            return;
+    _accountValidityChanged: function(accountManager, accountPath, valid) {
+        if (!valid) {
+            delete this._accounts[accountPath];
+            // We don't need to clean up connections, sources, etc; they'll
+            // get Closed and cleaned up independently.
+        } else
+            this._gotAccount(accountPath);
+    },
 
-        for (let i = 0; i < accounts.length; i++) {
-            let account = new Telepathy.Account(DBus.session,
-                                                Telepathy.ACCOUNT_MANAGER_NAME,
-                                                accounts[i]);
-            account.GetRemote('Connection', Lang.bind(this,
-                function (connPath, err) {
-                    if (!connPath || connPath == '/')
-                        return;
-
-                    let connReq = new Telepathy.ConnectionRequests(DBus.session,
-                                                                   Telepathy.pathToName(connPath),
-                                                                   connPath);
-                    connReq.GetRemote('Channels', Lang.bind(this,
-                        function(channels, err) {
-                            if (!channels)
-                                return;
-                            this._addChannels(account.getPath(), connPath, channels);
-                        }));
-                }));
-        }
+    _gotAccount: function(accountPath) {
+        let account = new Telepathy.Account(DBus.session,
+                                            Telepathy.ACCOUNT_MANAGER_NAME,
+                                            accountPath);
+        this._accounts[accountPath] = account;
+        account.GetRemote('Connection', Lang.bind(this,
+            function (connPath, err) {
+                if (!connPath || connPath == '/')
+                    return;
+
+                let connReq = new Telepathy.ConnectionRequests(DBus.session,
+                                                               Telepathy.pathToName(connPath),
+                                                               connPath);
+                connReq.GetRemote('Channels', Lang.bind(this,
+                    function(channels, err) {
+                        if (!channels)
+                            return;
+
+                        this._addChannels(accountPath, connPath, channels);
+                    }));
+            }));
     },
 
     get Interfaces() {



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