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;
451 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
453 priv = GET_PRIV (list);
455 return g_hash_table_find (priv->contacts,
456 (GHRFunc) tp_contact_list_find_foreach,
461 tp_contact_list_add (EmpathyContactList *list,
462 GossipContact *contact,
463 const gchar *message)
465 EmpathyTpContactListPriv *priv;
468 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
470 priv = GET_PRIV (list);
472 handle = gossip_contact_get_handle (contact);
473 gossip_telepathy_group_add_member (priv->subscribe, handle, message);
477 tp_contact_list_remove (EmpathyContactList *list,
478 GossipContact *contact,
479 const gchar *message)
481 EmpathyTpContactListPriv *priv;
484 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
486 priv = GET_PRIV (list);
488 handle = gossip_contact_get_handle (contact);
489 gossip_telepathy_group_remove_member (priv->subscribe, handle, message);
490 gossip_telepathy_group_remove_member (priv->publish, handle, message);
491 gossip_telepathy_group_remove_member (priv->known, handle, message);
495 tp_contact_list_get_contacts (EmpathyContactList *list)
497 EmpathyTpContactListPriv *priv;
498 GList *contacts = NULL;
500 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
502 priv = GET_PRIV (list);
504 /* FIXME: we should only return contacts that are in the contact list */
505 g_hash_table_foreach (priv->contacts,
506 (GHFunc) tp_contact_list_get_contacts_foreach,
513 empathy_tp_contact_list_get_account (EmpathyTpContactList *list)
515 EmpathyTpContactListPriv *priv;
517 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
519 priv = GET_PRIV (list);
521 return priv->account;
525 empathy_tp_contact_list_get_user (EmpathyTpContactList *list)
527 EmpathyTpContactListPriv *priv;
529 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
531 priv = GET_PRIV (list);
533 return priv->user_contact;
537 empathy_tp_contact_list_get_from_id (EmpathyTpContactList *list,
540 EmpathyTpContactListPriv *priv;
541 GossipContact *contact;
542 const gchar *contact_ids[] = {id, NULL};
545 GError *error = NULL;
547 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
548 g_return_val_if_fail (id != NULL, NULL);
550 priv = GET_PRIV (list);
552 contact = tp_contact_list_find (EMPATHY_CONTACT_LIST (list), id);
557 /* The id is unknown, requests a new handle */
558 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
559 TP_HANDLE_TYPE_CONTACT,
562 gossip_debug (DEBUG_DOMAIN,
563 "RequestHandle for %s failed: %s", id,
564 error ? error->message : "No error given");
565 g_clear_error (&error);
569 handle = g_array_index(handles, guint, 0);
570 g_array_free (handles, TRUE);
572 return empathy_tp_contact_list_get_from_handle (list, handle);
576 empathy_tp_contact_list_get_from_handle (EmpathyTpContactList *list,
579 GossipContact *contact;
583 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
585 handles = g_array_new (FALSE, FALSE, sizeof (guint));
586 g_array_append_val (handles, handle);
588 contacts = empathy_tp_contact_list_get_from_handles (list, handles);
589 g_array_free (handles, TRUE);
595 contact = contacts->data;
596 g_list_free (contacts);
602 empathy_tp_contact_list_get_from_handles (EmpathyTpContactList *list,
605 EmpathyTpContactListPriv *priv;
606 gchar **handles_names;
609 GList *contacts = NULL;
611 GError *error = NULL;
613 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
614 g_return_val_if_fail (handles != NULL, NULL);
616 priv = GET_PRIV (list);
618 /* Search all handles we already have */
619 new_handles = g_array_new (FALSE, FALSE, sizeof (guint));
620 for (i = 0; i < handles->len; i++) {
621 GossipContact *contact;
624 handle = g_array_index (handles, guint, i);
625 contact = g_hash_table_lookup (priv->contacts,
626 GUINT_TO_POINTER (handle));
629 contacts = g_list_prepend (contacts,
630 g_object_ref (contact));
632 g_array_append_val (new_handles, handle);
636 if (new_handles->len == 0) {
640 /* Holds all handles we don't have yet.
641 * FIXME: We should release them at some point. */
642 if (!tp_conn_hold_handles (DBUS_G_PROXY (priv->tp_conn),
643 TP_HANDLE_TYPE_CONTACT,
644 new_handles, &error)) {
645 gossip_debug (DEBUG_DOMAIN,
646 "HoldHandles Error: %s",
647 error ? error->message : "No error given");
648 g_clear_error (&error);
649 g_array_free (new_handles, TRUE);
653 /* Get the IDs of all new handles */
654 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
655 TP_HANDLE_TYPE_CONTACT,
659 gossip_debug (DEBUG_DOMAIN,
660 "InspectHandle Error: %s",
661 error ? error->message : "No error given");
662 g_clear_error (&error);
663 g_array_free (new_handles, TRUE);
667 /* Create contact objects */
668 for (i = 0, id = handles_names; *id && i < new_handles->len; id++, i++) {
669 GossipContact *contact;
672 handle = g_array_index (new_handles, guint, i);
673 contact = g_object_new (GOSSIP_TYPE_CONTACT,
674 "account", priv->account,
679 g_signal_connect (contact, "notify::groups",
680 G_CALLBACK (tp_contact_list_groups_updated_cb),
682 g_signal_connect (contact, "notify::subscription",
683 G_CALLBACK (tp_contact_list_subscription_updated_cb),
685 g_signal_connect (contact, "notify::name",
686 G_CALLBACK (tp_contact_list_name_updated_cb),
689 gossip_debug (DEBUG_DOMAIN, "new contact created: %s (%d)",
692 g_hash_table_insert (priv->contacts,
693 GUINT_TO_POINTER (handle),
696 contacts = g_list_prepend (contacts, g_object_ref (contact));
699 tp_contact_list_get_info (list, new_handles);
701 g_array_free (new_handles, TRUE);
702 g_strfreev (handles_names);
708 empathy_tp_contact_list_rename_group (EmpathyTpContactList *list,
709 const gchar *old_group,
710 const gchar *new_group)
712 EmpathyTpContactListPriv *priv;
713 GossipTelepathyGroup *group;
716 g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
717 g_return_if_fail (old_group != NULL);
718 g_return_if_fail (new_group != NULL);
720 priv = GET_PRIV (list);
722 group = g_hash_table_find (priv->groups,
723 (GHRFunc) tp_contact_list_find_group,
726 /* The group doesn't exists on this account */
730 gossip_debug (DEBUG_DOMAIN, "rename group %s to %s", group, new_group);
732 /* Remove all members from the old group */
733 members = gossip_telepathy_group_get_members (group);
734 gossip_telepathy_group_remove_members (group, members, "");
735 tp_contact_list_group_members_removed_cb (group, members,
737 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
739 g_hash_table_remove (priv->groups,
740 gossip_telepathy_group_get_object_path (group));
742 /* Add all members to the new group */
743 group = tp_contact_list_get_group (list, new_group);
745 gossip_telepathy_group_add_members (group, members, "");
750 empathy_tp_contact_list_get_groups (EmpathyTpContactList *list)
752 EmpathyTpContactListPriv *priv;
753 GList *groups = NULL;
755 g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
757 priv = GET_PRIV (list);
759 g_hash_table_foreach (priv->groups,
760 (GHFunc) tp_contact_list_get_groups_foreach,
763 groups = g_list_sort (groups, (GCompareFunc) strcmp);
769 tp_contact_list_finalize_proxies (EmpathyTpContactList *list)
771 EmpathyTpContactListPriv *priv;
773 priv = GET_PRIV (list);
776 g_signal_handlers_disconnect_by_func (priv->tp_conn,
777 tp_contact_list_destroy_cb,
779 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
780 G_CALLBACK (tp_contact_list_newchannel_cb),
784 if (priv->aliasing_iface) {
785 dbus_g_proxy_disconnect_signal (priv->aliasing_iface,
787 G_CALLBACK (tp_contact_list_aliases_update_cb),
791 if (priv->avatars_iface) {
792 dbus_g_proxy_disconnect_signal (priv->avatars_iface,
794 G_CALLBACK (tp_contact_list_avatar_update_cb),
798 if (priv->presence_iface) {
799 dbus_g_proxy_disconnect_signal (priv->presence_iface,
801 G_CALLBACK (tp_contact_list_presence_update_cb),
807 tp_contact_list_destroy_cb (DBusGProxy *proxy,
808 EmpathyTpContactList *list)
810 EmpathyTpContactListPriv *priv;
812 priv = GET_PRIV (list);
814 gossip_debug (DEBUG_DOMAIN, "Connection destroyed... "
815 "Account disconnected or CM crashed");
817 /* DBus proxies should NOT be used anymore */
818 g_object_unref (priv->tp_conn);
819 priv->tp_conn = NULL;
820 priv->aliasing_iface = NULL;
821 priv->avatars_iface = NULL;
822 priv->presence_iface = NULL;
824 /* Remove all contacts */
825 g_hash_table_foreach (priv->contacts,
826 (GHFunc) tp_contact_list_contact_removed_foreach,
828 g_hash_table_remove_all (priv->contacts);
830 /* Tell the world to not use us anymore */
831 g_signal_emit (list, signals[DESTROY], 0);
835 tp_contact_list_contact_removed_foreach (guint handle,
836 GossipContact *contact,
837 EmpathyTpContactList *list)
839 g_signal_handlers_disconnect_by_func (contact,
840 tp_contact_list_groups_updated_cb,
842 g_signal_handlers_disconnect_by_func (contact,
843 tp_contact_list_subscription_updated_cb,
845 g_signal_handlers_disconnect_by_func (contact,
846 tp_contact_list_name_updated_cb,
849 g_signal_emit_by_name (list, "contact-removed", contact);
853 tp_contact_list_block_contact (EmpathyTpContactList *list,
854 GossipContact *contact)
856 g_signal_handlers_block_by_func (contact,
857 tp_contact_list_groups_updated_cb,
859 g_signal_handlers_block_by_func (contact,
860 tp_contact_list_subscription_updated_cb,
862 g_signal_handlers_block_by_func (contact,
863 tp_contact_list_name_updated_cb,
868 tp_contact_list_unblock_contact (EmpathyTpContactList *list,
869 GossipContact *contact)
871 g_signal_handlers_unblock_by_func (contact,
872 tp_contact_list_groups_updated_cb,
874 g_signal_handlers_unblock_by_func (contact,
875 tp_contact_list_subscription_updated_cb,
877 g_signal_handlers_unblock_by_func (contact,
878 tp_contact_list_name_updated_cb,
883 tp_contact_list_find_foreach (guint handle,
884 GossipContact *contact,
887 if (strcmp (gossip_contact_get_id (contact), id) == 0) {
895 tp_contact_list_newchannel_cb (DBusGProxy *proxy,
896 const gchar *object_path,
897 const gchar *channel_type,
898 TelepathyHandleType handle_type,
899 guint channel_handle,
900 gboolean suppress_handle,
901 EmpathyTpContactList *list)
903 EmpathyTpContactListPriv *priv;
904 GossipTelepathyGroup *group;
906 const gchar *bus_name;
909 priv = GET_PRIV (list);
911 if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0 ||
916 bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn));
917 new_chan = tp_chan_new (tp_get_bus (),
920 channel_type, handle_type, channel_handle);
922 if (handle_type == TP_HANDLE_TYPE_LIST) {
923 TpContactListType list_type;
925 list_type = tp_contact_list_get_type (list, new_chan);
926 if (list_type == TP_CONTACT_LIST_TYPE_UNKNOWN) {
927 gossip_debug (DEBUG_DOMAIN, "Unknown contact list channel");
928 g_object_unref (new_chan);
932 gossip_debug (DEBUG_DOMAIN, "New contact list channel of type: %d",
935 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
938 case TP_CONTACT_LIST_TYPE_KNOWN:
940 g_object_unref (priv->known);
944 case TP_CONTACT_LIST_TYPE_PUBLISH:
946 g_object_unref (priv->publish);
948 priv->publish = group;
950 case TP_CONTACT_LIST_TYPE_SUBSCRIBE:
951 if (priv->subscribe) {
952 g_object_unref (priv->subscribe);
954 priv->subscribe = group;
957 g_assert_not_reached ();
960 /* Connect and setup the new contact-list group */
961 if (list_type == TP_CONTACT_LIST_TYPE_KNOWN ||
962 list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
963 g_signal_connect (group, "members-added",
964 G_CALLBACK (tp_contact_list_contact_added_cb),
966 g_signal_connect (group, "members-removed",
967 G_CALLBACK (tp_contact_list_contact_removed_cb),
970 members = gossip_telepathy_group_get_members (group);
971 tp_contact_list_contact_added_cb (group, members, 0,
972 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
974 g_array_free (members, TRUE);
976 if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
981 g_signal_connect (group, "local-pending",
982 G_CALLBACK (tp_contact_list_local_pending_cb),
985 info = gossip_telepathy_group_get_local_pending_members_with_info (group);
988 /* This happens with butterfly because
989 * GetLocalPendingMembersWithInfo is not
991 g_object_unref (new_chan);
995 pending = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
996 for (i = 0; info->len > i; i++) {
997 GValueArray *pending_struct;
1001 const gchar *message;
1003 pending_struct = g_ptr_array_index (info, i);
1004 member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
1005 invitor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
1006 reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
1007 message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
1009 g_array_insert_val (pending, 0, member);
1011 tp_contact_list_local_pending_cb (group, pending,
1016 g_value_array_free (pending_struct);
1019 g_ptr_array_free (info, TRUE);
1020 g_array_free (pending, TRUE);
1023 else if (handle_type == TP_HANDLE_TYPE_GROUP) {
1024 const gchar *object_path;
1026 object_path = dbus_g_proxy_get_path (DBUS_G_PROXY (new_chan));
1027 if (g_hash_table_lookup (priv->groups, object_path)) {
1028 g_object_unref (new_chan);
1032 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
1034 gossip_debug (DEBUG_DOMAIN, "New server-side group channel: %s",
1035 gossip_telepathy_group_get_name (group));
1037 dbus_g_proxy_connect_signal (DBUS_G_PROXY (new_chan), "Closed",
1039 (tp_contact_list_group_channel_closed_cb),
1042 g_hash_table_insert (priv->groups, g_strdup (object_path), group);
1043 g_signal_connect (group, "members-added",
1044 G_CALLBACK (tp_contact_list_group_members_added_cb),
1046 g_signal_connect (group, "members-removed",
1047 G_CALLBACK (tp_contact_list_group_members_removed_cb),
1050 members = gossip_telepathy_group_get_members (group);
1051 tp_contact_list_group_members_added_cb (group, members, 0,
1052 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
1054 g_array_free (members, TRUE);
1057 g_object_unref (new_chan);
1060 static TpContactListType
1061 tp_contact_list_get_type (EmpathyTpContactList *list,
1064 EmpathyTpContactListPriv *priv;
1066 gchar **handle_name;
1067 TpContactListType list_type;
1068 GError *error = NULL;
1070 priv = GET_PRIV (list);
1072 handles = g_array_new (FALSE, FALSE, sizeof (guint));
1073 g_array_append_val (handles, list_chan->handle);
1075 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
1076 TP_HANDLE_TYPE_LIST,
1080 gossip_debug (DEBUG_DOMAIN,
1081 "InspectHandle Error: %s",
1082 error ? error->message : "No error given");
1083 g_clear_error (&error);
1084 g_array_free (handles, TRUE);
1085 return TP_CONTACT_LIST_TYPE_UNKNOWN;
1088 if (strcmp (*handle_name, "subscribe") == 0) {
1089 list_type = TP_CONTACT_LIST_TYPE_SUBSCRIBE;
1090 } else if (strcmp (*handle_name, "publish") == 0) {
1091 list_type = TP_CONTACT_LIST_TYPE_PUBLISH;
1092 } else if (strcmp (*handle_name, "known") == 0) {
1093 list_type = TP_CONTACT_LIST_TYPE_KNOWN;
1095 list_type = TP_CONTACT_LIST_TYPE_UNKNOWN;
1098 g_strfreev (handle_name);
1099 g_array_free (handles, TRUE);
1105 tp_contact_list_contact_added_cb (GossipTelepathyGroup *group,
1109 const gchar *message,
1110 EmpathyTpContactList *list)
1112 EmpathyTpContactListPriv *priv;
1113 GList *added_list, *l;
1115 priv = GET_PRIV (list);
1117 added_list = empathy_tp_contact_list_get_from_handles (list, handles);
1119 for (l = added_list; l; l = l->next) {
1120 GossipContact *contact;
1122 contact = GOSSIP_CONTACT (l->data);
1123 tp_contact_list_block_contact (list, contact);
1124 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_BOTH);
1125 tp_contact_list_unblock_contact (list, contact);
1127 g_signal_emit_by_name (list, "contact-added", contact);
1129 g_object_unref (contact);
1132 g_list_free (added_list);
1136 tp_contact_list_contact_removed_cb (GossipTelepathyGroup *group,
1140 const gchar *message,
1141 EmpathyTpContactList *list)
1143 EmpathyTpContactListPriv *priv;
1144 GList *removed_list, *l;
1146 priv = GET_PRIV (list);
1148 removed_list = empathy_tp_contact_list_get_from_handles (list, handles);
1150 for (l = removed_list; l; l = l->next) {
1151 GossipContact *contact;
1154 contact = GOSSIP_CONTACT (l->data);
1156 handle = gossip_contact_get_handle (contact);
1157 g_hash_table_remove (priv->contacts, GUINT_TO_POINTER (handle));
1159 g_signal_emit_by_name (list, "contact-removed", contact);
1161 g_object_unref (contact);
1164 g_list_free (removed_list);
1168 tp_contact_list_local_pending_cb (GossipTelepathyGroup *group,
1172 const gchar *message,
1173 EmpathyTpContactList *list)
1175 EmpathyTpContactListPriv *priv;
1176 GList *pending_list, *l;
1178 priv = GET_PRIV (list);
1180 pending_list = empathy_tp_contact_list_get_from_handles (list, handles);
1182 for (l = pending_list; l; l = l->next) {
1183 GossipContact *contact;
1185 contact = GOSSIP_CONTACT (l->data);
1187 /* FIXME: Is that the correct way ? */
1188 tp_contact_list_block_contact (list, contact);
1189 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_FROM);
1190 tp_contact_list_unblock_contact (list, contact);
1191 g_signal_emit_by_name (list, "contact-added", contact);
1193 g_object_unref (contact);
1196 g_list_free (pending_list);
1200 tp_contact_list_groups_updated_cb (GossipContact *contact,
1202 EmpathyTpContactList *list)
1204 EmpathyTpContactListPriv *priv;
1205 TpContactListData data;
1208 priv = GET_PRIV (list);
1210 /* Make sure all groups are created */
1211 groups = gossip_contact_get_groups (contact);
1212 for (l = groups; l; l = l->next) {
1213 tp_contact_list_get_group (list, l->data);
1216 data.handle = gossip_contact_get_handle (contact);
1217 data.new_groups = groups;
1219 g_hash_table_foreach (priv->groups,
1220 (GHFunc) tp_contact_list_update_groups_foreach,
1225 tp_contact_list_subscription_updated_cb (GossipContact *contact,
1227 EmpathyTpContactList *list)
1229 EmpathyTpContactListPriv *priv;
1230 GossipSubscription subscription;
1233 priv = GET_PRIV (list);
1235 subscription = gossip_contact_get_subscription (contact);
1236 handle = gossip_contact_get_handle (contact);
1238 /* FIXME: what to do here, I'm a bit lost... */
1240 gossip_telepathy_group_add_member (priv->publish, handle, "");
1242 gossip_telepathy_group_remove_member (priv->publish, handle, "");
1247 tp_contact_list_name_updated_cb (GossipContact *contact,
1249 EmpathyTpContactList *list)
1251 EmpathyTpContactListPriv *priv;
1252 GHashTable *new_alias;
1253 const gchar *new_name;
1255 GError *error = NULL;
1257 priv = GET_PRIV (list);
1259 handle = gossip_contact_get_handle (contact);
1260 new_name = gossip_contact_get_name (contact);
1262 gossip_debug (DEBUG_DOMAIN, "renaming handle %d to %s",
1265 new_alias = g_hash_table_new_full (g_direct_hash,
1270 g_hash_table_insert (new_alias,
1271 GUINT_TO_POINTER (handle),
1272 g_strdup (new_name));
1274 if (!tp_conn_iface_aliasing_set_aliases (priv->aliasing_iface,
1277 gossip_debug (DEBUG_DOMAIN,
1278 "Couldn't rename contact: %s",
1279 error ? error->message : "No error given");
1280 g_clear_error (&error);
1283 g_hash_table_destroy (new_alias);
1287 tp_contact_list_update_groups_foreach (gchar *object_path,
1288 GossipTelepathyGroup *group,
1289 TpContactListData *data)
1292 gboolean found = FALSE;
1293 const gchar *group_name;
1296 is_member = gossip_telepathy_group_is_member (group, data->handle);
1297 group_name = gossip_telepathy_group_get_name (group);
1299 for (l = data->new_groups; l; l = l->next) {
1300 if (strcmp (group_name, l->data) == 0) {
1306 if (is_member && !found) {
1307 /* We are no longer member of this group */
1308 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1309 data->handle, group_name);
1310 gossip_telepathy_group_remove_member (group, data->handle, "");
1313 if (!is_member && found) {
1314 /* We are now member of this group */
1315 gossip_debug (DEBUG_DOMAIN, "Contact %d added to group '%s'",
1316 data->handle, group_name);
1317 gossip_telepathy_group_add_member (group, data->handle, "");
1321 static GossipTelepathyGroup *
1322 tp_contact_list_get_group (EmpathyTpContactList *list,
1325 EmpathyTpContactListPriv *priv;
1326 GossipTelepathyGroup *group;
1327 TpChan *group_channel;
1330 char *group_object_path;
1331 const char *names[2] = {name, NULL};
1332 GError *error = NULL;
1334 priv = GET_PRIV (list);
1336 group = g_hash_table_find (priv->groups,
1337 (GHRFunc) tp_contact_list_find_group,
1343 gossip_debug (DEBUG_DOMAIN, "creating new group: %s", name);
1345 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
1346 TP_HANDLE_TYPE_GROUP,
1350 gossip_debug (DEBUG_DOMAIN,
1351 "Couldn't request the creation of a new handle for group: %s",
1352 error ? error->message : "No error given");
1353 g_clear_error (&error);
1356 group_handle = g_array_index (handles, guint, 0);
1357 g_array_free (handles, TRUE);
1359 if (!tp_conn_request_channel (DBUS_G_PROXY (priv->tp_conn),
1360 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1361 TP_HANDLE_TYPE_GROUP,
1366 gossip_debug (DEBUG_DOMAIN,
1367 "Couldn't request the creation of a new group channel: %s",
1368 error ? error->message : "No error given");
1369 g_clear_error (&error);
1373 group_channel = tp_chan_new (tp_get_bus (),
1374 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn)),
1376 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1377 TP_HANDLE_TYPE_GROUP,
1380 dbus_g_proxy_connect_signal (DBUS_G_PROXY (group_channel),
1383 (tp_contact_list_group_channel_closed_cb),
1387 group = gossip_telepathy_group_new (group_channel, priv->tp_conn);
1388 g_hash_table_insert (priv->groups, group_object_path, group);
1389 g_signal_connect (group, "members-added",
1390 G_CALLBACK (tp_contact_list_group_members_added_cb),
1392 g_signal_connect (group, "members-removed",
1393 G_CALLBACK (tp_contact_list_group_members_removed_cb),
1400 tp_contact_list_find_group (gchar *key,
1401 GossipTelepathyGroup *group,
1404 if (strcmp (group_name, gossip_telepathy_group_get_name (group)) == 0) {
1412 tp_contact_list_get_groups_foreach (gchar *key,
1413 GossipTelepathyGroup *group,
1418 name = gossip_telepathy_group_get_name (group);
1419 *groups = g_list_append (*groups, g_strdup (name));
1423 tp_contact_list_group_channel_closed_cb (TpChan *channel,
1424 EmpathyTpContactList *list)
1426 EmpathyTpContactListPriv *priv;
1428 priv = GET_PRIV (list);
1430 g_hash_table_remove (priv->groups,
1431 dbus_g_proxy_get_path (DBUS_G_PROXY (channel)));
1435 tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group,
1439 const gchar *message,
1440 EmpathyTpContactList *list)
1442 EmpathyTpContactListPriv *priv;
1443 GList *added_list, *l;
1444 const gchar *group_name;
1446 priv = GET_PRIV (list);
1448 group_name = gossip_telepathy_group_get_name (group);
1449 added_list = empathy_tp_contact_list_get_from_handles (list, members);
1451 for (l = added_list; l; l = l->next) {
1452 GossipContact *contact;
1453 GList *contact_groups;
1455 contact = GOSSIP_CONTACT (l->data);
1456 contact_groups = gossip_contact_get_groups (contact);
1458 if (!g_list_find_custom (contact_groups,
1460 (GCompareFunc) strcmp)) {
1461 gossip_debug (DEBUG_DOMAIN, "Contact %s added to group '%s'",
1462 gossip_contact_get_name (contact),
1464 contact_groups = g_list_append (contact_groups,
1465 g_strdup (group_name));
1466 tp_contact_list_block_contact (list, contact);
1467 gossip_contact_set_groups (contact, contact_groups);
1468 tp_contact_list_unblock_contact (list, contact);
1471 g_object_unref (contact);
1474 g_list_free (added_list);
1478 tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
1482 const gchar *message,
1483 EmpathyTpContactList *list)
1485 EmpathyTpContactListPriv *priv;
1486 GList *removed_list, *l;
1487 const gchar *group_name;
1489 priv = GET_PRIV (list);
1491 group_name = gossip_telepathy_group_get_name (group);
1492 removed_list = empathy_tp_contact_list_get_from_handles (list, members);
1494 for (l = removed_list; l; l = l->next) {
1495 GossipContact *contact;
1496 GList *contact_groups;
1499 /* FIXME: Does it leak ? */
1500 contact = GOSSIP_CONTACT (l->data);
1501 contact_groups = gossip_contact_get_groups (contact);
1502 contact_groups = g_list_copy (contact_groups);
1504 to_remove = g_list_find_custom (contact_groups,
1506 (GCompareFunc) strcmp);
1508 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1509 gossip_contact_get_handle (contact),
1511 contact_groups = g_list_remove_link (contact_groups,
1513 tp_contact_list_block_contact (list, contact);
1514 gossip_contact_set_groups (contact, contact_groups);
1515 tp_contact_list_unblock_contact (list, contact);
1518 g_list_free (contact_groups);
1520 g_object_unref (contact);
1523 g_list_free (removed_list);
1527 tp_contact_list_get_contacts_foreach (guint handle,
1528 GossipContact *contact,
1531 *contacts = g_list_append (*contacts, g_object_ref (contact));
1535 tp_contact_list_get_info (EmpathyTpContactList *list,
1538 EmpathyTpContactListPriv *priv;
1539 GError *error = NULL;
1541 priv = GET_PRIV (list);
1543 if (priv->presence_iface) {
1544 /* FIXME: We should use GetPresence instead */
1545 if (!tp_conn_iface_presence_request_presence (priv->presence_iface,
1547 gossip_debug (DEBUG_DOMAIN,
1548 "Could not request presences: %s",
1549 error ? error->message : "No error given");
1550 g_clear_error (&error);
1554 if (priv->aliasing_iface) {
1555 TpContactListAliasesRequestData *data;
1557 data = g_slice_new (TpContactListAliasesRequestData);
1559 data->handles = g_memdup (handles->data, handles->len * sizeof (guint));
1561 tp_conn_iface_aliasing_request_aliases_async (priv->aliasing_iface,
1563 (tp_conn_iface_aliasing_request_aliases_reply)
1564 tp_contact_list_request_aliases_cb,
1568 if (priv->avatars_iface) {
1571 for (i = 0; i < handles->len; i++) {
1574 handle = g_array_index (handles, gint, i);
1575 tp_contact_list_request_avatar (list, handle);
1581 tp_contact_list_request_avatar (EmpathyTpContactList *list,
1584 EmpathyTpContactListPriv *priv;
1586 priv = GET_PRIV (list);
1588 /* We queue avatar requests to not send too many dbus async
1589 * calls at once. If we don't we reach the dbus's limit of
1591 priv->avatar_requests_queue = g_list_append (priv->avatar_requests_queue,
1592 GUINT_TO_POINTER (handle));
1593 tp_contact_list_start_avatar_requests (list);
1597 tp_contact_list_start_avatar_requests (EmpathyTpContactList *list)
1599 EmpathyTpContactListPriv *priv;
1600 TpContactListAvatarRequestData *data;
1602 priv = GET_PRIV (list);
1604 while (n_avatar_requests < MAX_AVATAR_REQUESTS &&
1605 priv->avatar_requests_queue) {
1606 data = g_slice_new (TpContactListAvatarRequestData);
1608 data->handle = GPOINTER_TO_UINT (priv->avatar_requests_queue->data);
1610 n_avatar_requests++;
1611 priv->avatar_requests_queue = g_list_remove (priv->avatar_requests_queue,
1612 priv->avatar_requests_queue->data);
1614 tp_conn_iface_avatars_request_avatar_async (priv->avatars_iface,
1616 (tp_conn_iface_avatars_request_avatar_reply)
1617 tp_contact_list_request_avatar_cb,
1623 tp_contact_list_avatar_update_cb (DBusGProxy *proxy,
1626 EmpathyTpContactList *list)
1628 gossip_debug (DEBUG_DOMAIN, "Changing avatar for %d to %s",
1631 tp_contact_list_request_avatar (list, handle);
1635 tp_contact_list_request_avatar_cb (DBusGProxy *proxy,
1636 GArray *avatar_data,
1639 TpContactListAvatarRequestData *data)
1641 GossipContact *contact;
1643 contact = empathy_tp_contact_list_get_from_handle (data->list, data->handle);
1646 gossip_debug (DEBUG_DOMAIN, "Error requesting avatar for %s: %s",
1647 gossip_contact_get_name (contact),
1648 error ? error->message : "No error given");
1650 GossipAvatar *avatar;
1652 avatar = gossip_avatar_new (avatar_data->data,
1655 tp_contact_list_block_contact (data->list, contact);
1656 gossip_contact_set_avatar (contact, avatar);
1657 tp_contact_list_unblock_contact (data->list, contact);
1658 gossip_avatar_unref (avatar);
1661 n_avatar_requests--;
1662 tp_contact_list_start_avatar_requests (data->list);
1664 g_slice_free (TpContactListAvatarRequestData, data);
1668 tp_contact_list_aliases_update_cb (DBusGProxy *proxy,
1669 GPtrArray *renamed_handlers,
1670 EmpathyTpContactList *list)
1674 for (i = 0; renamed_handlers->len > i; i++) {
1677 GValueArray *renamed_struct;
1678 GossipContact *contact;
1680 renamed_struct = g_ptr_array_index (renamed_handlers, i);
1681 handle = g_value_get_uint(g_value_array_get_nth (renamed_struct, 0));
1682 alias = g_value_get_string(g_value_array_get_nth (renamed_struct, 1));
1684 if (alias && *alias == '\0') {
1688 contact = empathy_tp_contact_list_get_from_handle (list, handle);
1689 tp_contact_list_block_contact (list, contact);
1690 gossip_contact_set_name (contact, alias);
1691 tp_contact_list_unblock_contact (list, contact);
1693 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (update cb)",
1699 tp_contact_list_request_aliases_cb (DBusGProxy *proxy,
1700 gchar **contact_names,
1702 TpContactListAliasesRequestData *data)
1707 for (name = contact_names; *name && !error; name++) {
1708 GossipContact *contact;
1710 contact = empathy_tp_contact_list_get_from_handle (data->list,
1712 tp_contact_list_block_contact (data->list, contact);
1713 gossip_contact_set_name (contact, *name);
1714 tp_contact_list_unblock_contact (data->list, contact);
1716 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (request cb)",
1717 data->handles[i], *name);
1722 g_free (data->handles);
1723 g_slice_free (TpContactListAliasesRequestData, data);
1727 tp_contact_list_presence_update_cb (DBusGProxy *proxy,
1728 GHashTable *handle_table,
1729 EmpathyTpContactList *list)
1731 g_hash_table_foreach (handle_table,
1732 (GHFunc) tp_contact_list_parse_presence_foreach,
1737 tp_contact_list_parse_presence_foreach (guint handle,
1738 GValueArray *presence_struct,
1739 EmpathyTpContactList *list)
1741 GHashTable *presences_table;
1742 GossipContact *contact;
1743 GossipPresence *presence = NULL;
1745 contact = empathy_tp_contact_list_get_from_handle (list, handle);
1746 presences_table = g_value_get_boxed (g_value_array_get_nth (presence_struct, 1));
1748 g_hash_table_foreach (presences_table,
1749 (GHFunc) tp_contact_list_presences_table_foreach,
1752 gossip_debug (DEBUG_DOMAIN, "Presence changed for %s (%d) to %s (%d)",
1753 gossip_contact_get_name (contact),
1755 presence ? gossip_presence_get_status (presence) : "unset",
1756 presence ? gossip_presence_get_state (presence) : MC_PRESENCE_UNSET);
1758 tp_contact_list_block_contact (list, contact);
1759 gossip_contact_set_presence (contact, presence);
1760 tp_contact_list_unblock_contact (list, contact);
1764 tp_contact_list_presences_table_foreach (const gchar *state_str,
1765 GHashTable *presences_table,
1766 GossipPresence **presence)
1769 const GValue *message;
1771 state = gossip_presence_state_from_str (state_str);
1772 if ((state == MC_PRESENCE_UNSET) || (state == MC_PRESENCE_OFFLINE)) {
1777 g_object_unref (*presence);
1781 *presence = gossip_presence_new ();
1782 gossip_presence_set_state (*presence, state);
1784 message = g_hash_table_lookup (presences_table, "message");
1785 if (message != NULL) {
1786 gossip_presence_set_status (*presence,
1787 g_value_get_string (message));
1792 tp_contact_list_status_changed_cb (MissionControl *mc,
1793 TelepathyConnectionStatus status,
1794 McPresence presence,
1795 TelepathyConnectionStatusReason reason,
1796 const gchar *unique_name,
1797 EmpathyTpContactList *list)
1799 EmpathyTpContactListPriv *priv;
1802 priv = GET_PRIV (list);
1804 account = mc_account_lookup (unique_name);
1805 if (status != TP_CONN_STATUS_DISCONNECTED ||
1806 !gossip_account_equal (account, priv->account)) {
1807 g_object_unref (account);
1811 /* We are disconnected, do just like if the connection was destroyed */
1812 g_signal_handlers_disconnect_by_func (priv->tp_conn,
1813 tp_contact_list_destroy_cb,
1815 tp_contact_list_destroy_cb (DBUS_G_PROXY (priv->tp_conn), list);
1817 g_object_unref (account);