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,
970 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
971 EmpathyContact *old_contact,
972 EmpathyContact *new_contact,
975 EmpathyContactListStore *store)
977 EmpathyContactListStorePriv *priv;
979 priv = GET_PRIV (store);
981 DEBUG ("Contact %s (%d) renamed to %s (%d)",
982 empathy_contact_get_id (old_contact),
983 empathy_contact_get_handle (old_contact),
984 empathy_contact_get_id (new_contact),
985 empathy_contact_get_handle (new_contact));
987 /* add the new contact */
988 contact_list_store_add_contact_and_connect (store, new_contact);
990 /* remove old contact */
991 contact_list_store_remove_contact_and_disconnect (store, old_contact);
995 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
996 EmpathyContact *contact,
999 EmpathyContactListStore *store)
1001 EmpathyContactListStorePriv *priv;
1002 gboolean show_active;
1004 priv = GET_PRIV (store);
1006 DEBUG ("Updating groups for contact %s (%d)",
1007 empathy_contact_get_id (contact),
1008 empathy_contact_get_handle (contact));
1010 /* We do this to make sure the groups are correct, if not, we
1011 * would have to check the groups already set up for each
1012 * contact and then see what has been updated.
1014 show_active = priv->show_active;
1015 priv->show_active = FALSE;
1016 contact_list_store_remove_contact (store, contact);
1017 contact_list_store_add_contact (store, contact);
1018 priv->show_active = show_active;
1022 contact_list_store_add_contact (EmpathyContactListStore *store,
1023 EmpathyContact *contact)
1025 EmpathyContactListStorePriv *priv;
1027 GList *groups = NULL, *l;
1028 TpConnection *connection;
1029 EmpathyContactListFlags flags = 0;
1031 priv = GET_PRIV (store);
1033 if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
1034 (!priv->show_offline && !empathy_contact_is_online (contact))) {
1038 if (priv->show_groups) {
1039 groups = empathy_contact_list_get_groups (priv->list, contact);
1042 connection = empathy_contact_get_connection (contact);
1043 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
1044 flags = empathy_contact_manager_get_flags_for_connection (
1045 EMPATHY_CONTACT_MANAGER (priv->list), connection);
1047 /* If no groups just add it at the top level. */
1049 GtkTreeModel *model = GTK_TREE_MODEL (store);
1051 if (gtk_tree_model_get_iter_first (model, &iter)) do {
1054 gtk_tree_model_get (model, &iter,
1055 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
1064 } while (gtk_tree_model_iter_next (model, &iter));
1066 gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
1067 gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
1068 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1069 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1070 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1071 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1072 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1073 empathy_contact_get_capabilities (contact) &
1074 EMPATHY_CAPABILITIES_AUDIO,
1075 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1076 empathy_contact_get_capabilities (contact) &
1077 EMPATHY_CAPABILITIES_VIDEO,
1078 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1082 /* Else add to each group. */
1083 for (l = groups; l; l = l->next) {
1084 GtkTreeIter iter_group;
1086 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);
1088 gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
1090 gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
1091 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1092 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1093 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1094 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1095 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1096 empathy_contact_get_capabilities (contact) &
1097 EMPATHY_CAPABILITIES_AUDIO,
1098 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1099 empathy_contact_get_capabilities (contact) &
1100 EMPATHY_CAPABILITIES_VIDEO,
1101 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1105 g_list_free (groups);
1107 contact_list_store_contact_update (store, contact);
1112 contact_list_store_remove_contact (EmpathyContactListStore *store,
1113 EmpathyContact *contact)
1115 EmpathyContactListStorePriv *priv;
1116 GtkTreeModel *model;
1119 priv = GET_PRIV (store);
1121 iters = contact_list_store_find_contact (store, contact);
1126 /* Clean up model */
1127 model = GTK_TREE_MODEL (store);
1129 for (l = iters; l; l = l->next) {
1132 /* NOTE: it is only <= 2 here because we have
1133 * separators after the group name, otherwise it
1136 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
1137 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1138 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1140 gtk_tree_store_remove (GTK_TREE_STORE (store), l->data);
1144 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1145 g_list_free (iters);
1149 list_store_contact_is_favourite (EmpathyContactListStore *store,
1150 EmpathyContact *contact)
1152 EmpathyContactListStorePriv *priv;
1154 priv = GET_PRIV (store);
1156 return empathy_contact_list_is_favourite (priv->list, contact);
1160 contact_list_store_contact_update (EmpathyContactListStore *store,
1161 EmpathyContact *contact)
1163 EmpathyContactListStorePriv *priv;
1164 ShowActiveData *data;
1165 GtkTreeModel *model;
1168 gboolean should_be_in_list;
1169 gboolean was_online = TRUE;
1170 gboolean now_online = FALSE;
1171 gboolean set_model = FALSE;
1172 gboolean do_remove = FALSE;
1173 gboolean do_set_active = FALSE;
1174 gboolean do_set_refresh = FALSE;
1175 gboolean show_avatar = FALSE;
1176 GdkPixbuf *pixbuf_avatar;
1177 GdkPixbuf *pixbuf_status;
1179 priv = GET_PRIV (store);
1181 model = GTK_TREE_MODEL (store);
1183 iters = contact_list_store_find_contact (store, contact);
1190 /* Get online state now. */
1191 now_online = empathy_contact_is_online (contact);
1193 if (priv->show_offline || now_online) {
1194 should_be_in_list = TRUE;
1196 should_be_in_list = FALSE;
1199 if (!in_list && !should_be_in_list) {
1200 /* Nothing to do. */
1201 DEBUG ("Contact:'%s' in list:NO, should be:NO",
1202 empathy_contact_get_name (contact));
1204 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1205 g_list_free (iters);
1208 else if (in_list && !should_be_in_list) {
1209 DEBUG ("Contact:'%s' in list:YES, should be:NO",
1210 empathy_contact_get_name (contact));
1212 if (priv->show_active) {
1214 do_set_active = TRUE;
1215 do_set_refresh = TRUE;
1218 DEBUG ("Remove item (after timeout)");
1220 DEBUG ("Remove item (now)!");
1221 contact_list_store_remove_contact (store, contact);
1224 else if (!in_list && should_be_in_list) {
1225 DEBUG ("Contact:'%s' in list:NO, should be:YES",
1226 empathy_contact_get_name (contact));
1228 contact_list_store_add_contact (store, contact);
1230 if (priv->show_active) {
1231 do_set_active = TRUE;
1233 DEBUG ("Set active (contact added)");
1236 DEBUG ("Contact:'%s' in list:YES, should be:YES",
1237 empathy_contact_get_name (contact));
1239 /* Get online state before. */
1240 if (iters && g_list_length (iters) > 0) {
1241 gtk_tree_model_get (model, iters->data,
1242 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online,
1246 /* Is this really an update or an online/offline. */
1247 if (priv->show_active) {
1248 if (was_online != now_online) {
1249 do_set_active = TRUE;
1250 do_set_refresh = TRUE;
1252 DEBUG ("Set active (contact updated %s)",
1253 was_online ? "online -> offline" :
1254 "offline -> online");
1256 /* Was TRUE for presence updates. */
1257 /* do_set_active = FALSE; */
1258 do_set_refresh = TRUE;
1260 DEBUG ("Set active (contact updated)");
1267 if (priv->show_avatars && !priv->is_compact) {
1270 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
1271 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1272 for (l = iters; l && set_model; l = l->next) {
1273 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1274 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, list_store_contact_is_favourite (store, contact),
1275 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1276 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1277 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1278 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
1279 EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact),
1280 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1281 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1282 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1283 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1284 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1285 empathy_contact_get_capabilities (contact) &
1286 EMPATHY_CAPABILITIES_AUDIO,
1287 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1288 empathy_contact_get_capabilities (contact) &
1289 EMPATHY_CAPABILITIES_VIDEO,
1293 if (pixbuf_avatar) {
1294 g_object_unref (pixbuf_avatar);
1297 if (priv->show_active && do_set_active) {
1298 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1300 if (do_set_active) {
1301 data = contact_list_store_contact_active_new (store, contact, do_remove);
1302 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1303 (GSourceFunc) contact_list_store_contact_active_cb,
1308 /* FIXME: when someone goes online then offline quickly, the
1309 * first timeout sets the user to be inactive and the second
1310 * timeout removes the user from the contact list, really we
1311 * should remove the first timeout.
1313 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1314 g_list_free (iters);
1318 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1320 EmpathyContactListStore *store)
1322 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1323 empathy_contact_get_name (contact));
1325 contact_list_store_contact_update (store, contact);
1329 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1330 EmpathyContact *contact,
1332 gboolean set_changed)
1334 EmpathyContactListStorePriv *priv;
1335 GtkTreeModel *model;
1338 priv = GET_PRIV (store);
1339 model = GTK_TREE_MODEL (store);
1341 iters = contact_list_store_find_contact (store, contact);
1342 for (l = iters; l; l = l->next) {
1345 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1346 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, active,
1349 DEBUG ("Set item %s", active ? "active" : "inactive");
1352 path = gtk_tree_model_get_path (model, l->data);
1353 gtk_tree_model_row_changed (model, path, l->data);
1354 gtk_tree_path_free (path);
1358 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1359 g_list_free (iters);
1363 static ShowActiveData *
1364 contact_list_store_contact_active_new (EmpathyContactListStore *store,
1365 EmpathyContact *contact,
1368 ShowActiveData *data;
1370 DEBUG ("Contact:'%s' now active, and %s be removed",
1371 empathy_contact_get_name (contact),
1372 remove_ ? "WILL" : "WILL NOT");
1374 data = g_slice_new0 (ShowActiveData);
1376 data->store = g_object_ref (store);
1377 data->contact = g_object_ref (contact);
1378 data->remove = remove_;
1384 contact_list_store_contact_active_free (ShowActiveData *data)
1386 g_object_unref (data->contact);
1387 g_object_unref (data->store);
1389 g_slice_free (ShowActiveData, data);
1393 contact_list_store_contact_active_cb (ShowActiveData *data)
1395 EmpathyContactListStorePriv *priv;
1397 priv = GET_PRIV (data->store);
1400 !priv->show_offline &&
1401 !empathy_contact_is_online (data->contact)) {
1402 DEBUG ("Contact:'%s' active timeout, removing item",
1403 empathy_contact_get_name (data->contact));
1404 contact_list_store_remove_contact (data->store, data->contact);
1407 DEBUG ("Contact:'%s' no longer active",
1408 empathy_contact_get_name (data->contact));
1410 contact_list_store_contact_set_active (data->store,
1415 contact_list_store_contact_active_free (data);
1421 contact_list_store_get_group_foreach (GtkTreeModel *model,
1429 /* Groups are only at the top level. */
1430 if (gtk_tree_path_get_depth (path) != 1) {
1434 gtk_tree_model_get (model, iter,
1435 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &str,
1436 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1439 if (is_group && !tp_strdiff (str, fg->name)) {
1450 contact_list_store_get_group (EmpathyContactListStore *store,
1452 GtkTreeIter *iter_group_to_set,
1453 GtkTreeIter *iter_separator_to_set,
1456 EmpathyContactListStorePriv *priv;
1457 GtkTreeModel *model;
1458 GtkTreeIter iter_group;
1459 GtkTreeIter iter_separator;
1462 priv = GET_PRIV (store);
1464 memset (&fg, 0, sizeof (fg));
1468 model = GTK_TREE_MODEL (store);
1469 gtk_tree_model_foreach (model,
1470 (GtkTreeModelForeachFunc) contact_list_store_get_group_foreach,
1478 gtk_tree_store_append (GTK_TREE_STORE (store), &iter_group, NULL);
1479 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_group,
1480 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1481 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1482 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1483 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1484 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1487 if (iter_group_to_set) {
1488 *iter_group_to_set = iter_group;
1491 gtk_tree_store_append (GTK_TREE_STORE (store),
1494 gtk_tree_store_set (GTK_TREE_STORE (store), &iter_separator,
1495 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1498 if (iter_separator_to_set) {
1499 *iter_separator_to_set = iter_separator;
1506 if (iter_group_to_set) {
1507 *iter_group_to_set = fg.iter;
1510 iter_separator = fg.iter;
1512 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1513 gboolean is_separator;
1515 gtk_tree_model_get (model, &iter_separator,
1516 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1519 if (is_separator && iter_separator_to_set) {
1520 *iter_separator_to_set = iter_separator;
1527 contact_list_store_state_sort_func (GtkTreeModel *model,
1528 GtkTreeIter *iter_a,
1529 GtkTreeIter *iter_b,
1533 gchar *name_a, *name_b;
1534 gboolean is_separator_a, is_separator_b;
1535 gboolean is_favourite_a, is_favourite_b;
1536 EmpathyContact *contact_a, *contact_b;
1538 gtk_tree_model_get (model, iter_a,
1539 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1540 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1541 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1542 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_a,
1544 gtk_tree_model_get (model, iter_b,
1545 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1546 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1547 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1548 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_b,
1551 /* Separator, favourites group, or other group? */
1552 if (is_separator_a || is_separator_b) {
1553 if (is_separator_a) {
1555 } else if (is_separator_b) {
1558 } else if (is_favourite_a && !is_favourite_b) {
1560 } else if (!is_favourite_a && is_favourite_b) {
1562 } else if (!contact_a && contact_b) {
1564 } else if (contact_a && !contact_b) {
1566 } else if (!contact_a && !contact_b) {
1568 ret_val = g_utf8_collate (name_a, name_b);
1575 /* If we managed to get this far, we can start looking at
1578 ret_val = -tp_connection_presence_type_cmp_availability (
1579 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1580 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1583 /* Fallback: compare by name */
1584 ret_val = g_utf8_collate (name_a, name_b);
1592 g_object_unref (contact_a);
1596 g_object_unref (contact_b);
1603 contact_list_store_name_sort_func (GtkTreeModel *model,
1604 GtkTreeIter *iter_a,
1605 GtkTreeIter *iter_b,
1608 gchar *name_a, *name_b;
1609 EmpathyContact *contact_a, *contact_b;
1610 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1611 gboolean is_favourite_a, is_favourite_b;
1614 gtk_tree_model_get (model, iter_a,
1615 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1616 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1617 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1618 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_a,
1620 gtk_tree_model_get (model, iter_b,
1621 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1622 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1623 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1624 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAVOURITE, &is_favourite_b,
1627 /* If contact is NULL it means it's a group. */
1629 if (is_separator_a || is_separator_b) {
1630 if (is_separator_a) {
1632 } else if (is_separator_b) {
1635 } else if (is_favourite_a && !is_favourite_b) {
1637 } else if (!is_favourite_a && is_favourite_b) {
1639 } else if (!contact_a && contact_b) {
1641 } else if (contact_a && !contact_b) {
1644 ret_val = g_utf8_collate (name_a, name_b);
1651 g_object_unref (contact_a);
1655 g_object_unref (contact_b);
1662 contact_list_store_find_contact_foreach (GtkTreeModel *model,
1667 EmpathyContact *contact;
1669 gtk_tree_model_get (model, iter,
1670 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1673 if (contact == fc->contact) {
1675 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
1679 g_object_unref (contact);
1686 contact_list_store_find_contact (EmpathyContactListStore *store,
1687 EmpathyContact *contact)
1689 EmpathyContactListStorePriv *priv;
1690 GtkTreeModel *model;
1694 priv = GET_PRIV (store);
1696 memset (&fc, 0, sizeof (fc));
1698 fc.contact = contact;
1700 model = GTK_TREE_MODEL (store);
1701 gtk_tree_model_foreach (model,
1702 (GtkTreeModelForeachFunc) contact_list_store_find_contact_foreach,
1713 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1716 EmpathyContactListStore *store)
1718 EmpathyContactListStorePriv *priv;
1719 gboolean show_avatar = FALSE;
1720 EmpathyContact *contact;
1721 GdkPixbuf *pixbuf_status;
1723 priv = GET_PRIV (store);
1725 if (priv->show_avatars && !priv->is_compact) {
1729 gtk_tree_model_get (model, iter,
1730 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1733 if (contact == NULL){
1736 /* get icon from hash_table */
1737 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1739 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1740 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1741 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1742 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
1749 contact_list_store_get_contact_status_icon_with_icon_name (
1750 EmpathyContactListStore *store,
1751 EmpathyContact *contact,
1752 const gchar *status_icon_name)
1754 GdkPixbuf *pixbuf_status = NULL;
1755 EmpathyContactListStorePriv *priv;
1756 const gchar *protocol_name = NULL;
1757 gchar *icon_name = NULL;
1759 priv = GET_PRIV (store);
1761 if (priv->show_protocols) {
1762 protocol_name = empathy_protocol_name_for_contact (contact);
1763 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1765 icon_name = g_strdup_printf ("%s", status_icon_name);
1767 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1768 if (pixbuf_status == NULL) {
1769 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1771 priv->show_protocols);
1772 if (pixbuf_status != NULL) {
1773 g_hash_table_insert (priv->status_icons,
1774 g_strdup (icon_name),
1780 return pixbuf_status;
1784 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1785 EmpathyContact *contact)
1787 GdkPixbuf *pixbuf_status = NULL;
1788 const gchar *status_icon_name = NULL;
1790 status_icon_name = empathy_icon_name_for_contact (contact);
1791 if (status_icon_name == NULL)
1794 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1799 return pixbuf_status;