1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2008 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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
31 #include <glib/gi18n-lib.h>
34 #include <telepathy-glib/util.h>
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-tp-chat.h>
38 #include <libempathy/empathy-enum-types.h>
39 #include <libempathy/empathy-contact-manager.h>
41 #include "empathy-contact-list-store.h"
42 #include "empathy-ui-utils.h"
43 #include "empathy-gtk-enum-types.h"
44 #include "empathy-images.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
47 #include <libempathy/empathy-debug.h>
49 /* Active users are those which have recently changed state
50 * (e.g. online, offline or from normal to a busy state).
53 /* Time in seconds user is shown as active */
54 #define ACTIVE_USER_SHOW_TIME 7
56 /* Time in seconds after connecting which we wait before active users are enabled */
57 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
59 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactListStore)
61 EmpathyContactList *list;
62 gboolean show_offline;
63 gboolean show_avatars;
66 gboolean show_protocols;
68 EmpathyContactListStoreSort sort_criterium;
71 gboolean dispose_has_run;
72 GHashTable *status_icons;
73 /* Hash: EmpathyContact* -> GQueue (GtkTreeIter *) */
74 GHashTable *empathy_contact_cache;
75 /* Hash: char *groupname -> GtkTreeIter * */
76 GHashTable *empathy_group_cache;
77 } EmpathyContactListStorePriv;
80 EmpathyContactListStore *store;
81 EmpathyContact *contact;
85 static void contact_list_store_dispose (GObject *object);
86 static void contact_list_store_get_property (GObject *object,
90 static void contact_list_store_set_property (GObject *object,
94 static void contact_list_store_setup (EmpathyContactListStore *store);
95 static gboolean contact_list_store_inibit_active_cb (EmpathyContactListStore *store);
96 static void contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
97 EmpathyContact *contact,
98 EmpathyContact *actor,
102 EmpathyContactListStore *store);
103 static void contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
104 EmpathyContact *old_contact,
105 EmpathyContact *new_contact,
108 EmpathyContactListStore *store);
109 static void contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
110 EmpathyContact *contact,
113 EmpathyContactListStore *store);
114 static void contact_list_store_add_contact (EmpathyContactListStore *store,
115 EmpathyContact *contact);
116 static void contact_list_store_remove_contact (EmpathyContactListStore *store,
117 EmpathyContact *contact);
118 static void contact_list_store_contact_update (EmpathyContactListStore *store,
119 EmpathyContact *contact);
120 static void contact_list_store_contact_updated_cb (EmpathyContact *contact,
122 EmpathyContactListStore *store);
123 static void contact_list_store_contact_set_active (EmpathyContactListStore *store,
124 EmpathyContact *contact,
126 gboolean set_changed);
127 static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store,
128 EmpathyContact *contact,
130 static void contact_list_store_contact_active_free (ShowActiveData *data);
131 static gboolean contact_list_store_contact_active_cb (ShowActiveData *data);
132 static void contact_list_store_get_group (EmpathyContactListStore *store,
134 GtkTreeIter *iter_group_to_set,
135 GtkTreeIter *iter_separator_to_set,
137 gboolean is_fake_group);
138 static gint contact_list_store_state_sort_func (GtkTreeModel *model,
142 static gint contact_list_store_name_sort_func (GtkTreeModel *model,
146 static GList * contact_list_store_find_contact (EmpathyContactListStore *store,
147 EmpathyContact *contact);
148 static gboolean contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
151 EmpathyContactListStore *store);
164 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
167 contact_list_store_chat_state_changed_cb (TpChannel *self,
168 guint contact_handle,
172 EmpathyContactListStorePriv *priv = GET_PRIV (store);
175 contacts = empathy_contact_list_get_members (priv->list);
177 for (l = contacts; l != NULL; l = l->next) {
178 EmpathyContact *contact = EMPATHY_CONTACT (l->data);
180 if (empathy_contact_get_handle (contact) == contact_handle) {
181 contact_list_store_contact_update (store, contact);
186 g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
187 g_list_free (contacts);
191 contact_list_store_iface_setup (gpointer user_data)
193 EmpathyContactListStore *store = user_data;
194 EmpathyContactListStorePriv *priv = GET_PRIV (store);
197 /* Signal connection. */
198 g_signal_connect (priv->list,
200 G_CALLBACK (contact_list_store_member_renamed_cb),
202 g_signal_connect (priv->list,
204 G_CALLBACK (contact_list_store_members_changed_cb),
206 g_signal_connect (priv->list,
208 G_CALLBACK (contact_list_store_groups_changed_cb),
211 if (EMPATHY_IS_TP_CHAT (priv->list)) {
212 g_signal_connect (priv->list,
213 "chat-state-changed",
214 G_CALLBACK (contact_list_store_chat_state_changed_cb),
218 /* Add contacts already created. */
219 contacts = empathy_contact_list_get_members (priv->list);
220 for (l = contacts; l; l = l->next) {
221 contact_list_store_members_changed_cb (priv->list, l->data,
226 g_object_unref (l->data);
228 g_list_free (contacts);
230 priv->setup_idle_id = 0;
236 contact_list_store_set_contact_list (EmpathyContactListStore *store,
237 EmpathyContactList *list_iface)
239 EmpathyContactListStorePriv *priv = GET_PRIV (store);
241 priv->list = g_object_ref (list_iface);
243 /* Let a chance to have all properties set before populating */
244 priv->setup_idle_id = g_idle_add (contact_list_store_iface_setup, store);
248 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
250 GObjectClass *object_class = G_OBJECT_CLASS (klass);
252 object_class->dispose = contact_list_store_dispose;
253 object_class->get_property = contact_list_store_get_property;
254 object_class->set_property = contact_list_store_set_property;
256 g_object_class_install_property (object_class,
258 g_param_spec_object ("contact-list",
259 "The contact list iface",
260 "The contact list iface",
261 EMPATHY_TYPE_CONTACT_LIST,
262 G_PARAM_CONSTRUCT_ONLY |
264 g_object_class_install_property (object_class,
266 g_param_spec_boolean ("show-offline",
268 "Whether contact list should display "
272 g_object_class_install_property (object_class,
274 g_param_spec_boolean ("show-avatars",
276 "Whether contact list should display "
277 "avatars for contacts",
280 g_object_class_install_property (object_class,
282 g_param_spec_boolean ("show-protocols",
284 "Whether contact list should display "
285 "protocols for contacts",
288 g_object_class_install_property (object_class,
290 g_param_spec_boolean ("show-groups",
292 "Whether contact list should display "
296 g_object_class_install_property (object_class,
298 g_param_spec_boolean ("is-compact",
300 "Whether the contact list is in compact mode or not",
304 g_object_class_install_property (object_class,
306 g_param_spec_enum ("sort-criterium",
308 "The sort criterium to use for sorting the contact list",
309 EMPATHY_TYPE_CONTACT_LIST_STORE_SORT,
310 EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
313 g_type_class_add_private (object_class, sizeof (EmpathyContactListStorePriv));
317 g_queue_free_full_iter (gpointer data)
319 GQueue *queue = (GQueue *) data;
320 g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
321 g_queue_free (queue);
326 empathy_contact_list_store_init (EmpathyContactListStore *store)
328 EmpathyContactListStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
329 EMPATHY_TYPE_CONTACT_LIST_STORE, EmpathyContactListStorePriv);
332 priv->show_avatars = TRUE;
333 priv->show_groups = TRUE;
334 priv->show_protocols = FALSE;
335 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
336 (GSourceFunc) contact_list_store_inibit_active_cb,
338 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
339 priv->empathy_contact_cache = g_hash_table_new_full (NULL, NULL, NULL,
340 g_queue_free_full_iter);
341 priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
343 (GDestroyNotify) gtk_tree_iter_free);
344 contact_list_store_setup (store);
348 contact_list_store_dispose (GObject *object)
350 EmpathyContactListStorePriv *priv = GET_PRIV (object);
353 if (priv->dispose_has_run)
355 priv->dispose_has_run = TRUE;
357 contacts = empathy_contact_list_get_members (priv->list);
358 for (l = contacts; l; l = l->next) {
359 g_signal_handlers_disconnect_by_func (l->data,
360 G_CALLBACK (contact_list_store_contact_updated_cb),
363 g_object_unref (l->data);
365 g_list_free (contacts);
367 g_signal_handlers_disconnect_by_func (priv->list,
368 G_CALLBACK (contact_list_store_member_renamed_cb),
370 g_signal_handlers_disconnect_by_func (priv->list,
371 G_CALLBACK (contact_list_store_members_changed_cb),
373 g_signal_handlers_disconnect_by_func (priv->list,
374 G_CALLBACK (contact_list_store_groups_changed_cb),
376 g_object_unref (priv->list);
378 if (priv->inhibit_active) {
379 g_source_remove (priv->inhibit_active);
382 if (priv->setup_idle_id != 0) {
383 g_source_remove (priv->setup_idle_id);
386 g_hash_table_destroy (priv->status_icons);
387 g_hash_table_destroy (priv->empathy_contact_cache);
388 g_hash_table_destroy (priv->empathy_group_cache);
389 G_OBJECT_CLASS (empathy_contact_list_store_parent_class)->dispose (object);
393 contact_list_store_get_property (GObject *object,
398 EmpathyContactListStorePriv *priv;
400 priv = GET_PRIV (object);
403 case PROP_CONTACT_LIST:
404 g_value_set_object (value, priv->list);
406 case PROP_SHOW_OFFLINE:
407 g_value_set_boolean (value, priv->show_offline);
409 case PROP_SHOW_AVATARS:
410 g_value_set_boolean (value, priv->show_avatars);
412 case PROP_SHOW_PROTOCOLS:
413 g_value_set_boolean (value, priv->show_protocols);
415 case PROP_SHOW_GROUPS:
416 g_value_set_boolean (value, priv->show_groups);
418 case PROP_IS_COMPACT:
419 g_value_set_boolean (value, priv->is_compact);
421 case PROP_SORT_CRITERIUM:
422 g_value_set_enum (value, priv->sort_criterium);
425 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
431 contact_list_store_set_property (GObject *object,
437 case PROP_CONTACT_LIST:
438 contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
439 g_value_get_object (value));
441 case PROP_SHOW_OFFLINE:
442 empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
443 g_value_get_boolean (value));
445 case PROP_SHOW_AVATARS:
446 empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
447 g_value_get_boolean (value));
449 case PROP_SHOW_PROTOCOLS:
450 empathy_contact_list_store_set_show_protocols (EMPATHY_CONTACT_LIST_STORE (object),
451 g_value_get_boolean (value));
453 case PROP_SHOW_GROUPS:
454 empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
455 g_value_get_boolean (value));
457 case PROP_IS_COMPACT:
458 empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
459 g_value_get_boolean (value));
461 case PROP_SORT_CRITERIUM:
462 empathy_contact_list_store_set_sort_criterium (EMPATHY_CONTACT_LIST_STORE (object),
463 g_value_get_enum (value));
466 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
471 EmpathyContactListStore *
472 empathy_contact_list_store_new (EmpathyContactList *list_iface)
474 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
476 return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
477 "contact-list", list_iface,
482 empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store)
484 EmpathyContactListStorePriv *priv;
486 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
488 priv = GET_PRIV (store);
494 empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store)
496 EmpathyContactListStorePriv *priv;
498 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
500 priv = GET_PRIV (store);
502 return priv->show_offline;
506 empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
507 gboolean show_offline)
509 EmpathyContactListStorePriv *priv;
511 gboolean show_active;
513 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
515 priv = GET_PRIV (store);
517 priv->show_offline = show_offline;
518 show_active = priv->show_active;
520 /* Disable temporarily. */
521 priv->show_active = FALSE;
523 contacts = empathy_contact_list_get_members (priv->list);
524 for (l = contacts; l; l = l->next) {
525 contact_list_store_contact_update (store, l->data);
527 g_object_unref (l->data);
529 g_list_free (contacts);
531 /* Restore to original setting. */
532 priv->show_active = show_active;
534 g_object_notify (G_OBJECT (store), "show-offline");
538 empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store)
540 EmpathyContactListStorePriv *priv;
542 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
544 priv = GET_PRIV (store);
546 return priv->show_avatars;
550 empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
551 gboolean show_avatars)
553 EmpathyContactListStorePriv *priv;
556 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
558 priv = GET_PRIV (store);
560 priv->show_avatars = show_avatars;
562 model = GTK_TREE_MODEL (store);
564 gtk_tree_model_foreach (model,
565 (GtkTreeModelForeachFunc)
566 contact_list_store_update_list_mode_foreach,
569 g_object_notify (G_OBJECT (store), "show-avatars");
574 empathy_contact_list_store_get_show_protocols (EmpathyContactListStore *store)
576 EmpathyContactListStorePriv *priv;
578 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
580 priv = GET_PRIV (store);
582 return priv->show_protocols;
586 empathy_contact_list_store_set_show_protocols (EmpathyContactListStore *store,
587 gboolean show_protocols)
589 EmpathyContactListStorePriv *priv;
592 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
594 priv = GET_PRIV (store);
596 priv->show_protocols = show_protocols;
598 model = GTK_TREE_MODEL (store);
600 gtk_tree_model_foreach (model,
601 (GtkTreeModelForeachFunc)
602 contact_list_store_update_list_mode_foreach,
605 g_object_notify (G_OBJECT (store), "show-protocols");
609 empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
611 EmpathyContactListStorePriv *priv;
613 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
615 priv = GET_PRIV (store);
617 return priv->show_groups;
621 empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
622 gboolean show_groups)
624 EmpathyContactListStorePriv *priv;
626 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
628 priv = GET_PRIV (store);
630 if (priv->show_groups == show_groups) {
634 priv->show_groups = show_groups;
636 if (priv->setup_idle_id == 0) {
637 /* Remove all contacts and add them back, not optimized but
638 * that's the easy way :)
640 * This is only done if there's not a pending setup idle
641 * callback, otherwise it will race and the contacts will get
645 gtk_tree_store_clear (GTK_TREE_STORE (store));
647 /* Also clear the cache */
648 g_hash_table_remove_all (priv->empathy_contact_cache);
649 g_hash_table_remove_all (priv->empathy_group_cache);
651 contacts = empathy_contact_list_get_members (priv->list);
652 for (l = contacts; l; l = l->next) {
653 contact_list_store_members_changed_cb (priv->list,
659 g_object_unref (l->data);
661 g_list_free (contacts);
664 g_object_notify (G_OBJECT (store), "show-groups");
668 empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store)
670 EmpathyContactListStorePriv *priv;
672 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
674 priv = GET_PRIV (store);
676 return priv->is_compact;
680 empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
683 EmpathyContactListStorePriv *priv;
686 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
688 priv = GET_PRIV (store);
690 priv->is_compact = is_compact;
692 model = GTK_TREE_MODEL (store);
694 gtk_tree_model_foreach (model,
695 (GtkTreeModelForeachFunc)
696 contact_list_store_update_list_mode_foreach,
699 g_object_notify (G_OBJECT (store), "is-compact");
702 EmpathyContactListStoreSort
703 empathy_contact_list_store_get_sort_criterium (EmpathyContactListStore *store)
705 EmpathyContactListStorePriv *priv;
707 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), 0);
709 priv = GET_PRIV (store);
711 return priv->sort_criterium;
715 empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *store,
716 EmpathyContactListStoreSort sort_criterium)
718 EmpathyContactListStorePriv *priv;
720 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
722 priv = GET_PRIV (store);
724 priv->sort_criterium = sort_criterium;
726 switch (sort_criterium) {
727 case EMPATHY_CONTACT_LIST_STORE_SORT_STATE:
728 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
729 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
733 case EMPATHY_CONTACT_LIST_STORE_SORT_NAME:
734 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
735 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
740 g_assert_not_reached ();
743 g_object_notify (G_OBJECT (store), "sort-criterium");
747 empathy_contact_list_store_row_separator_func (GtkTreeModel *model,
751 gboolean is_separator = FALSE;
753 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
755 gtk_tree_model_get (model, iter,
756 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
763 empathy_contact_list_store_get_parent_group (GtkTreeModel *model,
765 gboolean *path_is_group,
766 gboolean *is_fake_group)
768 GtkTreeIter parent_iter, iter;
773 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
776 *path_is_group = FALSE;
779 if (!gtk_tree_model_get_iter (model, &iter, path)) {
783 gtk_tree_model_get (model, &iter,
784 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
785 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
792 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter)) {
798 gtk_tree_model_get (model, &iter,
799 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
800 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
801 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake,
810 *path_is_group = TRUE;
813 if (is_fake_group != NULL)
814 *is_fake_group = fake;
820 contact_list_store_setup (EmpathyContactListStore *store)
822 EmpathyContactListStorePriv *priv;
824 GDK_TYPE_PIXBUF, /* Status pixbuf */
825 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
826 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
827 G_TYPE_STRING, /* Name */
828 G_TYPE_UINT, /* Presence type */
829 G_TYPE_STRING, /* Status string */
830 G_TYPE_BOOLEAN, /* Compact view */
831 EMPATHY_TYPE_CONTACT, /* Contact type */
832 G_TYPE_BOOLEAN, /* Is group */
833 G_TYPE_BOOLEAN, /* Is active */
834 G_TYPE_BOOLEAN, /* Is online */
835 G_TYPE_BOOLEAN, /* Is separator */
836 G_TYPE_BOOLEAN, /* Can make audio calls */
837 G_TYPE_BOOLEAN, /* Can make video calls */
838 EMPATHY_TYPE_CONTACT_LIST_FLAGS, /* Flags */
839 G_TYPE_BOOLEAN, /* Is a fake group */
842 priv = GET_PRIV (store);
844 gtk_tree_store_set_column_types (GTK_TREE_STORE (store),
845 EMPATHY_CONTACT_LIST_STORE_COL_COUNT,
849 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
850 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
851 contact_list_store_name_sort_func,
853 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
854 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
855 contact_list_store_state_sort_func,
858 priv->sort_criterium = EMPATHY_CONTACT_LIST_STORE_SORT_NAME;
859 empathy_contact_list_store_set_sort_criterium (store, priv->sort_criterium);
863 contact_list_store_inibit_active_cb (EmpathyContactListStore *store)
865 EmpathyContactListStorePriv *priv;
867 priv = GET_PRIV (store);
869 priv->show_active = TRUE;
870 priv->inhibit_active = 0;
876 contact_list_store_add_contact_and_connect (EmpathyContactListStore *store, EmpathyContact *contact)
878 g_signal_connect (contact, "notify::presence",
879 G_CALLBACK (contact_list_store_contact_updated_cb),
881 g_signal_connect (contact, "notify::presence-message",
882 G_CALLBACK (contact_list_store_contact_updated_cb),
884 g_signal_connect (contact, "notify::name",
885 G_CALLBACK (contact_list_store_contact_updated_cb),
887 g_signal_connect (contact, "notify::avatar",
888 G_CALLBACK (contact_list_store_contact_updated_cb),
890 g_signal_connect (contact, "notify::capabilities",
891 G_CALLBACK (contact_list_store_contact_updated_cb),
894 contact_list_store_add_contact (store, contact);
898 contact_list_store_remove_contact_and_disconnect (EmpathyContactListStore *store, EmpathyContact *contact)
900 g_signal_handlers_disconnect_by_func (contact,
901 G_CALLBACK (contact_list_store_contact_updated_cb),
904 contact_list_store_remove_contact (store, contact);
908 contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
909 EmpathyContact *contact,
910 EmpathyContact *actor,
914 EmpathyContactListStore *store)
916 DEBUG ("Contact %s (%d) %s",
917 empathy_contact_get_id (contact),
918 empathy_contact_get_handle (contact),
919 is_member ? "added" : "removed");
922 contact_list_store_add_contact_and_connect (store, contact);
924 contact_list_store_remove_contact_and_disconnect (store, contact);
929 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
930 EmpathyContact *old_contact,
931 EmpathyContact *new_contact,
934 EmpathyContactListStore *store)
936 DEBUG ("Contact %s (%d) renamed to %s (%d)",
937 empathy_contact_get_id (old_contact),
938 empathy_contact_get_handle (old_contact),
939 empathy_contact_get_id (new_contact),
940 empathy_contact_get_handle (new_contact));
942 /* add the new contact */
943 contact_list_store_add_contact_and_connect (store, new_contact);
945 /* remove old contact */
946 contact_list_store_remove_contact_and_disconnect (store, old_contact);
950 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
951 EmpathyContact *contact,
954 EmpathyContactListStore *store)
956 EmpathyContactListStorePriv *priv;
957 gboolean show_active;
959 priv = GET_PRIV (store);
961 DEBUG ("Updating groups for contact %s (%d)",
962 empathy_contact_get_id (contact),
963 empathy_contact_get_handle (contact));
965 /* We do this to make sure the groups are correct, if not, we
966 * would have to check the groups already set up for each
967 * contact and then see what has been updated.
969 show_active = priv->show_active;
970 priv->show_active = FALSE;
971 contact_list_store_remove_contact (store, contact);
972 contact_list_store_add_contact (store, contact);
973 priv->show_active = show_active;
977 add_contact_to_store (GtkTreeStore *store,
980 EmpathyContact *contact,
981 EmpathyContactListFlags flags)
983 EmpathyContactListStorePriv *priv = GET_PRIV (store);
986 gtk_tree_store_insert_with_values (store, iter, parent, 0,
987 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_alias (contact),
988 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
989 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
990 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
991 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
992 empathy_contact_get_capabilities (contact) &
993 EMPATHY_CAPABILITIES_AUDIO,
994 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
995 empathy_contact_get_capabilities (contact) &
996 EMPATHY_CAPABILITIES_VIDEO,
997 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1000 queue = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1002 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
1004 queue = g_queue_new ();
1005 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
1006 g_hash_table_insert (priv->empathy_contact_cache, contact,
1012 contact_list_store_add_contact (EmpathyContactListStore *store,
1013 EmpathyContact *contact)
1015 EmpathyContactListStorePriv *priv;
1017 GList *groups = NULL, *l;
1018 TpConnection *connection;
1019 EmpathyContactListFlags flags = 0;
1020 char *protocol_name;
1022 priv = GET_PRIV (store);
1024 if (EMP_STR_EMPTY (empathy_contact_get_alias (contact)) ||
1025 (!priv->show_offline && !empathy_contact_is_online (contact))) {
1029 if (priv->show_groups) {
1030 groups = empathy_contact_list_get_groups (priv->list, contact);
1033 connection = empathy_contact_get_connection (contact);
1034 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
1035 flags = empathy_contact_manager_get_flags_for_connection (
1036 EMPATHY_CONTACT_MANAGER (priv->list), connection);
1039 tp_connection_parse_object_path (connection, &protocol_name, NULL);
1042 GtkTreeIter iter_group, *parent;
1044 parent = &iter_group;
1046 if (!priv->show_groups) {
1050 add_contact_to_store (GTK_TREE_STORE (store), &iter, parent,
1054 g_free (protocol_name);
1056 /* Else add to each group. */
1057 for (l = groups; l; l = l->next) {
1058 GtkTreeIter iter_group;
1060 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL, FALSE);
1062 add_contact_to_store (GTK_TREE_STORE (store), &iter, &iter_group, contact, flags);
1065 g_list_free (groups);
1067 contact_list_store_contact_update (store, contact);
1071 contact_list_store_remove_contact (EmpathyContactListStore *store,
1072 EmpathyContact *contact)
1074 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1075 GtkTreeModel *model;
1079 row_refs = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1084 /* Clean up model */
1085 model = GTK_TREE_MODEL (store);
1087 for (l = g_queue_peek_head_link (row_refs); l; l = l->next) {
1088 GtkTreeIter *iter = l->data;
1091 /* NOTE: it is only <= 2 here because we have
1092 * separators after the group name, otherwise it
1095 if (gtk_tree_model_iter_parent (model, &parent, iter) &&
1096 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1098 gtk_tree_model_get (model, &parent,
1099 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &group_name,
1101 g_hash_table_remove (priv->empathy_group_cache,
1103 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1105 gtk_tree_store_remove (GTK_TREE_STORE (store), iter);
1109 g_hash_table_remove (priv->empathy_contact_cache, contact);
1113 contact_list_store_contact_update (EmpathyContactListStore *store,
1114 EmpathyContact *contact)
1116 EmpathyContactListStorePriv *priv;
1117 ShowActiveData *data;
1118 GtkTreeModel *model;
1121 gboolean should_be_in_list;
1122 gboolean was_online = TRUE;
1123 gboolean now_online = FALSE;
1124 gboolean set_model = FALSE;
1125 gboolean do_remove = FALSE;
1126 gboolean do_set_active = FALSE;
1127 gboolean do_set_refresh = FALSE;
1128 gboolean show_avatar = FALSE;
1129 GdkPixbuf *pixbuf_avatar;
1130 GdkPixbuf *pixbuf_status;
1132 priv = GET_PRIV (store);
1134 model = GTK_TREE_MODEL (store);
1136 iters = contact_list_store_find_contact (store, contact);
1143 /* Get online state now. */
1144 now_online = empathy_contact_is_online (contact);
1146 if (priv->show_offline || now_online) {
1147 should_be_in_list = TRUE;
1149 should_be_in_list = FALSE;
1152 if (!in_list && !should_be_in_list) {
1153 /* Nothing to do. */
1154 DEBUG ("Contact:'%s' in list:NO, should be:NO",
1155 empathy_contact_get_alias (contact));
1157 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1158 g_list_free (iters);
1161 else if (in_list && !should_be_in_list) {
1162 DEBUG ("Contact:'%s' in list:YES, should be:NO",
1163 empathy_contact_get_alias (contact));
1165 if (priv->show_active) {
1167 do_set_active = TRUE;
1168 do_set_refresh = TRUE;
1171 DEBUG ("Remove item (after timeout)");
1173 DEBUG ("Remove item (now)!");
1174 contact_list_store_remove_contact (store, contact);
1177 else if (!in_list && should_be_in_list) {
1178 DEBUG ("Contact:'%s' in list:NO, should be:YES",
1179 empathy_contact_get_alias (contact));
1181 contact_list_store_add_contact (store, contact);
1183 if (priv->show_active) {
1184 do_set_active = TRUE;
1186 DEBUG ("Set active (contact added)");
1189 DEBUG ("Contact:'%s' in list:YES, should be:YES",
1190 empathy_contact_get_alias (contact));
1192 /* Get online state before. */
1193 if (iters && g_list_length (iters) > 0) {
1194 gtk_tree_model_get (model, iters->data,
1195 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online,
1199 /* Is this really an update or an online/offline. */
1200 if (priv->show_active) {
1201 if (was_online != now_online) {
1202 do_set_active = TRUE;
1203 do_set_refresh = TRUE;
1205 DEBUG ("Set active (contact updated %s)",
1206 was_online ? "online -> offline" :
1207 "offline -> online");
1209 /* Was TRUE for presence updates. */
1210 /* do_set_active = FALSE; */
1211 do_set_refresh = TRUE;
1213 DEBUG ("Set active (contact updated)");
1220 if (priv->show_avatars && !priv->is_compact) {
1223 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
1224 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1225 for (l = iters; l && set_model; l = l->next) {
1226 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1227 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1228 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1229 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1230 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_alias (contact),
1231 EMPATHY_CONTACT_LIST_STORE_COL_PRESENCE_TYPE,
1232 empathy_contact_get_presence (contact),
1233 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
1234 empathy_contact_get_presence_message (contact),
1235 EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
1236 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1237 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1238 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1239 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1240 empathy_contact_get_capabilities (contact) &
1241 EMPATHY_CAPABILITIES_AUDIO,
1242 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1243 empathy_contact_get_capabilities (contact) &
1244 EMPATHY_CAPABILITIES_VIDEO,
1248 if (pixbuf_avatar) {
1249 g_object_unref (pixbuf_avatar);
1252 if (priv->show_active && do_set_active) {
1253 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1255 if (do_set_active) {
1256 data = contact_list_store_contact_active_new (store, contact, do_remove);
1257 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1258 (GSourceFunc) contact_list_store_contact_active_cb,
1263 /* FIXME: when someone goes online then offline quickly, the
1264 * first timeout sets the user to be inactive and the second
1265 * timeout removes the user from the contact list, really we
1266 * should remove the first timeout.
1268 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1269 g_list_free (iters);
1273 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1275 EmpathyContactListStore *store)
1277 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1278 empathy_contact_get_alias (contact));
1280 contact_list_store_contact_update (store, contact);
1284 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1285 EmpathyContact *contact,
1287 gboolean set_changed)
1289 GtkTreeModel *model;
1292 model = GTK_TREE_MODEL (store);
1294 iters = contact_list_store_find_contact (store, contact);
1295 for (l = iters; l; l = l->next) {
1298 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1299 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, active,
1302 DEBUG ("Set item %s", active ? "active" : "inactive");
1305 path = gtk_tree_model_get_path (model, l->data);
1306 gtk_tree_model_row_changed (model, path, l->data);
1307 gtk_tree_path_free (path);
1311 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1312 g_list_free (iters);
1316 static ShowActiveData *
1317 contact_list_store_contact_active_new (EmpathyContactListStore *store,
1318 EmpathyContact *contact,
1321 ShowActiveData *data;
1323 DEBUG ("Contact:'%s' now active, and %s be removed",
1324 empathy_contact_get_alias (contact),
1325 remove_ ? "WILL" : "WILL NOT");
1327 data = g_slice_new0 (ShowActiveData);
1329 data->store = g_object_ref (store);
1330 data->contact = g_object_ref (contact);
1331 data->remove = remove_;
1337 contact_list_store_contact_active_free (ShowActiveData *data)
1339 g_object_unref (data->contact);
1340 g_object_unref (data->store);
1342 g_slice_free (ShowActiveData, data);
1346 contact_list_store_contact_active_cb (ShowActiveData *data)
1348 EmpathyContactListStorePriv *priv;
1350 priv = GET_PRIV (data->store);
1353 !priv->show_offline &&
1354 !empathy_contact_is_online (data->contact)) {
1355 DEBUG ("Contact:'%s' active timeout, removing item",
1356 empathy_contact_get_alias (data->contact));
1357 contact_list_store_remove_contact (data->store, data->contact);
1360 DEBUG ("Contact:'%s' no longer active",
1361 empathy_contact_get_alias (data->contact));
1363 contact_list_store_contact_set_active (data->store,
1368 contact_list_store_contact_active_free (data);
1374 contact_list_store_get_group (EmpathyContactListStore *store,
1376 GtkTreeIter *iter_group_to_set,
1377 GtkTreeIter *iter_separator_to_set,
1379 gboolean is_fake_group)
1381 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1382 GtkTreeModel *model;
1383 GtkTreeIter iter_group;
1384 GtkTreeIter iter_separator;
1387 model = GTK_TREE_MODEL (store);
1388 iter = g_hash_table_lookup (priv->empathy_group_cache, name);
1395 gtk_tree_store_insert_with_values (GTK_TREE_STORE (store), &iter_group, NULL, 0,
1396 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1397 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1398 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1399 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1400 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1401 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, is_fake_group,
1404 g_hash_table_insert (priv->empathy_group_cache,
1405 g_strdup (name), gtk_tree_iter_copy (&iter_group));
1407 if (iter_group_to_set) {
1408 *iter_group_to_set = iter_group;
1411 gtk_tree_store_insert_with_values (GTK_TREE_STORE (store), &iter_separator, &iter_group, 0,
1412 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1415 if (iter_separator_to_set) {
1416 *iter_separator_to_set = iter_separator;
1423 if (iter_group_to_set) {
1424 *iter_group_to_set = *iter;
1427 iter_separator = *iter;
1429 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1430 gboolean is_separator;
1432 gtk_tree_model_get (model, &iter_separator,
1433 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1436 if (is_separator && iter_separator_to_set) {
1437 *iter_separator_to_set = iter_separator;
1444 compare_separator_and_groups (gboolean is_separator_a,
1445 gboolean is_separator_b,
1446 const gchar *name_a,
1447 const gchar *name_b,
1448 EmpathyContact *contact_a,
1449 EmpathyContact *contact_b,
1450 gboolean fake_group_a,
1451 gboolean fake_group_b)
1453 if (is_separator_a || is_separator_b) {
1454 /* We have at least one separator */
1455 if (is_separator_a) {
1457 } else if (is_separator_b) {
1462 /* One group and one contact */
1463 if (!contact_a && contact_b) {
1465 } else if (contact_a && !contact_b) {
1467 } else if (!contact_a && !contact_b) {
1468 return g_utf8_collate (name_a, name_b);
1471 /* Two contacts, ordering depends of the sorting policy */
1476 contact_list_store_contact_sort (EmpathyContact *contact_a,
1477 EmpathyContact *contact_b)
1479 TpAccount *account_a, *account_b;
1482 g_return_val_if_fail (contact_a != NULL || contact_b != NULL, 0);
1485 ret_val = g_utf8_collate (empathy_contact_get_alias (contact_a),
1486 empathy_contact_get_alias (contact_b));
1492 ret_val = g_utf8_collate (empathy_contact_get_id (contact_a),
1493 empathy_contact_get_id (contact_b));
1498 account_a = empathy_contact_get_account (contact_a);
1499 account_b = empathy_contact_get_account (contact_b);
1502 ret_val = strcmp (tp_account_get_protocol (account_a),
1503 tp_account_get_protocol (account_b));
1509 ret_val = strcmp (tp_proxy_get_object_path (account_a),
1510 tp_proxy_get_object_path (account_b));
1517 contact_list_store_state_sort_func (GtkTreeModel *model,
1518 GtkTreeIter *iter_a,
1519 GtkTreeIter *iter_b,
1523 gchar *name_a, *name_b;
1524 gboolean is_separator_a, is_separator_b;
1525 EmpathyContact *contact_a, *contact_b;
1526 gboolean fake_group_a, fake_group_b;
1528 gtk_tree_model_get (model, iter_a,
1529 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1530 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1531 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1532 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_a,
1534 gtk_tree_model_get (model, iter_b,
1535 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1536 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1537 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1538 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_b,
1541 if (contact_a == NULL || contact_b == NULL) {
1542 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1543 name_a, name_b, contact_a, contact_b, fake_group_a, fake_group_b);
1547 /* If we managed to get this far, we can start looking at
1550 ret_val = -tp_connection_presence_type_cmp_availability (
1551 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1552 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1555 /* Fallback: compare by name et al. */
1556 ret_val = contact_list_store_contact_sort (contact_a, contact_b);
1564 g_object_unref (contact_a);
1568 g_object_unref (contact_b);
1575 contact_list_store_name_sort_func (GtkTreeModel *model,
1576 GtkTreeIter *iter_a,
1577 GtkTreeIter *iter_b,
1580 gchar *name_a, *name_b;
1581 EmpathyContact *contact_a, *contact_b;
1582 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1584 gboolean fake_group_a, fake_group_b;
1586 gtk_tree_model_get (model, iter_a,
1587 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1588 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1589 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1590 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_a,
1592 gtk_tree_model_get (model, iter_b,
1593 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1594 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1595 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1596 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_b,
1599 if (contact_a == NULL || contact_b == NULL)
1600 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1601 name_a, name_b, contact_a, contact_b, fake_group_a, fake_group_b);
1603 ret_val = contact_list_store_contact_sort (contact_a, contact_b);
1606 g_object_unref (contact_a);
1610 g_object_unref (contact_b);
1617 contact_list_store_find_contact (EmpathyContactListStore *store,
1618 EmpathyContact *contact)
1620 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1621 GQueue *row_refs_queue;
1623 GList *iters_list = NULL;
1625 row_refs_queue = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1626 if (!row_refs_queue)
1629 for (i = g_queue_peek_head_link (row_refs_queue) ; i != NULL ;
1631 GtkTreeIter *iter = i->data;
1633 iters_list = g_list_prepend
1634 (iters_list, gtk_tree_iter_copy (iter));
1641 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1644 EmpathyContactListStore *store)
1646 EmpathyContactListStorePriv *priv;
1647 gboolean show_avatar = FALSE;
1648 EmpathyContact *contact;
1649 GdkPixbuf *pixbuf_status;
1651 priv = GET_PRIV (store);
1653 if (priv->show_avatars && !priv->is_compact) {
1657 gtk_tree_model_get (model, iter,
1658 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1661 if (contact == NULL){
1664 /* get icon from hash_table */
1665 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1667 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1668 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1669 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1670 EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
1677 contact_list_store_get_contact_status_icon_with_icon_name (
1678 EmpathyContactListStore *store,
1679 EmpathyContact *contact,
1680 const gchar *status_icon_name)
1682 GdkPixbuf *pixbuf_status = NULL;
1683 EmpathyContactListStorePriv *priv;
1684 const gchar *protocol_name = NULL;
1685 gchar *icon_name = NULL;
1687 priv = GET_PRIV (store);
1689 if (priv->show_protocols) {
1690 protocol_name = empathy_protocol_name_for_contact (contact);
1691 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1693 icon_name = g_strdup_printf ("%s", status_icon_name);
1695 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1696 if (pixbuf_status == NULL) {
1697 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1699 priv->show_protocols);
1700 if (pixbuf_status != NULL) {
1701 g_hash_table_insert (priv->status_icons,
1702 g_strdup (icon_name),
1708 return pixbuf_status;
1712 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1713 EmpathyContact *contact)
1715 GdkPixbuf *pixbuf_status = NULL;
1716 EmpathyContactListStorePriv *priv;
1717 const gchar *status_icon_name = NULL;
1718 gboolean composing = FALSE;
1720 priv = GET_PRIV (store);
1722 if (EMPATHY_IS_TP_CHAT (priv->list)) {
1723 if (empathy_tp_chat_get_chat_state (EMPATHY_TP_CHAT (priv->list),
1725 TP_CHANNEL_CHAT_STATE_COMPOSING)
1730 status_icon_name = EMPATHY_IMAGE_TYPING;
1732 status_icon_name = empathy_icon_name_for_contact (contact);
1735 if (status_icon_name == NULL)
1738 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1743 return pixbuf_status;