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>
33 #include <telepathy-glib/util.h>
35 #include <libempathy/empathy-utils.h>
36 #include <libempathy/empathy-enum-types.h>
37 #include <libempathy/empathy-contact-manager.h>
39 #include "empathy-contact-list-store.h"
40 #include "empathy-ui-utils.h"
41 #include "empathy-gtk-enum-types.h"
43 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
44 #include <libempathy/empathy-debug.h>
46 /* Active users are those which have recently changed state
47 * (e.g. online, offline or from normal to a busy state).
50 /* Time in seconds user is shown as active */
51 #define ACTIVE_USER_SHOW_TIME 7
53 /* Time in seconds after connecting which we wait before active users are enabled */
54 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
56 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactListStore)
58 EmpathyContactList *list;
59 gboolean show_offline;
60 gboolean show_avatars;
63 gboolean show_protocols;
65 EmpathyContactListStoreSort sort_criterium;
68 gboolean dispose_has_run;
69 GHashTable *status_icons;
70 } EmpathyContactListStorePriv;
79 EmpathyContact *contact;
85 EmpathyContactListStore *store;
86 EmpathyContact *contact;
90 static void contact_list_store_dispose (GObject *object);
91 static void contact_list_store_get_property (GObject *object,
95 static void contact_list_store_set_property (GObject *object,
99 static void contact_list_store_setup (EmpathyContactListStore *store);
100 static gboolean contact_list_store_inibit_active_cb (EmpathyContactListStore *store);
101 static void contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
102 EmpathyContact *contact,
103 EmpathyContact *actor,
107 EmpathyContactListStore *store);
108 static void contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
109 EmpathyContact *old_contact,
110 EmpathyContact *new_contact,
113 EmpathyContactListStore *store);
114 static void contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
115 EmpathyContact *contact,
118 EmpathyContactListStore *store);
119 static void contact_list_store_add_contact (EmpathyContactListStore *store,
120 EmpathyContact *contact);
121 static void contact_list_store_remove_contact (EmpathyContactListStore *store,
122 EmpathyContact *contact);
123 static void contact_list_store_contact_update (EmpathyContactListStore *store,
124 EmpathyContact *contact);
125 static void contact_list_store_contact_updated_cb (EmpathyContact *contact,
127 EmpathyContactListStore *store);
128 static void contact_list_store_contact_set_active (EmpathyContactListStore *store,
129 EmpathyContact *contact,
131 gboolean set_changed);
132 static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store,
133 EmpathyContact *contact,
135 static void contact_list_store_contact_active_free (ShowActiveData *data);
136 static gboolean contact_list_store_contact_active_cb (ShowActiveData *data);
137 static gboolean contact_list_store_get_group_foreach (GtkTreeModel *model,
141 static void contact_list_store_get_group (EmpathyContactListStore *store,
143 GtkTreeIter *iter_group_to_set,
144 GtkTreeIter *iter_separator_to_set,
146 static gint contact_list_store_state_sort_func (GtkTreeModel *model,
150 static gint contact_list_store_name_sort_func (GtkTreeModel *model,
154 static gboolean contact_list_store_find_contact_foreach (GtkTreeModel *model,
158 static GList * contact_list_store_find_contact (EmpathyContactListStore *store,
159 EmpathyContact *contact);
160 static gboolean contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
163 EmpathyContactListStore *store);
176 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
179 contact_list_store_iface_setup (gpointer user_data)
181 EmpathyContactListStore *store = user_data;
182 EmpathyContactListStorePriv *priv = GET_PRIV (store);
185 /* Signal connection. */
186 g_signal_connect (priv->list,
188 G_CALLBACK (contact_list_store_member_renamed_cb),
190 g_signal_connect (priv->list,
192 G_CALLBACK (contact_list_store_members_changed_cb),
194 g_signal_connect (priv->list,
196 G_CALLBACK (contact_list_store_groups_changed_cb),
199 /* Add contacts already created. */
200 contacts = empathy_contact_list_get_members (priv->list);
201 for (l = contacts; l; l = l->next) {
202 contact_list_store_members_changed_cb (priv->list, l->data,
207 g_object_unref (l->data);
209 g_list_free (contacts);
211 priv->setup_idle_id = 0;
217 contact_list_store_set_contact_list (EmpathyContactListStore *store,
218 EmpathyContactList *list_iface)
220 EmpathyContactListStorePriv *priv = GET_PRIV (store);
222 priv->list = g_object_ref (list_iface);
224 /* Let a chance to have all properties set before populating */
225 priv->setup_idle_id = g_idle_add (contact_list_store_iface_setup, store);
229 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
231 GObjectClass *object_class = G_OBJECT_CLASS (klass);
233 object_class->dispose = contact_list_store_dispose;
234 object_class->get_property = contact_list_store_get_property;
235 object_class->set_property = contact_list_store_set_property;
237 g_object_class_install_property (object_class,
239 g_param_spec_object ("contact-list",
240 "The contact list iface",
241 "The contact list iface",
242 EMPATHY_TYPE_CONTACT_LIST,
243 G_PARAM_CONSTRUCT_ONLY |
245 g_object_class_install_property (object_class,
247 g_param_spec_boolean ("show-offline",
249 "Whether contact list should display "
253 g_object_class_install_property (object_class,
255 g_param_spec_boolean ("show-avatars",
257 "Whether contact list should display "
258 "avatars for contacts",
261 g_object_class_install_property (object_class,
263 g_param_spec_boolean ("show-protocols",
265 "Whether contact list should display "
266 "protocols for contacts",
269 g_object_class_install_property (object_class,
271 g_param_spec_boolean ("show-groups",
273 "Whether contact list should display "
277 g_object_class_install_property (object_class,
279 g_param_spec_boolean ("is-compact",
281 "Whether the contact list is in compact mode or not",
285 g_object_class_install_property (object_class,
287 g_param_spec_enum ("sort-criterium",
289 "The sort criterium to use for sorting the contact list",
290 EMPATHY_TYPE_CONTACT_LIST_STORE_SORT,
291 EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
294 g_type_class_add_private (object_class, sizeof (EmpathyContactListStorePriv));
298 empathy_contact_list_store_init (EmpathyContactListStore *store)
300 EmpathyContactListStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
301 EMPATHY_TYPE_CONTACT_LIST_STORE, EmpathyContactListStorePriv);
304 priv->show_avatars = TRUE;
305 priv->show_groups = TRUE;
306 priv->show_protocols = FALSE;
307 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
308 (GSourceFunc) contact_list_store_inibit_active_cb,
310 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
311 contact_list_store_setup (store);
315 contact_list_store_dispose (GObject *object)
317 EmpathyContactListStorePriv *priv = GET_PRIV (object);
320 if (priv->dispose_has_run)
322 priv->dispose_has_run = TRUE;
324 contacts = empathy_contact_list_get_members (priv->list);
325 for (l = contacts; l; l = l->next) {
326 g_signal_handlers_disconnect_by_func (l->data,
327 G_CALLBACK (contact_list_store_contact_updated_cb),
330 g_object_unref (l->data);
332 g_list_free (contacts);
334 g_signal_handlers_disconnect_by_func (priv->list,
335 G_CALLBACK (contact_list_store_member_renamed_cb),
337 g_signal_handlers_disconnect_by_func (priv->list,
338 G_CALLBACK (contact_list_store_members_changed_cb),
340 g_signal_handlers_disconnect_by_func (priv->list,
341 G_CALLBACK (contact_list_store_groups_changed_cb),
343 g_object_unref (priv->list);
345 if (priv->inhibit_active) {
346 g_source_remove (priv->inhibit_active);
349 if (priv->setup_idle_id != 0) {
350 g_source_remove (priv->setup_idle_id);
353 g_hash_table_destroy (priv->status_icons);
354 G_OBJECT_CLASS (empathy_contact_list_store_parent_class)->dispose (object);
358 contact_list_store_get_property (GObject *object,
363 EmpathyContactListStorePriv *priv;
365 priv = GET_PRIV (object);
368 case PROP_CONTACT_LIST:
369 g_value_set_object (value, priv->list);
371 case PROP_SHOW_OFFLINE:
372 g_value_set_boolean (value, priv->show_offline);
374 case PROP_SHOW_AVATARS:
375 g_value_set_boolean (value, priv->show_avatars);
377 case PROP_SHOW_PROTOCOLS:
378 g_value_set_boolean (value, priv->show_protocols);
380 case PROP_SHOW_GROUPS:
381 g_value_set_boolean (value, priv->show_groups);
383 case PROP_IS_COMPACT:
384 g_value_set_boolean (value, priv->is_compact);
386 case PROP_SORT_CRITERIUM:
387 g_value_set_enum (value, priv->sort_criterium);
390 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
396 contact_list_store_set_property (GObject *object,
401 EmpathyContactListStorePriv *priv;
403 priv = GET_PRIV (object);
406 case PROP_CONTACT_LIST:
407 contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
408 g_value_get_object (value));
410 case PROP_SHOW_OFFLINE:
411 empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
412 g_value_get_boolean (value));
414 case PROP_SHOW_AVATARS:
415 empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
416 g_value_get_boolean (value));
418 case PROP_SHOW_PROTOCOLS:
419 empathy_contact_list_store_set_show_protocols (EMPATHY_CONTACT_LIST_STORE (object),
420 g_value_get_boolean (value));
422 case PROP_SHOW_GROUPS:
423 empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
424 g_value_get_boolean (value));
426 case PROP_IS_COMPACT:
427 empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
428 g_value_get_boolean (value));
430 case PROP_SORT_CRITERIUM:
431 empathy_contact_list_store_set_sort_criterium (EMPATHY_CONTACT_LIST_STORE (object),
432 g_value_get_enum (value));
435 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
440 EmpathyContactListStore *
441 empathy_contact_list_store_new (EmpathyContactList *list_iface)
443 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
445 return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
446 "contact-list", list_iface,
451 empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store)
453 EmpathyContactListStorePriv *priv;
455 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
457 priv = GET_PRIV (store);
463 empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store)
465 EmpathyContactListStorePriv *priv;
467 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
469 priv = GET_PRIV (store);
471 return priv->show_offline;
475 empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
476 gboolean show_offline)
478 EmpathyContactListStorePriv *priv;
480 gboolean show_active;
482 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
484 priv = GET_PRIV (store);
486 priv->show_offline = show_offline;
487 show_active = priv->show_active;
489 /* Disable temporarily. */
490 priv->show_active = FALSE;
492 contacts = empathy_contact_list_get_members (priv->list);
493 for (l = contacts; l; l = l->next) {
494 contact_list_store_contact_update (store, l->data);
496 g_object_unref (l->data);
498 g_list_free (contacts);
500 /* Restore to original setting. */
501 priv->show_active = show_active;
503 g_object_notify (G_OBJECT (store), "show-offline");
507 empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store)
509 EmpathyContactListStorePriv *priv;
511 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
513 priv = GET_PRIV (store);
515 return priv->show_avatars;
519 empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
520 gboolean show_avatars)
522 EmpathyContactListStorePriv *priv;
525 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
527 priv = GET_PRIV (store);
529 priv->show_avatars = show_avatars;
531 model = GTK_TREE_MODEL (store);
533 gtk_tree_model_foreach (model,
534 (GtkTreeModelForeachFunc)
535 contact_list_store_update_list_mode_foreach,
538 g_object_notify (G_OBJECT (store), "show-avatars");
543 empathy_contact_list_store_get_show_protocols (EmpathyContactListStore *store)
545 EmpathyContactListStorePriv *priv;
547 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
549 priv = GET_PRIV (store);
551 return priv->show_protocols;
555 empathy_contact_list_store_set_show_protocols (EmpathyContactListStore *store,
556 gboolean show_protocols)
558 EmpathyContactListStorePriv *priv;
561 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
563 priv = GET_PRIV (store);
565 priv->show_protocols = show_protocols;
567 model = GTK_TREE_MODEL (store);
569 gtk_tree_model_foreach (model,
570 (GtkTreeModelForeachFunc)
571 contact_list_store_update_list_mode_foreach,
574 g_object_notify (G_OBJECT (store), "show-protocols");
578 empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
580 EmpathyContactListStorePriv *priv;
582 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
584 priv = GET_PRIV (store);
586 return priv->show_groups;
590 empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
591 gboolean show_groups)
593 EmpathyContactListStorePriv *priv;
596 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
598 priv = GET_PRIV (store);
600 if (priv->show_groups == show_groups) {
604 priv->show_groups = show_groups;
606 /* Remove all contacts and add them back, not optimized but that's the
608 gtk_tree_store_clear (GTK_TREE_STORE (store));
609 contacts = empathy_contact_list_get_members (priv->list);
610 for (l = contacts; l; l = l->next) {
611 contact_list_store_members_changed_cb (priv->list, l->data,
616 g_object_unref (l->data);
618 g_list_free (contacts);
620 g_object_notify (G_OBJECT (store), "show-groups");
624 empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store)
626 EmpathyContactListStorePriv *priv;
628 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
630 priv = GET_PRIV (store);
632 return priv->is_compact;
636 empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
639 EmpathyContactListStorePriv *priv;
642 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
644 priv = GET_PRIV (store);
646 priv->is_compact = is_compact;
648 model = GTK_TREE_MODEL (store);
650 gtk_tree_model_foreach (model,
651 (GtkTreeModelForeachFunc)
652 contact_list_store_update_list_mode_foreach,
655 g_object_notify (G_OBJECT (store), "is-compact");
658 EmpathyContactListStoreSort
659 empathy_contact_list_store_get_sort_criterium (EmpathyContactListStore *store)
661 EmpathyContactListStorePriv *priv;
663 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), 0);
665 priv = GET_PRIV (store);
667 return priv->sort_criterium;
671 empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *store,
672 EmpathyContactListStoreSort sort_criterium)
674 EmpathyContactListStorePriv *priv;
676 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
678 priv = GET_PRIV (store);
680 priv->sort_criterium = sort_criterium;
682 switch (sort_criterium) {
683 case EMPATHY_CONTACT_LIST_STORE_SORT_STATE:
684 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
685 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
689 case EMPATHY_CONTACT_LIST_STORE_SORT_NAME:
690 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
691 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
696 g_object_notify (G_OBJECT (store), "sort-criterium");
700 empathy_contact_list_store_row_separator_func (GtkTreeModel *model,
704 gboolean is_separator = FALSE;
706 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
708 gtk_tree_model_get (model, iter,
709 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
716 empathy_contact_list_store_get_parent_group (GtkTreeModel *model,
718 gboolean *path_is_group)
720 GtkTreeIter parent_iter, iter;
724 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
727 *path_is_group = FALSE;
730 if (!gtk_tree_model_get_iter (model, &iter, path)) {
734 gtk_tree_model_get (model, &iter,
735 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
736 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
743 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter)) {
749 gtk_tree_model_get (model, &iter,
750 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
751 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
760 *path_is_group = TRUE;
767 empathy_contact_list_store_search_equal_func (GtkTreeModel *model,
771 gpointer search_data)
773 gchar *name, *name_folded;
777 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
783 gtk_tree_model_get (model, iter,
784 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
791 name_folded = g_utf8_casefold (name, -1);
792 key_folded = g_utf8_casefold (key, -1);
794 if (name_folded && key_folded &&
795 strstr (name_folded, key_folded)) {
802 g_free (name_folded);
809 contact_list_store_setup (EmpathyContactListStore *store)
811 EmpathyContactListStorePriv *priv;
813 GDK_TYPE_PIXBUF, /* Status pixbuf */
814 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
815 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
816 G_TYPE_STRING, /* Name */
817 G_TYPE_STRING, /* Status string */
818 G_TYPE_BOOLEAN, /* Show status */
819 EMPATHY_TYPE_CONTACT, /* Contact type */
820 G_TYPE_BOOLEAN, /* Is group */
821 G_TYPE_BOOLEAN, /* Is active */
822 G_TYPE_BOOLEAN, /* Is online */
823 G_TYPE_BOOLEAN, /* Is separator */
824 G_TYPE_BOOLEAN, /* Can make audio calls */
825 G_TYPE_BOOLEAN, /* Can make video calls */
826 EMPATHY_TYPE_CONTACT_LIST_FLAGS, /* Flags */
827 G_TYPE_BOOLEAN, /* Is a favourite */
830 priv = GET_PRIV (store);
832 gtk_tree_store_set_column_types (GTK_TREE_STORE (store),
833 EMPATHY_CONTACT_LIST_STORE_COL_COUNT,
837 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
838 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
839 contact_list_store_name_sort_func,
841 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
842 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
843 contact_list_store_state_sort_func,
846 priv->sort_criterium = EMPATHY_CONTACT_LIST_STORE_SORT_NAME;
847 empathy_contact_list_store_set_sort_criterium (store, priv->sort_criterium);
851 contact_list_store_inibit_active_cb (EmpathyContactListStore *store)
853 EmpathyContactListStorePriv *priv;
855 priv = GET_PRIV (store);
857 priv->show_active = TRUE;
858 priv->inhibit_active = 0;
864 contact_list_store_add_contact_and_connect (EmpathyContactListStore *store, EmpathyContact *contact)
866 g_signal_connect (contact, "notify::presence",
867 G_CALLBACK (contact_list_store_contact_updated_cb),
869 g_signal_connect (contact, "notify::presence-message",
870 G_CALLBACK (contact_list_store_contact_updated_cb),
872 g_signal_connect (contact, "notify::name",
873 G_CALLBACK (contact_list_store_contact_updated_cb),
875 g_signal_connect (contact, "notify::avatar",
876 G_CALLBACK (contact_list_store_contact_updated_cb),
878 g_signal_connect (contact, "notify::capabilities",
879 G_CALLBACK (contact_list_store_contact_updated_cb),
882 contact_list_store_add_contact (store, contact);
886 contact_list_store_remove_contact_and_disconnect (EmpathyContactListStore *store, EmpathyContact *contact)
888 g_signal_handlers_disconnect_by_func (contact,
889 G_CALLBACK (contact_list_store_contact_updated_cb),
892 contact_list_store_remove_contact (store, contact);
896 contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
897 EmpathyContact *contact,
898 EmpathyContact *actor,
902 EmpathyContactListStore *store)
904 EmpathyContactListStorePriv *priv;
906 priv = GET_PRIV (store);
908 DEBUG ("Contact %s (%d) %s",
909 empathy_contact_get_id (contact),
910 empathy_contact_get_handle (contact),
911 is_member ? "added" : "removed");
914 contact_list_store_add_contact_and_connect (store, contact);
916 contact_list_store_remove_contact_and_disconnect (store, contact);
921 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
922 EmpathyContact *old_contact,
923 EmpathyContact *new_contact,
926 EmpathyContactListStore *store)
928 EmpathyContactListStorePriv *priv;
930 priv = GET_PRIV (store);
932 DEBUG ("Contact %s (%d) renamed to %s (%d)",
933 empathy_contact_get_id (old_contact),
934 empathy_contact_get_handle (old_contact),
935 empathy_contact_get_id (new_contact),
936 empathy_contact_get_handle (new_contact));
938 /* add the new contact */
939 contact_list_store_add_contact_and_connect (store, new_contact);
941 /* remove old contact */
942 contact_list_store_remove_contact_and_disconnect (store, old_contact);
946 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
947 EmpathyContact *contact,
950 EmpathyContactListStore *store)
952 EmpathyContactListStorePriv *priv;
953 gboolean show_active;
955 priv = GET_PRIV (store);
957 DEBUG ("Updating groups for contact %s (%d)",
958 empathy_contact_get_id (contact),
959 empathy_contact_get_handle (contact));
961 /* We do this to make sure the groups are correct, if not, we
962 * would have to check the groups already set up for each
963 * contact and then see what has been updated.
965 show_active = priv->show_active;
966 priv->show_active = FALSE;
967 contact_list_store_remove_contact (store, contact);
968 contact_list_store_add_contact (store, contact);
969 priv->show_active = show_active;
973 contact_list_store_add_contact (EmpathyContactListStore *store,
974 EmpathyContact *contact)
976 EmpathyContactListStorePriv *priv;
978 GList *groups = NULL, *l;
979 TpConnection *connection;
980 EmpathyContactListFlags flags = 0;
982 priv = GET_PRIV (store);
984 if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
985 (!priv->show_offline && !empathy_contact_is_online (contact))) {
989 if (priv->show_groups) {
990 groups = empathy_contact_list_get_groups (priv->list, contact);
993 connection = empathy_contact_get_connection (contact);
994 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
995 flags = empathy_contact_manager_get_flags_for_connection (
996 EMPATHY_CONTACT_MANAGER (priv->list), connection);
998 /* If no groups just add it at the top level. */
1000 GtkTreeModel *model = GTK_TREE_MODEL (store);
1002 if (gtk_tree_model_get_iter_first (model, &iter)) do {
1005 gtk_tree_model_get (model, &iter,
1006 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
1015 } while (gtk_tree_model_iter_next (model, &iter));
1017 gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
1018 gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
1019 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1020 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1021 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1022 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1023 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1024 empathy_contact_get_capabilities (contact) &
1025 EMPATHY_CAPABILITIES_AUDIO,
1026 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1027 empathy_contact_get_capabilities (contact) &
1028 EMPATHY_CAPABILITIES_VIDEO,
1029 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1033 /* Else add to each group. */
1034 for (l = groups; l; l = l->next) {
1035 GtkTreeIter iter_group;
1037 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);
1039 gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
1041 gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
1042 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1043 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1044 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1045 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1046 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1047 empathy_contact_get_capabilities (contact) &
1048 EMPATHY_CAPABILITIES_AUDIO,
1049 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1050 empathy_contact_get_capabilities (contact) &
1051 EMPATHY_CAPABILITIES_VIDEO,
1052 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1056 g_list_free (groups);
1058 contact_list_store_contact_update (store, contact);
1063 contact_list_store_remove_contact (EmpathyContactListStore *store,
1064 EmpathyContact *contact)
1066 EmpathyContactListStorePriv *priv;
1067 GtkTreeModel *model;
1070 priv = GET_PRIV (store);
1072 iters = contact_list_store_find_contact (store, contact);
1077 /* Clean up model */
1078 model = GTK_TREE_MODEL (store);
1080 for (l = iters; l; l = l->next) {
1083 /* NOTE: it is only <= 2 here because we have
1084 * separators after the group name, otherwise it
1087 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
1088 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1089 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1091 gtk_tree_store_remove (GTK_TREE_STORE (store), l->data);
1095 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1096 g_list_free (iters);
1100 list_store_contact_is_favourite (EmpathyContactListStore *store,
1101 EmpathyContact *contact)
1103 EmpathyContactListStorePriv *priv;
1105 priv = GET_PRIV (store);
1107 return empathy_contact_list_contact_is_favourite (priv->list, contact);
1111 contact_list_store_contact_update (EmpathyContactListStore *store,
1112 EmpathyContact *contact)
1114 EmpathyContactListStorePriv *priv;
1115 ShowActiveData *data;
1116 GtkTreeModel *model;
1119 gboolean should_be_in_list;
1120 gboolean was_online = TRUE;
1121 gboolean now_online = FALSE;
1122 gboolean set_model = FALSE;
1123 gboolean do_remove = FALSE;
1124 gboolean do_set_active = FALSE;
1125 gboolean do_set_refresh = FALSE;
1126 gboolean show_avatar = FALSE;
1127 GdkPixbuf *pixbuf_avatar;
1128 GdkPixbuf *pixbuf_status;
1130 priv = GET_PRIV (store);
1132 model = GTK_TREE_MODEL (store);
1134 iters = contact_list_store_find_contact (store, contact);
1141 /* Get online state now. */
1142 now_online = empathy_contact_is_online (contact);
1144 if (priv->show_offline || now_online) {
1145 should_be_in_list = TRUE;
1147 should_be_in_list = FALSE;
1150 if (!in_list && !should_be_in_list) {
1151 /* Nothing to do. */
1152 DEBUG ("Contact:'%s' in list:NO, should be:NO",
1153 empathy_contact_get_name (contact));
1155 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1156 g_list_free (iters);
1159 else if (in_list && !should_be_in_list) {
1160 DEBUG ("Contact:'%s' in list:YES, should be:NO",
1161 empathy_contact_get_name (contact));
1163 if (priv->show_active) {
1165 do_set_active = TRUE;
1166 do_set_refresh = TRUE;
1169 DEBUG ("Remove item (after timeout)");
1171 DEBUG ("Remove item (now)!");
1172 contact_list_store_remove_contact (store, contact);
1175 else if (!in_list && should_be_in_list) {
1176 DEBUG ("Contact:'%s' in list:NO, should be:YES",
1177 empathy_contact_get_name (contact));
1179 contact_list_store_add_contact (store, contact);
1181 if (priv->show_active) {
1182 do_set_active = TRUE;
1184 DEBUG ("Set active (contact added)");
1187 DEBUG ("Contact:'%s' in list:YES, should be:YES",
1188 empathy_contact_get_name (contact));
1190 /* Get online state before. */
1191 if (iters && g_list_length (iters) > 0) {
1192 gtk_tree_model_get (model, iters->data,
1193 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online,
1197 /* Is this really an update or an online/offline. */
1198 if (priv->show_active) {
1199 if (was_online != now_online) {
1200 do_set_active = TRUE;
1201 do_set_refresh = TRUE;
1203 DEBUG ("Set active (contact updated %s)",
1204 was_online ? "online -> offline" :
1205 "offline -> online");
1207 /* Was TRUE for presence updates. */
1208 /* do_set_active = FALSE; */
1209 do_set_refresh = TRUE;
1211 DEBUG ("Set active (contact updated)");
1218 if (priv->show_avatars && !priv->is_compact) {
1221 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
1222 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1223 for (l = iters; l && set_model; l = l->next) {
1224 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1225 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, list_store_contact_is_favourite (store, contact),
1226 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1227 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1228 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1229 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1230 EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact),
1231 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1232 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1233 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1234 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1235 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1236 empathy_contact_get_capabilities (contact) &
1237 EMPATHY_CAPABILITIES_AUDIO,
1238 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1239 empathy_contact_get_capabilities (contact) &
1240 EMPATHY_CAPABILITIES_VIDEO,
1244 if (pixbuf_avatar) {
1245 g_object_unref (pixbuf_avatar);
1248 if (priv->show_active && do_set_active) {
1249 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1251 if (do_set_active) {
1252 data = contact_list_store_contact_active_new (store, contact, do_remove);
1253 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1254 (GSourceFunc) contact_list_store_contact_active_cb,
1259 /* FIXME: when someone goes online then offline quickly, the
1260 * first timeout sets the user to be inactive and the second
1261 * timeout removes the user from the contact list, really we
1262 * should remove the first timeout.
1264 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1265 g_list_free (iters);
1269 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1271 EmpathyContactListStore *store)
1273 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1274 empathy_contact_get_name (contact));
1276 contact_list_store_contact_update (store, contact);
1280 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1281 EmpathyContact *contact,
1283 gboolean set_changed)
1285 EmpathyContactListStorePriv *priv;
1286 GtkTreeModel *model;
1289 priv = GET_PRIV (store);
1290 model = GTK_TREE_MODEL (store);
1292 iters = contact_list_store_find_contact (store, contact);
1293 for (l = iters; l; l = l->next) {
1296 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1297 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, active,
1300 DEBUG ("Set item %s", active ? "active" : "inactive");
1303 path = gtk_tree_model_get_path (model, l->data);
1304 gtk_tree_model_row_changed (model, path, l->data);
1305 gtk_tree_path_free (path);
1309 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1310 g_list_free (iters);
1314 static ShowActiveData *
1315 contact_list_store_contact_active_new (EmpathyContactListStore *store,
1316 EmpathyContact *contact,
1319 ShowActiveData *data;
1321 DEBUG ("Contact:'%s' now active, and %s be removed",
1322 empathy_contact_get_name (contact),
1323 remove_ ? "WILL" : "WILL NOT");
1325 data = g_slice_new0 (ShowActiveData);
1327 data->store = g_object_ref (store);
1328 data->contact = g_object_ref (contact);
1329 data->remove = remove_;
1335 contact_list_store_contact_active_free (ShowActiveData *data)
1337 g_object_unref (data->contact);
1338 g_object_unref (data->store);
1340 g_slice_free (ShowActiveData, data);
1344 contact_list_store_contact_active_cb (ShowActiveData *data)
1346 EmpathyContactListStorePriv *priv;
1348 priv = GET_PRIV (data->store);
1351 !priv->show_offline &&
1352 !empathy_contact_is_online (data->contact)) {
1353 DEBUG ("Contact:'%s' active timeout, removing item",
1354 empathy_contact_get_name (data->contact));
1355 contact_list_store_remove_contact (data->store, data->contact);
1358 DEBUG ("Contact:'%s' no longer active",
1359 empathy_contact_get_name (data->contact));
1361 contact_list_store_contact_set_active (data->store,
1366 contact_list_store_contact_active_free (data);
1372 contact_list_store_get_group_foreach (GtkTreeModel *model,
1380 /* Groups are only at the top level. */
1381 if (gtk_tree_path_get_depth (path) != 1) {
1385 gtk_tree_model_get (model, iter,
1386 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &str,
1387 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1390 if (is_group && !tp_strdiff (str, fg->name)) {
1401 contact_list_store_get_group (EmpathyContactListStore *store,
1403 GtkTreeIter *iter_group_to_set,
1404 GtkTreeIter *iter_separator_to_set,
1407 EmpathyContactListStorePriv *priv;
1408 GtkTreeModel *model;
1409 GtkTreeIter iter_group;
1410 GtkTreeIter iter_separator;
1413 priv = GET_PRIV (store);
1415 memset (&fg, 0, sizeof (fg));
1419 model = GTK_TREE_MODEL (store);
1420 gtk_tree_model_foreach (model,
1421 (GtkTreeModelForeachFunc) contact_list_store_get_group_foreach,
1429 gtk_tree_store_append (GTK_TREE_STORE (store), &iter_group, NULL);
1430 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_group,
1431 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1432 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1433 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1434 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1435 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1438 if (iter_group_to_set) {
1439 *iter_group_to_set = iter_group;
1442 gtk_tree_store_append (GTK_TREE_STORE (store),
1445 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_separator,
1446 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1449 #if HAVE_FAVOURITE_CONTACTS
1450 /* add a second separator for the favourite contacts group, to
1451 * always be sorted at the end. This will provide a visual
1452 * distinction between the end of the favourites and the
1453 * beginning of the ungrouped contacts */
1454 if (!g_strcmp0 (name, EMPATHY_GROUP_FAVOURITES)) {
1455 gtk_tree_store_append (GTK_TREE_STORE (store),
1458 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_separator,
1459 EMPATHY_CONTACT_LIST_STORE_COL_NAME, EMPATHY_GROUP_FAVOURITES,
1460 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1463 #endif /* HAVE_FAVOURITE_CONTACTS */
1465 if (iter_separator_to_set) {
1466 *iter_separator_to_set = iter_separator;
1473 if (iter_group_to_set) {
1474 *iter_group_to_set = fg.iter;
1477 iter_separator = fg.iter;
1479 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1480 gboolean is_separator;
1482 gtk_tree_model_get (model, &iter_separator,
1483 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1486 if (is_separator && iter_separator_to_set) {
1487 *iter_separator_to_set = iter_separator;
1494 contact_list_store_state_sort_func (GtkTreeModel *model,
1495 GtkTreeIter *iter_a,
1496 GtkTreeIter *iter_b,
1500 gchar *name_a, *name_b;
1501 gboolean is_separator_a, is_separator_b;
1502 EmpathyContact *contact_a, *contact_b;
1504 gtk_tree_model_get (model, iter_a,
1505 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1506 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1507 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1509 gtk_tree_model_get (model, iter_b,
1510 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1511 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1512 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1515 /* Separator, favourites group, or other group? */
1516 if (is_separator_a || is_separator_b) {
1517 if (is_separator_a) {
1518 #if HAVE_FAVOURITE_CONTACTS
1519 /* sort the special favourites group 2nd separator at
1521 if (!g_strcmp0 (name_a, EMPATHY_GROUP_FAVOURITES)) {
1528 #endif /* HAVE_FAVOURITE_CONTACTS */
1529 } else if (is_separator_b) {
1530 #if HAVE_FAVOURITE_CONTACTS
1531 if (!g_strcmp0 (name_b, EMPATHY_GROUP_FAVOURITES)) {
1538 #endif /* HAVE_FAVOURITE_CONTACTS */
1540 #if HAVE_FAVOURITE_CONTACTS
1541 } else if (!contact_a && !g_strcmp0 (name_a,
1542 EMPATHY_GROUP_FAVOURITES)) {
1544 } else if (!contact_b && !g_strcmp0 (name_b,
1545 EMPATHY_GROUP_FAVOURITES)) {
1547 #endif /* HAVE_FAVOURITE_CONTACTS */
1548 } else if (!contact_a && contact_b) {
1550 } else if (contact_a && !contact_b) {
1552 } else if (!contact_a && !contact_b) {
1554 ret_val = g_utf8_collate (name_a, name_b);
1561 /* If we managed to get this far, we can start looking at
1564 ret_val = -tp_connection_presence_type_cmp_availability (
1565 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1566 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1569 /* Fallback: compare by name */
1570 ret_val = g_utf8_collate (name_a, name_b);
1578 g_object_unref (contact_a);
1582 g_object_unref (contact_b);
1589 contact_list_store_name_sort_func (GtkTreeModel *model,
1590 GtkTreeIter *iter_a,
1591 GtkTreeIter *iter_b,
1594 gchar *name_a, *name_b;
1595 EmpathyContact *contact_a, *contact_b;
1596 gboolean is_separator_a, is_separator_b;
1599 gtk_tree_model_get (model, iter_a,
1600 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1601 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1602 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1604 gtk_tree_model_get (model, iter_b,
1605 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1606 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1607 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1610 /* If contact is NULL it means it's a group. */
1612 if (is_separator_a || is_separator_b) {
1613 if (is_separator_a) {
1614 #if HAVE_FAVOURITE_CONTACTS
1615 /* sort the special favourites group 2nd separator at
1617 if (!g_strcmp0 (name_a, EMPATHY_GROUP_FAVOURITES)) {
1624 #endif /* HAVE_FAVOURITE_CONTACTS */
1625 } else if (is_separator_b) {
1626 #if HAVE_FAVOURITE_CONTACTS
1627 if (!g_strcmp0 (name_b, EMPATHY_GROUP_FAVOURITES)) {
1634 #endif /* HAVE_FAVOURITE_CONTACTS */
1636 #if HAVE_FAVOURITE_CONTACTS
1637 } else if (!contact_a && !g_strcmp0 (name_a,
1638 EMPATHY_GROUP_FAVOURITES)) {
1640 } else if (!contact_b && !g_strcmp0 (name_b,
1641 EMPATHY_GROUP_FAVOURITES)) {
1643 #endif /* HAVE_FAVOURITE_CONTACTS */
1644 } else if (!contact_a && contact_b) {
1646 } else if (contact_a && !contact_b) {
1649 ret_val = g_utf8_collate (name_a, name_b);
1656 g_object_unref (contact_a);
1660 g_object_unref (contact_b);
1667 contact_list_store_find_contact_foreach (GtkTreeModel *model,
1672 EmpathyContact *contact;
1674 gtk_tree_model_get (model, iter,
1675 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1678 if (contact == fc->contact) {
1680 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
1684 g_object_unref (contact);
1691 contact_list_store_find_contact (EmpathyContactListStore *store,
1692 EmpathyContact *contact)
1694 EmpathyContactListStorePriv *priv;
1695 GtkTreeModel *model;
1699 priv = GET_PRIV (store);
1701 memset (&fc, 0, sizeof (fc));
1703 fc.contact = contact;
1705 model = GTK_TREE_MODEL (store);
1706 gtk_tree_model_foreach (model,
1707 (GtkTreeModelForeachFunc) contact_list_store_find_contact_foreach,
1718 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1721 EmpathyContactListStore *store)
1723 EmpathyContactListStorePriv *priv;
1724 gboolean show_avatar = FALSE;
1725 EmpathyContact *contact;
1726 GdkPixbuf *pixbuf_status;
1728 priv = GET_PRIV (store);
1730 if (priv->show_avatars && !priv->is_compact) {
1734 gtk_tree_model_get (model, iter,
1735 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1738 if (contact == NULL){
1741 /* get icon from hash_table */
1742 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1744 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1745 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1746 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1747 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1754 contact_list_store_get_contact_status_icon_with_icon_name (
1755 EmpathyContactListStore *store,
1756 EmpathyContact *contact,
1757 const gchar *status_icon_name)
1759 GdkPixbuf *pixbuf_status = NULL;
1760 EmpathyContactListStorePriv *priv;
1761 const gchar *protocol_name = NULL;
1762 gchar *icon_name = NULL;
1764 priv = GET_PRIV (store);
1766 if (priv->show_protocols) {
1767 protocol_name = empathy_protocol_name_for_contact (contact);
1768 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1770 icon_name = g_strdup_printf ("%s", status_icon_name);
1772 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1773 if (pixbuf_status == NULL) {
1774 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1776 priv->show_protocols);
1777 if (pixbuf_status != NULL) {
1778 g_hash_table_insert (priv->status_icons,
1779 g_strdup (icon_name),
1785 return pixbuf_status;
1789 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1790 EmpathyContact *contact)
1792 GdkPixbuf *pixbuf_status = NULL;
1793 const gchar *status_icon_name = NULL;
1795 status_icon_name = empathy_icon_name_for_contact (contact);
1796 if (status_icon_name == NULL)
1799 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1804 return pixbuf_status;