diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2009-08-26 19:00:24 +0800 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2009-08-26 21:49:36 +0800 |
commit | cb4361a992c348f7c57ec75afb1c642fba20fb15 (patch) | |
tree | f2654b0095a106c65cdeb4bac5fa3fca626895c6 | |
parent | 151a069b2039195a33d0e0540deec1803ddd3d23 (diff) | |
download | gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.tar gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.tar.gz gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.tar.bz2 gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.tar.lz gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.tar.xz gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.tar.zst gsoc2013-empathy-cb4361a992c348f7c57ec75afb1c642fba20fb15.zip |
Ensure all accounts when getting all properties
This introduces a check on the number of accounts, as MC5 could come
back advertising less accounts than we have. In that case, we find the
one which have gone and remove them from our cache.
-rw-r--r-- | libempathy/empathy-account-manager.c | 80 |
1 files changed, 71 insertions, 9 deletions
diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 365f39ef1..5548a90e6 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -364,6 +364,76 @@ empathy_account_manager_ensure_account (EmpathyAccountManager *manager, static void +account_manager_ensure_all_accounts (EmpathyAccountManager *manager, + GPtrArray *accounts) +{ + int i, missing_accounts; + GHashTableIter iter; + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + gpointer value; + EmpathyAccount *account; + gboolean found = FALSE; + const gchar *name; + + /* ensure all accounts coming from MC5 first */ + for (i = 0; i < accounts->len; i++) + { + name = g_ptr_array_index (accounts, i); + + account = empathy_account_manager_ensure_account (manager, name); + empathy_account_refresh_properties (account); + } + + missing_accounts = empathy_account_manager_get_count (manager) - + accounts->len; + + if (missing_accounts > 0) + { + /* look for accounts we have and the Tp AccountManager doesn't, + * and remove them from our cache. + */ + + DEBUG ("%d missing accounts", missing_accounts); + + g_hash_table_iter_init (&iter, priv->accounts); + + while (g_hash_table_iter_next (&iter, NULL, &value) && + missing_accounts > 0) + { + account = value; + + /* look for this account in the AccountManager provided array */ + for (i = 0; i < accounts->len; i++) + { + name = g_ptr_array_index (accounts, i); + + if (!tp_strdiff + (name, empathy_account_get_unique_name (account))) + { + found = TRUE; + break; + } + } + + if (!found) + { + DEBUG ("Account %s was not found, remove it from the cache", + empathy_account_get_unique_name (account)); + + g_object_ref (account); + g_hash_table_iter_remove (&iter); + g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account); + g_object_unref (account); + + missing_accounts--; + } + + found = FALSE; + } + } +} + +static void account_manager_got_all_cb (TpProxy *proxy, GHashTable *properties, const GError *error, @@ -372,7 +442,6 @@ account_manager_got_all_cb (TpProxy *proxy, { EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object); GPtrArray *accounts; - int i; if (error != NULL) { @@ -384,14 +453,7 @@ account_manager_got_all_cb (TpProxy *proxy, EMPATHY_ARRAY_TYPE_OBJECT); if (accounts != NULL) - { - for (i = 0; i < accounts->len; i++) - { - gchar *name = g_ptr_array_index (accounts, i); - - empathy_account_manager_ensure_account (manager, name); - } - } + account_manager_ensure_all_accounts (manager, accounts); empathy_account_manager_check_ready (manager); } |