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_favourites_changed_cb (EmpathyContactList *list_iface,
109 EmpathyContact *contact,
110 gboolean is_favourite,
111 EmpathyContactListStore *store);
112 static void contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
113 EmpathyContact *old_contact,
114 EmpathyContact *new_contact,
117 EmpathyContactListStore *store);
118 static void contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
119 EmpathyContact *contact,
122 EmpathyContactListStore *store);
123 static void contact_list_store_add_contact (EmpathyContactListStore *store,
124 EmpathyContact *contact);
125 static void contact_list_store_remove_contact (EmpathyContactListStore *store,
126 EmpathyContact *contact);
127 static void contact_list_store_contact_update (EmpathyContactListStore *store,
128 EmpathyContact *contact);
129 static void contact_list_store_contact_updated_cb (EmpathyContact *contact,
131 EmpathyContactListStore *store);
132 static void contact_list_store_contact_set_active (EmpathyContactListStore *store,
133 EmpathyContact *contact,
135 gboolean set_changed);
136 static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store,
137 EmpathyContact *contact,
139 static void contact_list_store_contact_active_free (ShowActiveData *data);
140 static gboolean contact_list_store_contact_active_cb (ShowActiveData *data);
141 static gboolean contact_list_store_get_group_foreach (GtkTreeModel *model,
145 static void contact_list_store_get_group (EmpathyContactListStore *store,
147 GtkTreeIter *iter_group_to_set,
148 GtkTreeIter *iter_separator_to_set,
150 static gint contact_list_store_state_sort_func (GtkTreeModel *model,
154 static gint contact_list_store_name_sort_func (GtkTreeModel *model,
158 static gboolean contact_list_store_find_contact_foreach (GtkTreeModel *model,
162 static GList * contact_list_store_find_contact (EmpathyContactListStore *store,
163 EmpathyContact *contact);
164 static gboolean contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
167 EmpathyContactListStore *store);
180 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
183 contact_list_store_iface_setup (gpointer user_data)
185 EmpathyContactListStore *store = user_data;
186 EmpathyContactListStorePriv *priv = GET_PRIV (store);
189 /* Signal connection. */
190 g_signal_connect (priv->list,
192 G_CALLBACK (contact_list_store_member_renamed_cb),
194 g_signal_connect (priv->list,
196 G_CALLBACK (contact_list_store_members_changed_cb),
198 g_signal_connect (priv->list,
199 "favourites-changed",
200 G_CALLBACK (contact_list_store_favourites_changed_cb),
202 g_signal_connect (priv->list,
204 G_CALLBACK (contact_list_store_groups_changed_cb),
207 /* Add contacts already created. */
208 contacts = empathy_contact_list_get_members (priv->list);
209 for (l = contacts; l; l = l->next) {
210 contact_list_store_members_changed_cb (priv->list, l->data,
215 g_object_unref (l->data);
217 g_list_free (contacts);
219 priv->setup_idle_id = 0;
225 contact_list_store_set_contact_list (EmpathyContactListStore *store,
226 EmpathyContactList *list_iface)
228 EmpathyContactListStorePriv *priv = GET_PRIV (store);
230 priv->list = g_object_ref (list_iface);
232 /* Let a chance to have all properties set before populating */
233 priv->setup_idle_id = g_idle_add (contact_list_store_iface_setup, store);
237 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
239 GObjectClass *object_class = G_OBJECT_CLASS (klass);
241 object_class->dispose = contact_list_store_dispose;
242 object_class->get_property = contact_list_store_get_property;
243 object_class->set_property = contact_list_store_set_property;
245 g_object_class_install_property (object_class,
247 g_param_spec_object ("contact-list",
248 "The contact list iface",
249 "The contact list iface",
250 EMPATHY_TYPE_CONTACT_LIST,
251 G_PARAM_CONSTRUCT_ONLY |
253 g_object_class_install_property (object_class,
255 g_param_spec_boolean ("show-offline",
257 "Whether contact list should display "
261 g_object_class_install_property (object_class,
263 g_param_spec_boolean ("show-avatars",
265 "Whether contact list should display "
266 "avatars for contacts",
269 g_object_class_install_property (object_class,
271 g_param_spec_boolean ("show-protocols",
273 "Whether contact list should display "
274 "protocols for contacts",
277 g_object_class_install_property (object_class,
279 g_param_spec_boolean ("show-groups",
281 "Whether contact list should display "
285 g_object_class_install_property (object_class,
287 g_param_spec_boolean ("is-compact",
289 "Whether the contact list is in compact mode or not",
293 g_object_class_install_property (object_class,
295 g_param_spec_enum ("sort-criterium",
297 "The sort criterium to use for sorting the contact list",
298 EMPATHY_TYPE_CONTACT_LIST_STORE_SORT,
299 EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
302 g_type_class_add_private (object_class, sizeof (EmpathyContactListStorePriv));
306 empathy_contact_list_store_init (EmpathyContactListStore *store)
308 EmpathyContactListStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
309 EMPATHY_TYPE_CONTACT_LIST_STORE, EmpathyContactListStorePriv);
312 priv->show_avatars = TRUE;
313 priv->show_groups = TRUE;
314 priv->show_protocols = FALSE;
315 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
316 (GSourceFunc) contact_list_store_inibit_active_cb,
318 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
319 contact_list_store_setup (store);
323 contact_list_store_dispose (GObject *object)
325 EmpathyContactListStorePriv *priv = GET_PRIV (object);
328 if (priv->dispose_has_run)
330 priv->dispose_has_run = TRUE;
332 contacts = empathy_contact_list_get_members (priv->list);
333 for (l = contacts; l; l = l->next) {
334 g_signal_handlers_disconnect_by_func (l->data,
335 G_CALLBACK (contact_list_store_contact_updated_cb),
338 g_object_unref (l->data);
340 g_list_free (contacts);
342 g_signal_handlers_disconnect_by_func (priv->list,
343 G_CALLBACK (contact_list_store_member_renamed_cb),
345 g_signal_handlers_disconnect_by_func (priv->list,
346 G_CALLBACK (contact_list_store_members_changed_cb),
348 g_signal_handlers_disconnect_by_func (priv->list,
349 G_CALLBACK (contact_list_store_favourites_changed_cb),
351 g_signal_handlers_disconnect_by_func (priv->list,
352 G_CALLBACK (contact_list_store_groups_changed_cb),
354 g_object_unref (priv->list);
356 if (priv->inhibit_active) {
357 g_source_remove (priv->inhibit_active);
360 if (priv->setup_idle_id != 0) {
361 g_source_remove (priv->setup_idle_id);
364 g_hash_table_destroy (priv->status_icons);
365 G_OBJECT_CLASS (empathy_contact_list_store_parent_class)->dispose (object);
369 contact_list_store_get_property (GObject *object,
374 EmpathyContactListStorePriv *priv;
376 priv = GET_PRIV (object);
379 case PROP_CONTACT_LIST:
380 g_value_set_object (value, priv->list);
382 case PROP_SHOW_OFFLINE:
383 g_value_set_boolean (value, priv->show_offline);
385 case PROP_SHOW_AVATARS:
386 g_value_set_boolean (value, priv->show_avatars);
388 case PROP_SHOW_PROTOCOLS:
389 g_value_set_boolean (value, priv->show_protocols);
391 case PROP_SHOW_GROUPS:
392 g_value_set_boolean (value, priv->show_groups);
394 case PROP_IS_COMPACT:
395 g_value_set_boolean (value, priv->is_compact);
397 case PROP_SORT_CRITERIUM:
398 g_value_set_enum (value, priv->sort_criterium);
401 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
407 contact_list_store_set_property (GObject *object,
412 EmpathyContactListStorePriv *priv;
414 priv = GET_PRIV (object);
417 case PROP_CONTACT_LIST:
418 contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
419 g_value_get_object (value));
421 case PROP_SHOW_OFFLINE:
422 empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
423 g_value_get_boolean (value));
425 case PROP_SHOW_AVATARS:
426 empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
427 g_value_get_boolean (value));
429 case PROP_SHOW_PROTOCOLS:
430 empathy_contact_list_store_set_show_protocols (EMPATHY_CONTACT_LIST_STORE (object),
431 g_value_get_boolean (value));
433 case PROP_SHOW_GROUPS:
434 empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
435 g_value_get_boolean (value));
437 case PROP_IS_COMPACT:
438 empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
439 g_value_get_boolean (value));
441 case PROP_SORT_CRITERIUM:
442 empathy_contact_list_store_set_sort_criterium (EMPATHY_CONTACT_LIST_STORE (object),
443 g_value_get_enum (value));
446 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
451 EmpathyContactListStore *
452 empathy_contact_list_store_new (EmpathyContactList *list_iface)
454 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
456 return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
457 "contact-list", list_iface,
462 empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store)
464 EmpathyContactListStorePriv *priv;
466 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
468 priv = GET_PRIV (store);
474 empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store)
476 EmpathyContactListStorePriv *priv;
478 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
480 priv = GET_PRIV (store);
482 return priv->show_offline;
486 empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
487 gboolean show_offline)
489 EmpathyContactListStorePriv *priv;
491 gboolean show_active;
493 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
495 priv = GET_PRIV (store);
497 priv->show_offline = show_offline;
498 show_active = priv->show_active;
500 /* Disable temporarily. */
501 priv->show_active = FALSE;
503 contacts = empathy_contact_list_get_members (priv->list);
504 for (l = contacts; l; l = l->next) {
505 contact_list_store_contact_update (store, l->data);
507 g_object_unref (l->data);
509 g_list_free (contacts);
511 /* Restore to original setting. */
512 priv->show_active = show_active;
514 g_object_notify (G_OBJECT (store), "show-offline");
518 empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store)
520 EmpathyContactListStorePriv *priv;
522 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
524 priv = GET_PRIV (store);
526 return priv->show_avatars;
530 empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
531 gboolean show_avatars)
533 EmpathyContactListStorePriv *priv;
536 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
538 priv = GET_PRIV (store);
540 priv->show_avatars = show_avatars;
542 model = GTK_TREE_MODEL (store);
544 gtk_tree_model_foreach (model,
545 (GtkTreeModelForeachFunc)
546 contact_list_store_update_list_mode_foreach,
549 g_object_notify (G_OBJECT (store), "show-avatars");
554 empathy_contact_list_store_get_show_protocols (EmpathyContactListStore *store)
556 EmpathyContactListStorePriv *priv;
558 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
560 priv = GET_PRIV (store);
562 return priv->show_protocols;
566 empathy_contact_list_store_set_show_protocols (EmpathyContactListStore *store,
567 gboolean show_protocols)
569 EmpathyContactListStorePriv *priv;
572 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
574 priv = GET_PRIV (store);
576 priv->show_protocols = show_protocols;
578 model = GTK_TREE_MODEL (store);
580 gtk_tree_model_foreach (model,
581 (GtkTreeModelForeachFunc)
582 contact_list_store_update_list_mode_foreach,
585 g_object_notify (G_OBJECT (store), "show-protocols");
589 empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
591 EmpathyContactListStorePriv *priv;
593 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
595 priv = GET_PRIV (store);
597 return priv->show_groups;
601 empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
602 gboolean show_groups)
604 EmpathyContactListStorePriv *priv;
607 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
609 priv = GET_PRIV (store);
611 if (priv->show_groups == show_groups) {
615 priv->show_groups = show_groups;
617 /* Remove all contacts and add them back, not optimized but that's the
619 gtk_tree_store_clear (GTK_TREE_STORE (store));
620 contacts = empathy_contact_list_get_members (priv->list);
621 for (l = contacts; l; l = l->next) {
622 contact_list_store_members_changed_cb (priv->list, l->data,
627 g_object_unref (l->data);
629 g_list_free (contacts);
631 g_object_notify (G_OBJECT (store), "show-groups");
635 empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store)
637 EmpathyContactListStorePriv *priv;
639 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
641 priv = GET_PRIV (store);
643 return priv->is_compact;
647 empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
650 EmpathyContactListStorePriv *priv;
653 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
655 priv = GET_PRIV (store);
657 priv->is_compact = is_compact;
659 model = GTK_TREE_MODEL (store);
661 gtk_tree_model_foreach (model,
662 (GtkTreeModelForeachFunc)
663 contact_list_store_update_list_mode_foreach,
666 g_object_notify (G_OBJECT (store), "is-compact");
669 EmpathyContactListStoreSort
670 empathy_contact_list_store_get_sort_criterium (EmpathyContactListStore *store)
672 EmpathyContactListStorePriv *priv;
674 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), 0);
676 priv = GET_PRIV (store);
678 return priv->sort_criterium;
682 empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *store,
683 EmpathyContactListStoreSort sort_criterium)
685 EmpathyContactListStorePriv *priv;
687 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
689 priv = GET_PRIV (store);
691 priv->sort_criterium = sort_criterium;
693 switch (sort_criterium) {
694 case EMPATHY_CONTACT_LIST_STORE_SORT_STATE:
695 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
696 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
700 case EMPATHY_CONTACT_LIST_STORE_SORT_NAME:
701 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
702 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
707 g_object_notify (G_OBJECT (store), "sort-criterium");
711 empathy_contact_list_store_row_separator_func (GtkTreeModel *model,
715 gboolean is_separator = FALSE;
717 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
719 gtk_tree_model_get (model, iter,
720 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
727 empathy_contact_list_store_get_parent_group (GtkTreeModel *model,
729 gboolean *path_is_group)
731 GtkTreeIter parent_iter, iter;
735 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
738 *path_is_group = FALSE;
741 if (!gtk_tree_model_get_iter (model, &iter, path)) {
745 gtk_tree_model_get (model, &iter,
746 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
747 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
754 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter)) {
760 gtk_tree_model_get (model, &iter,
761 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
762 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
771 *path_is_group = TRUE;
778 empathy_contact_list_store_search_equal_func (GtkTreeModel *model,
782 gpointer search_data)
784 gchar *name, *name_folded;
788 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
794 gtk_tree_model_get (model, iter,
795 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
802 name_folded = g_utf8_casefold (name, -1);
803 key_folded = g_utf8_casefold (key, -1);
805 if (name_folded && key_folded &&
806 strstr (name_folded, key_folded)) {
813 g_free (name_folded);
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_STRING, /* Status string */
829 G_TYPE_BOOLEAN, /* Show status */
830 EMPATHY_TYPE_CONTACT, /* Contact type */
831 G_TYPE_BOOLEAN, /* Is group */
832 G_TYPE_BOOLEAN, /* Is active */
833 G_TYPE_BOOLEAN, /* Is online */
834 G_TYPE_BOOLEAN, /* Is separator */
835 G_TYPE_BOOLEAN, /* Can make audio calls */
836 G_TYPE_BOOLEAN, /* Can make video calls */
837 EMPATHY_TYPE_CONTACT_LIST_FLAGS, /* Flags */
838 G_TYPE_BOOLEAN, /* Is a favourite */
841 priv = GET_PRIV (store);
843 gtk_tree_store_set_column_types (GTK_TREE_STORE (store),
844 EMPATHY_CONTACT_LIST_STORE_COL_COUNT,
848 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
849 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
850 contact_list_store_name_sort_func,
852 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
853 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
854 contact_list_store_state_sort_func,
857 priv->sort_criterium = EMPATHY_CONTACT_LIST_STORE_SORT_NAME;
858 empathy_contact_list_store_set_sort_criterium (store, priv->sort_criterium);
862 contact_list_store_inibit_active_cb (EmpathyContactListStore *store)
864 EmpathyContactListStorePriv *priv;
866 priv = GET_PRIV (store);
868 priv->show_active = TRUE;
869 priv->inhibit_active = 0;
875 contact_list_store_add_contact_and_connect (EmpathyContactListStore *store, EmpathyContact *contact)
877 g_signal_connect (contact, "notify::presence",
878 G_CALLBACK (contact_list_store_contact_updated_cb),
880 g_signal_connect (contact, "notify::presence-message",
881 G_CALLBACK (contact_list_store_contact_updated_cb),
883 g_signal_connect (contact, "notify::name",
884 G_CALLBACK (contact_list_store_contact_updated_cb),
886 g_signal_connect (contact, "notify::avatar",
887 G_CALLBACK (contact_list_store_contact_updated_cb),
889 g_signal_connect (contact, "notify::capabilities",
890 G_CALLBACK (contact_list_store_contact_updated_cb),
893 contact_list_store_add_contact (store, contact);
897 contact_list_store_remove_contact_and_disconnect (EmpathyContactListStore *store, EmpathyContact *contact)
899 g_signal_handlers_disconnect_by_func (contact,
900 G_CALLBACK (contact_list_store_contact_updated_cb),
903 contact_list_store_remove_contact (store, contact);
907 contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
908 EmpathyContact *contact,
909 EmpathyContact *actor,
913 EmpathyContactListStore *store)
915 EmpathyContactListStorePriv *priv;
917 priv = GET_PRIV (store);
919 DEBUG ("Contact %s (%d) %s",
920 empathy_contact_get_id (contact),
921 empathy_contact_get_handle (contact),
922 is_member ? "added" : "removed");
925 contact_list_store_add_contact_and_connect (store, contact);
927 contact_list_store_remove_contact_and_disconnect (store, contact);
932 contact_list_store_change_contact_favourite_status (EmpathyContactListStore *store,
933 EmpathyContact *contact,
934 gboolean is_favourite)
938 iters = contact_list_store_find_contact (store, contact);
939 for (l = iters; l; l = l->next) {
940 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
941 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE,
946 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
951 contact_list_store_favourites_changed_cb (EmpathyContactList *list_iface,
952 EmpathyContact *contact,
953 gboolean is_favourite,
954 EmpathyContactListStore *store)
956 EmpathyContactListStorePriv *priv;
958 priv = GET_PRIV (store);
960 DEBUG ("Contact %s (%d) is %s a favourite",
961 empathy_contact_get_id (contact),
962 empathy_contact_get_handle (contact),
963 is_favourite ? "now" : "no longer");
965 contact_list_store_change_contact_favourite_status (store, contact, is_favourite);
969 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
970 EmpathyContact *old_contact,
971 EmpathyContact *new_contact,
974 EmpathyContactListStore *store)
976 EmpathyContactListStorePriv *priv;
978 priv = GET_PRIV (store);
980 DEBUG ("Contact %s (%d) renamed to %s (%d)",
981 empathy_contact_get_id (old_contact),
982 empathy_contact_get_handle (old_contact),
983 empathy_contact_get_id (new_contact),
984 empathy_contact_get_handle (new_contact));
986 /* add the new contact */
987 contact_list_store_add_contact_and_connect (store, new_contact);
989 /* remove old contact */
990 contact_list_store_remove_contact_and_disconnect (store, old_contact);
994 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
995 EmpathyContact *contact,
998 EmpathyContactListStore *store)
1000 EmpathyContactListStorePriv *priv;
1001 gboolean show_active;
1003 priv = GET_PRIV (store);
1005 DEBUG ("Updating groups for contact %s (%d)",
1006 empathy_contact_get_id (contact),
1007 empathy_contact_get_handle (contact));
1009 /* We do this to make sure the groups are correct, if not, we
1010 * would have to check the groups already set up for each
1011 * contact and then see what has been updated.
1013 show_active = priv->show_active;
1014 priv->show_active = FALSE;
1015 contact_list_store_remove_contact (store, contact);
1016 contact_list_store_add_contact (store, contact);
1017 priv->show_active = show_active;
1021 contact_list_store_add_contact (EmpathyContactListStore *store,
1022 EmpathyContact *contact)
1024 EmpathyContactListStorePriv *priv;
1026 GList *groups = NULL, *l;
1027 TpConnection *connection;
1028 EmpathyContactListFlags flags = 0;
1030 priv = GET_PRIV (store);
1032 if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
1033 (!priv->show_offline && !empathy_contact_is_online (contact))) {
1037 if (priv->show_groups) {
1038 groups = empathy_contact_list_get_groups (priv->list, contact);
1041 connection = empathy_contact_get_connection (contact);
1042 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
1043 flags = empathy_contact_manager_get_flags_for_connection (
1044 EMPATHY_CONTACT_MANAGER (priv->list), connection);
1046 /* If no groups just add it at the top level. */
1048 GtkTreeModel *model = GTK_TREE_MODEL (store);
1050 if (gtk_tree_model_get_iter_first (model, &iter)) do {
1053 gtk_tree_model_get (model, &iter,
1054 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
1063 } while (gtk_tree_model_iter_next (model, &iter));
1065 gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
1066 gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
1067 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1068 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1069 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1070 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1071 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1072 empathy_contact_get_capabilities (contact) &
1073 EMPATHY_CAPABILITIES_AUDIO,
1074 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1075 empathy_contact_get_capabilities (contact) &
1076 EMPATHY_CAPABILITIES_VIDEO,
1077 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1081 /* Else add to each group. */
1082 for (l = groups; l; l = l->next) {
1083 GtkTreeIter iter_group;
1085 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);
1087 gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
1089 gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
1090 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1091 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1092 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1093 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1094 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1095 empathy_contact_get_capabilities (contact) &
1096 EMPATHY_CAPABILITIES_AUDIO,
1097 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1098 empathy_contact_get_capabilities (contact) &
1099 EMPATHY_CAPABILITIES_VIDEO,
1100 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1104 g_list_free (groups);
1106 contact_list_store_contact_update (store, contact);
1111 contact_list_store_remove_contact (EmpathyContactListStore *store,
1112 EmpathyContact *contact)
1114 EmpathyContactListStorePriv *priv;
1115 GtkTreeModel *model;
1118 priv = GET_PRIV (store);
1120 iters = contact_list_store_find_contact (store, contact);
1125 /* Clean up model */
1126 model = GTK_TREE_MODEL (store);
1128 for (l = iters; l; l = l->next) {
1131 /* NOTE: it is only <= 2 here because we have
1132 * separators after the group name, otherwise it
1135 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
1136 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1137 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1139 gtk_tree_store_remove (GTK_TREE_STORE (store), l->data);
1143 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1144 g_list_free (iters);
1148 list_store_contact_is_favourite (EmpathyContactListStore *store,
1149 EmpathyContact *contact)
1151 EmpathyContactListStorePriv *priv;
1153 priv = GET_PRIV (store);
1155 return empathy_contact_list_is_favourite (priv->list, contact);
1159 contact_list_store_contact_update (EmpathyContactListStore *store,
1160 EmpathyContact *contact)
1162 EmpathyContactListStorePriv *priv;
1163 ShowActiveData *data;
1164 GtkTreeModel *model;
1167 gboolean should_be_in_list;
1168 gboolean was_online = TRUE;
1169 gboolean now_online = FALSE;
1170 gboolean set_model = FALSE;
1171 gboolean do_remove = FALSE;
1172 gboolean do_set_active = FALSE;
1173 gboolean do_set_refresh = FALSE;
1174 gboolean show_avatar = FALSE;
1175 GdkPixbuf *pixbuf_avatar;
1176 GdkPixbuf *pixbuf_status;
1178 priv = GET_PRIV (store);
1180 model = GTK_TREE_MODEL (store);
1182 iters = contact_list_store_find_contact (store, contact);
1189 /* Get online state now. */
1190 now_online = empathy_contact_is_online (contact);
1192 if (priv->show_offline || now_online) {
1193 should_be_in_list = TRUE;
1195 should_be_in_list = FALSE;
1198 if (!in_list && !should_be_in_list) {
1199 /* Nothing to do. */
1200 DEBUG ("Contact:'%s' in list:NO, should be:NO",
1201 empathy_contact_get_name (contact));
1203 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1204 g_list_free (iters);
1207 else if (in_list && !should_be_in_list) {
1208 DEBUG ("Contact:'%s' in list:YES, should be:NO",
1209 empathy_contact_get_name (contact));
1211 if (priv->show_active) {
1213 do_set_active = TRUE;
1214 do_set_refresh = TRUE;
1217 DEBUG ("Remove item (after timeout)");
1219 DEBUG ("Remove item (now)!");
1220 contact_list_store_remove_contact (store, contact);
1223 else if (!in_list && should_be_in_list) {
1224 DEBUG ("Contact:'%s' in list:NO, should be:YES",
1225 empathy_contact_get_name (contact));
1227 contact_list_store_add_contact (store, contact);
1229 if (priv->show_active) {
1230 do_set_active = TRUE;
1232 DEBUG ("Set active (contact added)");
1235 DEBUG ("Contact:'%s' in list:YES, should be:YES",
1236 empathy_contact_get_name (contact));
1238 /* Get online state before. */
1239 if (iters && g_list_length (iters) > 0) {
1240 gtk_tree_model_get (model, iters->data,
1241 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online,
1245 /* Is this really an update or an online/offline. */
1246 if (priv->show_active) {
1247 if (was_online != now_online) {
1248 do_set_active = TRUE;
1249 do_set_refresh = TRUE;
1251 DEBUG ("Set active (contact updated %s)",
1252 was_online ? "online -> offline" :
1253 "offline -> online");
1255 /* Was TRUE for presence updates. */
1256 /* do_set_active = FALSE; */
1257 do_set_refresh = TRUE;
1259 DEBUG ("Set active (contact updated)");
1266 if (priv->show_avatars && !priv->is_compact) {
1269 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
1270 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1271 for (l = iters; l && set_model; l = l->next) {
1272 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1273 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, list_store_contact_is_favourite (store, contact),
1274 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1275 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1276 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1277 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1278 EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact),
1279 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1280 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1281 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1282 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1283 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1284 empathy_contact_get_capabilities (contact) &
1285 EMPATHY_CAPABILITIES_AUDIO,
1286 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1287 empathy_contact_get_capabilities (contact) &
1288 EMPATHY_CAPABILITIES_VIDEO,
1292 if (pixbuf_avatar) {
1293 g_object_unref (pixbuf_avatar);
1296 if (priv->show_active && do_set_active) {
1297 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1299 if (do_set_active) {
1300 data = contact_list_store_contact_active_new (store, contact, do_remove);
1301 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1302 (GSourceFunc) contact_list_store_contact_active_cb,
1307 /* FIXME: when someone goes online then offline quickly, the
1308 * first timeout sets the user to be inactive and the second
1309 * timeout removes the user from the contact list, really we
1310 * should remove the first timeout.
1312 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1313 g_list_free (iters);
1317 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1319 EmpathyContactListStore *store)
1321 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1322 empathy_contact_get_name (contact));
1324 contact_list_store_contact_update (store, contact);
1328 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1329 EmpathyContact *contact,
1331 gboolean set_changed)
1333 EmpathyContactListStorePriv *priv;
1334 GtkTreeModel *model;
1337 priv = GET_PRIV (store);
1338 model = GTK_TREE_MODEL (store);
1340 iters = contact_list_store_find_contact (store, contact);
1341 for (l = iters; l; l = l->next) {
1344 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1345 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, active,
1348 DEBUG ("Set item %s", active ? "active" : "inactive");
1351 path = gtk_tree_model_get_path (model, l->data);
1352 gtk_tree_model_row_changed (model, path, l->data);
1353 gtk_tree_path_free (path);
1357 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1358 g_list_free (iters);
1362 static ShowActiveData *
1363 contact_list_store_contact_active_new (EmpathyContactListStore *store,
1364 EmpathyContact *contact,
1367 ShowActiveData *data;
1369 DEBUG ("Contact:'%s' now active, and %s be removed",
1370 empathy_contact_get_name (contact),
1371 remove_ ? "WILL" : "WILL NOT");
1373 data = g_slice_new0 (ShowActiveData);
1375 data->store = g_object_ref (store);
1376 data->contact = g_object_ref (contact);
1377 data->remove = remove_;
1383 contact_list_store_contact_active_free (ShowActiveData *data)
1385 g_object_unref (data->contact);
1386 g_object_unref (data->store);
1388 g_slice_free (ShowActiveData, data);
1392 contact_list_store_contact_active_cb (ShowActiveData *data)
1394 EmpathyContactListStorePriv *priv;
1396 priv = GET_PRIV (data->store);
1399 !priv->show_offline &&
1400 !empathy_contact_is_online (data->contact)) {
1401 DEBUG ("Contact:'%s' active timeout, removing item",
1402 empathy_contact_get_name (data->contact));
1403 contact_list_store_remove_contact (data->store, data->contact);
1406 DEBUG ("Contact:'%s' no longer active",
1407 empathy_contact_get_name (data->contact));
1409 contact_list_store_contact_set_active (data->store,
1414 contact_list_store_contact_active_free (data);
1420 contact_list_store_get_group_foreach (GtkTreeModel *model,
1428 /* Groups are only at the top level. */
1429 if (gtk_tree_path_get_depth (path) != 1) {
1433 gtk_tree_model_get (model, iter,
1434 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &str,
1435 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1438 if (is_group && !tp_strdiff (str, fg->name)) {
1449 contact_list_store_get_group (EmpathyContactListStore *store,
1451 GtkTreeIter *iter_group_to_set,
1452 GtkTreeIter *iter_separator_to_set,
1455 EmpathyContactListStorePriv *priv;
1456 GtkTreeModel *model;
1457 GtkTreeIter iter_group;
1458 GtkTreeIter iter_separator;
1461 priv = GET_PRIV (store);
1463 memset (&fg, 0, sizeof (fg));
1467 model = GTK_TREE_MODEL (store);
1468 gtk_tree_model_foreach (model,
1469 (GtkTreeModelForeachFunc) contact_list_store_get_group_foreach,
1477 gtk_tree_store_append (GTK_TREE_STORE (store), &iter_group, NULL);
1478 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_group,
1479 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1480 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1481 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1482 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1483 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1486 if (iter_group_to_set) {
1487 *iter_group_to_set = iter_group;
1490 gtk_tree_store_append (GTK_TREE_STORE (store),
1493 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_separator,
1494 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1497 if (iter_separator_to_set) {
1498 *iter_separator_to_set = iter_separator;
1505 if (iter_group_to_set) {
1506 *iter_group_to_set = fg.iter;
1509 iter_separator = fg.iter;
1511 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1512 gboolean is_separator;
1514 gtk_tree_model_get (model, &iter_separator,
1515 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1518 if (is_separator && iter_separator_to_set) {
1519 *iter_separator_to_set = iter_separator;
1526 contact_list_store_state_sort_func (GtkTreeModel *model,
1527 GtkTreeIter *iter_a,
1528 GtkTreeIter *iter_b,
1532 gchar *name_a, *name_b;
1533 gboolean is_separator_a, is_separator_b;
1534 gboolean is_favourite_a, is_favourite_b;
1535 EmpathyContact *contact_a, *contact_b;
1537 gtk_tree_model_get (model, iter_a,
1538 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1539 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1540 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1541 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_a,
1543 gtk_tree_model_get (model, iter_b,
1544 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1545 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1546 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1547 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_b,
1550 /* Separator, favourites group, or other group? */
1551 if (is_separator_a || is_separator_b) {
1552 if (is_separator_a) {
1554 } else if (is_separator_b) {
1557 } else if (is_favourite_a && !is_favourite_b) {
1559 } else if (!is_favourite_a && is_favourite_b) {
1561 } else if (!contact_a && contact_b) {
1563 } else if (contact_a && !contact_b) {
1565 } else if (!contact_a && !contact_b) {
1567 ret_val = g_utf8_collate (name_a, name_b);
1574 /* If we managed to get this far, we can start looking at
1577 ret_val = -tp_connection_presence_type_cmp_availability (
1578 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1579 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1582 /* Fallback: compare by name */
1583 ret_val = g_utf8_collate (name_a, name_b);
1591 g_object_unref (contact_a);
1595 g_object_unref (contact_b);
1602 contact_list_store_name_sort_func (GtkTreeModel *model,
1603 GtkTreeIter *iter_a,
1604 GtkTreeIter *iter_b,
1607 gchar *name_a, *name_b;
1608 EmpathyContact *contact_a, *contact_b;
1609 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1610 gboolean is_favourite_a, is_favourite_b;
1613 gtk_tree_model_get (model, iter_a,
1614 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1615 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1616 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1617 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_a,
1619 gtk_tree_model_get (model, iter_b,
1620 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1621 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1622 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1623 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_b,
1626 /* If contact is NULL it means it's a group. */
1628 if (is_separator_a || is_separator_b) {
1629 if (is_separator_a) {
1631 } else if (is_separator_b) {
1634 } else if (is_favourite_a && !is_favourite_b) {
1636 } else if (!is_favourite_a && is_favourite_b) {
1638 } else if (!contact_a && contact_b) {
1640 } else if (contact_a && !contact_b) {
1643 ret_val = g_utf8_collate (name_a, name_b);
1650 g_object_unref (contact_a);
1654 g_object_unref (contact_b);
1661 contact_list_store_find_contact_foreach (GtkTreeModel *model,
1666 EmpathyContact *contact;
1668 gtk_tree_model_get (model, iter,
1669 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1672 if (contact == fc->contact) {
1674 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
1678 g_object_unref (contact);
1685 contact_list_store_find_contact (EmpathyContactListStore *store,
1686 EmpathyContact *contact)
1688 EmpathyContactListStorePriv *priv;
1689 GtkTreeModel *model;
1693 priv = GET_PRIV (store);
1695 memset (&fc, 0, sizeof (fc));
1697 fc.contact = contact;
1699 model = GTK_TREE_MODEL (store);
1700 gtk_tree_model_foreach (model,
1701 (GtkTreeModelForeachFunc) contact_list_store_find_contact_foreach,
1712 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1715 EmpathyContactListStore *store)
1717 EmpathyContactListStorePriv *priv;
1718 gboolean show_avatar = FALSE;
1719 EmpathyContact *contact;
1720 GdkPixbuf *pixbuf_status;
1722 priv = GET_PRIV (store);
1724 if (priv->show_avatars && !priv->is_compact) {
1728 gtk_tree_model_get (model, iter,
1729 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1732 if (contact == NULL){
1735 /* get icon from hash_table */
1736 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1738 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1739 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1740 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1741 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1748 contact_list_store_get_contact_status_icon_with_icon_name (
1749 EmpathyContactListStore *store,
1750 EmpathyContact *contact,
1751 const gchar *status_icon_name)
1753 GdkPixbuf *pixbuf_status = NULL;
1754 EmpathyContactListStorePriv *priv;
1755 const gchar *protocol_name = NULL;
1756 gchar *icon_name = NULL;
1758 priv = GET_PRIV (store);
1760 if (priv->show_protocols) {
1761 protocol_name = empathy_protocol_name_for_contact (contact);
1762 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1764 icon_name = g_strdup_printf ("%s", status_icon_name);
1766 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1767 if (pixbuf_status == NULL) {
1768 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1770 priv->show_protocols);
1771 if (pixbuf_status != NULL) {
1772 g_hash_table_insert (priv->status_icons,
1773 g_strdup (icon_name),
1779 return pixbuf_status;
1783 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1784 EmpathyContact *contact)
1786 GdkPixbuf *pixbuf_status = NULL;
1787 const gchar *status_icon_name = NULL;
1789 status_icon_name = empathy_icon_name_for_contact (contact);
1790 if (status_icon_name == NULL)
1793 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1798 return pixbuf_status;