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-enum-types.h>
38 #include <libempathy/empathy-contact-manager.h>
40 #include "empathy-contact-list-store.h"
41 #include "empathy-ui-utils.h"
42 #include "empathy-gtk-enum-types.h"
44 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
45 #include <libempathy/empathy-debug.h>
47 /* Active users are those which have recently changed state
48 * (e.g. online, offline or from normal to a busy state).
51 /* Time in seconds user is shown as active */
52 #define ACTIVE_USER_SHOW_TIME 7
54 /* Time in seconds after connecting which we wait before active users are enabled */
55 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
57 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactListStore)
59 EmpathyContactList *list;
60 gboolean show_offline;
61 gboolean show_avatars;
64 gboolean show_protocols;
66 EmpathyContactListStoreSort sort_criterium;
69 gboolean dispose_has_run;
70 GHashTable *status_icons;
71 } EmpathyContactListStorePriv;
80 EmpathyContact *contact;
86 EmpathyContactListStore *store;
87 EmpathyContact *contact;
91 static void contact_list_store_dispose (GObject *object);
92 static void contact_list_store_get_property (GObject *object,
96 static void contact_list_store_set_property (GObject *object,
100 static void contact_list_store_setup (EmpathyContactListStore *store);
101 static gboolean contact_list_store_inibit_active_cb (EmpathyContactListStore *store);
102 static void contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
103 EmpathyContact *contact,
104 EmpathyContact *actor,
108 EmpathyContactListStore *store);
109 static void contact_list_store_favourites_changed_cb (EmpathyContactList *list_iface,
110 EmpathyContact *contact,
111 gboolean is_favourite,
112 EmpathyContactListStore *store);
113 static void contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
114 EmpathyContact *old_contact,
115 EmpathyContact *new_contact,
118 EmpathyContactListStore *store);
119 static void contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
120 EmpathyContact *contact,
123 EmpathyContactListStore *store);
124 static void contact_list_store_add_contact (EmpathyContactListStore *store,
125 EmpathyContact *contact);
126 static void contact_list_store_remove_contact (EmpathyContactListStore *store,
127 EmpathyContact *contact);
128 static void contact_list_store_contact_update (EmpathyContactListStore *store,
129 EmpathyContact *contact);
130 static void contact_list_store_contact_updated_cb (EmpathyContact *contact,
132 EmpathyContactListStore *store);
133 static void contact_list_store_contact_set_active (EmpathyContactListStore *store,
134 EmpathyContact *contact,
136 gboolean set_changed);
137 static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store,
138 EmpathyContact *contact,
140 static void contact_list_store_contact_active_free (ShowActiveData *data);
141 static gboolean contact_list_store_contact_active_cb (ShowActiveData *data);
142 static gboolean contact_list_store_get_group_foreach (GtkTreeModel *model,
146 static void contact_list_store_get_group (EmpathyContactListStore *store,
148 GtkTreeIter *iter_group_to_set,
149 GtkTreeIter *iter_separator_to_set,
151 static gint contact_list_store_state_sort_func (GtkTreeModel *model,
155 static gint contact_list_store_name_sort_func (GtkTreeModel *model,
159 static gboolean contact_list_store_find_contact_foreach (GtkTreeModel *model,
163 static GList * contact_list_store_find_contact (EmpathyContactListStore *store,
164 EmpathyContact *contact);
165 static gboolean contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
168 EmpathyContactListStore *store);
181 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
184 contact_list_store_iface_setup (gpointer user_data)
186 EmpathyContactListStore *store = user_data;
187 EmpathyContactListStorePriv *priv = GET_PRIV (store);
190 /* Signal connection. */
191 g_signal_connect (priv->list,
193 G_CALLBACK (contact_list_store_member_renamed_cb),
195 g_signal_connect (priv->list,
197 G_CALLBACK (contact_list_store_members_changed_cb),
199 g_signal_connect (priv->list,
200 "favourites-changed",
201 G_CALLBACK (contact_list_store_favourites_changed_cb),
203 g_signal_connect (priv->list,
205 G_CALLBACK (contact_list_store_groups_changed_cb),
208 /* Add contacts already created. */
209 contacts = empathy_contact_list_get_members (priv->list);
210 for (l = contacts; l; l = l->next) {
211 contact_list_store_members_changed_cb (priv->list, l->data,
216 g_object_unref (l->data);
218 g_list_free (contacts);
220 priv->setup_idle_id = 0;
226 contact_list_store_set_contact_list (EmpathyContactListStore *store,
227 EmpathyContactList *list_iface)
229 EmpathyContactListStorePriv *priv = GET_PRIV (store);
231 priv->list = g_object_ref (list_iface);
233 /* Let a chance to have all properties set before populating */
234 priv->setup_idle_id = g_idle_add (contact_list_store_iface_setup, store);
238 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
240 GObjectClass *object_class = G_OBJECT_CLASS (klass);
242 object_class->dispose = contact_list_store_dispose;
243 object_class->get_property = contact_list_store_get_property;
244 object_class->set_property = contact_list_store_set_property;
246 g_object_class_install_property (object_class,
248 g_param_spec_object ("contact-list",
249 "The contact list iface",
250 "The contact list iface",
251 EMPATHY_TYPE_CONTACT_LIST,
252 G_PARAM_CONSTRUCT_ONLY |
254 g_object_class_install_property (object_class,
256 g_param_spec_boolean ("show-offline",
258 "Whether contact list should display "
262 g_object_class_install_property (object_class,
264 g_param_spec_boolean ("show-avatars",
266 "Whether contact list should display "
267 "avatars for contacts",
270 g_object_class_install_property (object_class,
272 g_param_spec_boolean ("show-protocols",
274 "Whether contact list should display "
275 "protocols for contacts",
278 g_object_class_install_property (object_class,
280 g_param_spec_boolean ("show-groups",
282 "Whether contact list should display "
286 g_object_class_install_property (object_class,
288 g_param_spec_boolean ("is-compact",
290 "Whether the contact list is in compact mode or not",
294 g_object_class_install_property (object_class,
296 g_param_spec_enum ("sort-criterium",
298 "The sort criterium to use for sorting the contact list",
299 EMPATHY_TYPE_CONTACT_LIST_STORE_SORT,
300 EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
303 g_type_class_add_private (object_class, sizeof (EmpathyContactListStorePriv));
307 empathy_contact_list_store_init (EmpathyContactListStore *store)
309 EmpathyContactListStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
310 EMPATHY_TYPE_CONTACT_LIST_STORE, EmpathyContactListStorePriv);
313 priv->show_avatars = TRUE;
314 priv->show_groups = TRUE;
315 priv->show_protocols = FALSE;
316 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
317 (GSourceFunc) contact_list_store_inibit_active_cb,
319 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
320 contact_list_store_setup (store);
324 contact_list_store_dispose (GObject *object)
326 EmpathyContactListStorePriv *priv = GET_PRIV (object);
329 if (priv->dispose_has_run)
331 priv->dispose_has_run = TRUE;
333 contacts = empathy_contact_list_get_members (priv->list);
334 for (l = contacts; l; l = l->next) {
335 g_signal_handlers_disconnect_by_func (l->data,
336 G_CALLBACK (contact_list_store_contact_updated_cb),
339 g_object_unref (l->data);
341 g_list_free (contacts);
343 g_signal_handlers_disconnect_by_func (priv->list,
344 G_CALLBACK (contact_list_store_member_renamed_cb),
346 g_signal_handlers_disconnect_by_func (priv->list,
347 G_CALLBACK (contact_list_store_members_changed_cb),
349 g_signal_handlers_disconnect_by_func (priv->list,
350 G_CALLBACK (contact_list_store_favourites_changed_cb),
352 g_signal_handlers_disconnect_by_func (priv->list,
353 G_CALLBACK (contact_list_store_groups_changed_cb),
355 g_object_unref (priv->list);
357 if (priv->inhibit_active) {
358 g_source_remove (priv->inhibit_active);
361 if (priv->setup_idle_id != 0) {
362 g_source_remove (priv->setup_idle_id);
365 g_hash_table_destroy (priv->status_icons);
366 G_OBJECT_CLASS (empathy_contact_list_store_parent_class)->dispose (object);
370 contact_list_store_get_property (GObject *object,
375 EmpathyContactListStorePriv *priv;
377 priv = GET_PRIV (object);
380 case PROP_CONTACT_LIST:
381 g_value_set_object (value, priv->list);
383 case PROP_SHOW_OFFLINE:
384 g_value_set_boolean (value, priv->show_offline);
386 case PROP_SHOW_AVATARS:
387 g_value_set_boolean (value, priv->show_avatars);
389 case PROP_SHOW_PROTOCOLS:
390 g_value_set_boolean (value, priv->show_protocols);
392 case PROP_SHOW_GROUPS:
393 g_value_set_boolean (value, priv->show_groups);
395 case PROP_IS_COMPACT:
396 g_value_set_boolean (value, priv->is_compact);
398 case PROP_SORT_CRITERIUM:
399 g_value_set_enum (value, priv->sort_criterium);
402 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
408 contact_list_store_set_property (GObject *object,
413 EmpathyContactListStorePriv *priv;
415 priv = GET_PRIV (object);
418 case PROP_CONTACT_LIST:
419 contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
420 g_value_get_object (value));
422 case PROP_SHOW_OFFLINE:
423 empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
424 g_value_get_boolean (value));
426 case PROP_SHOW_AVATARS:
427 empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
428 g_value_get_boolean (value));
430 case PROP_SHOW_PROTOCOLS:
431 empathy_contact_list_store_set_show_protocols (EMPATHY_CONTACT_LIST_STORE (object),
432 g_value_get_boolean (value));
434 case PROP_SHOW_GROUPS:
435 empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
436 g_value_get_boolean (value));
438 case PROP_IS_COMPACT:
439 empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
440 g_value_get_boolean (value));
442 case PROP_SORT_CRITERIUM:
443 empathy_contact_list_store_set_sort_criterium (EMPATHY_CONTACT_LIST_STORE (object),
444 g_value_get_enum (value));
447 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
452 EmpathyContactListStore *
453 empathy_contact_list_store_new (EmpathyContactList *list_iface)
455 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
457 return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
458 "contact-list", list_iface,
463 empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store)
465 EmpathyContactListStorePriv *priv;
467 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
469 priv = GET_PRIV (store);
475 empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store)
477 EmpathyContactListStorePriv *priv;
479 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
481 priv = GET_PRIV (store);
483 return priv->show_offline;
487 empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
488 gboolean show_offline)
490 EmpathyContactListStorePriv *priv;
492 gboolean show_active;
494 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
496 priv = GET_PRIV (store);
498 priv->show_offline = show_offline;
499 show_active = priv->show_active;
501 /* Disable temporarily. */
502 priv->show_active = FALSE;
504 contacts = empathy_contact_list_get_members (priv->list);
505 for (l = contacts; l; l = l->next) {
506 contact_list_store_contact_update (store, l->data);
508 g_object_unref (l->data);
510 g_list_free (contacts);
512 /* Restore to original setting. */
513 priv->show_active = show_active;
515 g_object_notify (G_OBJECT (store), "show-offline");
519 empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store)
521 EmpathyContactListStorePriv *priv;
523 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
525 priv = GET_PRIV (store);
527 return priv->show_avatars;
531 empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
532 gboolean show_avatars)
534 EmpathyContactListStorePriv *priv;
537 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
539 priv = GET_PRIV (store);
541 priv->show_avatars = show_avatars;
543 model = GTK_TREE_MODEL (store);
545 gtk_tree_model_foreach (model,
546 (GtkTreeModelForeachFunc)
547 contact_list_store_update_list_mode_foreach,
550 g_object_notify (G_OBJECT (store), "show-avatars");
555 empathy_contact_list_store_get_show_protocols (EmpathyContactListStore *store)
557 EmpathyContactListStorePriv *priv;
559 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
561 priv = GET_PRIV (store);
563 return priv->show_protocols;
567 empathy_contact_list_store_set_show_protocols (EmpathyContactListStore *store,
568 gboolean show_protocols)
570 EmpathyContactListStorePriv *priv;
573 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
575 priv = GET_PRIV (store);
577 priv->show_protocols = show_protocols;
579 model = GTK_TREE_MODEL (store);
581 gtk_tree_model_foreach (model,
582 (GtkTreeModelForeachFunc)
583 contact_list_store_update_list_mode_foreach,
586 g_object_notify (G_OBJECT (store), "show-protocols");
590 empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
592 EmpathyContactListStorePriv *priv;
594 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
596 priv = GET_PRIV (store);
598 return priv->show_groups;
602 empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
603 gboolean show_groups)
605 EmpathyContactListStorePriv *priv;
608 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
610 priv = GET_PRIV (store);
612 if (priv->show_groups == show_groups) {
616 priv->show_groups = show_groups;
618 /* Remove all contacts and add them back, not optimized but that's the
620 gtk_tree_store_clear (GTK_TREE_STORE (store));
621 contacts = empathy_contact_list_get_members (priv->list);
622 for (l = contacts; l; l = l->next) {
623 contact_list_store_members_changed_cb (priv->list, l->data,
628 g_object_unref (l->data);
630 g_list_free (contacts);
632 g_object_notify (G_OBJECT (store), "show-groups");
636 empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store)
638 EmpathyContactListStorePriv *priv;
640 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
642 priv = GET_PRIV (store);
644 return priv->is_compact;
648 empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
651 EmpathyContactListStorePriv *priv;
654 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
656 priv = GET_PRIV (store);
658 priv->is_compact = is_compact;
660 model = GTK_TREE_MODEL (store);
662 gtk_tree_model_foreach (model,
663 (GtkTreeModelForeachFunc)
664 contact_list_store_update_list_mode_foreach,
667 g_object_notify (G_OBJECT (store), "is-compact");
670 EmpathyContactListStoreSort
671 empathy_contact_list_store_get_sort_criterium (EmpathyContactListStore *store)
673 EmpathyContactListStorePriv *priv;
675 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), 0);
677 priv = GET_PRIV (store);
679 return priv->sort_criterium;
683 empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *store,
684 EmpathyContactListStoreSort sort_criterium)
686 EmpathyContactListStorePriv *priv;
688 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
690 priv = GET_PRIV (store);
692 priv->sort_criterium = sort_criterium;
694 switch (sort_criterium) {
695 case EMPATHY_CONTACT_LIST_STORE_SORT_STATE:
696 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
697 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
701 case EMPATHY_CONTACT_LIST_STORE_SORT_NAME:
702 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
703 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
708 g_object_notify (G_OBJECT (store), "sort-criterium");
712 empathy_contact_list_store_row_separator_func (GtkTreeModel *model,
716 gboolean is_separator = FALSE;
718 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
720 gtk_tree_model_get (model, iter,
721 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
728 empathy_contact_list_store_get_parent_group (GtkTreeModel *model,
730 gboolean *path_is_group)
732 GtkTreeIter parent_iter, iter;
736 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
739 *path_is_group = FALSE;
742 if (!gtk_tree_model_get_iter (model, &iter, path)) {
746 gtk_tree_model_get (model, &iter,
747 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
748 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
755 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter)) {
761 gtk_tree_model_get (model, &iter,
762 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
763 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
772 *path_is_group = TRUE;
779 empathy_contact_list_store_search_equal_func (GtkTreeModel *model,
783 gpointer search_data)
785 gchar *name, *name_folded;
789 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
795 gtk_tree_model_get (model, iter,
796 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
803 name_folded = g_utf8_casefold (name, -1);
804 key_folded = g_utf8_casefold (key, -1);
806 if (name_folded && key_folded &&
807 strstr (name_folded, key_folded)) {
814 g_free (name_folded);
821 contact_list_store_setup (EmpathyContactListStore *store)
823 EmpathyContactListStorePriv *priv;
825 GDK_TYPE_PIXBUF, /* Status pixbuf */
826 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
827 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
828 G_TYPE_STRING, /* Name */
829 G_TYPE_STRING, /* Status string */
830 G_TYPE_BOOLEAN, /* Show status */
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 favourite */
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 EmpathyContactListStorePriv *priv;
918 priv = GET_PRIV (store);
920 DEBUG ("Contact %s (%d) %s",
921 empathy_contact_get_id (contact),
922 empathy_contact_get_handle (contact),
923 is_member ? "added" : "removed");
926 contact_list_store_add_contact_and_connect (store, contact);
928 contact_list_store_remove_contact_and_disconnect (store, contact);
933 contact_list_store_change_contact_favourite_status (EmpathyContactListStore *store,
934 EmpathyContact *contact,
935 gboolean is_favourite)
939 iters = contact_list_store_find_contact (store, contact);
940 for (l = iters; l; l = l->next) {
941 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
942 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE,
947 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
952 contact_list_store_favourites_changed_cb (EmpathyContactList *list_iface,
953 EmpathyContact *contact,
954 gboolean is_favourite,
955 EmpathyContactListStore *store)
957 EmpathyContactListStorePriv *priv;
959 priv = GET_PRIV (store);
961 DEBUG ("Contact %s (%d) is %s a favourite",
962 empathy_contact_get_id (contact),
963 empathy_contact_get_handle (contact),
964 is_favourite ? "now" : "no longer");
966 contact_list_store_change_contact_favourite_status (store, contact,
971 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
972 EmpathyContact *old_contact,
973 EmpathyContact *new_contact,
976 EmpathyContactListStore *store)
978 EmpathyContactListStorePriv *priv;
980 priv = GET_PRIV (store);
982 DEBUG ("Contact %s (%d) renamed to %s (%d)",
983 empathy_contact_get_id (old_contact),
984 empathy_contact_get_handle (old_contact),
985 empathy_contact_get_id (new_contact),
986 empathy_contact_get_handle (new_contact));
988 /* add the new contact */
989 contact_list_store_add_contact_and_connect (store, new_contact);
991 /* remove old contact */
992 contact_list_store_remove_contact_and_disconnect (store, old_contact);
996 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
997 EmpathyContact *contact,
1000 EmpathyContactListStore *store)
1002 EmpathyContactListStorePriv *priv;
1003 gboolean show_active;
1005 priv = GET_PRIV (store);
1007 DEBUG ("Updating groups for contact %s (%d)",
1008 empathy_contact_get_id (contact),
1009 empathy_contact_get_handle (contact));
1011 /* We do this to make sure the groups are correct, if not, we
1012 * would have to check the groups already set up for each
1013 * contact and then see what has been updated.
1015 show_active = priv->show_active;
1016 priv->show_active = FALSE;
1017 contact_list_store_remove_contact (store, contact);
1018 contact_list_store_add_contact (store, contact);
1019 priv->show_active = show_active;
1023 add_contact_to_store (GtkTreeStore *store,
1025 EmpathyContact *contact,
1026 EmpathyContactListFlags flags)
1028 gtk_tree_store_set (store, iter,
1029 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1030 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1031 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1032 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1033 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1034 empathy_contact_get_capabilities (contact) &
1035 EMPATHY_CAPABILITIES_AUDIO,
1036 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1037 empathy_contact_get_capabilities (contact) &
1038 EMPATHY_CAPABILITIES_VIDEO,
1039 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1044 contact_list_store_add_contact (EmpathyContactListStore *store,
1045 EmpathyContact *contact)
1047 EmpathyContactListStorePriv *priv;
1049 GList *groups = NULL, *l;
1050 TpConnection *connection;
1051 EmpathyContactListFlags flags = 0;
1053 priv = GET_PRIV (store);
1055 if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
1056 (!priv->show_offline && !empathy_contact_is_online (contact))) {
1060 if (priv->show_groups) {
1061 groups = empathy_contact_list_get_groups (priv->list, contact);
1064 connection = empathy_contact_get_connection (contact);
1065 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
1066 flags = empathy_contact_manager_get_flags_for_connection (
1067 EMPATHY_CONTACT_MANAGER (priv->list), connection);
1070 #if HAVE_FAVOURITE_CONTACTS
1071 GtkTreeIter iter_group;
1073 contact_list_store_get_group (store, EMPATHY_CONTACT_LIST_STORE_UNGROUPED,
1074 &iter_group, NULL, NULL);
1076 gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
1079 /* FIXME: remove this in 2.31.x */
1080 /* If no groups just add it at the top level. */
1081 GtkTreeModel *model = GTK_TREE_MODEL (store);
1083 if (gtk_tree_model_get_iter_first (model, &iter)) do {
1086 gtk_tree_model_get (model, &iter,
1087 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
1096 } while (gtk_tree_model_iter_next (model, &iter));
1098 gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
1101 add_contact_to_store (GTK_TREE_STORE (store), &iter, contact, flags);
1104 /* Else add to each group. */
1105 for (l = groups; l; l = l->next) {
1106 GtkTreeIter iter_group;
1108 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);
1110 gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
1113 add_contact_to_store (GTK_TREE_STORE (store), &iter, contact, flags);
1116 g_list_free (groups);
1118 contact_list_store_contact_update (store, contact);
1123 contact_list_store_remove_contact (EmpathyContactListStore *store,
1124 EmpathyContact *contact)
1126 EmpathyContactListStorePriv *priv;
1127 GtkTreeModel *model;
1130 priv = GET_PRIV (store);
1132 iters = contact_list_store_find_contact (store, contact);
1137 /* Clean up model */
1138 model = GTK_TREE_MODEL (store);
1140 for (l = iters; l; l = l->next) {
1143 /* NOTE: it is only <= 2 here because we have
1144 * separators after the group name, otherwise it
1147 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
1148 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1149 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1151 gtk_tree_store_remove (GTK_TREE_STORE (store), l->data);
1155 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1156 g_list_free (iters);
1160 list_store_contact_is_favourite (EmpathyContactListStore *store,
1161 EmpathyContact *contact)
1163 EmpathyContactListStorePriv *priv;
1165 priv = GET_PRIV (store);
1167 return empathy_contact_list_is_favourite (priv->list, contact);
1171 contact_list_store_contact_update (EmpathyContactListStore *store,
1172 EmpathyContact *contact)
1174 EmpathyContactListStorePriv *priv;
1175 ShowActiveData *data;
1176 GtkTreeModel *model;
1179 gboolean should_be_in_list;
1180 gboolean was_online = TRUE;
1181 gboolean now_online = FALSE;
1182 gboolean set_model = FALSE;
1183 gboolean do_remove = FALSE;
1184 gboolean do_set_active = FALSE;
1185 gboolean do_set_refresh = FALSE;
1186 gboolean show_avatar = FALSE;
1187 GdkPixbuf *pixbuf_avatar;
1188 GdkPixbuf *pixbuf_status;
1190 priv = GET_PRIV (store);
1192 model = GTK_TREE_MODEL (store);
1194 iters = contact_list_store_find_contact (store, contact);
1201 /* Get online state now. */
1202 now_online = empathy_contact_is_online (contact);
1204 if (priv->show_offline || now_online) {
1205 should_be_in_list = TRUE;
1207 should_be_in_list = FALSE;
1210 if (!in_list && !should_be_in_list) {
1211 /* Nothing to do. */
1212 DEBUG ("Contact:'%s' in list:NO, should be:NO",
1213 empathy_contact_get_name (contact));
1215 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1216 g_list_free (iters);
1219 else if (in_list && !should_be_in_list) {
1220 DEBUG ("Contact:'%s' in list:YES, should be:NO",
1221 empathy_contact_get_name (contact));
1223 if (priv->show_active) {
1225 do_set_active = TRUE;
1226 do_set_refresh = TRUE;
1229 DEBUG ("Remove item (after timeout)");
1231 DEBUG ("Remove item (now)!");
1232 contact_list_store_remove_contact (store, contact);
1235 else if (!in_list && should_be_in_list) {
1236 DEBUG ("Contact:'%s' in list:NO, should be:YES",
1237 empathy_contact_get_name (contact));
1239 contact_list_store_add_contact (store, contact);
1241 if (priv->show_active) {
1242 do_set_active = TRUE;
1244 DEBUG ("Set active (contact added)");
1247 DEBUG ("Contact:'%s' in list:YES, should be:YES",
1248 empathy_contact_get_name (contact));
1250 /* Get online state before. */
1251 if (iters && g_list_length (iters) > 0) {
1252 gtk_tree_model_get (model, iters->data,
1253 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online,
1257 /* Is this really an update or an online/offline. */
1258 if (priv->show_active) {
1259 if (was_online != now_online) {
1260 do_set_active = TRUE;
1261 do_set_refresh = TRUE;
1263 DEBUG ("Set active (contact updated %s)",
1264 was_online ? "online -> offline" :
1265 "offline -> online");
1267 /* Was TRUE for presence updates. */
1268 /* do_set_active = FALSE; */
1269 do_set_refresh = TRUE;
1271 DEBUG ("Set active (contact updated)");
1278 if (priv->show_avatars && !priv->is_compact) {
1281 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
1282 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1283 for (l = iters; l && set_model; l = l->next) {
1284 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1285 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, list_store_contact_is_favourite (store, contact),
1286 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1287 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1288 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1289 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1290 EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact),
1291 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1292 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1293 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1294 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1295 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1296 empathy_contact_get_capabilities (contact) &
1297 EMPATHY_CAPABILITIES_AUDIO,
1298 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1299 empathy_contact_get_capabilities (contact) &
1300 EMPATHY_CAPABILITIES_VIDEO,
1304 if (pixbuf_avatar) {
1305 g_object_unref (pixbuf_avatar);
1308 if (priv->show_active && do_set_active) {
1309 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1311 if (do_set_active) {
1312 data = contact_list_store_contact_active_new (store, contact, do_remove);
1313 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1314 (GSourceFunc) contact_list_store_contact_active_cb,
1319 /* FIXME: when someone goes online then offline quickly, the
1320 * first timeout sets the user to be inactive and the second
1321 * timeout removes the user from the contact list, really we
1322 * should remove the first timeout.
1324 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1325 g_list_free (iters);
1329 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1331 EmpathyContactListStore *store)
1333 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1334 empathy_contact_get_name (contact));
1336 contact_list_store_contact_update (store, contact);
1340 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1341 EmpathyContact *contact,
1343 gboolean set_changed)
1345 EmpathyContactListStorePriv *priv;
1346 GtkTreeModel *model;
1349 priv = GET_PRIV (store);
1350 model = GTK_TREE_MODEL (store);
1352 iters = contact_list_store_find_contact (store, contact);
1353 for (l = iters; l; l = l->next) {
1356 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1357 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, active,
1360 DEBUG ("Set item %s", active ? "active" : "inactive");
1363 path = gtk_tree_model_get_path (model, l->data);
1364 gtk_tree_model_row_changed (model, path, l->data);
1365 gtk_tree_path_free (path);
1369 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1370 g_list_free (iters);
1374 static ShowActiveData *
1375 contact_list_store_contact_active_new (EmpathyContactListStore *store,
1376 EmpathyContact *contact,
1379 ShowActiveData *data;
1381 DEBUG ("Contact:'%s' now active, and %s be removed",
1382 empathy_contact_get_name (contact),
1383 remove_ ? "WILL" : "WILL NOT");
1385 data = g_slice_new0 (ShowActiveData);
1387 data->store = g_object_ref (store);
1388 data->contact = g_object_ref (contact);
1389 data->remove = remove_;
1395 contact_list_store_contact_active_free (ShowActiveData *data)
1397 g_object_unref (data->contact);
1398 g_object_unref (data->store);
1400 g_slice_free (ShowActiveData, data);
1404 contact_list_store_contact_active_cb (ShowActiveData *data)
1406 EmpathyContactListStorePriv *priv;
1408 priv = GET_PRIV (data->store);
1411 !priv->show_offline &&
1412 !empathy_contact_is_online (data->contact)) {
1413 DEBUG ("Contact:'%s' active timeout, removing item",
1414 empathy_contact_get_name (data->contact));
1415 contact_list_store_remove_contact (data->store, data->contact);
1418 DEBUG ("Contact:'%s' no longer active",
1419 empathy_contact_get_name (data->contact));
1421 contact_list_store_contact_set_active (data->store,
1426 contact_list_store_contact_active_free (data);
1432 contact_list_store_get_group_foreach (GtkTreeModel *model,
1440 /* Groups are only at the top level. */
1441 if (gtk_tree_path_get_depth (path) != 1) {
1445 gtk_tree_model_get (model, iter,
1446 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &str,
1447 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1450 if (is_group && !tp_strdiff (str, fg->name)) {
1461 contact_list_store_get_group (EmpathyContactListStore *store,
1463 GtkTreeIter *iter_group_to_set,
1464 GtkTreeIter *iter_separator_to_set,
1467 EmpathyContactListStorePriv *priv;
1468 GtkTreeModel *model;
1469 GtkTreeIter iter_group;
1470 GtkTreeIter iter_separator;
1473 priv = GET_PRIV (store);
1475 memset (&fg, 0, sizeof (fg));
1479 model = GTK_TREE_MODEL (store);
1480 gtk_tree_model_foreach (model,
1481 (GtkTreeModelForeachFunc) contact_list_store_get_group_foreach,
1489 gtk_tree_store_append (GTK_TREE_STORE (store), &iter_group, NULL);
1490 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_group,
1491 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1492 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1493 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1494 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1495 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1498 if (iter_group_to_set) {
1499 *iter_group_to_set = iter_group;
1502 gtk_tree_store_append (GTK_TREE_STORE (store),
1505 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_separator,
1506 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1509 if (iter_separator_to_set) {
1510 *iter_separator_to_set = iter_separator;
1517 if (iter_group_to_set) {
1518 *iter_group_to_set = fg.iter;
1521 iter_separator = fg.iter;
1523 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1524 gboolean is_separator;
1526 gtk_tree_model_get (model, &iter_separator,
1527 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1530 if (is_separator && iter_separator_to_set) {
1531 *iter_separator_to_set = iter_separator;
1538 compare_separator_and_groups (gboolean is_separator_a,
1539 gboolean is_separator_b,
1540 gboolean is_favourite_a,
1541 gboolean is_favourite_b,
1542 const gchar *name_a,
1543 const gchar *name_b,
1544 EmpathyContact *contact_a,
1545 EmpathyContact *contact_b)
1547 if (is_separator_a || is_separator_b) {
1548 /* We have at least one separator */
1549 if (is_separator_a) {
1551 } else if (is_separator_b) {
1556 /* Favorites are displayed first */
1557 if (is_favourite_a && !is_favourite_b) {
1559 } else if (!is_favourite_a && is_favourite_b) {
1561 /* One group and one contact */
1562 } else if (!contact_a && contact_b) {
1564 } else if (contact_a && !contact_b) {
1566 } else if (!contact_a && !contact_b) {
1567 /* Two groups. The 'Ungrouped' fake group is display at the bottom of the
1569 if (!tp_strdiff (name_a, EMPATHY_CONTACT_LIST_STORE_UNGROUPED))
1571 else if (!tp_strdiff (name_b, EMPATHY_CONTACT_LIST_STORE_UNGROUPED))
1574 return g_utf8_collate (name_a, name_b);
1577 /* Two contacts, ordering depends of the sorting policy */
1582 contact_list_store_state_sort_func (GtkTreeModel *model,
1583 GtkTreeIter *iter_a,
1584 GtkTreeIter *iter_b,
1588 gchar *name_a, *name_b;
1589 gboolean is_separator_a, is_separator_b;
1590 gboolean is_favourite_a, is_favourite_b;
1591 EmpathyContact *contact_a, *contact_b;
1593 gtk_tree_model_get (model, iter_a,
1594 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1595 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1596 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1597 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_a,
1599 gtk_tree_model_get (model, iter_b,
1600 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1601 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1602 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1603 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_b,
1606 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1607 is_favourite_a, is_favourite_b, name_a, name_b, contact_a, contact_b);
1613 /* If we managed to get this far, we can start looking at
1616 ret_val = -tp_connection_presence_type_cmp_availability (
1617 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1618 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1621 /* Fallback: compare by name */
1622 ret_val = g_utf8_collate (name_a, name_b);
1630 g_object_unref (contact_a);
1634 g_object_unref (contact_b);
1641 contact_list_store_name_sort_func (GtkTreeModel *model,
1642 GtkTreeIter *iter_a,
1643 GtkTreeIter *iter_b,
1646 gchar *name_a, *name_b;
1647 EmpathyContact *contact_a, *contact_b;
1648 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1649 gboolean is_favourite_a, is_favourite_b;
1652 gtk_tree_model_get (model, iter_a,
1653 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1654 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1655 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1656 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_a,
1658 gtk_tree_model_get (model, iter_b,
1659 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1660 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1661 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1662 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_b,
1665 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1666 is_favourite_a, is_favourite_b, name_a, name_b, contact_a, contact_b);
1669 ret_val = g_utf8_collate (name_a, name_b);
1672 g_object_unref (contact_a);
1676 g_object_unref (contact_b);
1683 contact_list_store_find_contact_foreach (GtkTreeModel *model,
1688 EmpathyContact *contact;
1690 gtk_tree_model_get (model, iter,
1691 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1694 if (contact == fc->contact) {
1696 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
1700 g_object_unref (contact);
1707 contact_list_store_find_contact (EmpathyContactListStore *store,
1708 EmpathyContact *contact)
1710 EmpathyContactListStorePriv *priv;
1711 GtkTreeModel *model;
1715 priv = GET_PRIV (store);
1717 memset (&fc, 0, sizeof (fc));
1719 fc.contact = contact;
1721 model = GTK_TREE_MODEL (store);
1722 gtk_tree_model_foreach (model,
1723 (GtkTreeModelForeachFunc) contact_list_store_find_contact_foreach,
1734 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1737 EmpathyContactListStore *store)
1739 EmpathyContactListStorePriv *priv;
1740 gboolean show_avatar = FALSE;
1741 EmpathyContact *contact;
1742 GdkPixbuf *pixbuf_status;
1744 priv = GET_PRIV (store);
1746 if (priv->show_avatars && !priv->is_compact) {
1750 gtk_tree_model_get (model, iter,
1751 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1754 if (contact == NULL){
1757 /* get icon from hash_table */
1758 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1760 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1761 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1762 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1763 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1770 contact_list_store_get_contact_status_icon_with_icon_name (
1771 EmpathyContactListStore *store,
1772 EmpathyContact *contact,
1773 const gchar *status_icon_name)
1775 GdkPixbuf *pixbuf_status = NULL;
1776 EmpathyContactListStorePriv *priv;
1777 const gchar *protocol_name = NULL;
1778 gchar *icon_name = NULL;
1780 priv = GET_PRIV (store);
1782 if (priv->show_protocols) {
1783 protocol_name = empathy_protocol_name_for_contact (contact);
1784 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1786 icon_name = g_strdup_printf ("%s", status_icon_name);
1788 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1789 if (pixbuf_status == NULL) {
1790 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1792 priv->show_protocols);
1793 if (pixbuf_status != NULL) {
1794 g_hash_table_insert (priv->status_icons,
1795 g_strdup (icon_name),
1801 return pixbuf_status;
1805 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1806 EmpathyContact *contact)
1808 GdkPixbuf *pixbuf_status = NULL;
1809 const gchar *status_icon_name = NULL;
1811 status_icon_name = empathy_icon_name_for_contact (contact);
1812 if (status_icon_name == NULL)
1815 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1820 return pixbuf_status;