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 "empathy-session.h"
38 #include "gossip-debug.h"
39 #include "gossip-telepathy-group.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 {
50 GossipContact *own_contact;
52 GossipTelepathyGroup *known;
53 GossipTelepathyGroup *publish;
54 GossipTelepathyGroup *subscribe;
59 DBusGProxy *aliasing_iface;
60 DBusGProxy *avatars_iface;
61 DBusGProxy *presence_iface;
63 GList *avatar_requests_queue;
67 CONTACT_LIST_TYPE_KNOWN,
68 CONTACT_LIST_TYPE_PUBLISH,
69 CONTACT_LIST_TYPE_SUBSCRIBE,
70 CONTACT_LIST_TYPE_UNKNOWN,
71 CONTACT_LIST_TYPE_COUNT
80 EmpathyContactList *list;
82 } ContactListAvatarRequestData;
85 EmpathyContactList *list;
87 } ContactListAliasesRequestData;
89 static void empathy_contact_list_class_init (EmpathyContactListClass *klass);
90 static void empathy_contact_list_init (EmpathyContactList *list);
91 static void contact_list_finalize (GObject *object);
92 static void contact_list_finalize_proxies (EmpathyContactList *list);
93 static void contact_list_contact_removed_foreach (guint handle,
94 GossipContact *contact,
95 EmpathyContactList *list);
96 static void contact_list_destroy_cb (DBusGProxy *proxy,
97 EmpathyContactList *list);
98 static gboolean contact_list_find_foreach (guint handle,
99 GossipContact *contact,
101 static void contact_list_newchannel_cb (DBusGProxy *proxy,
102 const gchar *object_path,
103 const gchar *channel_type,
104 TelepathyHandleType handle_type,
105 guint channel_handle,
106 gboolean suppress_handle,
107 EmpathyContactList *list);
108 static ContactListType contact_list_get_type (EmpathyContactList *list,
110 static void contact_list_contact_added_cb (GossipTelepathyGroup *group,
114 const gchar *message,
115 EmpathyContactList *list);
116 static void contact_list_contact_removed_cb (GossipTelepathyGroup *group,
120 const gchar *message,
121 EmpathyContactList *list);
122 static void contact_list_local_pending_cb (GossipTelepathyGroup *group,
126 const gchar *message,
127 EmpathyContactList *list);
128 static void contact_list_groups_updated_cb (GossipContact *contact,
130 EmpathyContactList *list);
131 static void contact_list_subscription_updated_cb (GossipContact *contact,
133 EmpathyContactList *list);
134 static void contact_list_name_updated_cb (GossipContact *contact,
136 EmpathyContactList *list);
137 static void contact_list_update_groups_foreach (gchar *object_path,
138 GossipTelepathyGroup *group,
139 ContactListData *data);
140 static GossipTelepathyGroup * contact_list_get_group (EmpathyContactList *list,
142 static gboolean contact_list_find_group (gchar *key,
143 GossipTelepathyGroup *group,
145 static void contact_list_get_groups_foreach (gchar *key,
146 GossipTelepathyGroup *group,
148 static void contact_list_group_channel_closed_cb (TpChan *channel,
149 EmpathyContactList *list);
150 static void contact_list_group_members_added_cb (GossipTelepathyGroup *group,
154 const gchar *message,
155 EmpathyContactList *list);
156 static void contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
160 const gchar *message,
161 EmpathyContactList *list);
162 static void contact_list_get_contacts_foreach (guint handle,
163 GossipContact *contact,
165 static void contact_list_get_info (EmpathyContactList *list,
167 static void contact_list_request_avatar (EmpathyContactList *list,
169 static void contact_list_start_avatar_requests (EmpathyContactList *list);
170 static void contact_list_avatar_update_cb (DBusGProxy *proxy,
173 EmpathyContactList *list);
174 static void contact_list_request_avatar_cb (DBusGProxy *proxy,
178 ContactListAvatarRequestData *data);
179 static void contact_list_aliases_update_cb (DBusGProxy *proxy,
181 EmpathyContactList *list);
182 static void contact_list_request_aliases_cb (DBusGProxy *proxy,
183 gchar **contact_names,
185 ContactListAliasesRequestData *data);
186 static void contact_list_presence_update_cb (DBusGProxy *proxy,
187 GHashTable *handle_table,
188 EmpathyContactList *list);
189 static void contact_list_parse_presence_foreach (guint handle,
190 GValueArray *presence_struct,
191 EmpathyContactList *list);
192 static void contact_list_presences_table_foreach (const gchar *state_str,
193 GHashTable *presences_table,
194 GossipPresence **presence);
195 static GossipPresenceState contact_list_presence_state_from_str (const gchar *str);
204 static guint signals[LAST_SIGNAL];
205 static guint n_avatar_requests = 0;
207 G_DEFINE_TYPE (EmpathyContactList, empathy_contact_list, G_TYPE_OBJECT);
210 empathy_contact_list_class_init (EmpathyContactListClass *klass)
212 GObjectClass *object_class = G_OBJECT_CLASS (klass);
214 object_class->finalize = contact_list_finalize;
216 signals[CONTACT_ADDED] =
217 g_signal_new ("contact-added",
218 G_TYPE_FROM_CLASS (klass),
222 g_cclosure_marshal_VOID__OBJECT,
224 1, GOSSIP_TYPE_CONTACT);
226 signals[CONTACT_REMOVED] =
227 g_signal_new ("contact-removed",
228 G_TYPE_FROM_CLASS (klass),
232 g_cclosure_marshal_VOID__OBJECT,
234 1, GOSSIP_TYPE_CONTACT);
237 g_signal_new ("destroy",
238 G_TYPE_FROM_CLASS (klass),
242 g_cclosure_marshal_VOID__VOID,
246 g_type_class_add_private (object_class, sizeof (EmpathyContactListPriv));
250 empathy_contact_list_init (EmpathyContactList *list)
252 EmpathyContactListPriv *priv;
254 priv = GET_PRIV (list);
256 priv->groups = g_hash_table_new_full (g_str_hash,
258 (GDestroyNotify) g_free,
259 (GDestroyNotify) g_object_unref);
260 priv->contacts = g_hash_table_new_full (g_direct_hash,
263 (GDestroyNotify) g_object_unref);
268 contact_list_finalize (GObject *object)
270 EmpathyContactListPriv *priv;
271 EmpathyContactList *list;
273 list = EMPATHY_CONTACT_LIST (object);
274 priv = GET_PRIV (list);
276 gossip_debug (DEBUG_DOMAIN, "finalize: %p", object);
279 contact_list_finalize_proxies (list);
280 g_object_unref (priv->tp_conn);
284 g_object_unref (priv->known);
287 if (priv->subscribe) {
288 g_object_unref (priv->subscribe);
292 g_object_unref (priv->publish);
295 g_object_unref (priv->account);
296 g_object_unref (priv->own_contact);
297 g_hash_table_destroy (priv->groups);
298 g_hash_table_destroy (priv->contacts);
300 G_OBJECT_CLASS (empathy_contact_list_parent_class)->finalize (object);
304 empathy_contact_list_new (McAccount *account)
306 EmpathyContactListPriv *priv;
307 EmpathyContactList *list;
311 GError *error = NULL;
313 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
315 mc = empathy_session_get_mission_control ();
317 if (mission_control_get_connection_status (mc, account, NULL) != 0) {
318 /* The account is not connected, nothing to do. */
322 tp_conn = mission_control_get_connection (mc, account, NULL);
323 g_return_val_if_fail (tp_conn != NULL, NULL);
325 list = g_object_new (EMPATHY_TYPE_CONTACT_LIST, NULL);
326 priv = GET_PRIV (list);
328 priv->tp_conn = tp_conn;
329 priv->account = g_object_ref (account);
331 g_signal_connect (priv->tp_conn, "destroy",
332 G_CALLBACK (contact_list_destroy_cb),
335 priv->aliasing_iface = tp_conn_get_interface (priv->tp_conn,
336 TELEPATHY_CONN_IFACE_ALIASING_QUARK);
337 priv->avatars_iface = tp_conn_get_interface (priv->tp_conn,
338 TELEPATHY_CONN_IFACE_AVATARS_QUARK);
339 priv->presence_iface = tp_conn_get_interface (priv->tp_conn,
340 TELEPATHY_CONN_IFACE_PRESENCE_QUARK);
342 if (priv->aliasing_iface) {
343 dbus_g_proxy_connect_signal (priv->aliasing_iface,
345 G_CALLBACK (contact_list_aliases_update_cb),
349 if (priv->avatars_iface) {
350 dbus_g_proxy_connect_signal (priv->avatars_iface,
352 G_CALLBACK (contact_list_avatar_update_cb),
356 if (priv->presence_iface) {
357 dbus_g_proxy_connect_signal (priv->presence_iface,
359 G_CALLBACK (contact_list_presence_update_cb),
363 /* Get our own handle and contact */
364 if (!tp_conn_get_self_handle (DBUS_G_PROXY (priv->tp_conn),
366 gossip_debug (DEBUG_DOMAIN, "GetSelfHandle Error: %s",
367 error ? error->message : "No error given");
368 g_clear_error (&error);
370 priv->own_contact = empathy_contact_list_get_from_handle (list, handle);
377 empathy_contact_list_setup (EmpathyContactList *list)
379 EmpathyContactListPriv *priv;
381 GError *error = NULL;
384 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
386 priv = GET_PRIV (list);
388 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
389 G_CALLBACK (contact_list_newchannel_cb),
392 /* Get existing channels */
393 if (!tp_conn_list_channels (DBUS_G_PROXY (priv->tp_conn),
396 gossip_debug (DEBUG_DOMAIN,
397 "Failed to get list of open channels: %s",
398 error ? error->message : "No error given");
399 g_clear_error (&error);
403 for (i = 0; channels->len > i; i++) {
404 GValueArray *chan_struct;
405 const gchar *object_path;
406 const gchar *chan_iface;
407 TelepathyHandleType handle_type;
410 chan_struct = g_ptr_array_index (channels, i);
411 object_path = g_value_get_boxed (g_value_array_get_nth (chan_struct, 0));
412 chan_iface = g_value_get_string (g_value_array_get_nth (chan_struct, 1));
413 handle_type = g_value_get_uint (g_value_array_get_nth (chan_struct, 2));
414 handle = g_value_get_uint (g_value_array_get_nth (chan_struct, 3));
416 contact_list_newchannel_cb (DBUS_G_PROXY (priv->tp_conn),
417 object_path, chan_iface,
421 g_value_array_free (chan_struct);
424 g_ptr_array_free (channels, TRUE);
428 empathy_contact_list_get_account (EmpathyContactList *list)
430 EmpathyContactListPriv *priv;
432 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
434 priv = GET_PRIV (list);
436 return priv->account;
440 empathy_contact_list_get_own (EmpathyContactList *list)
442 EmpathyContactListPriv *priv;
444 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
446 priv = GET_PRIV (list);
448 return priv->own_contact;
452 empathy_contact_list_find (EmpathyContactList *list,
455 EmpathyContactListPriv *priv;
456 GossipContact *contact;
458 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
460 priv = GET_PRIV (list);
462 contact = g_hash_table_find (priv->contacts,
463 (GHRFunc) contact_list_find_foreach,
470 empathy_contact_list_add (EmpathyContactList *list,
472 const gchar *message)
474 EmpathyContactListPriv *priv;
476 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
478 priv = GET_PRIV (list);
480 gossip_telepathy_group_add_member (priv->subscribe, handle, message);
484 empathy_contact_list_remove (EmpathyContactList *list,
487 EmpathyContactListPriv *priv;
489 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
491 priv = GET_PRIV (list);
493 gossip_telepathy_group_remove_member (priv->subscribe, handle, "");
494 gossip_telepathy_group_remove_member (priv->publish, handle, "");
495 gossip_telepathy_group_remove_member (priv->known, handle, "");
499 empathy_contact_list_get_from_id (EmpathyContactList *list,
502 EmpathyContactListPriv *priv;
503 GossipContact *contact;
504 const gchar *contact_ids[] = {id, NULL};
507 GError *error = NULL;
509 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
510 g_return_val_if_fail (id != NULL, NULL);
512 priv = GET_PRIV (list);
514 contact = empathy_contact_list_find (list, id);
519 /* The id is unknown, requests a new handle */
520 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
521 TP_HANDLE_TYPE_CONTACT,
524 gossip_debug (DEBUG_DOMAIN,
525 "RequestHandle for %s failed: %s", id,
526 error ? error->message : "No error given");
527 g_clear_error (&error);
531 handle = g_array_index(handles, guint, 0);
532 g_array_free (handles, TRUE);
534 return empathy_contact_list_get_from_handle (list, handle);
538 empathy_contact_list_get_from_handle (EmpathyContactList *list,
541 GossipContact *contact;
545 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
547 handles = g_array_new (FALSE, FALSE, sizeof (guint));
548 g_array_append_val (handles, handle);
550 contacts = empathy_contact_list_get_from_handles (list, handles);
551 g_array_free (handles, TRUE);
557 contact = contacts->data;
558 g_list_free (contacts);
564 empathy_contact_list_get_from_handles (EmpathyContactList *list,
567 EmpathyContactListPriv *priv;
568 gchar **handles_names;
571 GList *contacts = NULL;
573 GError *error = NULL;
575 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
576 g_return_val_if_fail (handles != NULL, NULL);
578 priv = GET_PRIV (list);
580 /* Search all handles we already have */
581 new_handles = g_array_new (FALSE, FALSE, sizeof (guint));
582 for (i = 0; i < handles->len; i++) {
583 GossipContact *contact;
586 handle = g_array_index (handles, guint, i);
587 contact = g_hash_table_lookup (priv->contacts,
588 GUINT_TO_POINTER (handle));
591 contacts = g_list_prepend (contacts,
592 g_object_ref (contact));
594 g_array_append_val (new_handles, handle);
598 if (new_handles->len == 0) {
602 /* Holds all handles we don't have yet.
603 * FIXME: We should release them at some point. */
604 if (!tp_conn_hold_handles (DBUS_G_PROXY (priv->tp_conn),
605 TP_HANDLE_TYPE_CONTACT,
606 new_handles, &error)) {
607 gossip_debug (DEBUG_DOMAIN,
608 "HoldHandles Error: %s",
609 error ? error->message : "No error given");
610 g_clear_error (&error);
611 g_array_free (new_handles, TRUE);
615 /* Get the IDs of all new handles */
616 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
617 TP_HANDLE_TYPE_CONTACT,
621 gossip_debug (DEBUG_DOMAIN,
622 "InspectHandle Error: %s",
623 error ? error->message : "No error given");
624 g_clear_error (&error);
625 g_array_free (new_handles, TRUE);
629 /* Create contact objects */
630 for (i = 0, id = handles_names; *id && i < new_handles->len; id++, i++) {
631 GossipContact *contact;
634 handle = g_array_index (new_handles, guint, i);
635 contact = g_object_new (GOSSIP_TYPE_CONTACT,
636 "account", priv->account,
641 g_signal_connect (contact, "notify::groups",
642 G_CALLBACK (contact_list_groups_updated_cb),
644 g_signal_connect (contact, "notify::subscription",
645 G_CALLBACK (contact_list_subscription_updated_cb),
647 g_signal_connect (contact, "notify::name",
648 G_CALLBACK (contact_list_name_updated_cb),
651 gossip_debug (DEBUG_DOMAIN, "new contact created: %s (%d)",
654 g_hash_table_insert (priv->contacts,
655 GUINT_TO_POINTER (handle),
658 contacts = g_list_prepend (contacts, g_object_ref (contact));
661 contact_list_get_info (list, new_handles);
663 g_array_free (new_handles, TRUE);
664 g_strfreev (handles_names);
670 empathy_contact_list_rename_group (EmpathyContactList *list,
671 const gchar *old_group,
672 const gchar *new_group)
674 EmpathyContactListPriv *priv;
675 GossipTelepathyGroup *group;
678 g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
679 g_return_if_fail (old_group != NULL);
680 g_return_if_fail (new_group != NULL);
682 priv = GET_PRIV (list);
684 group = g_hash_table_find (priv->groups,
685 (GHRFunc) contact_list_find_group,
688 /* The group doesn't exists on this account */
692 gossip_debug (DEBUG_DOMAIN, "rename group %s to %s", group, new_group);
694 /* Remove all members from the old group */
695 members = gossip_telepathy_group_get_members (group);
696 gossip_telepathy_group_remove_members (group, members, "");
697 contact_list_group_members_removed_cb (group, members,
699 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
701 g_hash_table_remove (priv->groups,
702 gossip_telepathy_group_get_object_path (group));
704 /* Add all members to the new group */
705 group = contact_list_get_group (list, new_group);
707 gossip_telepathy_group_add_members (group, members, "");
712 empathy_contact_list_get_groups (EmpathyContactList *list)
714 EmpathyContactListPriv *priv;
715 GList *groups = NULL;
717 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
719 priv = GET_PRIV (list);
721 g_hash_table_foreach (priv->groups,
722 (GHFunc) contact_list_get_groups_foreach,
725 groups = g_list_sort (groups, (GCompareFunc) strcmp);
731 empathy_contact_list_get_contacts (EmpathyContactList *list)
733 EmpathyContactListPriv *priv;
734 GList *contacts = NULL;
736 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list), NULL);
738 priv = GET_PRIV (list);
740 /* FIXME: we should only return contacts that are in the contact list */
741 g_hash_table_foreach (priv->contacts,
742 (GHFunc) contact_list_get_contacts_foreach,
749 contact_list_finalize_proxies (EmpathyContactList *list)
751 EmpathyContactListPriv *priv;
753 priv = GET_PRIV (list);
755 g_signal_handlers_disconnect_by_func (priv->tp_conn,
756 contact_list_destroy_cb,
758 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_conn), "NewChannel",
759 G_CALLBACK (contact_list_newchannel_cb),
762 if (priv->aliasing_iface) {
763 dbus_g_proxy_disconnect_signal (priv->aliasing_iface,
765 G_CALLBACK (contact_list_aliases_update_cb),
769 if (priv->avatars_iface) {
770 dbus_g_proxy_disconnect_signal (priv->avatars_iface,
772 G_CALLBACK (contact_list_avatar_update_cb),
776 if (priv->presence_iface) {
777 dbus_g_proxy_disconnect_signal (priv->presence_iface,
779 G_CALLBACK (contact_list_presence_update_cb),
785 contact_list_destroy_cb (DBusGProxy *proxy,
786 EmpathyContactList *list)
788 EmpathyContactListPriv *priv;
790 priv = GET_PRIV (list);
792 gossip_debug (DEBUG_DOMAIN, "Connection destroyed. "
793 "Account disconnected or CM crashed.");
795 /* DBus proxies should NOT be used anymore */
796 g_object_unref (priv->tp_conn);
797 priv->tp_conn = NULL;
798 priv->aliasing_iface = NULL;
799 priv->avatars_iface = NULL;
800 priv->presence_iface = NULL;
802 /* Remove all contacts */
803 g_hash_table_foreach (priv->contacts,
804 (GHFunc) contact_list_contact_removed_foreach,
806 g_hash_table_remove_all (priv->contacts);
808 /* Tell the world to not use us anymore */
809 g_signal_emit (list, signals[DESTROY], 0);
813 contact_list_contact_removed_foreach (guint handle,
814 GossipContact *contact,
815 EmpathyContactList *list)
817 g_signal_handlers_disconnect_by_func (contact,
818 contact_list_groups_updated_cb,
820 g_signal_handlers_disconnect_by_func (contact,
821 contact_list_subscription_updated_cb,
823 g_signal_handlers_disconnect_by_func (contact,
824 contact_list_name_updated_cb,
827 g_signal_emit (list, signals[CONTACT_REMOVED], 0, contact);
831 contact_list_block_contact (EmpathyContactList *list,
832 GossipContact *contact)
834 g_signal_handlers_block_by_func (contact,
835 contact_list_groups_updated_cb,
837 g_signal_handlers_block_by_func (contact,
838 contact_list_subscription_updated_cb,
840 g_signal_handlers_block_by_func (contact,
841 contact_list_name_updated_cb,
846 contact_list_unblock_contact (EmpathyContactList *list,
847 GossipContact *contact)
849 g_signal_handlers_unblock_by_func (contact,
850 contact_list_groups_updated_cb,
852 g_signal_handlers_unblock_by_func (contact,
853 contact_list_subscription_updated_cb,
855 g_signal_handlers_unblock_by_func (contact,
856 contact_list_name_updated_cb,
861 contact_list_find_foreach (guint handle,
862 GossipContact *contact,
865 if (strcmp (gossip_contact_get_id (contact), id) == 0) {
873 contact_list_newchannel_cb (DBusGProxy *proxy,
874 const gchar *object_path,
875 const gchar *channel_type,
876 TelepathyHandleType handle_type,
877 guint channel_handle,
878 gboolean suppress_handle,
879 EmpathyContactList *list)
881 EmpathyContactListPriv *priv;
882 GossipTelepathyGroup *group;
884 const gchar *bus_name;
887 priv = GET_PRIV (list);
889 if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST) != 0 ||
894 bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn));
895 new_chan = tp_chan_new (tp_get_bus (),
898 channel_type, handle_type, channel_handle);
900 if (handle_type == TP_HANDLE_TYPE_LIST) {
901 ContactListType list_type;
903 list_type = contact_list_get_type (list, new_chan);
904 if (list_type == CONTACT_LIST_TYPE_UNKNOWN) {
905 gossip_debug (DEBUG_DOMAIN, "Unknown contact list channel");
906 g_object_unref (new_chan);
910 gossip_debug (DEBUG_DOMAIN, "New contact list channel of type: %d",
913 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
916 case CONTACT_LIST_TYPE_KNOWN:
918 g_object_unref (priv->known);
922 case CONTACT_LIST_TYPE_PUBLISH:
924 g_object_unref (priv->publish);
926 priv->publish = group;
928 case CONTACT_LIST_TYPE_SUBSCRIBE:
929 if (priv->subscribe) {
930 g_object_unref (priv->subscribe);
932 priv->subscribe = group;
935 g_assert_not_reached ();
938 /* Connect and setup the new contact-list group */
939 if (list_type == CONTACT_LIST_TYPE_KNOWN ||
940 list_type == CONTACT_LIST_TYPE_SUBSCRIBE) {
941 g_signal_connect (group, "members-added",
942 G_CALLBACK (contact_list_contact_added_cb),
944 g_signal_connect (group, "members-removed",
945 G_CALLBACK (contact_list_contact_removed_cb),
948 members = gossip_telepathy_group_get_members (group);
949 contact_list_contact_added_cb (group, members, 0,
950 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
952 g_array_free (members, TRUE);
954 if (list_type == CONTACT_LIST_TYPE_PUBLISH) {
959 g_signal_connect (group, "local-pending",
960 G_CALLBACK (contact_list_local_pending_cb),
963 info = gossip_telepathy_group_get_local_pending_members_with_info (group);
966 /* This happens with butterfly because
967 * GetLocalPendingMembersWithInfo is not
969 g_object_unref (new_chan);
973 pending = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
974 for (i = 0; info->len > i; i++) {
975 GValueArray *pending_struct;
979 const gchar *message;
981 pending_struct = g_ptr_array_index (info, i);
982 member = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
983 invitor = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
984 reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
985 message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
987 g_array_insert_val (pending, 0, member);
989 contact_list_local_pending_cb (group, pending,
994 g_value_array_free (pending_struct);
997 g_ptr_array_free (info, TRUE);
998 g_array_free (pending, TRUE);
1001 else if (handle_type == TP_HANDLE_TYPE_GROUP) {
1002 const gchar *object_path;
1004 object_path = dbus_g_proxy_get_path (DBUS_G_PROXY (new_chan));
1005 if (g_hash_table_lookup (priv->groups, object_path)) {
1006 g_object_unref (new_chan);
1010 group = gossip_telepathy_group_new (new_chan, priv->tp_conn);
1012 gossip_debug (DEBUG_DOMAIN, "New server-side group channel: %s",
1013 gossip_telepathy_group_get_name (group));
1015 dbus_g_proxy_connect_signal (DBUS_G_PROXY (new_chan), "Closed",
1017 (contact_list_group_channel_closed_cb),
1020 g_hash_table_insert (priv->groups, g_strdup (object_path), group);
1021 g_signal_connect (group, "members-added",
1022 G_CALLBACK (contact_list_group_members_added_cb),
1024 g_signal_connect (group, "members-removed",
1025 G_CALLBACK (contact_list_group_members_removed_cb),
1028 members = gossip_telepathy_group_get_members (group);
1029 contact_list_group_members_added_cb (group, members, 0,
1030 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
1032 g_array_free (members, TRUE);
1035 g_object_unref (new_chan);
1038 static ContactListType
1039 contact_list_get_type (EmpathyContactList *list,
1042 EmpathyContactListPriv *priv;
1044 gchar **handle_name;
1045 ContactListType list_type;
1046 GError *error = NULL;
1048 priv = GET_PRIV (list);
1050 handles = g_array_new (FALSE, FALSE, sizeof (guint));
1051 g_array_append_val (handles, list_chan->handle);
1053 if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
1054 TP_HANDLE_TYPE_LIST,
1058 gossip_debug (DEBUG_DOMAIN,
1059 "InspectHandle Error: %s",
1060 error ? error->message : "No error given");
1061 g_clear_error (&error);
1062 g_array_free (handles, TRUE);
1063 return CONTACT_LIST_TYPE_UNKNOWN;
1066 if (strcmp (*handle_name, "subscribe") == 0) {
1067 list_type = CONTACT_LIST_TYPE_SUBSCRIBE;
1068 } else if (strcmp (*handle_name, "publish") == 0) {
1069 list_type = CONTACT_LIST_TYPE_PUBLISH;
1070 } else if (strcmp (*handle_name, "known") == 0) {
1071 list_type = CONTACT_LIST_TYPE_KNOWN;
1073 list_type = CONTACT_LIST_TYPE_UNKNOWN;
1076 g_strfreev (handle_name);
1077 g_array_free (handles, TRUE);
1083 contact_list_contact_added_cb (GossipTelepathyGroup *group,
1087 const gchar *message,
1088 EmpathyContactList *list)
1090 EmpathyContactListPriv *priv;
1091 GList *added_list, *l;
1093 priv = GET_PRIV (list);
1095 added_list = empathy_contact_list_get_from_handles (list, handles);
1097 for (l = added_list; l; l = l->next) {
1098 GossipContact *contact;
1100 contact = GOSSIP_CONTACT (l->data);
1101 contact_list_block_contact (list, contact);
1102 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_BOTH);
1103 contact_list_unblock_contact (list, contact);
1105 g_signal_emit (list, signals[CONTACT_ADDED], 0, contact);
1107 g_object_unref (contact);
1110 g_list_free (added_list);
1114 contact_list_contact_removed_cb (GossipTelepathyGroup *group,
1118 const gchar *message,
1119 EmpathyContactList *list)
1121 EmpathyContactListPriv *priv;
1122 GList *removed_list, *l;
1124 priv = GET_PRIV (list);
1126 removed_list = empathy_contact_list_get_from_handles (list, handles);
1128 for (l = removed_list; l; l = l->next) {
1129 GossipContact *contact;
1132 contact = GOSSIP_CONTACT (l->data);
1134 handle = gossip_contact_get_handle (contact);
1135 g_hash_table_remove (priv->contacts, GUINT_TO_POINTER (handle));
1137 g_signal_emit (list, signals[CONTACT_REMOVED], 0, contact);
1139 g_object_unref (contact);
1142 g_list_free (removed_list);
1146 contact_list_local_pending_cb (GossipTelepathyGroup *group,
1150 const gchar *message,
1151 EmpathyContactList *list)
1153 EmpathyContactListPriv *priv;
1154 GList *pending_list, *l;
1156 priv = GET_PRIV (list);
1158 pending_list = empathy_contact_list_get_from_handles (list, handles);
1160 for (l = pending_list; l; l = l->next) {
1161 GossipContact *contact;
1163 contact = GOSSIP_CONTACT (l->data);
1165 /* FIXME: Is that the correct way ? */
1166 contact_list_block_contact (list, contact);
1167 gossip_contact_set_subscription (contact, GOSSIP_SUBSCRIPTION_FROM);
1168 contact_list_unblock_contact (list, contact);
1169 g_signal_emit (list, signals[CONTACT_ADDED], 0, contact);
1171 g_object_unref (contact);
1174 g_list_free (pending_list);
1178 contact_list_groups_updated_cb (GossipContact *contact,
1180 EmpathyContactList *list)
1182 EmpathyContactListPriv *priv;
1183 ContactListData data;
1186 priv = GET_PRIV (list);
1188 /* Make sure all groups are created */
1189 groups = gossip_contact_get_groups (contact);
1190 for (l = groups; l; l = l->next) {
1191 contact_list_get_group (list, l->data);
1194 data.handle = gossip_contact_get_handle (contact);
1195 data.new_groups = groups;
1197 g_hash_table_foreach (priv->groups,
1198 (GHFunc) contact_list_update_groups_foreach,
1203 contact_list_subscription_updated_cb (GossipContact *contact,
1205 EmpathyContactList *list)
1207 EmpathyContactListPriv *priv;
1208 GossipSubscription subscription;
1211 priv = GET_PRIV (list);
1213 subscription = gossip_contact_get_subscription (contact);
1214 handle = gossip_contact_get_handle (contact);
1216 /* FIXME: what to do here, I'm a bit lost... */
1218 gossip_telepathy_group_add_member (priv->publish, handle, "");
1220 gossip_telepathy_group_remove_member (priv->publish, handle, "");
1225 contact_list_name_updated_cb (GossipContact *contact,
1227 EmpathyContactList *list)
1229 EmpathyContactListPriv *priv;
1230 GHashTable *new_alias;
1231 const gchar *new_name;
1233 GError *error = NULL;
1235 priv = GET_PRIV (list);
1237 handle = gossip_contact_get_handle (contact);
1238 new_name = gossip_contact_get_name (contact);
1240 gossip_debug (DEBUG_DOMAIN, "renaming handle %d to %s",
1243 new_alias = g_hash_table_new_full (g_direct_hash,
1248 g_hash_table_insert (new_alias,
1249 GUINT_TO_POINTER (handle),
1250 g_strdup (new_name));
1252 if (!tp_conn_iface_aliasing_set_aliases (priv->aliasing_iface,
1255 gossip_debug (DEBUG_DOMAIN,
1256 "Couldn't rename contact: %s",
1257 error ? error->message : "No error given");
1258 g_clear_error (&error);
1261 g_hash_table_destroy (new_alias);
1265 contact_list_update_groups_foreach (gchar *object_path,
1266 GossipTelepathyGroup *group,
1267 ContactListData *data)
1270 gboolean found = FALSE;
1271 const gchar *group_name;
1274 is_member = gossip_telepathy_group_is_member (group, data->handle);
1275 group_name = gossip_telepathy_group_get_name (group);
1277 for (l = data->new_groups; l; l = l->next) {
1278 if (strcmp (group_name, l->data) == 0) {
1284 if (is_member && !found) {
1285 /* We are no longer member of this group */
1286 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1287 data->handle, group_name);
1288 gossip_telepathy_group_remove_member (group, data->handle, "");
1291 if (!is_member && found) {
1292 /* We are now member of this group */
1293 gossip_debug (DEBUG_DOMAIN, "Contact %d added to group '%s'",
1294 data->handle, group_name);
1295 gossip_telepathy_group_add_member (group, data->handle, "");
1299 static GossipTelepathyGroup *
1300 contact_list_get_group (EmpathyContactList *list,
1303 EmpathyContactListPriv *priv;
1304 GossipTelepathyGroup *group;
1305 TpChan *group_channel;
1308 char *group_object_path;
1309 const char *names[2] = {name, NULL};
1310 GError *error = NULL;
1312 priv = GET_PRIV (list);
1314 group = g_hash_table_find (priv->groups,
1315 (GHRFunc) contact_list_find_group,
1321 gossip_debug (DEBUG_DOMAIN, "creating new group: %s", name);
1323 if (!tp_conn_request_handles (DBUS_G_PROXY (priv->tp_conn),
1324 TP_HANDLE_TYPE_GROUP,
1328 gossip_debug (DEBUG_DOMAIN,
1329 "Couldn't request the creation of a new handle for group: %s",
1330 error ? error->message : "No error given");
1331 g_clear_error (&error);
1334 group_handle = g_array_index (handles, guint, 0);
1335 g_array_free (handles, TRUE);
1337 if (!tp_conn_request_channel (DBUS_G_PROXY (priv->tp_conn),
1338 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1339 TP_HANDLE_TYPE_GROUP,
1344 gossip_debug (DEBUG_DOMAIN,
1345 "Couldn't request the creation of a new group channel: %s",
1346 error ? error->message : "No error given");
1347 g_clear_error (&error);
1351 group_channel = tp_chan_new (tp_get_bus (),
1352 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->tp_conn)),
1354 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
1355 TP_HANDLE_TYPE_GROUP,
1358 dbus_g_proxy_connect_signal (DBUS_G_PROXY (group_channel),
1361 (contact_list_group_channel_closed_cb),
1365 group = gossip_telepathy_group_new (group_channel, priv->tp_conn);
1366 g_hash_table_insert (priv->groups, group_object_path, group);
1367 g_signal_connect (group, "members-added",
1368 G_CALLBACK (contact_list_group_members_added_cb),
1370 g_signal_connect (group, "members-removed",
1371 G_CALLBACK (contact_list_group_members_removed_cb),
1378 contact_list_find_group (gchar *key,
1379 GossipTelepathyGroup *group,
1382 if (strcmp (group_name, gossip_telepathy_group_get_name (group)) == 0) {
1390 contact_list_get_groups_foreach (gchar *key,
1391 GossipTelepathyGroup *group,
1396 name = gossip_telepathy_group_get_name (group);
1397 *groups = g_list_append (*groups, g_strdup (name));
1401 contact_list_group_channel_closed_cb (TpChan *channel,
1402 EmpathyContactList *list)
1404 EmpathyContactListPriv *priv;
1406 priv = GET_PRIV (list);
1408 g_hash_table_remove (priv->groups,
1409 dbus_g_proxy_get_path (DBUS_G_PROXY (channel)));
1413 contact_list_group_members_added_cb (GossipTelepathyGroup *group,
1417 const gchar *message,
1418 EmpathyContactList *list)
1420 EmpathyContactListPriv *priv;
1421 GList *added_list, *l;
1422 const gchar *group_name;
1424 priv = GET_PRIV (list);
1426 group_name = gossip_telepathy_group_get_name (group);
1427 added_list = empathy_contact_list_get_from_handles (list, members);
1429 for (l = added_list; l; l = l->next) {
1430 GossipContact *contact;
1431 GList *contact_groups;
1433 contact = GOSSIP_CONTACT (l->data);
1434 contact_groups = gossip_contact_get_groups (contact);
1436 if (!g_list_find_custom (contact_groups,
1438 (GCompareFunc) strcmp)) {
1439 gossip_debug (DEBUG_DOMAIN, "Contact %s added to group '%s'",
1440 gossip_contact_get_name (contact),
1442 contact_groups = g_list_append (contact_groups,
1443 g_strdup (group_name));
1444 contact_list_block_contact (list, contact);
1445 gossip_contact_set_groups (contact, contact_groups);
1446 contact_list_unblock_contact (list, contact);
1449 g_object_unref (contact);
1452 g_list_free (added_list);
1456 contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
1460 const gchar *message,
1461 EmpathyContactList *list)
1463 EmpathyContactListPriv *priv;
1464 GList *removed_list, *l;
1465 const gchar *group_name;
1467 priv = GET_PRIV (list);
1469 group_name = gossip_telepathy_group_get_name (group);
1470 removed_list = empathy_contact_list_get_from_handles (list, members);
1472 for (l = removed_list; l; l = l->next) {
1473 GossipContact *contact;
1474 GList *contact_groups;
1477 /* FIXME: Does it leak ? */
1478 contact = GOSSIP_CONTACT (l->data);
1479 contact_groups = gossip_contact_get_groups (contact);
1480 contact_groups = g_list_copy (contact_groups);
1482 to_remove = g_list_find_custom (contact_groups,
1484 (GCompareFunc) strcmp);
1486 gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
1487 gossip_contact_get_handle (contact),
1489 contact_groups = g_list_remove_link (contact_groups,
1491 contact_list_block_contact (list, contact);
1492 gossip_contact_set_groups (contact, contact_groups);
1493 contact_list_unblock_contact (list, contact);
1496 g_list_free (contact_groups);
1498 g_object_unref (contact);
1501 g_list_free (removed_list);
1505 contact_list_get_contacts_foreach (guint handle,
1506 GossipContact *contact,
1509 *contacts = g_list_append (*contacts, g_object_ref (contact));
1513 contact_list_get_info (EmpathyContactList *list,
1516 EmpathyContactListPriv *priv;
1517 GError *error = NULL;
1519 priv = GET_PRIV (list);
1521 if (priv->presence_iface) {
1522 /* FIXME: We should use GetPresence instead */
1523 if (!tp_conn_iface_presence_request_presence (priv->presence_iface,
1525 gossip_debug (DEBUG_DOMAIN,
1526 "Could not request presences: %s",
1527 error ? error->message : "No error given");
1528 g_clear_error (&error);
1532 if (priv->aliasing_iface) {
1533 ContactListAliasesRequestData *data;
1535 data = g_slice_new (ContactListAliasesRequestData);
1537 data->handles = g_memdup (handles->data, handles->len * sizeof (guint));
1539 tp_conn_iface_aliasing_request_aliases_async (priv->aliasing_iface,
1541 (tp_conn_iface_aliasing_request_aliases_reply)
1542 contact_list_request_aliases_cb,
1546 if (priv->avatars_iface) {
1549 for (i = 0; i < handles->len; i++) {
1552 handle = g_array_index (handles, gint, i);
1553 contact_list_request_avatar (list, handle);
1559 contact_list_request_avatar (EmpathyContactList *list,
1562 EmpathyContactListPriv *priv;
1564 priv = GET_PRIV (list);
1566 /* We queue avatar requests to not send too many dbus async
1567 * calls at once. If we don't we reach the dbus's limit of
1569 priv->avatar_requests_queue = g_list_append (priv->avatar_requests_queue,
1570 GUINT_TO_POINTER (handle));
1571 contact_list_start_avatar_requests (list);
1575 contact_list_start_avatar_requests (EmpathyContactList *list)
1577 EmpathyContactListPriv *priv;
1578 ContactListAvatarRequestData *data;
1580 priv = GET_PRIV (list);
1582 while (n_avatar_requests < MAX_AVATAR_REQUESTS &&
1583 priv->avatar_requests_queue) {
1584 data = g_slice_new (ContactListAvatarRequestData);
1586 data->handle = GPOINTER_TO_UINT (priv->avatar_requests_queue->data);
1588 n_avatar_requests++;
1589 priv->avatar_requests_queue = g_list_remove (priv->avatar_requests_queue,
1590 priv->avatar_requests_queue->data);
1592 tp_conn_iface_avatars_request_avatar_async (priv->avatars_iface,
1594 (tp_conn_iface_avatars_request_avatar_reply)
1595 contact_list_request_avatar_cb,
1601 contact_list_avatar_update_cb (DBusGProxy *proxy,
1604 EmpathyContactList *list)
1606 gossip_debug (DEBUG_DOMAIN, "Changing avatar for %d to %s",
1609 contact_list_request_avatar (list, handle);
1613 contact_list_request_avatar_cb (DBusGProxy *proxy,
1614 GArray *avatar_data,
1617 ContactListAvatarRequestData *data)
1619 GossipContact *contact;
1621 contact = empathy_contact_list_get_from_handle (data->list, data->handle);
1624 gossip_debug (DEBUG_DOMAIN, "Error requesting avatar for %s: %s",
1625 gossip_contact_get_name (contact),
1626 error ? error->message : "No error given");
1628 GossipAvatar *avatar;
1630 avatar = gossip_avatar_new (avatar_data->data,
1633 contact_list_block_contact (data->list, contact);
1634 gossip_contact_set_avatar (contact, avatar);
1635 contact_list_unblock_contact (data->list, contact);
1636 gossip_avatar_unref (avatar);
1639 n_avatar_requests--;
1640 contact_list_start_avatar_requests (data->list);
1642 g_slice_free (ContactListAvatarRequestData, data);
1646 contact_list_aliases_update_cb (DBusGProxy *proxy,
1647 GPtrArray *renamed_handlers,
1648 EmpathyContactList *list)
1652 for (i = 0; renamed_handlers->len > i; i++) {
1655 GValueArray *renamed_struct;
1656 GossipContact *contact;
1658 renamed_struct = g_ptr_array_index (renamed_handlers, i);
1659 handle = g_value_get_uint(g_value_array_get_nth (renamed_struct, 0));
1660 alias = g_value_get_string(g_value_array_get_nth (renamed_struct, 1));
1662 if (alias && *alias == '\0') {
1666 contact = empathy_contact_list_get_from_handle (list, handle);
1667 contact_list_block_contact (list, contact);
1668 gossip_contact_set_name (contact, alias);
1669 contact_list_unblock_contact (list, contact);
1671 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (update cb)",
1677 contact_list_request_aliases_cb (DBusGProxy *proxy,
1678 gchar **contact_names,
1680 ContactListAliasesRequestData *data)
1685 for (name = contact_names; *name && !error; name++) {
1686 GossipContact *contact;
1688 contact = empathy_contact_list_get_from_handle (data->list,
1690 contact_list_block_contact (data->list, contact);
1691 gossip_contact_set_name (contact, *name);
1692 contact_list_unblock_contact (data->list, contact);
1694 gossip_debug (DEBUG_DOMAIN, "contact %d renamed to %s (request cb)",
1695 data->handles[i], *name);
1700 g_free (data->handles);
1701 g_slice_free (ContactListAliasesRequestData, data);
1705 contact_list_presence_update_cb (DBusGProxy *proxy,
1706 GHashTable *handle_table,
1707 EmpathyContactList *list)
1709 g_hash_table_foreach (handle_table,
1710 (GHFunc) contact_list_parse_presence_foreach,
1715 contact_list_parse_presence_foreach (guint handle,
1716 GValueArray *presence_struct,
1717 EmpathyContactList *list)
1719 GHashTable *presences_table;
1720 GossipContact *contact;
1721 GossipPresence *presence = NULL;
1723 contact = empathy_contact_list_get_from_handle (list, handle);
1724 presences_table = g_value_get_boxed (g_value_array_get_nth (presence_struct, 1));
1726 g_hash_table_foreach (presences_table,
1727 (GHFunc) contact_list_presences_table_foreach,
1730 gossip_debug (DEBUG_DOMAIN, "Presence changed for %s (%d)",
1731 gossip_contact_get_name (contact),
1734 contact_list_block_contact (list, contact);
1736 gossip_contact_add_presence (contact, presence);
1737 g_object_unref (presence);
1739 g_object_set (contact, "presences", NULL, NULL);
1741 contact_list_unblock_contact (list, contact);
1745 contact_list_presences_table_foreach (const gchar *state_str,
1746 GHashTable *presences_table,
1747 GossipPresence **presence)
1749 GossipPresenceState state;
1750 const GValue *message;
1753 g_object_unref (*presence);
1757 state = contact_list_presence_state_from_str (state_str);
1758 if (state == GOSSIP_PRESENCE_STATE_UNAVAILABLE) {
1762 *presence = gossip_presence_new ();
1763 gossip_presence_set_state (*presence, state);
1765 message = g_hash_table_lookup (presences_table, "message");
1766 if (message != NULL) {
1767 gossip_presence_set_status (*presence,
1768 g_value_get_string (message));
1771 gossip_presence_set_resource (*presence, "");
1774 static GossipPresenceState
1775 contact_list_presence_state_from_str (const gchar *str)
1777 if (strcmp (str, "available") == 0) {
1778 return GOSSIP_PRESENCE_STATE_AVAILABLE;
1779 } else if ((strcmp (str, "dnd") == 0) || (strcmp (str, "busy") == 0)) {
1780 return GOSSIP_PRESENCE_STATE_BUSY;
1781 } else if ((strcmp (str, "away") == 0) || (strcmp (str, "brb") == 0)) {
1782 return GOSSIP_PRESENCE_STATE_AWAY;
1783 } else if (strcmp (str, "xa") == 0) {
1784 return GOSSIP_PRESENCE_STATE_EXT_AWAY;
1785 } else if (strcmp (str, "hidden") == 0) {
1786 return GOSSIP_PRESENCE_STATE_HIDDEN;
1787 } else if (strcmp (str, "offline") == 0) {
1788 return GOSSIP_PRESENCE_STATE_UNAVAILABLE;
1789 } else if (strcmp (str, "chat") == 0) {
1790 /* We don't support chat, so treat it like available. */
1791 return GOSSIP_PRESENCE_STATE_AVAILABLE;
1794 return GOSSIP_PRESENCE_STATE_AVAILABLE;