diff options
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-contact-manager.c | 14 | ||||
-rw-r--r-- | libempathy/empathy-tp-contact-factory.c | 8 | ||||
-rw-r--r-- | libempathy/empathy-utils.c | 31 | ||||
-rw-r--r-- | libempathy/empathy-utils.h | 3 |
4 files changed, 33 insertions, 23 deletions
diff --git a/libempathy/empathy-contact-manager.c b/libempathy/empathy-contact-manager.c index a151dbd26..cad19293e 100644 --- a/libempathy/empathy-contact-manager.c +++ b/libempathy/empathy-contact-manager.c @@ -38,6 +38,7 @@ struct _EmpathyContactManagerPriv { GHashTable *lists; MissionControl *mc; + gpointer token; }; static void empathy_contact_manager_class_init (EmpathyContactManagerClass *klass); @@ -188,11 +189,7 @@ contact_manager_finalize (GObject *object) { EmpathyContactManagerPriv *priv = GET_PRIV (object); - dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), - "AccountStatusChanged", - G_CALLBACK (contact_manager_status_changed_cb), - object); - + empathy_disconnect_account_status_changed (priv->token); g_hash_table_foreach (priv->lists, contact_manager_disconnect_foreach, object); @@ -224,10 +221,9 @@ empathy_contact_manager_init (EmpathyContactManager *manager) (GDestroyNotify) g_object_unref); priv->mc = empathy_mission_control_new (); - - empathy_connect_to_account_status_changed (priv->mc, - G_CALLBACK (contact_manager_status_changed_cb), - manager, NULL); + priv->token = empathy_connect_to_account_status_changed (priv->mc, + G_CALLBACK (contact_manager_status_changed_cb), + manager, NULL); /* Get ContactList for existing connections */ accounts = mission_control_get_online_connections (priv->mc, NULL); diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c index 678e53b36..1c7c33f76 100644 --- a/libempathy/empathy-tp-contact-factory.c +++ b/libempathy/empathy-tp-contact-factory.c @@ -44,6 +44,7 @@ struct _EmpathyTpContactFactoryPriv { GList *contacts; EmpathyContact *user; + gpointer token; }; static void empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass); @@ -1196,10 +1197,7 @@ tp_contact_factory_finalize (GObject *object) object, mc_account_get_normalized_name (priv->account)); - dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), - "AccountStatusChanged", - G_CALLBACK (tp_contact_factory_status_changed_cb), - object); + empathy_disconnect_account_status_changed (priv->token); for (l = priv->contacts; l; l = l->next) { g_object_weak_unref (G_OBJECT (l->data), @@ -1277,7 +1275,7 @@ empathy_tp_contact_factory_init (EmpathyTpContactFactory *tp_factory) EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory); priv->mc = empathy_mission_control_new (); - empathy_connect_to_account_status_changed (priv->mc, + priv->token = empathy_connect_to_account_status_changed (priv->mc, G_CALLBACK (tp_contact_factory_status_changed_cb), tp_factory, NULL); } diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 46fb97027..3876cdf48 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -639,16 +639,16 @@ typedef void (*AccountStatusChangedFunc) (MissionControl *mc, McPresence presence, TpConnectionStatusReason reason, const gchar *unique_name, - gpointer *user_data); + gpointer user_data); typedef struct { AccountStatusChangedFunc handler; gpointer user_data; GClosureNotify free_func; + MissionControl *mc; } AccountStatusChangedData; typedef struct { - MissionControl *mc; TpConnectionStatus status; McPresence presence; TpConnectionStatusReason reason; @@ -665,6 +665,7 @@ account_status_changed_data_free (gpointer ptr, if (data->free_func) { data->free_func (data->user_data, closure); } + g_object_unref (data->mc); g_slice_free (AccountStatusChangedData, data); } @@ -673,7 +674,7 @@ account_status_changed_invoke_callback (gpointer data) { InvocationData *invocation_data = data; - invocation_data->data->handler (invocation_data->mc, + invocation_data->data->handler (invocation_data->data->mc, invocation_data->status, invocation_data->presence, invocation_data->reason, @@ -697,18 +698,18 @@ account_status_changed_cb (MissionControl *mc, InvocationData *invocation_data; invocation_data = g_slice_new (InvocationData); - invocation_data->mc = mc; invocation_data->status = status; invocation_data->presence = presence; invocation_data->reason = reason; invocation_data->unique_name = g_strdup (unique_name); invocation_data->data = data; + g_idle_add_full (G_PRIORITY_HIGH, account_status_changed_invoke_callback, invocation_data, NULL); } -void +gpointer empathy_connect_to_account_status_changed (MissionControl *mc, GCallback handler, gpointer user_data, @@ -716,16 +717,30 @@ empathy_connect_to_account_status_changed (MissionControl *mc, { AccountStatusChangedData *data; - g_return_if_fail (IS_MISSIONCONTROL (mc)); - g_return_if_fail (handler != NULL); + g_return_val_if_fail (IS_MISSIONCONTROL (mc), NULL); + g_return_val_if_fail (handler != NULL, NULL); data = g_slice_new (AccountStatusChangedData); - data->handler = (AccountStatusChangedFunc) handler; data->user_data = user_data; data->free_func = free_func; + data->mc = g_object_ref (mc); + dbus_g_proxy_connect_signal (DBUS_G_PROXY (mc), "AccountStatusChanged", G_CALLBACK (account_status_changed_cb), data, account_status_changed_data_free); + + return data; +} + +void +empathy_disconnect_account_status_changed (gpointer token) +{ + AccountStatusChangedData *data = token; + + dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (data->mc), + "AccountStatusChanged", + G_CALLBACK (account_status_changed_cb), + data); } diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 2b14374fb..421031704 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -102,10 +102,11 @@ void empathy_run_until_ready_full (gpointer object, gpointer user_data, GMainLoop **loop); McAccount * empathy_channel_get_account (TpChannel *channel); -void empathy_connect_to_account_status_changed (MissionControl *mc, +gpointer empathy_connect_to_account_status_changed (MissionControl *mc, GCallback handler, gpointer user_data, GClosureNotify free_func); +void empathy_disconnect_account_status_changed (gpointer token); G_END_DECLS |