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-helpers.h>
29 #include <libtelepathy/tp-conn.h>
30 #include <libtelepathy/tp-chan.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-tp-contact-list.h"
37 #include "empathy-contact-list.h"
38 #include "gossip-telepathy-group.h"
39 #include "gossip-debug.h"
40 #include "gossip-utils.h"
42 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
43 EMPATHY_TYPE_TP_CONTACT_LIST, EmpathyTpContactListPriv))
45 #define DEBUG_DOMAIN "TpContactList"
46 #define MAX_AVATAR_REQUESTS 10
48 struct _EmpathyTpContactListPriv {
52 GossipContact *user_contact;
54 GossipTelepathyGroup *known;
55 GossipTelepathyGroup *publish;
56 GossipTelepathyGroup *subscribe;
61 DBusGProxy *aliasing_iface;
62 DBusGProxy *avatars_iface;
63 DBusGProxy *presence_iface;
65 GList *avatar_requests_queue;
69 TP_CONTACT_LIST_TYPE_KNOWN,
70 TP_CONTACT_LIST_TYPE_PUBLISH,
71 TP_CONTACT_LIST_TYPE_SUBSCRIBE,
72 TP_CONTACT_LIST_TYPE_UNKNOWN,
73 TP_CONTACT_LIST_TYPE_COUNT
82 EmpathyTpContactList *list;
84 } TpContactListAvatarRequestData;
87 EmpathyTpContactList *list;
89 } TpContactListAliasesRequestData;
91 static void empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass);
92 static void tp_contact_list_iface_init (EmpathyContactListIface *iface);
93 static void empathy_tp_contact_list_init (EmpathyTpContactList *list);
94 static void tp_contact_list_finalize (GObject *object);
95 static void tp_contact_list_finalize_proxies (EmpathyTpContactList *list);
96 static void tp_contact_list_setup (EmpathyContactList *list);
97 static GossipContact * tp_contact_list_find (EmpathyContactList *list,
99 static void tp_contact_list_add (EmpathyContactList *list,
100 GossipContact *contact,
101 const gchar *message);
102 static void tp_contact_list_remove (EmpathyContactList *list,
103 GossipContact *contact,
104 const gchar *message);
105 static GList * tp_contact_list_get_contacts (EmpathyContactList *list);
106 static void tp_contact_list_contact_removed_foreach (guint handle,
107 GossipContact *contact,
108 EmpathyTpContactList *list);
109 static void tp_contact_list_destroy_cb (DBusGProxy *proxy,
110 EmpathyTpContactList *list);
111 static gboolean tp_contact_list_find_foreach (guint handle,
112 GossipContact *contact,
114 static void tp_contact_list_newchannel_cb (DBusGProxy *proxy,
115 const gchar *object_path,
116 const gchar *channel_type,
117 TelepathyHandleType handle_type,
118 guint channel_handle,
119 gboolean suppress_handle,
120 EmpathyTpContactList *list);
121 static TpContactListType tp_contact_list_get_type (EmpathyTpContactList *list,
123 static void tp_contact_list_contact_added_cb (GossipTelepathyGroup *group,
127 const gchar *message,
128 EmpathyTpContactList *list);
129 static void tp_contact_list_contact_removed_cb (GossipTelepathyGroup *group,
133 const gchar *message,
134 EmpathyTpContactList *list);
135 static void tp_contact_list_local_pending_cb (GossipTelepathyGroup *group,
139 const gchar *message,
140 EmpathyTpContactList *list);
141 static void tp_contact_list_groups_updated_cb (GossipContact *contact,
143 EmpathyTpContactList *list);
144 static void tp_contact_list_subscription_updated_cb (GossipContact *contact,
146 EmpathyTpContactList *list);
147 static void tp_contact_list_name_updated_cb (GossipContact *contact,
149 EmpathyTpContactList *list);
150 static void tp_contact_list_update_groups_foreach (gchar *object_path,
151 GossipTelepathyGroup *group,
152 TpContactListData *data);
153 static GossipTelepathyGroup * tp_contact_list_get_group (EmpathyTpContactList *list,
155 static gboolean tp_contact_list_find_group (gchar *key,
156 GossipTelepathyGroup *group,
158 static void tp_contact_list_get_groups_foreach (gchar *key,
159 GossipTelepathyGroup *group,
161 static void tp_contact_list_group_channel_closed_cb (TpChan *channel,
162 EmpathyTpContactList *list);
163 static void tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group,
167 const gchar *message,
168 EmpathyTpContactList *list);
169 static void tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
173 const gchar *message,
174 EmpathyTpContactList *list);
175 static void tp_contact_list_get_contacts_foreach (guint handle,
176 GossipContact *contact,
178 static void tp_contact_list_get_info (EmpathyTpContactList *list,
180 static void tp_contact_list_request_avatar (EmpathyTpContactList *list,
182 static void tp_contact_list_start_avatar_requests (EmpathyTpContactList *list);
183 static void tp_contact_list_avatar_update_cb (DBusGProxy *proxy,
186 EmpathyTpContactList *list);
187 static void tp_contact_list_request_avatar_cb (DBusGProxy *proxy,
191 TpContactListAvatarRequestData *data);
192 static void tp_contact_list_aliases_update_cb (DBusGProxy *proxy,
194 EmpathyTpContactList *list);
195 static void tp_contact_list_request_aliases_cb (DBusGProxy *proxy,
196 gchar **contact_names,
198 TpContactListAliasesRequestData *data);
199 static void tp_contact_list_presence_update_cb (DBusGProxy *proxy,
200 GHashTable *handle_table,
201 EmpathyTpContactList *list);
202 static void tp_contact_list_parse_presence_foreach (guint handle,
203 GValueArray *presence_struct,
204 EmpathyTpContactList *list);
205 static void tp_contact_list_presences_table_foreach (const gchar *state_str,
206 GHashTable *presences_table,
207 GossipPresence **presence);
208 static void tp_contact_list_status_changed_cb (MissionControl *mc,
209 TelepathyConnectionStatus status,
211 TelepathyConnectionStatusReason reason,
212 const gchar *unique_name,
213 EmpathyTpContactList *list);
220 static guint signals[LAST_SIGNAL];
221 static guint n_avatar_requests = 0;
223 G_DEFINE_TYPE_WITH_CODE (EmpathyTpContactList, empathy_tp_contact_list, G_TYPE_OBJECT,
224 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
225 tp_contact_list_iface_init));
228 empathy_tp_contact_list_class_init (EmpathyTpContactListClass *klass)
230 GObjectClass *object_class = G_OBJECT_CLASS (klass);
232 object_class->finalize = tp_contact_list_finalize;
235 g_signal_new ("destroy",
236 G_TYPE_FROM_CLASS (klass),
240 g_cclosure_marshal_VOID__VOID,
244 g_type_class_add_private (object_class, sizeof (EmpathyTpContactListPriv));
248 tp_contact_list_iface_init (EmpathyContactListIface *iface)
250 iface->setup = tp_contact_list_setup;
251 iface->find = tp_contact_list_find;
252 iface->add = tp_contact_list_add;
253 iface->remove = tp_contact_list_remove;
254 iface->get_contacts = tp_contact_list_get_contacts;
258 empathy_tp_contact_list_init (EmpathyTpContactList *list)
260 EmpathyTpContactListPriv *priv;
262 priv = GET_PRIV (list);
264 priv->groups = g_hash_table_new_full (g_str_hash,
266 (GDestroyNotify) g_free,
267 (GDestroyNotify) g_object_unref);
268 priv->contacts = g_hash_table_new_full (g_direct_hash,
271 (GDestroyNotify) g_object_unref);
275 tp_contact_list_finalize (GObject *object)
277 EmpathyTpContactListPriv *priv;
278 EmpathyTpContactList *list;
280 list = EMPATHY_TP_CONTACT_LIST (object);
281 priv = GET_PRIV (list);
283 gossip_debug (DEBUG_DOMAIN, "finalize: %p", object);
285 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
286 "AccountStatusChanged",
287 G_CALLBACK (tp_contact_list_status_changed_cb),
290 tp_contact_list_finalize_proxies (list);
293 g_object_unref (priv->tp_conn);
297 g_object_unref (priv->known);
300 if (priv->subscribe) {
301 g_object_unref (priv->subscribe);
305 g_object_unref (priv->publish);
308 g_object_unref (priv->account);
309 g_object_unref (priv->user_contact);
310 g_object_unref (priv->mc);
311 g_hash_table_destroy (priv->groups);
312 g_hash_table_destroy (priv->contacts);
314 G_OBJECT_CLASS (empathy_tp_contact_list_parent_class)->finalize (object);
317 EmpathyTpContactList *
318 empathy_tp_contact_list_new (McAccount *account)
320 EmpathyTpContactListPriv *priv;
321 EmpathyTpContactList *list;
324 GError *error = NULL;
326 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
328 mc = gossip_mission_control_new ();
330 if (mission_control_get_connection_status (mc, account, NULL) != 0) {
331 /* The account is not connected, nothing to do. */
335 list = g_object_new (EMPATHY_TYPE_TP_CONTACT_LIST, NULL);
336 priv = GET_PRIV (list);
338 priv->tp_conn = mission_control_get_connection (mc, account, NULL);
339 priv->account = g_object_ref (account);
342 g_signal_connect (priv->tp_conn, "destroy",
343 G_CALLBACK (tp_contact_list_destroy_cb),
345 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
346 "AccountStatusChanged",
347 G_CALLBACK (tp_contact_list_status_changed_cb),
350 priv->aliasing_iface = tp_conn_get_interface (priv->tp_conn,
351 TELEPATHY_CONN_IFACE_ALIASING_QUARK);
352 priv->avatars_iface = tp_conn_get_interface (priv->tp_conn,
353 TELEPATHY_CONN_IFACE_AVATARS_QUARK);
354 priv->presence_iface = tp_conn_get_interface (priv->tp_conn,
355 TELEPATHY_CONN_IFACE_PRESENCE_QUARK);
357 if (priv->aliasing_iface) {
358 dbus_g_proxy_connect_signal (priv->aliasing_iface,
360 G_CALLBACK (tp_contact_list_aliases_update_cb),
364 if (priv->avatars_iface) {
365 dbus_g_proxy_connect_signal (priv->avatars_iface,
367 G_CALLBACK (tp_contact_list_avatar_update_cb),
371 if (priv->presence_iface) {
372 dbus_g_proxy_connect_signal (priv->presence_iface,
374 G_CALLBACK (tp_contact_list_presence_update_cb),
378 /* Get our own handle and contact */
379 if (!tp_conn_get_self_handle (DBUS_G_PROXY (priv->tp_conn),
381 gossip_debug (DEBUG_DOMAIN, "GetSelfHandle Error: %s",
382 error ? error->message : "No error given");
383 g_clear_error (&error);
385 priv->user_contact = empathy_tp_contact_list_get_from_handle (list, handle);
392 tp_contact_list_setup (EmpathyContactList *list)
394 EmpathyTpContactListPriv *priv;
396 GError *error = NULL;
399 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
401 priv = GET_PRIV (list);
403 gossip_debug (DEBUG_DOMAIN, "setup contact list: %p", list);
405 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
406 G_CALLBACK (tp_contact_list_newchannel_cb),
409 /* Get existing channels */
410 if (!tp_conn_list_channels (DBUS_G_PROXY (priv->tp_conn),
413 gossip_debug (DEBUG_DOMAIN,
414 "Failed to get list of open channels: %s",
415 error ? error->message : "No error given");
416 g_clear_error (&error);
420 for (i = 0; channels->len > i; i++) {
421 GValueArray *chan_struct;
422 const gchar *object_path;
423 const gchar *chan_iface;
424 TelepathyHandleType handle_type;
427 chan_struct = g_ptr_array_index (channels, i);
428 object_path = g_value_get_boxed (g_value_array_get_nth (chan_struct, 0));
429 chan_iface = g_value_get_string (g_value_array_get_nth (chan_struct, 1));
430 handle_type = g_value_get_uint (g_value_array_get_nth (chan_struct, 2));
431 handle = g_value_get_uint (g_value_array_get_nth (chan_struct, 3));
433 tp_contact_list_newchannel_cb (DBUS_G_PROXY (priv->tp_conn),
434 object_path, chan_iface,
437 EMPATHY_TP_CONTACT_LIST (list));
439 g_value_array_free (chan_struct);
442 g_ptr_array_free (channels, TRUE);
445 static GossipContact *
446 tp_contact_list_find (EmpathyContactList *list,
449 EmpathyTpContactListPriv *priv;
450 GossipContact *contact;
452 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
454 priv = GET_PRIV (list);
456 contact = g_hash_table_find (priv->contacts,
457 (GHRFunc) tp_contact_list_find_foreach,
464 tp_contact_list_add (EmpathyContactList *list,
465 GossipContact *contact,
466 const gchar *message)
468 EmpathyTpContactListPriv *priv;
471 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
473 priv = GET_PRIV (list);
475 handle = gossip_contact_get_handle (contact);
476 gossip_telepathy_group_add_member (priv->subscribe, handle, message);
480 tp_contact_list_remove (EmpathyContactList *list,
481 GossipContact *contact,
482 const gchar *message)
484 EmpathyTpContactListPriv *priv;
487 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
489 priv = GET_PRIV (list);
491 handle = gossip_contact_get_handle (contact);
492 gossip_telepathy_group_remove_member (priv->subscribe, handle, message);
493 gossip_telepathy_group_remove_member (priv->publish, handle, message);
494 gossip_telepathy_group_remove_member (priv->known, handle, message);
498 tp_contact_list_get_contacts (EmpathyContactList *list)
500 EmpathyTpContactListPriv *priv;
501 GList *contacts = NULL;
503 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
505 priv = GET_PRIV (list);
507 /* FIXME: we should only return contacts that are in the contact list */
508 g_hash_table_foreach (priv->contacts,
509 (GHFunc) tp_contact_list_get_contacts_foreach,
516 empathy_tp_contact_list_get_account (EmpathyTpContactList *list)
518 EmpathyTpContactListPriv *priv;
520 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
522 priv = GET_PRIV (list);
524 return priv->account;
528 empathy_tp_contact_list_get_user (EmpathyTpContactList *list)
530 EmpathyTpContactListPriv *priv;
532 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
534 priv = GET_PRIV (list);
536 return priv->user_contact;
540 empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list,
543 EmpathyTpContactListPriv *priv;
544 GossipContact *contact;
545 const gchar *contact_ids[] = {id, NULL};
548 GError *error = NULL;
550 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
551 g_return_val_if_fail (id != NULL, NULL);
553 priv = GET_PRIV (list);
555 contact = tp_contact_list_find (EMPATHY_CONTACT_LIST (list), id);
560 /* The id is unknown, requests a new handle */
561 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
562 TP_HANDLE_TYPE_CONTACT,
565 gossip_debug (DEBUG_DOMAIN,
566 "RequestHandle for %s failed: %s", id,
567 error ? error->message : "No error given");
568 g_clear_error (&error);
572 handle = g_array_index(handles, guint, 0);
573 g_array_free (handles, TRUE);
575 return empathy_tp_contact_list_get_from_handle (list, handle);
579 empathy_tp_contact_list_get_from_handle (EmpathyTpContactList *list,
582 GossipContact *contact;
586 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
588 handles = g_array_new (FALSE, FALSE, sizeof (guint));
589 g_array_append_val (handles, handle);
591 contacts = empathy_tp_contact_list_get_from_handles (list, handles);
592 g_array_free (handles, TRUE);
598 contact = contacts->data;
599 g_list_free (contacts);
605 empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list,
608 EmpathyTpContactListPriv *priv;
609 gchar **handles_names;
612 GList *contacts = NULL;
614 GError *error = NULL;
616 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
617 g_return_val_if_fail (handles != NULL, NULL);
619 priv = GET_PRIV (list);
621 /* Search all handles we already have */
622 new_handles = g_array_new (FALSE, FALSE, sizeof (guint));
623 for (i = 0; i < handles->len; i++) {
624 GossipContact *contact;
627 handle = g_array_index (handles, guint, i);
628 contact = g_hash_table_lookup (priv->contacts,
629 GUINT_TO_POINTER (handle));
632 contacts = g_list_prepend (contacts,
633 g_object_ref (contact));
635 g_array_append_val (new_handles, handle);
639 if (new_handles->len == 0) {
643 /* Holds all handles we don't have yet.
644 * FIXME: We should release them at some point. */
645 if (!tp_conn_hold_handles (DBUS_G_PROXY (priv->tp_conn),
646 TP_HANDLE_TYPE_CONTACT,
647 new_handles, &error)) {
648 gossip_debug (DEBUG_DOMAIN,
649 "HoldHandles Error: %s",
650 error ? error->message : "No error given");
651 g_clear_error (&error);
652 g_array_free (new_handles, TRUE);
656 /* Get the IDs of all new handles */
657 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
658 TP_HANDLE_TYPE_CONTACT,
662 gossip_debug (DEBUG_DOMAIN,
663 "InspectHandle Error: %s",
664 error ? error->message : "No error given");
665 g_clear_error (&error);
666 g_array_free (new_handles, TRUE);
670 /* Create contact objects */
671 for (i = 0, id = handles_names; *id && i < new_handles->len; id++, i++) {
672 GossipContact *contact;
675 handle = g_array_index (new_handles, guint, i);
676 contact = g_object_new (GOSSIP_TYPE_CONTACT,
677 "account", priv->account,
682 g_signal_connect (contact, "notify::groups",
683 G_CALLBACK (tp_contact_list_groups_updated_cb),
685 g_signal_connect (contact, "notify::subscription",
686 G_CALLBACK (tp_contact_list_subscription_updated_cb),
688 g_signal_connect (contact, "notify::name",
689 G_CALLBACK (tp_contact_list_name_updated_cb),
692 gossip_debug (DEBUG_DOMAIN, "new contact created: %s (%d)",
695 g_hash_table_insert (priv->contacts,
696 GUINT_TO_POINTER (handle),
699 contacts = g_list_prepend (contacts, g_object_ref (contact));
702 tp_contact_list_get_info (list, new_handles);
704 g_array_free (new_handles, TRUE);
705 g_strfreev (handles_names);
711 empathy_tp_contact_list_rename_group (EmpathyTpContactList *list,
712 const gchar *old_group,
713 const gchar *new_group)
715 EmpathyTpContactListPriv *priv;
716 GossipTelepathyGroup *group;
719 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
720 g_return_if_fail (old_group != NULL);
721 g_return_if_fail (new_group != NULL);
723 priv = GET_PRIV (list);
725 group = g_hash_table_find (priv->groups,
726 (GHRFunc) tp_contact_list_find_group,
729 /* The group doesn't exists on this account */
733 gossip_debug (DEBUG_DOMAIN, "rename group %s to %s", group, new_group);
735 /* Remove all members from the old group */
736 members = gossip_telepathy_group_get_members (group);
737 gossip_telepathy_group_remove_members (group, members, "");
738 tp_contact_list_group_members_removed_cb (group, members,
740 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
742 g_hash_table_remove (priv->groups,
743 gossip_telepathy_group_get_object_path (group));
745 /* Add all members to the new group */
746 group = tp_contact_list_get_group (list, new_group);
748 gossip_telepathy_group_add_members (group, members, "");
753 empathy_tp_contact_list_get_groups (EmpathyTpContactList *list)
755 EmpathyTpContactListPriv *priv;
756 GList *groups = NULL;
758 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
760 priv = GET_PRIV (list);
762 g_hash_table_foreach (priv->groups,
763 (GHFunc) tp_contact_list_get_groups_foreach,
766 groups = g_list_sort (groups, (GCompareFunc) strcmp);
772 tp_contact_list_finalize_proxies (EmpathyTpContactList *list)
774 EmpathyTpContactListPriv *priv;
776 priv = GET_PRIV (list);
779 g_signal_handlers_disconnect_by_func (priv->tp_conn,
780 tp_contact_list_destroy_cb,
782 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
783 G_CALLBACK (tp_contact_list_newchannel_cb),
787 if (priv->aliasing_iface) {
788 dbus_g_proxy_disconnect_signal (priv->aliasing_iface,
790 G_CALLBACK (tp_contact_list_aliases_update_cb),
794 if (priv->avatars_iface) {
795 dbus_g_proxy_disconnect_signal (priv->avatars_iface,
797 G_CALLBACK (tp_contact_list_avatar_update_cb),
801 if (priv->presence_iface) {
802 dbus_g_proxy_disconnect_signal (priv->presence_iface,
804 G_CALLBACK (tp_contact_list_presence_update_cb),
810 tp_contact_list_destroy_cb (DBusGProxy *proxy,
811 EmpathyTpContactList *list)
813 EmpathyTpContactListPriv *priv;
815 priv = GET_PRIV (list);
817 gossip_debug (DEBUG_DOMAIN, "Connection destroyed... "
818 "Account disconnected or CM crashed");
820 /* DBus proxies should NOT be used anymore */
821 g_object_unref (priv->tp_conn);
822 priv->tp_conn = NULL;
823 priv->aliasing_iface = NULL;
824 priv->avatars_iface = NULL;
825 priv->presence_iface = NULL;
827 /* Remove all contacts */
828 g_hash_table_foreach (priv->contacts,
829 (GHFunc) tp_contact_list_contact_removed_foreach,
831 g_hash_table_remove_all (priv->contacts);
833 /* Tell the world to not use us anymore */
834 g_signal_emit (list, signals[DESTROY], 0);
838 tp_contact_list_contact_removed_foreach (guint handle,
839 GossipContact *contact,
840 EmpathyTpContactList *list)
842 g_signal_handlers_disconnect_by_func (contact,
843 tp_contact_list_groups_updated_cb,
845 g_signal_handlers_disconnect_by_func (contact,
846 tp_contact_list_subscription_updated_cb,
848 g_signal_handlers_disconnect_by_func (contact,
849 tp_contact_list_name_updated_cb,
852 g_signal_emit_by_name (list, "contact-removed", contact);
856 tp_contact_list_block_contact (EmpathyTpContactList *list,
857 GossipContact *contact)
859 g_signal_handlers_block_by_func (contact,
860 tp_contact_list_groups_updated_cb,
862 g_signal_handlers_block_by_func (contact,
863 tp_contact_list_subscription_updated_cb,
865 g_signal_handlers_block_by_func (contact,
866 tp_contact_list_name_updated_cb,
871 tp_contact_list_unblock_contact (EmpathyTpContactList *list,
872 GossipContact *contact)
874 g_signal_handlers_unblock_by_func (contact,
875 tp_contact_list_groups_updated_cb,
877 g_signal_handlers_unblock_by_func (contact,
878 tp_contact_list_subscription_updated_cb,
880 g_signal_handlers_unblock_by_func (contact,
881 tp_contact_list_name_updated_cb,
886 tp_contact_list_find_foreach (guint handle,
887 GossipContact *contact,
890 if (strcmp (gossip_contact_get_id (contact), id) == 0) {
898 tp_contact_list_newchannel_cb (DBusGProxy *proxy,
899 const gchar *object_path,
900 const gchar *channel_type,
901 TelepathyHandleType handle_type,
902 guint channel_handle,
903 gboolean suppress_handle,
904 EmpathyTpContactList *list)
906 EmpathyTpContactListPriv *priv;
907 GossipTelepathyGroup *group;
909 const gchar *bus_name;
912 priv = GET_PRIV (list);
914 if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0 ||
919 bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn));
920 new_chan = tp_chan_new (tp_get_bus (),
923 channel_type, handle_type, channel_handle);
925 if (handle_type == TP_HANDLE_TYPE_LIST) {
926 TpContactListType list_type;
928 list_type = tp_contact_list_get_type (list, new_chan);
929 if (list_type == TP_CONTACT_LIST_TYPE_UNKNOWN) {
930 gossip_debug (DEBUG_DOMAIN, "Unknown contact list channel");
931 g_object_unref (new_chan);
935 gossip_debug (DEBUG_DOMAIN, "New contact list channel of type: %d",
938 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
941 case TP_CONTACT_LIST_TYPE_KNOWN:
943 g_object_unref (priv->known);
947 case TP_CONTACT_LIST_TYPE_PUBLISH:
949 g_object_unref (priv->publish);
951 priv->publish = group;
953 case TP_CONTACT_LIST_TYPE_SUBSCRIBE:
954 if (priv->subscribe) {
955 g_object_unref (priv->subscribe);
957 priv->subscribe = group;
960 g_assert_not_reached ();
963 /* Connect and setup the new contact-list group */
964 if (list_type == TP_CONTACT_LIST_TYPE_KNOWN ||
965 list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
966 g_signal_connect (group, "members-added",
967 G_CALLBACK (tp_contact_list_contact_added_cb),
969 g_signal_connect (group, "members-removed",
970 G_CALLBACK (tp_contact_list_contact_removed_cb),
973 members = gossip_telepathy_group_get_members (group);
974 tp_contact_list_contact_added_cb (group, members, 0,
975 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
977 g_array_free (members, TRUE);
979 if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
984 g_signal_connect (group, "local-pending",
985 G_CALLBACK (tp_contact_list_local_pending_cb),
988 info = gossip_telepathy_group_get_local_pending_members_with_info (group);
991 /* This happens with butterfly because
992 * GetLocalPendingMembersWithInfo is not
994 g_object_unref (new_chan);
998 pending = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
999 for (i = 0; info->len > i; i++) {
1000 GValueArray *pending_struct;
1004 const gchar *message;
1006 pending_struct = g_ptr_array_index (info, i);
1007 member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
1008 invitor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
1009 reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
1010 message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
1012 g_array_insert_val (pending, 0, member);
1014 tp_contact_list_local_pending_cb (group, pending,
1019 g_value_array_free (pending_struct);
1022 g_ptr_array_free (info, TRUE);
1023 g_array_free (pending, TRUE);
1026 else if (handle_type == TP_HANDLE_TYPE_GROUP) {
1027 const gchar *object_path;
1029 object_path = dbus_g_proxy_get_path (DBUS_G_PROXY (new_chan));
1030 if (g_hash_table_lookup (priv->groups, object_path)) {
1031 g_object_unref (new_chan);
1035 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
1037 gossip_debug (DEBUG_DOMAIN, "New server-side group channel: %s",
1038 gossip_telepathy_group_get_name (group));
1040 dbus_g_proxy_connect_signal (DBUS_G_PROXY (new_chan), "Closed",
1042 (tp_contact_list_group_channel_closed_cb),
1045 g_hash_table_insert (priv->groups, g_strdup (object_path), group);
1046 g_signal_connect (group, "members-added",
1047 G_CALLBACK (tp_contact_list_group_members_added_cb),
1049 g_signal_connect (group, "members-removed",
1050 G_CALLBACK (tp_contact_list_group_members_removed_cb),
1053 members = gossip_telepathy_group_get_members (group);
1054 tp_contact_list_group_members_added_cb (group, members, 0,
1055 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
1057 g_array_free (members, TRUE);
1060 g_object_unref (new_chan);
1063 static TpContactListType
1064 tp_contact_list_get_type (EmpathyTpContactList *list,
1067 EmpathyTpContactListPriv *priv;
1069 gchar **handle_name;
1070 TpContactListType list_type;
1071 GError *error = NULL;
1073 priv = GET_PRIV (list);
1075 handles = g_array_new (FALSE, FALSE, sizeof (guint));
1076 g_array_append_val (handles, list_chan->handle);
1078 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
1079 TP_HANDLE_TYPE_LIST,
1083 gossip_debug (DEBUG_DOMAIN,
1084 "InspectHandle Error: %s",
1085 error ? error->message : "No error given");
1086 g_clear_error (&error);
1087 g_array_free (handles, TRUE);
1088 return TP_CONTACT_LIST_TYPE_UNKNOWN;
1091 if (strcmp (*handle_name, "subscribe") == 0) {
1092 list_type = TP_CONTACT_LIST_TYPE_SUBSCRIBE;
1093 } else if (strcmp (*handle_name, "publish") == 0) {
1094 list_type = TP_CONTACT_LIST_TYPE_PUBLISH;
1095 } else if (strcmp (*handle_name, "known") == 0) {
1096 list_type = TP_CONTACT_LIST_TYPE_KNOWN;
1098 list_type = TP_CONTACT_LIST_TYPE_UNKNOWN;
1101 g_strfreev (handle_name);
1102 g_array_free (handles, TRUE);
1108 tp_contact_list_contact_added_cb (GossipTelepathyGroup *group,
1112 const gchar *message,
1113 EmpathyTpContactList *list)
1115 EmpathyTpContactListPriv *priv;
1116 GList *added_list, *l;
1118 priv = GET_PRIV (list);
1120 added_list = empathy_tp_contact_list_get_from_handles (list, handles);
1122 for (l = added_list; l; l = l->next) {
1123 GossipContact *contact;
1125 contact = GOSSIP_CONTACT (l->data);
1126 tp_contact_list_block_contact (list, contact);
1127 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_BOTH);
1128 tp_contact_list_unblock_contact (list, contact);
1130 g_signal_emit_by_name (list, "contact-added", contact);
1132 g_object_unref (contact);
1135 g_list_free (added_list);
1139 tp_contact_list_contact_removed_cb (GossipTelepathyGroup *group,
1143 const gchar *message,
1144 EmpathyTpContactList *list)
1146 EmpathyTpContactListPriv *priv;
1147 GList *removed_list, *l;
1149 priv = GET_PRIV (list);
1151 removed_list = empathy_tp_contact_list_get_from_handles (list, handles);
1153 for (l = removed_list; l; l = l->next) {
1154 GossipContact *contact;
1157 contact = GOSSIP_CONTACT (l->data);
1159 handle = gossip_contact_get_handle (contact);
1160 g_hash_table_remove (priv->contacts, GUINT_TO_POINTER (handle));
1162 g_signal_emit_by_name (list, "contact-removed", contact);
1164 g_object_unref (contact);
1167 g_list_free (removed_list);
1171 tp_contact_list_local_pending_cb (GossipTelepathyGroup *group,
1175 const gchar *message,
1176 EmpathyTpContactList *list)
1178 EmpathyTpContactListPriv *priv;
1179 GList *pending_list, *l;
1181 priv = GET_PRIV (list);
1183 pending_list = empathy_tp_contact_list_get_from_handles (list, handles);
1185 for (l = pending_list; l; l = l->next) {
1186 GossipContact *contact;
1188 contact = GOSSIP_CONTACT (l->data);
1190 /* FIXME: Is that the correct way ? */
1191 tp_contact_list_block_contact (list, contact);
1192 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_FROM);
1193 tp_contact_list_unblock_contact (list, contact);
1194 g_signal_emit_by_name (list, "contact-added", contact);
1196 g_object_unref (contact);
1199 g_list_free (pending_list);
1203 tp_contact_list_groups_updated_cb (GossipContact *contact,
1205 EmpathyTpContactList *list)
1207 EmpathyTpContactListPriv *priv;
1208 TpContactListData data;
1211 priv = GET_PRIV (list);
1213 /* Make sure all groups are created */
1214 groups = gossip_contact_get_groups (contact);
1215 for (l = groups; l; l = l->next) {
1216 tp_contact_list_get_group (list, l->data);
1219 data.handle = gossip_contact_get_handle (contact);
1220 data.new_groups = groups;
1222 g_hash_table_foreach (priv->groups,
1223 (GHFunc) tp_contact_list_update_groups_foreach,
1228 tp_contact_list_subscription_updated_cb (GossipContact *contact,
1230 EmpathyTpContactList *list)
1232 EmpathyTpContactListPriv *priv;
1233 GossipSubscription subscription;
1236 priv = GET_PRIV (list);
1238 subscription = gossip_contact_get_subscription (contact);
1239 handle = gossip_contact_get_handle (contact);
1241 /* FIXME: what to do here, I'm a bit lost... */
1243 gossip_telepathy_group_add_member (priv->publish, handle, "");
1245 gossip_telepathy_group_remove_member (priv->publish, handle, "");
1250 tp_contact_list_name_updated_cb (GossipContact *contact,
1252 EmpathyTpContactList *list)
1254 EmpathyTpContactListPriv *priv;
1255 GHashTable *new_alias;
1256 const gchar *new_name;
1258 GError *error = NULL;
1260 priv = GET_PRIV (list);
1262 handle = gossip_contact_get_handle (contact);
1263 new_name = gossip_contact_get_name (contact);
1265 gossip_debug (DEBUG_DOMAIN, "renaming handle %d to %s",
1268 new_alias = g_hash_table_new_full (g_direct_hash,
1273 g_hash_table_insert (new_alias,
1274 GUINT_TO_POINTER (handle),
1275 g_strdup (new_name));
1277 if (!tp_conn_iface_aliasing_set_aliases (priv->aliasing_iface,
1280 gossip_debug (DEBUG_DOMAIN,
1281 "Couldn't rename contact: %s",
1282 error ? error->message : "No error given");
1283 g_clear_error (&error);
1286 g_hash_table_destroy (new_alias);
1290 tp_contact_list_update_groups_foreach (gchar *object_path,
1291 GossipTelepathyGroup *group,
1292 TpContactListData *data)
1295 gboolean found = FALSE;
1296 const gchar *group_name;
1299 is_member = gossip_telepathy_group_is_member (group, data->handle);
1300 group_name = gossip_telepathy_group_get_name (group);
1302 for (l = data->new_groups; l; l = l->next) {
1303 if (strcmp (group_name, l->data) == 0) {
1309 if (is_member && !found) {
1310 /* We are no longer member of this group */
1311 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1312 data->handle, group_name);
1313 gossip_telepathy_group_remove_member (group, data->handle, "");
1316 if (!is_member && found) {
1317 /* We are now member of this group */
1318 gossip_debug (DEBUG_DOMAIN, "Contact %d added to group '%s'",
1319 data->handle, group_name);
1320 gossip_telepathy_group_add_member (group, data->handle, "");
1324 static GossipTelepathyGroup *
1325 tp_contact_list_get_group (EmpathyTpContactList *list,
1328 EmpathyTpContactListPriv *priv;
1329 GossipTelepathyGroup *group;
1330 TpChan *group_channel;
1333 char *group_object_path;
1334 const char *names[2] = {name, NULL};
1335 GError *error = NULL;
1337 priv = GET_PRIV (list);
1339 group = g_hash_table_find (priv->groups,
1340 (GHRFunc) tp_contact_list_find_group,
1346 gossip_debug (DEBUG_DOMAIN, "creating new group: %s", name);
1348 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
1349 TP_HANDLE_TYPE_GROUP,
1353 gossip_debug (DEBUG_DOMAIN,
1354 "Couldn't request the creation of a new handle for group: %s",
1355 error ? error->message : "No error given");
1356 g_clear_error (&error);
1359 group_handle = g_array_index (handles, guint, 0);
1360 g_array_free (handles, TRUE);
1362 if (!tp_conn_request_channel (DBUS_G_PROXY (priv->tp_conn),
1363 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1364 TP_HANDLE_TYPE_GROUP,
1369 gossip_debug (DEBUG_DOMAIN,
1370 "Couldn't request the creation of a new group channel: %s",
1371 error ? error->message : "No error given");
1372 g_clear_error (&error);
1376 group_channel = tp_chan_new (tp_get_bus (),
1377 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn)),
1379 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1380 TP_HANDLE_TYPE_GROUP,
1383 dbus_g_proxy_connect_signal (DBUS_G_PROXY (group_channel),
1386 (tp_contact_list_group_channel_closed_cb),
1390 group = gossip_telepathy_group_new (group_channel, priv->tp_conn);
1391 g_hash_table_insert (priv->groups, group_object_path, group);
1392 g_signal_connect (group, "members-added",
1393 G_CALLBACK (tp_contact_list_group_members_added_cb),
1395 g_signal_connect (group, "members-removed",
1396 G_CALLBACK (tp_contact_list_group_members_removed_cb),
1403 tp_contact_list_find_group (gchar *key,
1404 GossipTelepathyGroup *group,
1407 if (strcmp (group_name, gossip_telepathy_group_get_name (group)) == 0) {
1415 tp_contact_list_get_groups_foreach (gchar *key,
1416 GossipTelepathyGroup *group,
1421 name = gossip_telepathy_group_get_name (group);
1422 *groups = g_list_append (*groups, g_strdup (name));
1426 tp_contact_list_group_channel_closed_cb (TpChan *channel,
1427 EmpathyTpContactList *list)
1429 EmpathyTpContactListPriv *priv;
1431 priv = GET_PRIV (list);
1433 g_hash_table_remove (priv->groups,
1434 dbus_g_proxy_get_path (DBUS_G_PROXY (channel)));
1438 tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group,
1442 const gchar *message,
1443 EmpathyTpContactList *list)
1445 EmpathyTpContactListPriv *priv;
1446 GList *added_list, *l;
1447 const gchar *group_name;
1449 priv = GET_PRIV (list);
1451 group_name = gossip_telepathy_group_get_name (group);
1452 added_list = empathy_tp_contact_list_get_from_handles (list, members);
1454 for (l = added_list; l; l = l->next) {
1455 GossipContact *contact;
1456 GList *contact_groups;
1458 contact = GOSSIP_CONTACT (l->data);
1459 contact_groups = gossip_contact_get_groups (contact);
1461 if (!g_list_find_custom (contact_groups,
1463 (GCompareFunc) strcmp)) {
1464 gossip_debug (DEBUG_DOMAIN, "Contact %s added to group '%s'",
1465 gossip_contact_get_name (contact),
1467 contact_groups = g_list_append (contact_groups,
1468 g_strdup (group_name));
1469 tp_contact_list_block_contact (list, contact);
1470 gossip_contact_set_groups (contact, contact_groups);
1471 tp_contact_list_unblock_contact (list, contact);
1474 g_object_unref (contact);
1477 g_list_free (added_list);
1481 tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
1485 const gchar *message,
1486 EmpathyTpContactList *list)
1488 EmpathyTpContactListPriv *priv;
1489 GList *removed_list, *l;
1490 const gchar *group_name;
1492 priv = GET_PRIV (list);
1494 group_name = gossip_telepathy_group_get_name (group);
1495 removed_list = empathy_tp_contact_list_get_from_handles (list, members);
1497 for (l = removed_list; l; l = l->next) {
1498 GossipContact *contact;
1499 GList *contact_groups;
1502 /* FIXME: Does it leak ? */
1503 contact = GOSSIP_CONTACT (l->data);
1504 contact_groups = gossip_contact_get_groups (contact);
1505 contact_groups = g_list_copy (contact_groups);
1507 to_remove = g_list_find_custom (contact_groups,
1509 (GCompareFunc) strcmp);
1511 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1512 gossip_contact_get_handle (contact),
1514 contact_groups = g_list_remove_link (contact_groups,
1516 tp_contact_list_block_contact (list, contact);
1517 gossip_contact_set_groups (contact, contact_groups);
1518 tp_contact_list_unblock_contact (list, contact);
1521 g_list_free (contact_groups);
1523 g_object_unref (contact);
1526 g_list_free (removed_list);
1530 tp_contact_list_get_contacts_foreach (guint handle,
1531 GossipContact *contact,
1534 *contacts = g_list_append (*contacts, g_object_ref (contact));
1538 tp_contact_list_get_info (EmpathyTpContactList *list,
1541 EmpathyTpContactListPriv *priv;
1542 GError *error = NULL;
1544 priv = GET_PRIV (list);
1546 if (priv->presence_iface) {
1547 /* FIXME: We should use GetPresence instead */
1548 if (!tp_conn_iface_presence_request_presence (priv->presence_iface,
1550 gossip_debug (DEBUG_DOMAIN,
1551 "Could not request presences: %s",
1552 error ? error->message : "No error given");
1553 g_clear_error (&error);
1557 if (priv->aliasing_iface) {
1558 TpContactListAliasesRequestData *data;
1560 data = g_slice_new (TpContactListAliasesRequestData);
1562 data->handles = g_memdup (handles->data, handles->len * sizeof (guint));
1564 tp_conn_iface_aliasing_request_aliases_async (priv->aliasing_iface,
1566 (tp_conn_iface_aliasing_request_aliases_reply)
1567 tp_contact_list_request_aliases_cb,
1571 if (priv->avatars_iface) {
1574 for (i = 0; i < handles->len; i++) {
1577 handle = g_array_index (handles, gint, i);
1578 tp_contact_list_request_avatar (list, handle);
1584 tp_contact_list_request_avatar (EmpathyTpContactList *list,
1587 EmpathyTpContactListPriv *priv;
1589 priv = GET_PRIV (list);
1591 /* We queue avatar requests to not send too many dbus async
1592 * calls at once. If we don't we reach the dbus's limit of
1594 priv->avatar_requests_queue = g_list_append (priv->avatar_requests_queue,
1595 GUINT_TO_POINTER (handle));
1596 tp_contact_list_start_avatar_requests (list);
1600 tp_contact_list_start_avatar_requests (EmpathyTpContactList *list)
1602 EmpathyTpContactListPriv *priv;
1603 TpContactListAvatarRequestData *data;
1605 priv = GET_PRIV (list);
1607 while (n_avatar_requests < MAX_AVATAR_REQUESTS &&
1608 priv->avatar_requests_queue) {
1609 data = g_slice_new (TpContactListAvatarRequestData);
1611 data->handle = GPOINTER_TO_UINT (priv->avatar_requests_queue->data);
1613 n_avatar_requests++;
1614 priv->avatar_requests_queue = g_list_remove (priv->avatar_requests_queue,
1615 priv->avatar_requests_queue->data);
1617 tp_conn_iface_avatars_request_avatar_async (priv->avatars_iface,
1619 (tp_conn_iface_avatars_request_avatar_reply)
1620 tp_contact_list_request_avatar_cb,
1626 tp_contact_list_avatar_update_cb (DBusGProxy *proxy,
1629 EmpathyTpContactList *list)
1631 gossip_debug (DEBUG_DOMAIN, "Changing avatar for %d to %s",
1634 tp_contact_list_request_avatar (list, handle);
1638 tp_contact_list_request_avatar_cb (DBusGProxy *proxy,
1639 GArray *avatar_data,
1642 TpContactListAvatarRequestData *data)
1644 GossipContact *contact;
1646 contact = empathy_tp_contact_list_get_from_handle (data->list, data->handle);
1649 gossip_debug (DEBUG_DOMAIN, "Error requesting avatar for %s: %s",
1650 gossip_contact_get_name (contact),
1651 error ? error->message : "No error given");
1653 GossipAvatar *avatar;
1655 avatar = gossip_avatar_new (avatar_data->data,
1658 tp_contact_list_block_contact (data->list, contact);
1659 gossip_contact_set_avatar (contact, avatar);
1660 tp_contact_list_unblock_contact (data->list, contact);
1661 gossip_avatar_unref (avatar);
1664 n_avatar_requests--;
1665 tp_contact_list_start_avatar_requests (data->list);
1667 g_slice_free (TpContactListAvatarRequestData, data);
1671 tp_contact_list_aliases_update_cb (DBusGProxy *proxy,
1672 GPtrArray *renamed_handlers,
1673 EmpathyTpContactList *list)
1677 for (i = 0; renamed_handlers->len > i; i++) {
1680 GValueArray *renamed_struct;
1681 GossipContact *contact;
1683 renamed_struct = g_ptr_array_index (renamed_handlers, i);
1684 handle = g_value_get_uint(g_value_array_get_nth (renamed_struct, 0));
1685 alias = g_value_get_string(g_value_array_get_nth (renamed_struct, 1));
1687 if (alias && *alias == '\0') {
1691 contact = empathy_tp_contact_list_get_from_handle (list, handle);
1692 tp_contact_list_block_contact (list, contact);
1693 gossip_contact_set_name (contact, alias);
1694 tp_contact_list_unblock_contact (list, contact);
1696 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (update cb)",
1702 tp_contact_list_request_aliases_cb (DBusGProxy *proxy,
1703 gchar **contact_names,
1705 TpContactListAliasesRequestData *data)
1710 for (name = contact_names; *name && !error; name++) {
1711 GossipContact *contact;
1713 contact = empathy_tp_contact_list_get_from_handle (data->list,
1715 tp_contact_list_block_contact (data->list, contact);
1716 gossip_contact_set_name (contact, *name);
1717 tp_contact_list_unblock_contact (data->list, contact);
1719 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (request cb)",
1720 data->handles[i], *name);
1725 g_free (data->handles);
1726 g_slice_free (TpContactListAliasesRequestData, data);
1730 tp_contact_list_presence_update_cb (DBusGProxy *proxy,
1731 GHashTable *handle_table,
1732 EmpathyTpContactList *list)
1734 g_hash_table_foreach (handle_table,
1735 (GHFunc) tp_contact_list_parse_presence_foreach,
1740 tp_contact_list_parse_presence_foreach (guint handle,
1741 GValueArray *presence_struct,
1742 EmpathyTpContactList *list)
1744 GHashTable *presences_table;
1745 GossipContact *contact;
1746 GossipPresence *presence = NULL;
1748 contact = empathy_tp_contact_list_get_from_handle (list, handle);
1749 presences_table = g_value_get_boxed (g_value_array_get_nth (presence_struct, 1));
1751 g_hash_table_foreach (presences_table,
1752 (GHFunc) tp_contact_list_presences_table_foreach,
1755 gossip_debug (DEBUG_DOMAIN, "Presence changed for %s (%d) to %s (%d)",
1756 gossip_contact_get_name (contact),
1758 presence ? gossip_presence_get_status (presence) : "unset",
1759 presence ? gossip_presence_get_state (presence) : MC_PRESENCE_UNSET);
1761 tp_contact_list_block_contact (list, contact);
1762 gossip_contact_set_presence (contact, presence);
1763 tp_contact_list_unblock_contact (list, contact);
1767 tp_contact_list_presences_table_foreach (const gchar *state_str,
1768 GHashTable *presences_table,
1769 GossipPresence **presence)
1772 const GValue *message;
1774 state = gossip_presence_state_from_str (state_str);
1775 if ((state == MC_PRESENCE_UNSET) || (state == MC_PRESENCE_OFFLINE)) {
1780 g_object_unref (*presence);
1784 *presence = gossip_presence_new ();
1785 gossip_presence_set_state (*presence, state);
1787 message = g_hash_table_lookup (presences_table, "message");
1788 if (message != NULL) {
1789 gossip_presence_set_status (*presence,
1790 g_value_get_string (message));
1795 tp_contact_list_status_changed_cb (MissionControl *mc,
1796 TelepathyConnectionStatus status,
1797 McPresence presence,
1798 TelepathyConnectionStatusReason reason,
1799 const gchar *unique_name,
1800 EmpathyTpContactList *list)
1802 EmpathyTpContactListPriv *priv;
1805 priv = GET_PRIV (list);
1807 account = mc_account_lookup (unique_name);
1808 if (status != TP_CONN_STATUS_DISCONNECTED ||
1809 !gossip_account_equal (account, priv->account)) {
1810 g_object_unref (account);
1814 /* We are disconnected, do just like if the connection was destroyed */
1815 g_signal_handlers_disconnect_by_func (priv->tp_conn,
1816 tp_contact_list_destroy_cb,
1818 tp_contact_list_destroy_cb (DBUS_G_PROXY (priv->tp_conn), list);
1820 g_object_unref (account);