1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Xavier Claessens <xclaesse@gmail.com>
4 * Copyright (C) 2007 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <libtelepathy/tp-conn.h>
29 #include <libtelepathy/tp-chan.h>
30 #include <libtelepathy/tp-helpers.h>
31 #include <libtelepathy/tp-chan-type-contact-list-gen.h>
32 #include <libtelepathy/tp-conn-iface-aliasing-gen.h>
33 #include <libtelepathy/tp-conn-iface-presence-gen.h>
34 #include <libtelepathy/tp-conn-iface-avatars-gen.h>
36 #include "empathy-contact-list.h"
37 #include "gossip-telepathy-group.h"
38 #include "gossip-debug.h"
39 #include "gossip-utils.h"
41 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
42 EMPATHY_TYPE_CONTACT_LIST, EmpathyContactListPriv))
44 #define DEBUG_DOMAIN "ContactList"
45 #define MAX_AVATAR_REQUESTS 10
47 struct _EmpathyContactListPriv {
51 GossipContact *own_contact;
53 GossipTelepathyGroup *known;
54 GossipTelepathyGroup *publish;
55 GossipTelepathyGroup *subscribe;
60 DBusGProxy *aliasing_iface;
61 DBusGProxy *avatars_iface;
62 DBusGProxy *presence_iface;
64 GList *avatar_requests_queue;
68 CONTACT_LIST_TYPE_KNOWN,
69 CONTACT_LIST_TYPE_PUBLISH,
70 CONTACT_LIST_TYPE_SUBSCRIBE,
71 CONTACT_LIST_TYPE_UNKNOWN,
72 CONTACT_LIST_TYPE_COUNT
81 EmpathyContactList *list;
83 } ContactListAvatarRequestData;
86 EmpathyContactList *list;
88 } ContactListAliasesRequestData;
90 static void empathy_contact_list_class_init (EmpathyContactListClass *klass);
91 static void empathy_contact_list_init (EmpathyContactList *list);
92 static void contact_list_finalize (GObject *object);
93 static void contact_list_finalize_proxies (EmpathyContactList *list);
94 static void contact_list_contact_removed_foreach (guint handle,
95 GossipContact *contact,
96 EmpathyContactList *list);
97 static void contact_list_destroy_cb (DBusGProxy *proxy,
98 EmpathyContactList *list);
99 static gboolean contact_list_find_foreach (guint handle,
100 GossipContact *contact,
102 static void contact_list_newchannel_cb (DBusGProxy *proxy,
103 const gchar *object_path,
104 const gchar *channel_type,
105 TelepathyHandleType handle_type,
106 guint channel_handle,
107 gboolean suppress_handle,
108 EmpathyContactList *list);
109 static ContactListType contact_list_get_type (EmpathyContactList *list,
111 static void contact_list_contact_added_cb (GossipTelepathyGroup *group,
115 const gchar *message,
116 EmpathyContactList *list);
117 static void contact_list_contact_removed_cb (GossipTelepathyGroup *group,
121 const gchar *message,
122 EmpathyContactList *list);
123 static void contact_list_local_pending_cb (GossipTelepathyGroup *group,
127 const gchar *message,
128 EmpathyContactList *list);
129 static void contact_list_groups_updated_cb (GossipContact *contact,
131 EmpathyContactList *list);
132 static void contact_list_subscription_updated_cb (GossipContact *contact,
134 EmpathyContactList *list);
135 static void contact_list_name_updated_cb (GossipContact *contact,
137 EmpathyContactList *list);
138 static void contact_list_update_groups_foreach (gchar *object_path,
139 GossipTelepathyGroup *group,
140 ContactListData *data);
141 static GossipTelepathyGroup * contact_list_get_group (EmpathyContactList *list,
143 static gboolean contact_list_find_group (gchar *key,
144 GossipTelepathyGroup *group,
146 static void contact_list_get_groups_foreach (gchar *key,
147 GossipTelepathyGroup *group,
149 static void contact_list_group_channel_closed_cb (TpChan *channel,
150 EmpathyContactList *list);
151 static void contact_list_group_members_added_cb (GossipTelepathyGroup *group,
155 const gchar *message,
156 EmpathyContactList *list);
157 static void contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
161 const gchar *message,
162 EmpathyContactList *list);
163 static void contact_list_get_contacts_foreach (guint handle,
164 GossipContact *contact,
166 static void contact_list_get_info (EmpathyContactList *list,
168 static void contact_list_request_avatar (EmpathyContactList *list,
170 static void contact_list_start_avatar_requests (EmpathyContactList *list);
171 static void contact_list_avatar_update_cb (DBusGProxy *proxy,
174 EmpathyContactList *list);
175 static void contact_list_request_avatar_cb (DBusGProxy *proxy,
179 ContactListAvatarRequestData *data);
180 static void contact_list_aliases_update_cb (DBusGProxy *proxy,
182 EmpathyContactList *list);
183 static void contact_list_request_aliases_cb (DBusGProxy *proxy,
184 gchar **contact_names,
186 ContactListAliasesRequestData *data);
187 static void contact_list_presence_update_cb (DBusGProxy *proxy,
188 GHashTable *handle_table,
189 EmpathyContactList *list);
190 static void contact_list_parse_presence_foreach (guint handle,
191 GValueArray *presence_struct,
192 EmpathyContactList *list);
193 static void contact_list_presences_table_foreach (const gchar *state_str,
194 GHashTable *presences_table,
195 GossipPresence **presence);
196 static void contact_list_status_changed_cb (MissionControl *mc,
197 TelepathyConnectionStatus status,
199 TelepathyConnectionStatusReason reason,
200 const gchar *unique_name,
201 EmpathyContactList *list);
210 static guint signals[LAST_SIGNAL];
211 static guint n_avatar_requests = 0;
213 G_DEFINE_TYPE (EmpathyContactList, empathy_contact_list, G_TYPE_OBJECT);
216 empathy_contact_list_class_init (EmpathyContactListClass *klass)
218 GObjectClass *object_class = G_OBJECT_CLASS (klass);
220 object_class->finalize = contact_list_finalize;
222 signals[CONTACT_ADDED] =
223 g_signal_new ("contact-added",
224 G_TYPE_FROM_CLASS (klass),
228 g_cclosure_marshal_VOID__OBJECT,
230 1, GOSSIP_TYPE_CONTACT);
232 signals[CONTACT_REMOVED] =
233 g_signal_new ("contact-removed",
234 G_TYPE_FROM_CLASS (klass),
238 g_cclosure_marshal_VOID__OBJECT,
240 1, GOSSIP_TYPE_CONTACT);
243 g_signal_new ("destroy",
244 G_TYPE_FROM_CLASS (klass),
248 g_cclosure_marshal_VOID__VOID,
252 g_type_class_add_private (object_class, sizeof (EmpathyContactListPriv));
256 empathy_contact_list_init (EmpathyContactList *list)
258 EmpathyContactListPriv *priv;
260 priv = GET_PRIV (list);
262 priv->groups = g_hash_table_new_full (g_str_hash,
264 (GDestroyNotify) g_free,
265 (GDestroyNotify) g_object_unref);
266 priv->contacts = g_hash_table_new_full (g_direct_hash,
269 (GDestroyNotify) g_object_unref);
274 contact_list_finalize (GObject *object)
276 EmpathyContactListPriv *priv;
277 EmpathyContactList *list;
279 list = EMPATHY_CONTACT_LIST (object);
280 priv = GET_PRIV (list);
282 gossip_debug (DEBUG_DOMAIN, "finalize: %p", object);
284 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
285 "AccountStatusChanged",
286 G_CALLBACK (contact_list_status_changed_cb),
289 contact_list_finalize_proxies (list);
292 g_object_unref (priv->tp_conn);
296 g_object_unref (priv->known);
299 if (priv->subscribe) {
300 g_object_unref (priv->subscribe);
304 g_object_unref (priv->publish);
307 g_object_unref (priv->account);
308 g_object_unref (priv->own_contact);
309 g_object_unref (priv->mc);
310 g_hash_table_destroy (priv->groups);
311 g_hash_table_destroy (priv->contacts);
313 G_OBJECT_CLASS (empathy_contact_list_parent_class)->finalize (object);
317 empathy_contact_list_new (McAccount *account)
319 EmpathyContactListPriv *priv;
320 EmpathyContactList *list;
323 GError *error = NULL;
325 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
327 mc = mission_control_new (tp_get_bus ());
329 if (mission_control_get_connection_status (mc, account, NULL) != 0) {
330 /* The account is not connected, nothing to do. */
334 list = g_object_new (EMPATHY_TYPE_CONTACT_LIST, NULL);
335 priv = GET_PRIV (list);
337 priv->tp_conn = mission_control_get_connection (mc, account, NULL);
338 priv->account = g_object_ref (account);
341 g_signal_connect (priv->tp_conn, "destroy",
342 G_CALLBACK (contact_list_destroy_cb),
344 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
345 "AccountStatusChanged",
346 G_CALLBACK (contact_list_status_changed_cb),
349 priv->aliasing_iface = tp_conn_get_interface (priv->tp_conn,
350 TELEPATHY_CONN_IFACE_ALIASING_QUARK);
351 priv->avatars_iface = tp_conn_get_interface (priv->tp_conn,
352 TELEPATHY_CONN_IFACE_AVATARS_QUARK);
353 priv->presence_iface = tp_conn_get_interface (priv->tp_conn,
354 TELEPATHY_CONN_IFACE_PRESENCE_QUARK);
356 if (priv->aliasing_iface) {
357 dbus_g_proxy_connect_signal (priv->aliasing_iface,
359 G_CALLBACK (contact_list_aliases_update_cb),
363 if (priv->avatars_iface) {
364 dbus_g_proxy_connect_signal (priv->avatars_iface,
366 G_CALLBACK (contact_list_avatar_update_cb),
370 if (priv->presence_iface) {
371 dbus_g_proxy_connect_signal (priv->presence_iface,
373 G_CALLBACK (contact_list_presence_update_cb),
377 /* Get our own handle and contact */
378 if (!tp_conn_get_self_handle (DBUS_G_PROXY (priv->tp_conn),
380 gossip_debug (DEBUG_DOMAIN, "GetSelfHandle Error: %s",
381 error ? error->message : "No error given");
382 g_clear_error (&error);
384 priv->own_contact = empathy_contact_list_get_from_handle (list, handle);
391 empathy_contact_list_setup (EmpathyContactList *list)
393 EmpathyContactListPriv *priv;
395 GError *error = NULL;
398 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
400 priv = GET_PRIV (list);
402 gossip_debug (DEBUG_DOMAIN, "setup contact list: %p", list);
404 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
405 G_CALLBACK (contact_list_newchannel_cb),
408 /* Get existing channels */
409 if (!tp_conn_list_channels (DBUS_G_PROXY (priv->tp_conn),
412 gossip_debug (DEBUG_DOMAIN,
413 "Failed to get list of open channels: %s",
414 error ? error->message : "No error given");
415 g_clear_error (&error);
419 for (i = 0; channels->len > i; i++) {
420 GValueArray *chan_struct;
421 const gchar *object_path;
422 const gchar *chan_iface;
423 TelepathyHandleType handle_type;
426 chan_struct = g_ptr_array_index (channels, i);
427 object_path = g_value_get_boxed (g_value_array_get_nth (chan_struct, 0));
428 chan_iface = g_value_get_string (g_value_array_get_nth (chan_struct, 1));
429 handle_type = g_value_get_uint (g_value_array_get_nth (chan_struct, 2));
430 handle = g_value_get_uint (g_value_array_get_nth (chan_struct, 3));
432 contact_list_newchannel_cb (DBUS_G_PROXY (priv->tp_conn),
433 object_path, chan_iface,
437 g_value_array_free (chan_struct);
440 g_ptr_array_free (channels, TRUE);
444 empathy_contact_list_get_account (EmpathyContactList *list)
446 EmpathyContactListPriv *priv;
448 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
450 priv = GET_PRIV (list);
452 return priv->account;
456 empathy_contact_list_get_own (EmpathyContactList *list)
458 EmpathyContactListPriv *priv;
460 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
462 priv = GET_PRIV (list);
464 return priv->own_contact;
468 empathy_contact_list_find (EmpathyContactList *list,
471 EmpathyContactListPriv *priv;
472 GossipContact *contact;
474 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
476 priv = GET_PRIV (list);
478 contact = g_hash_table_find (priv->contacts,
479 (GHRFunc) contact_list_find_foreach,
486 empathy_contact_list_add (EmpathyContactList *list,
488 const gchar *message)
490 EmpathyContactListPriv *priv;
492 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
494 priv = GET_PRIV (list);
496 gossip_telepathy_group_add_member (priv->subscribe, handle, message);
500 empathy_contact_list_remove (EmpathyContactList *list,
503 EmpathyContactListPriv *priv;
505 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
507 priv = GET_PRIV (list);
509 gossip_telepathy_group_remove_member (priv->subscribe, handle, "");
510 gossip_telepathy_group_remove_member (priv->publish, handle, "");
511 gossip_telepathy_group_remove_member (priv->known, handle, "");
515 empathy_contact_list_get_from_id (EmpathyContactList *list,
518 EmpathyContactListPriv *priv;
519 GossipContact *contact;
520 const gchar *contact_ids[] = {id, NULL};
523 GError *error = NULL;
525 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
526 g_return_val_if_fail (id != NULL, NULL);
528 priv = GET_PRIV (list);
530 contact = empathy_contact_list_find (list, id);
535 /* The id is unknown, requests a new handle */
536 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
537 TP_HANDLE_TYPE_CONTACT,
540 gossip_debug (DEBUG_DOMAIN,
541 "RequestHandle for %s failed: %s", id,
542 error ? error->message : "No error given");
543 g_clear_error (&error);
547 handle = g_array_index(handles, guint, 0);
548 g_array_free (handles, TRUE);
550 return empathy_contact_list_get_from_handle (list, handle);
554 empathy_contact_list_get_from_handle (EmpathyContactList *list,
557 GossipContact *contact;
561 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
563 handles = g_array_new (FALSE, FALSE, sizeof (guint));
564 g_array_append_val (handles, handle);
566 contacts = empathy_contact_list_get_from_handles (list, handles);
567 g_array_free (handles, TRUE);
573 contact = contacts->data;
574 g_list_free (contacts);
580 empathy_contact_list_get_from_handles (EmpathyContactList *list,
583 EmpathyContactListPriv *priv;
584 gchar **handles_names;
587 GList *contacts = NULL;
589 GError *error = NULL;
591 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
592 g_return_val_if_fail (handles != NULL, NULL);
594 priv = GET_PRIV (list);
596 /* Search all handles we already have */
597 new_handles = g_array_new (FALSE, FALSE, sizeof (guint));
598 for (i = 0; i < handles->len; i++) {
599 GossipContact *contact;
602 handle = g_array_index (handles, guint, i);
603 contact = g_hash_table_lookup (priv->contacts,
604 GUINT_TO_POINTER (handle));
607 contacts = g_list_prepend (contacts,
608 g_object_ref (contact));
610 g_array_append_val (new_handles, handle);
614 if (new_handles->len == 0) {
618 /* Holds all handles we don't have yet.
619 * FIXME: We should release them at some point. */
620 if (!tp_conn_hold_handles (DBUS_G_PROXY (priv->tp_conn),
621 TP_HANDLE_TYPE_CONTACT,
622 new_handles, &error)) {
623 gossip_debug (DEBUG_DOMAIN,
624 "HoldHandles Error: %s",
625 error ? error->message : "No error given");
626 g_clear_error (&error);
627 g_array_free (new_handles, TRUE);
631 /* Get the IDs of all new handles */
632 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
633 TP_HANDLE_TYPE_CONTACT,
637 gossip_debug (DEBUG_DOMAIN,
638 "InspectHandle Error: %s",
639 error ? error->message : "No error given");
640 g_clear_error (&error);
641 g_array_free (new_handles, TRUE);
645 /* Create contact objects */
646 for (i = 0, id = handles_names; *id && i < new_handles->len; id++, i++) {
647 GossipContact *contact;
650 handle = g_array_index (new_handles, guint, i);
651 contact = g_object_new (GOSSIP_TYPE_CONTACT,
652 "account", priv->account,
657 g_signal_connect (contact, "notify::groups",
658 G_CALLBACK (contact_list_groups_updated_cb),
660 g_signal_connect (contact, "notify::subscription",
661 G_CALLBACK (contact_list_subscription_updated_cb),
663 g_signal_connect (contact, "notify::name",
664 G_CALLBACK (contact_list_name_updated_cb),
667 gossip_debug (DEBUG_DOMAIN, "new contact created: %s (%d)",
670 g_hash_table_insert (priv->contacts,
671 GUINT_TO_POINTER (handle),
674 contacts = g_list_prepend (contacts, g_object_ref (contact));
677 contact_list_get_info (list, new_handles);
679 g_array_free (new_handles, TRUE);
680 g_strfreev (handles_names);
686 empathy_contact_list_rename_group (EmpathyContactList *list,
687 const gchar *old_group,
688 const gchar *new_group)
690 EmpathyContactListPriv *priv;
691 GossipTelepathyGroup *group;
694 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
695 g_return_if_fail (old_group != NULL);
696 g_return_if_fail (new_group != NULL);
698 priv = GET_PRIV (list);
700 group = g_hash_table_find (priv->groups,
701 (GHRFunc) contact_list_find_group,
704 /* The group doesn't exists on this account */
708 gossip_debug (DEBUG_DOMAIN, "rename group %s to %s", group, new_group);
710 /* Remove all members from the old group */
711 members = gossip_telepathy_group_get_members (group);
712 gossip_telepathy_group_remove_members (group, members, "");
713 contact_list_group_members_removed_cb (group, members,
715 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
717 g_hash_table_remove (priv->groups,
718 gossip_telepathy_group_get_object_path (group));
720 /* Add all members to the new group */
721 group = contact_list_get_group (list, new_group);
723 gossip_telepathy_group_add_members (group, members, "");
728 empathy_contact_list_get_groups (EmpathyContactList *list)
730 EmpathyContactListPriv *priv;
731 GList *groups = NULL;
733 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
735 priv = GET_PRIV (list);
737 g_hash_table_foreach (priv->groups,
738 (GHFunc) contact_list_get_groups_foreach,
741 groups = g_list_sort (groups, (GCompareFunc) strcmp);
747 empathy_contact_list_get_contacts (EmpathyContactList *list)
749 EmpathyContactListPriv *priv;
750 GList *contacts = NULL;
752 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
754 priv = GET_PRIV (list);
756 /* FIXME: we should only return contacts that are in the contact list */
757 g_hash_table_foreach (priv->contacts,
758 (GHFunc) contact_list_get_contacts_foreach,
765 contact_list_finalize_proxies (EmpathyContactList *list)
767 EmpathyContactListPriv *priv;
769 priv = GET_PRIV (list);
772 g_signal_handlers_disconnect_by_func (priv->tp_conn,
773 contact_list_destroy_cb,
775 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
776 G_CALLBACK (contact_list_newchannel_cb),
780 if (priv->aliasing_iface) {
781 dbus_g_proxy_disconnect_signal (priv->aliasing_iface,
783 G_CALLBACK (contact_list_aliases_update_cb),
787 if (priv->avatars_iface) {
788 dbus_g_proxy_disconnect_signal (priv->avatars_iface,
790 G_CALLBACK (contact_list_avatar_update_cb),
794 if (priv->presence_iface) {
795 dbus_g_proxy_disconnect_signal (priv->presence_iface,
797 G_CALLBACK (contact_list_presence_update_cb),
803 contact_list_destroy_cb (DBusGProxy *proxy,
804 EmpathyContactList *list)
806 EmpathyContactListPriv *priv;
808 priv = GET_PRIV (list);
810 gossip_debug (DEBUG_DOMAIN, "Connection destroyed... "
811 "Account disconnected or CM crashed");
813 /* DBus proxies should NOT be used anymore */
814 g_object_unref (priv->tp_conn);
815 priv->tp_conn = NULL;
816 priv->aliasing_iface = NULL;
817 priv->avatars_iface = NULL;
818 priv->presence_iface = NULL;
820 /* Remove all contacts */
821 g_hash_table_foreach (priv->contacts,
822 (GHFunc) contact_list_contact_removed_foreach,
824 g_hash_table_remove_all (priv->contacts);
826 /* Tell the world to not use us anymore */
827 g_signal_emit (list, signals[DESTROY], 0);
831 contact_list_contact_removed_foreach (guint handle,
832 GossipContact *contact,
833 EmpathyContactList *list)
835 g_signal_handlers_disconnect_by_func (contact,
836 contact_list_groups_updated_cb,
838 g_signal_handlers_disconnect_by_func (contact,
839 contact_list_subscription_updated_cb,
841 g_signal_handlers_disconnect_by_func (contact,
842 contact_list_name_updated_cb,
845 g_signal_emit (list, signals[CONTACT_REMOVED], 0, contact);
849 contact_list_block_contact (EmpathyContactList *list,
850 GossipContact *contact)
852 g_signal_handlers_block_by_func (contact,
853 contact_list_groups_updated_cb,
855 g_signal_handlers_block_by_func (contact,
856 contact_list_subscription_updated_cb,
858 g_signal_handlers_block_by_func (contact,
859 contact_list_name_updated_cb,
864 contact_list_unblock_contact (EmpathyContactList *list,
865 GossipContact *contact)
867 g_signal_handlers_unblock_by_func (contact,
868 contact_list_groups_updated_cb,
870 g_signal_handlers_unblock_by_func (contact,
871 contact_list_subscription_updated_cb,
873 g_signal_handlers_unblock_by_func (contact,
874 contact_list_name_updated_cb,
879 contact_list_find_foreach (guint handle,
880 GossipContact *contact,
883 if (strcmp (gossip_contact_get_id (contact), id) == 0) {
891 contact_list_newchannel_cb (DBusGProxy *proxy,
892 const gchar *object_path,
893 const gchar *channel_type,
894 TelepathyHandleType handle_type,
895 guint channel_handle,
896 gboolean suppress_handle,
897 EmpathyContactList *list)
899 EmpathyContactListPriv *priv;
900 GossipTelepathyGroup *group;
902 const gchar *bus_name;
905 priv = GET_PRIV (list);
907 if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0 ||
912 bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn));
913 new_chan = tp_chan_new (tp_get_bus (),
916 channel_type, handle_type, channel_handle);
918 if (handle_type == TP_HANDLE_TYPE_LIST) {
919 ContactListType list_type;
921 list_type = contact_list_get_type (list, new_chan);
922 if (list_type == CONTACT_LIST_TYPE_UNKNOWN) {
923 gossip_debug (DEBUG_DOMAIN, "Unknown contact list channel");
924 g_object_unref (new_chan);
928 gossip_debug (DEBUG_DOMAIN, "New contact list channel of type: %d",
931 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
934 case CONTACT_LIST_TYPE_KNOWN:
936 g_object_unref (priv->known);
940 case CONTACT_LIST_TYPE_PUBLISH:
942 g_object_unref (priv->publish);
944 priv->publish = group;
946 case CONTACT_LIST_TYPE_SUBSCRIBE:
947 if (priv->subscribe) {
948 g_object_unref (priv->subscribe);
950 priv->subscribe = group;
953 g_assert_not_reached ();
956 /* Connect and setup the new contact-list group */
957 if (list_type == CONTACT_LIST_TYPE_KNOWN ||
958 list_type == CONTACT_LIST_TYPE_SUBSCRIBE) {
959 g_signal_connect (group, "members-added",
960 G_CALLBACK (contact_list_contact_added_cb),
962 g_signal_connect (group, "members-removed",
963 G_CALLBACK (contact_list_contact_removed_cb),
966 members = gossip_telepathy_group_get_members (group);
967 contact_list_contact_added_cb (group, members, 0,
968 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
970 g_array_free (members, TRUE);
972 if (list_type == CONTACT_LIST_TYPE_PUBLISH) {
977 g_signal_connect (group, "local-pending",
978 G_CALLBACK (contact_list_local_pending_cb),
981 info = gossip_telepathy_group_get_local_pending_members_with_info (group);
984 /* This happens with butterfly because
985 * GetLocalPendingMembersWithInfo is not
987 g_object_unref (new_chan);
991 pending = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
992 for (i = 0; info->len > i; i++) {
993 GValueArray *pending_struct;
997 const gchar *message;
999 pending_struct = g_ptr_array_index (info, i);
1000 member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
1001 invitor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
1002 reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
1003 message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
1005 g_array_insert_val (pending, 0, member);
1007 contact_list_local_pending_cb (group, pending,
1012 g_value_array_free (pending_struct);
1015 g_ptr_array_free (info, TRUE);
1016 g_array_free (pending, TRUE);
1019 else if (handle_type == TP_HANDLE_TYPE_GROUP) {
1020 const gchar *object_path;
1022 object_path = dbus_g_proxy_get_path (DBUS_G_PROXY (new_chan));
1023 if (g_hash_table_lookup (priv->groups, object_path)) {
1024 g_object_unref (new_chan);
1028 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
1030 gossip_debug (DEBUG_DOMAIN, "New server-side group channel: %s",
1031 gossip_telepathy_group_get_name (group));
1033 dbus_g_proxy_connect_signal (DBUS_G_PROXY (new_chan), "Closed",
1035 (contact_list_group_channel_closed_cb),
1038 g_hash_table_insert (priv->groups, g_strdup (object_path), group);
1039 g_signal_connect (group, "members-added",
1040 G_CALLBACK (contact_list_group_members_added_cb),
1042 g_signal_connect (group, "members-removed",
1043 G_CALLBACK (contact_list_group_members_removed_cb),
1046 members = gossip_telepathy_group_get_members (group);
1047 contact_list_group_members_added_cb (group, members, 0,
1048 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
1050 g_array_free (members, TRUE);
1053 g_object_unref (new_chan);
1056 static ContactListType
1057 contact_list_get_type (EmpathyContactList *list,
1060 EmpathyContactListPriv *priv;
1062 gchar **handle_name;
1063 ContactListType list_type;
1064 GError *error = NULL;
1066 priv = GET_PRIV (list);
1068 handles = g_array_new (FALSE, FALSE, sizeof (guint));
1069 g_array_append_val (handles, list_chan->handle);
1071 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
1072 TP_HANDLE_TYPE_LIST,
1076 gossip_debug (DEBUG_DOMAIN,
1077 "InspectHandle Error: %s",
1078 error ? error->message : "No error given");
1079 g_clear_error (&error);
1080 g_array_free (handles, TRUE);
1081 return CONTACT_LIST_TYPE_UNKNOWN;
1084 if (strcmp (*handle_name, "subscribe") == 0) {
1085 list_type = CONTACT_LIST_TYPE_SUBSCRIBE;
1086 } else if (strcmp (*handle_name, "publish") == 0) {
1087 list_type = CONTACT_LIST_TYPE_PUBLISH;
1088 } else if (strcmp (*handle_name, "known") == 0) {
1089 list_type = CONTACT_LIST_TYPE_KNOWN;
1091 list_type = CONTACT_LIST_TYPE_UNKNOWN;
1094 g_strfreev (handle_name);
1095 g_array_free (handles, TRUE);
1101 contact_list_contact_added_cb (GossipTelepathyGroup *group,
1105 const gchar *message,
1106 EmpathyContactList *list)
1108 EmpathyContactListPriv *priv;
1109 GList *added_list, *l;
1111 priv = GET_PRIV (list);
1113 added_list = empathy_contact_list_get_from_handles (list, handles);
1115 for (l = added_list; l; l = l->next) {
1116 GossipContact *contact;
1118 contact = GOSSIP_CONTACT (l->data);
1119 contact_list_block_contact (list, contact);
1120 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_BOTH);
1121 contact_list_unblock_contact (list, contact);
1123 g_signal_emit (list, signals[CONTACT_ADDED], 0, contact);
1125 g_object_unref (contact);
1128 g_list_free (added_list);
1132 contact_list_contact_removed_cb (GossipTelepathyGroup *group,
1136 const gchar *message,
1137 EmpathyContactList *list)
1139 EmpathyContactListPriv *priv;
1140 GList *removed_list, *l;
1142 priv = GET_PRIV (list);
1144 removed_list = empathy_contact_list_get_from_handles (list, handles);
1146 for (l = removed_list; l; l = l->next) {
1147 GossipContact *contact;
1150 contact = GOSSIP_CONTACT (l->data);
1152 handle = gossip_contact_get_handle (contact);
1153 g_hash_table_remove (priv->contacts, GUINT_TO_POINTER (handle));
1155 g_signal_emit (list, signals[CONTACT_REMOVED], 0, contact);
1157 g_object_unref (contact);
1160 g_list_free (removed_list);
1164 contact_list_local_pending_cb (GossipTelepathyGroup *group,
1168 const gchar *message,
1169 EmpathyContactList *list)
1171 EmpathyContactListPriv *priv;
1172 GList *pending_list, *l;
1174 priv = GET_PRIV (list);
1176 pending_list = empathy_contact_list_get_from_handles (list, handles);
1178 for (l = pending_list; l; l = l->next) {
1179 GossipContact *contact;
1181 contact = GOSSIP_CONTACT (l->data);
1183 /* FIXME: Is that the correct way ? */
1184 contact_list_block_contact (list, contact);
1185 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_FROM);
1186 contact_list_unblock_contact (list, contact);
1187 g_signal_emit (list, signals[CONTACT_ADDED], 0, contact);
1189 g_object_unref (contact);
1192 g_list_free (pending_list);
1196 contact_list_groups_updated_cb (GossipContact *contact,
1198 EmpathyContactList *list)
1200 EmpathyContactListPriv *priv;
1201 ContactListData data;
1204 priv = GET_PRIV (list);
1206 /* Make sure all groups are created */
1207 groups = gossip_contact_get_groups (contact);
1208 for (l = groups; l; l = l->next) {
1209 contact_list_get_group (list, l->data);
1212 data.handle = gossip_contact_get_handle (contact);
1213 data.new_groups = groups;
1215 g_hash_table_foreach (priv->groups,
1216 (GHFunc) contact_list_update_groups_foreach,
1221 contact_list_subscription_updated_cb (GossipContact *contact,
1223 EmpathyContactList *list)
1225 EmpathyContactListPriv *priv;
1226 GossipSubscription subscription;
1229 priv = GET_PRIV (list);
1231 subscription = gossip_contact_get_subscription (contact);
1232 handle = gossip_contact_get_handle (contact);
1234 /* FIXME: what to do here, I'm a bit lost... */
1236 gossip_telepathy_group_add_member (priv->publish, handle, "");
1238 gossip_telepathy_group_remove_member (priv->publish, handle, "");
1243 contact_list_name_updated_cb (GossipContact *contact,
1245 EmpathyContactList *list)
1247 EmpathyContactListPriv *priv;
1248 GHashTable *new_alias;
1249 const gchar *new_name;
1251 GError *error = NULL;
1253 priv = GET_PRIV (list);
1255 handle = gossip_contact_get_handle (contact);
1256 new_name = gossip_contact_get_name (contact);
1258 gossip_debug (DEBUG_DOMAIN, "renaming handle %d to %s",
1261 new_alias = g_hash_table_new_full (g_direct_hash,
1266 g_hash_table_insert (new_alias,
1267 GUINT_TO_POINTER (handle),
1268 g_strdup (new_name));
1270 if (!tp_conn_iface_aliasing_set_aliases (priv->aliasing_iface,
1273 gossip_debug (DEBUG_DOMAIN,
1274 "Couldn't rename contact: %s",
1275 error ? error->message : "No error given");
1276 g_clear_error (&error);
1279 g_hash_table_destroy (new_alias);
1283 contact_list_update_groups_foreach (gchar *object_path,
1284 GossipTelepathyGroup *group,
1285 ContactListData *data)
1288 gboolean found = FALSE;
1289 const gchar *group_name;
1292 is_member = gossip_telepathy_group_is_member (group, data->handle);
1293 group_name = gossip_telepathy_group_get_name (group);
1295 for (l = data->new_groups; l; l = l->next) {
1296 if (strcmp (group_name, l->data) == 0) {
1302 if (is_member && !found) {
1303 /* We are no longer member of this group */
1304 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1305 data->handle, group_name);
1306 gossip_telepathy_group_remove_member (group, data->handle, "");
1309 if (!is_member && found) {
1310 /* We are now member of this group */
1311 gossip_debug (DEBUG_DOMAIN, "Contact %d added to group '%s'",
1312 data->handle, group_name);
1313 gossip_telepathy_group_add_member (group, data->handle, "");
1317 static GossipTelepathyGroup *
1318 contact_list_get_group (EmpathyContactList *list,
1321 EmpathyContactListPriv *priv;
1322 GossipTelepathyGroup *group;
1323 TpChan *group_channel;
1326 char *group_object_path;
1327 const char *names[2] = {name, NULL};
1328 GError *error = NULL;
1330 priv = GET_PRIV (list);
1332 group = g_hash_table_find (priv->groups,
1333 (GHRFunc) contact_list_find_group,
1339 gossip_debug (DEBUG_DOMAIN, "creating new group: %s", name);
1341 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
1342 TP_HANDLE_TYPE_GROUP,
1346 gossip_debug (DEBUG_DOMAIN,
1347 "Couldn't request the creation of a new handle for group: %s",
1348 error ? error->message : "No error given");
1349 g_clear_error (&error);
1352 group_handle = g_array_index (handles, guint, 0);
1353 g_array_free (handles, TRUE);
1355 if (!tp_conn_request_channel (DBUS_G_PROXY (priv->tp_conn),
1356 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1357 TP_HANDLE_TYPE_GROUP,
1362 gossip_debug (DEBUG_DOMAIN,
1363 "Couldn't request the creation of a new group channel: %s",
1364 error ? error->message : "No error given");
1365 g_clear_error (&error);
1369 group_channel = tp_chan_new (tp_get_bus (),
1370 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn)),
1372 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1373 TP_HANDLE_TYPE_GROUP,
1376 dbus_g_proxy_connect_signal (DBUS_G_PROXY (group_channel),
1379 (contact_list_group_channel_closed_cb),
1383 group = gossip_telepathy_group_new (group_channel, priv->tp_conn);
1384 g_hash_table_insert (priv->groups, group_object_path, group);
1385 g_signal_connect (group, "members-added",
1386 G_CALLBACK (contact_list_group_members_added_cb),
1388 g_signal_connect (group, "members-removed",
1389 G_CALLBACK (contact_list_group_members_removed_cb),
1396 contact_list_find_group (gchar *key,
1397 GossipTelepathyGroup *group,
1400 if (strcmp (group_name, gossip_telepathy_group_get_name (group)) == 0) {
1408 contact_list_get_groups_foreach (gchar *key,
1409 GossipTelepathyGroup *group,
1414 name = gossip_telepathy_group_get_name (group);
1415 *groups = g_list_append (*groups, g_strdup (name));
1419 contact_list_group_channel_closed_cb (TpChan *channel,
1420 EmpathyContactList *list)
1422 EmpathyContactListPriv *priv;
1424 priv = GET_PRIV (list);
1426 g_hash_table_remove (priv->groups,
1427 dbus_g_proxy_get_path (DBUS_G_PROXY (channel)));
1431 contact_list_group_members_added_cb (GossipTelepathyGroup *group,
1435 const gchar *message,
1436 EmpathyContactList *list)
1438 EmpathyContactListPriv *priv;
1439 GList *added_list, *l;
1440 const gchar *group_name;
1442 priv = GET_PRIV (list);
1444 group_name = gossip_telepathy_group_get_name (group);
1445 added_list = empathy_contact_list_get_from_handles (list, members);
1447 for (l = added_list; l; l = l->next) {
1448 GossipContact *contact;
1449 GList *contact_groups;
1451 contact = GOSSIP_CONTACT (l->data);
1452 contact_groups = gossip_contact_get_groups (contact);
1454 if (!g_list_find_custom (contact_groups,
1456 (GCompareFunc) strcmp)) {
1457 gossip_debug (DEBUG_DOMAIN, "Contact %s added to group '%s'",
1458 gossip_contact_get_name (contact),
1460 contact_groups = g_list_append (contact_groups,
1461 g_strdup (group_name));
1462 contact_list_block_contact (list, contact);
1463 gossip_contact_set_groups (contact, contact_groups);
1464 contact_list_unblock_contact (list, contact);
1467 g_object_unref (contact);
1470 g_list_free (added_list);
1474 contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
1478 const gchar *message,
1479 EmpathyContactList *list)
1481 EmpathyContactListPriv *priv;
1482 GList *removed_list, *l;
1483 const gchar *group_name;
1485 priv = GET_PRIV (list);
1487 group_name = gossip_telepathy_group_get_name (group);
1488 removed_list = empathy_contact_list_get_from_handles (list, members);
1490 for (l = removed_list; l; l = l->next) {
1491 GossipContact *contact;
1492 GList *contact_groups;
1495 /* FIXME: Does it leak ? */
1496 contact = GOSSIP_CONTACT (l->data);
1497 contact_groups = gossip_contact_get_groups (contact);
1498 contact_groups = g_list_copy (contact_groups);
1500 to_remove = g_list_find_custom (contact_groups,
1502 (GCompareFunc) strcmp);
1504 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1505 gossip_contact_get_handle (contact),
1507 contact_groups = g_list_remove_link (contact_groups,
1509 contact_list_block_contact (list, contact);
1510 gossip_contact_set_groups (contact, contact_groups);
1511 contact_list_unblock_contact (list, contact);
1514 g_list_free (contact_groups);
1516 g_object_unref (contact);
1519 g_list_free (removed_list);
1523 contact_list_get_contacts_foreach (guint handle,
1524 GossipContact *contact,
1527 *contacts = g_list_append (*contacts, g_object_ref (contact));
1531 contact_list_get_info (EmpathyContactList *list,
1534 EmpathyContactListPriv *priv;
1535 GError *error = NULL;
1537 priv = GET_PRIV (list);
1539 if (priv->presence_iface) {
1540 /* FIXME: We should use GetPresence instead */
1541 if (!tp_conn_iface_presence_request_presence (priv->presence_iface,
1543 gossip_debug (DEBUG_DOMAIN,
1544 "Could not request presences: %s",
1545 error ? error->message : "No error given");
1546 g_clear_error (&error);
1550 if (priv->aliasing_iface) {
1551 ContactListAliasesRequestData *data;
1553 data = g_slice_new (ContactListAliasesRequestData);
1555 data->handles = g_memdup (handles->data, handles->len * sizeof (guint));
1557 tp_conn_iface_aliasing_request_aliases_async (priv->aliasing_iface,
1559 (tp_conn_iface_aliasing_request_aliases_reply)
1560 contact_list_request_aliases_cb,
1564 if (priv->avatars_iface) {
1567 for (i = 0; i < handles->len; i++) {
1570 handle = g_array_index (handles, gint, i);
1571 contact_list_request_avatar (list, handle);
1577 contact_list_request_avatar (EmpathyContactList *list,
1580 EmpathyContactListPriv *priv;
1582 priv = GET_PRIV (list);
1584 /* We queue avatar requests to not send too many dbus async
1585 * calls at once. If we don't we reach the dbus's limit of
1587 priv->avatar_requests_queue = g_list_append (priv->avatar_requests_queue,
1588 GUINT_TO_POINTER (handle));
1589 contact_list_start_avatar_requests (list);
1593 contact_list_start_avatar_requests (EmpathyContactList *list)
1595 EmpathyContactListPriv *priv;
1596 ContactListAvatarRequestData *data;
1598 priv = GET_PRIV (list);
1600 while (n_avatar_requests < MAX_AVATAR_REQUESTS &&
1601 priv->avatar_requests_queue) {
1602 data = g_slice_new (ContactListAvatarRequestData);
1604 data->handle = GPOINTER_TO_UINT (priv->avatar_requests_queue->data);
1606 n_avatar_requests++;
1607 priv->avatar_requests_queue = g_list_remove (priv->avatar_requests_queue,
1608 priv->avatar_requests_queue->data);
1610 tp_conn_iface_avatars_request_avatar_async (priv->avatars_iface,
1612 (tp_conn_iface_avatars_request_avatar_reply)
1613 contact_list_request_avatar_cb,
1619 contact_list_avatar_update_cb (DBusGProxy *proxy,
1622 EmpathyContactList *list)
1624 gossip_debug (DEBUG_DOMAIN, "Changing avatar for %d to %s",
1627 contact_list_request_avatar (list, handle);
1631 contact_list_request_avatar_cb (DBusGProxy *proxy,
1632 GArray *avatar_data,
1635 ContactListAvatarRequestData *data)
1637 GossipContact *contact;
1639 contact = empathy_contact_list_get_from_handle (data->list, data->handle);
1642 gossip_debug (DEBUG_DOMAIN, "Error requesting avatar for %s: %s",
1643 gossip_contact_get_name (contact),
1644 error ? error->message : "No error given");
1646 GossipAvatar *avatar;
1648 avatar = gossip_avatar_new (avatar_data->data,
1651 contact_list_block_contact (data->list, contact);
1652 gossip_contact_set_avatar (contact, avatar);
1653 contact_list_unblock_contact (data->list, contact);
1654 gossip_avatar_unref (avatar);
1657 n_avatar_requests--;
1658 contact_list_start_avatar_requests (data->list);
1660 g_slice_free (ContactListAvatarRequestData, data);
1664 contact_list_aliases_update_cb (DBusGProxy *proxy,
1665 GPtrArray *renamed_handlers,
1666 EmpathyContactList *list)
1670 for (i = 0; renamed_handlers->len > i; i++) {
1673 GValueArray *renamed_struct;
1674 GossipContact *contact;
1676 renamed_struct = g_ptr_array_index (renamed_handlers, i);
1677 handle = g_value_get_uint(g_value_array_get_nth (renamed_struct, 0));
1678 alias = g_value_get_string(g_value_array_get_nth (renamed_struct, 1));
1680 if (alias && *alias == '\0') {
1684 contact = empathy_contact_list_get_from_handle (list, handle);
1685 contact_list_block_contact (list, contact);
1686 gossip_contact_set_name (contact, alias);
1687 contact_list_unblock_contact (list, contact);
1689 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (update cb)",
1695 contact_list_request_aliases_cb (DBusGProxy *proxy,
1696 gchar **contact_names,
1698 ContactListAliasesRequestData *data)
1703 for (name = contact_names; *name && !error; name++) {
1704 GossipContact *contact;
1706 contact = empathy_contact_list_get_from_handle (data->list,
1708 contact_list_block_contact (data->list, contact);
1709 gossip_contact_set_name (contact, *name);
1710 contact_list_unblock_contact (data->list, contact);
1712 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (request cb)",
1713 data->handles[i], *name);
1718 g_free (data->handles);
1719 g_slice_free (ContactListAliasesRequestData, data);
1723 contact_list_presence_update_cb (DBusGProxy *proxy,
1724 GHashTable *handle_table,
1725 EmpathyContactList *list)
1727 g_hash_table_foreach (handle_table,
1728 (GHFunc) contact_list_parse_presence_foreach,
1733 contact_list_parse_presence_foreach (guint handle,
1734 GValueArray *presence_struct,
1735 EmpathyContactList *list)
1737 GHashTable *presences_table;
1738 GossipContact *contact;
1739 GossipPresence *presence = NULL;
1741 contact = empathy_contact_list_get_from_handle (list, handle);
1742 presences_table = g_value_get_boxed (g_value_array_get_nth (presence_struct, 1));
1744 g_hash_table_foreach (presences_table,
1745 (GHFunc) contact_list_presences_table_foreach,
1748 gossip_debug (DEBUG_DOMAIN, "Presence changed for %s (%d) to %s (%d)",
1749 gossip_contact_get_name (contact),
1751 presence ? gossip_presence_get_status (presence) : "unset",
1752 presence ? gossip_presence_get_state (presence) : MC_PRESENCE_UNSET);
1754 contact_list_block_contact (list, contact);
1755 gossip_contact_set_presence (contact, presence);
1756 contact_list_unblock_contact (list, contact);
1760 contact_list_presences_table_foreach (const gchar *state_str,
1761 GHashTable *presences_table,
1762 GossipPresence **presence)
1765 const GValue *message;
1767 state = gossip_presence_state_from_str (state_str);
1768 if ((state == MC_PRESENCE_UNSET) || (state == MC_PRESENCE_OFFLINE)) {
1773 g_object_unref (*presence);
1777 *presence = gossip_presence_new ();
1778 gossip_presence_set_state (*presence, state);
1780 message = g_hash_table_lookup (presences_table, "message");
1781 if (message != NULL) {
1782 gossip_presence_set_status (*presence,
1783 g_value_get_string (message));
1788 contact_list_status_changed_cb (MissionControl *mc,
1789 TelepathyConnectionStatus status,
1790 McPresence presence,
1791 TelepathyConnectionStatusReason reason,
1792 const gchar *unique_name,
1793 EmpathyContactList *list)
1795 EmpathyContactListPriv *priv;
1798 priv = GET_PRIV (list);
1800 account = mc_account_lookup (unique_name);
1801 if (status != TP_CONN_STATUS_DISCONNECTED ||
1802 !gossip_account_equal (account, priv->account)) {
1803 g_object_unref (account);
1807 /* We are disconnected, do just like if the connection was destroyed */
1808 g_signal_handlers_disconnect_by_func (priv->tp_conn,
1809 contact_list_destroy_cb,
1811 contact_list_destroy_cb (DBUS_G_PROXY (priv->tp_conn), list);
1813 g_object_unref (account);