[next] telepathy-glib: TpAccount: ensure connection is set to NULL before it unref all its contacts
Xavier Claessens
xclaesse at kemper.freedesktop.org
Wed May 9 13:10:46 PDT 2012
Module: telepathy-glib
Branch: next
Commit: a51964b574c9007b2308843a45d4b040bd3a73bd
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=a51964b574c9007b2308843a45d4b040bd3a73bd
Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date: Mon Apr 30 15:10:40 2012 +0200
TpAccount: ensure connection is set to NULL before it unref all its contacts
This is to let a chance to applications to properly remove all contacts
at once instead of getting weak notify on them.
https://bugzilla.gnome.org/show_bug.cgi?id=675141
---
telepathy-glib/account.c | 22 ++++++++++++++++++++--
telepathy-glib/connection.c | 5 ++++-
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c
index 256fc1a..86f790d 100644
--- a/telepathy-glib/account.c
+++ b/telepathy-glib/account.c
@@ -466,6 +466,18 @@ OUT:
g_object_unref (self);
}
+static void _tp_account_set_connection (TpAccount *account, const gchar *path);
+
+static void
+connection_invalidated_cb (TpConnection *connection,
+ guint domain,
+ gint code,
+ gchar *message,
+ TpAccount *account)
+{
+ _tp_account_set_connection (account, "/");
+}
+
static void
_tp_account_set_connection (TpAccount *account,
const gchar *path)
@@ -475,14 +487,17 @@ _tp_account_set_connection (TpAccount *account,
gboolean have_public_connection;
GError *error = NULL;
- /* Do nothing if we already have a connection for the same path */
if (priv->connection != NULL)
{
const gchar *current;
+ /* Do nothing if we already have a connection for the same path */
current = tp_proxy_get_object_path (priv->connection);
if (!tp_strdiff (current, path))
return;
+
+ g_signal_handlers_disconnect_by_func (priv->connection,
+ connection_invalidated_cb, account);
}
had_public_connection = (priv->connection != NULL &&
@@ -515,6 +530,9 @@ _tp_account_set_connection (TpAccount *account,
}
else
{
+ tp_g_signal_connect_object (priv->connection, "invalidated",
+ G_CALLBACK (connection_invalidated_cb), account, 0);
+
_tp_connection_set_account (priv->connection, account);
if (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CONNECTION))
{
@@ -1163,7 +1181,7 @@ _tp_account_dispose (GObject *object)
priv->dispose_has_run = TRUE;
- tp_clear_object (&self->priv->connection);
+ _tp_account_set_connection (self, "/");
/* release any references held by the object here */
if (G_OBJECT_CLASS (tp_account_parent_class)->dispose != NULL)
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index 3ec9e4f..e252f0a 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -1444,7 +1444,10 @@ tp_connection_constructed (GObject *object)
tp_cli_dbus_properties_call_get_all (self, -1,
TP_IFACE_CONNECTION, _tp_connection_got_properties, NULL, NULL, NULL);
- g_signal_connect (self, "invalidated",
+ /* Give a chance to TpAccount to know about invalidated connection before we
+ * unref all roster contacts. This is to let applications properly remove all
+ * contacts at once instead of getting weak notify on each. */
+ g_signal_connect_after (self, "invalidated",
G_CALLBACK (tp_connection_invalidated), NULL);
}
More information about the telepathy-commits
mailing list