From 067e77dceb1e0c01f33ce4c743e88c7214403b8a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 21 Jul 2009 19:02:37 +0100 Subject: Add removed signal on EmpathyAccount --- libempathy/empathy-account-manager.c | 17 +++++++++++++ libempathy/empathy-account.c | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c index 5d1363fce..7339acb9f 100644 --- a/libempathy/empathy-account-manager.c +++ b/libempathy/empathy-account-manager.c @@ -220,6 +220,20 @@ signal: priv->global_presence, priv->global_status, priv->global_status_message); } +static void +emp_account_removed_cb (EmpathyAccount *account, gpointer user_data) +{ + EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data); + EmpathyAccountManagerPriv *priv = GET_PRIV (manager); + + g_object_ref (account); + g_hash_table_remove (priv->accounts, + empathy_account_get_unique_name (account)); + + g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account); + g_object_unref (account); +} + static void empathy_account_manager_check_ready (EmpathyAccountManager *manager) { @@ -272,6 +286,9 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data) g_signal_connect (account, "presence-changed", G_CALLBACK (emp_account_presence_changed_cb), manager); + g_signal_connect (account, "removed", + G_CALLBACK (emp_account_removed_cb), manager); + empathy_account_manager_check_ready (manager); } diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c index 5727a8a25..51dd26316 100644 --- a/libempathy/empathy-account.c +++ b/libempathy/empathy-account.c @@ -42,6 +42,7 @@ enum { STATUS_CHANGED, PRESENCE_CHANGED, + REMOVED, LAST_SIGNAL }; @@ -84,6 +85,7 @@ struct _EmpathyAccountPriv gboolean enabled; gboolean valid; gboolean ready; + gboolean removed; /* Timestamp when the connection got connected in seconds since the epoch */ glong connect_time; @@ -324,6 +326,22 @@ empathy_account_properties_changed (TpAccount *proxy, empathy_account_update (account, properties); } +static void +empathy_account_removed_cb (TpAccount *proxy, + gpointer user_data, + GObject *weak_object) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->removed) + return; + + priv->removed = TRUE; + + g_signal_emit (account, signals[REMOVED], 0); +} + static void empathy_account_got_all_cb (TpProxy *proxy, GHashTable *properties, @@ -420,6 +438,21 @@ empathy_account_parse_unique_name (const gchar *bus_name, return TRUE; } +static void +account_invalidated_cb (TpProxy *proxy, guint domain, gint code, + gchar *message, gpointer user_data) +{ + EmpathyAccount *account = EMPATHY_ACCOUNT (user_data); + EmpathyAccountPriv *priv = GET_PRIV (account); + + if (priv->removed) + return; + + priv->removed = TRUE; + + g_signal_emit (account, signals[REMOVED], 0); +} + static void empathy_account_constructed (GObject *object) { @@ -428,6 +461,9 @@ empathy_account_constructed (GObject *object) priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL); + g_signal_connect (priv->account, "invalidated", + G_CALLBACK (account_invalidated_cb), object); + empathy_account_parse_unique_name (priv->unique_name, &(priv->proto_name), &(priv->cm_name)); @@ -437,6 +473,10 @@ empathy_account_constructed (GObject *object) empathy_account_properties_changed, NULL, NULL, object, NULL); + tp_cli_account_connect_to_removed (priv->account, + empathy_account_removed_cb, + NULL, NULL, object, NULL); + tp_cli_dbus_properties_call_get_all (priv->account, -1, TP_IFACE_ACCOUNT, empathy_account_got_all_cb, @@ -558,6 +598,13 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class) 0, NULL, NULL, _empathy_marshal_VOID__UINT_STRING_STRING, G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); + + signals[REMOVED] = g_signal_new ("removed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } void -- cgit v1.2.3