1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
31 #include <glib/gi18n-lib.h>
34 #include <telepathy-glib/util.h>
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-tp-chat.h>
38 #include <libempathy/empathy-enum-types.h>
39 #include <libempathy/empathy-contact-manager.h>
41 #include "empathy-contact-list-store.h"
42 #include "empathy-ui-utils.h"
43 #include "empathy-gtk-enum-types.h"
44 #include "empathy-images.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
47 #include <libempathy/empathy-debug.h>
49 /* Active users are those which have recently changed state
50 * (e.g. online, offline or from normal to a busy state).
53 /* Time in seconds user is shown as active */
54 #define ACTIVE_USER_SHOW_TIME 7
56 /* Time in seconds after connecting which we wait before active users are enabled */
57 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
59 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactListStore)
61 EmpathyContactList *list;
62 gboolean show_offline;
63 gboolean show_avatars;
66 gboolean show_protocols;
68 EmpathyContactListStoreSort sort_criterium;
71 gboolean dispose_has_run;
72 GHashTable *status_icons;
73 /* Hash: EmpathyContact* -> GQueue (GtkTreeIter *) */
74 GHashTable *empathy_contact_cache;
75 /* Hash: char *groupname -> GtkTreeIter * */
76 GHashTable *empathy_group_cache;
77 } EmpathyContactListStorePriv;
80 EmpathyContactListStore *store;
81 EmpathyContact *contact;
85 static void contact_list_store_dispose (GObject *object);
86 static void contact_list_store_get_property (GObject *object,
90 static void contact_list_store_set_property (GObject *object,
94 static void contact_list_store_setup (EmpathyContactListStore *store);
95 static gboolean contact_list_store_inibit_active_cb (EmpathyContactListStore *store);
96 static void contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
97 EmpathyContact *contact,
98 EmpathyContact *actor,
102 EmpathyContactListStore *store);
103 static void contact_list_store_favourites_changed_cb (EmpathyContactList *list_iface,
104 EmpathyContact *contact,
105 gboolean is_favourite,
106 EmpathyContactListStore *store);
107 static void contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
108 EmpathyContact *old_contact,
109 EmpathyContact *new_contact,
112 EmpathyContactListStore *store);
113 static void contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
114 EmpathyContact *contact,
117 EmpathyContactListStore *store);
118 static void contact_list_store_add_contact (EmpathyContactListStore *store,
119 EmpathyContact *contact);
120 static void contact_list_store_remove_contact (EmpathyContactListStore *store,
121 EmpathyContact *contact);
122 static void contact_list_store_contact_update (EmpathyContactListStore *store,
123 EmpathyContact *contact);
124 static void contact_list_store_contact_updated_cb (EmpathyContact *contact,
126 EmpathyContactListStore *store);
127 static void contact_list_store_contact_set_active (EmpathyContactListStore *store,
128 EmpathyContact *contact,
130 gboolean set_changed);
131 static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store,
132 EmpathyContact *contact,
134 static void contact_list_store_contact_active_free (ShowActiveData *data);
135 static gboolean contact_list_store_contact_active_cb (ShowActiveData *data);
136 static void contact_list_store_get_group (EmpathyContactListStore *store,
138 GtkTreeIter *iter_group_to_set,
139 GtkTreeIter *iter_separator_to_set,
141 gboolean is_fake_group);
142 static gint contact_list_store_state_sort_func (GtkTreeModel *model,
146 static gint contact_list_store_name_sort_func (GtkTreeModel *model,
150 static GList * contact_list_store_find_contact (EmpathyContactListStore *store,
151 EmpathyContact *contact);
152 static gboolean contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
155 EmpathyContactListStore *store);
168 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
171 contact_list_store_chat_state_changed_cb (TpChannel *self,
172 guint contact_handle,
176 EmpathyContactListStorePriv *priv = GET_PRIV (store);
179 contacts = empathy_contact_list_get_members (priv->list);
181 for (l = contacts; l != NULL; l = l->next) {
182 EmpathyContact *contact = EMPATHY_CONTACT (l->data);
184 if (empathy_contact_get_handle (contact) == contact_handle) {
185 contact_list_store_contact_update (store, contact);
190 g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
191 g_list_free (contacts);
195 contact_list_store_iface_setup (gpointer user_data)
197 EmpathyContactListStore *store = user_data;
198 EmpathyContactListStorePriv *priv = GET_PRIV (store);
201 /* Signal connection. */
202 g_signal_connect (priv->list,
204 G_CALLBACK (contact_list_store_member_renamed_cb),
206 g_signal_connect (priv->list,
208 G_CALLBACK (contact_list_store_members_changed_cb),
210 g_signal_connect (priv->list,
211 "favourites-changed",
212 G_CALLBACK (contact_list_store_favourites_changed_cb),
214 g_signal_connect (priv->list,
216 G_CALLBACK (contact_list_store_groups_changed_cb),
219 if (EMPATHY_IS_TP_CHAT (priv->list)) {
220 g_signal_connect (priv->list,
221 "chat-state-changed",
222 G_CALLBACK (contact_list_store_chat_state_changed_cb),
226 /* Add contacts already created. */
227 contacts = empathy_contact_list_get_members (priv->list);
228 for (l = contacts; l; l = l->next) {
229 contact_list_store_members_changed_cb (priv->list, l->data,
234 g_object_unref (l->data);
236 g_list_free (contacts);
238 priv->setup_idle_id = 0;
244 contact_list_store_set_contact_list (EmpathyContactListStore *store,
245 EmpathyContactList *list_iface)
247 EmpathyContactListStorePriv *priv = GET_PRIV (store);
249 priv->list = g_object_ref (list_iface);
251 /* Let a chance to have all properties set before populating */
252 priv->setup_idle_id = g_idle_add (contact_list_store_iface_setup, store);
256 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
258 GObjectClass *object_class = G_OBJECT_CLASS (klass);
260 object_class->dispose = contact_list_store_dispose;
261 object_class->get_property = contact_list_store_get_property;
262 object_class->set_property = contact_list_store_set_property;
264 g_object_class_install_property (object_class,
266 g_param_spec_object ("contact-list",
267 "The contact list iface",
268 "The contact list iface",
269 EMPATHY_TYPE_CONTACT_LIST,
270 G_PARAM_CONSTRUCT_ONLY |
272 g_object_class_install_property (object_class,
274 g_param_spec_boolean ("show-offline",
276 "Whether contact list should display "
280 g_object_class_install_property (object_class,
282 g_param_spec_boolean ("show-avatars",
284 "Whether contact list should display "
285 "avatars for contacts",
288 g_object_class_install_property (object_class,
290 g_param_spec_boolean ("show-protocols",
292 "Whether contact list should display "
293 "protocols for contacts",
296 g_object_class_install_property (object_class,
298 g_param_spec_boolean ("show-groups",
300 "Whether contact list should display "
304 g_object_class_install_property (object_class,
306 g_param_spec_boolean ("is-compact",
308 "Whether the contact list is in compact mode or not",
312 g_object_class_install_property (object_class,
314 g_param_spec_enum ("sort-criterium",
316 "The sort criterium to use for sorting the contact list",
317 EMPATHY_TYPE_CONTACT_LIST_STORE_SORT,
318 EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
321 g_type_class_add_private (object_class, sizeof (EmpathyContactListStorePriv));
325 g_queue_free_full_iter (gpointer data)
327 GQueue *queue = (GQueue *) data;
328 g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
329 g_queue_free (queue);
334 empathy_contact_list_store_init (EmpathyContactListStore *store)
336 EmpathyContactListStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
337 EMPATHY_TYPE_CONTACT_LIST_STORE, EmpathyContactListStorePriv);
340 priv->show_avatars = TRUE;
341 priv->show_groups = TRUE;
342 priv->show_protocols = FALSE;
343 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
344 (GSourceFunc) contact_list_store_inibit_active_cb,
346 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
347 priv->empathy_contact_cache = g_hash_table_new_full (NULL, NULL, NULL,
348 g_queue_free_full_iter);
349 priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
351 (GDestroyNotify) gtk_tree_iter_free);
352 contact_list_store_setup (store);
356 contact_list_store_dispose (GObject *object)
358 EmpathyContactListStorePriv *priv = GET_PRIV (object);
361 if (priv->dispose_has_run)
363 priv->dispose_has_run = TRUE;
365 contacts = empathy_contact_list_get_members (priv->list);
366 for (l = contacts; l; l = l->next) {
367 g_signal_handlers_disconnect_by_func (l->data,
368 G_CALLBACK (contact_list_store_contact_updated_cb),
371 g_object_unref (l->data);
373 g_list_free (contacts);
375 g_signal_handlers_disconnect_by_func (priv->list,
376 G_CALLBACK (contact_list_store_member_renamed_cb),
378 g_signal_handlers_disconnect_by_func (priv->list,
379 G_CALLBACK (contact_list_store_members_changed_cb),
381 g_signal_handlers_disconnect_by_func (priv->list,
382 G_CALLBACK (contact_list_store_favourites_changed_cb),
384 g_signal_handlers_disconnect_by_func (priv->list,
385 G_CALLBACK (contact_list_store_groups_changed_cb),
387 g_object_unref (priv->list);
389 if (priv->inhibit_active) {
390 g_source_remove (priv->inhibit_active);
393 if (priv->setup_idle_id != 0) {
394 g_source_remove (priv->setup_idle_id);
397 g_hash_table_destroy (priv->status_icons);
398 g_hash_table_destroy (priv->empathy_contact_cache);
399 g_hash_table_destroy (priv->empathy_group_cache);
400 G_OBJECT_CLASS (empathy_contact_list_store_parent_class)->dispose (object);
404 contact_list_store_get_property (GObject *object,
409 EmpathyContactListStorePriv *priv;
411 priv = GET_PRIV (object);
414 case PROP_CONTACT_LIST:
415 g_value_set_object (value, priv->list);
417 case PROP_SHOW_OFFLINE:
418 g_value_set_boolean (value, priv->show_offline);
420 case PROP_SHOW_AVATARS:
421 g_value_set_boolean (value, priv->show_avatars);
423 case PROP_SHOW_PROTOCOLS:
424 g_value_set_boolean (value, priv->show_protocols);
426 case PROP_SHOW_GROUPS:
427 g_value_set_boolean (value, priv->show_groups);
429 case PROP_IS_COMPACT:
430 g_value_set_boolean (value, priv->is_compact);
432 case PROP_SORT_CRITERIUM:
433 g_value_set_enum (value, priv->sort_criterium);
436 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
442 contact_list_store_set_property (GObject *object,
448 case PROP_CONTACT_LIST:
449 contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
450 g_value_get_object (value));
452 case PROP_SHOW_OFFLINE:
453 empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
454 g_value_get_boolean (value));
456 case PROP_SHOW_AVATARS:
457 empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
458 g_value_get_boolean (value));
460 case PROP_SHOW_PROTOCOLS:
461 empathy_contact_list_store_set_show_protocols (EMPATHY_CONTACT_LIST_STORE (object),
462 g_value_get_boolean (value));
464 case PROP_SHOW_GROUPS:
465 empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
466 g_value_get_boolean (value));
468 case PROP_IS_COMPACT:
469 empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
470 g_value_get_boolean (value));
472 case PROP_SORT_CRITERIUM:
473 empathy_contact_list_store_set_sort_criterium (EMPATHY_CONTACT_LIST_STORE (object),
474 g_value_get_enum (value));
477 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
482 EmpathyContactListStore *
483 empathy_contact_list_store_new (EmpathyContactList *list_iface)
485 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
487 return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
488 "contact-list", list_iface,
493 empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store)
495 EmpathyContactListStorePriv *priv;
497 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
499 priv = GET_PRIV (store);
505 empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store)
507 EmpathyContactListStorePriv *priv;
509 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
511 priv = GET_PRIV (store);
513 return priv->show_offline;
517 empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
518 gboolean show_offline)
520 EmpathyContactListStorePriv *priv;
522 gboolean show_active;
524 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
526 priv = GET_PRIV (store);
528 priv->show_offline = show_offline;
529 show_active = priv->show_active;
531 /* Disable temporarily. */
532 priv->show_active = FALSE;
534 contacts = empathy_contact_list_get_members (priv->list);
535 for (l = contacts; l; l = l->next) {
536 contact_list_store_contact_update (store, l->data);
538 g_object_unref (l->data);
540 g_list_free (contacts);
542 /* Restore to original setting. */
543 priv->show_active = show_active;
545 g_object_notify (G_OBJECT (store), "show-offline");
549 empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store)
551 EmpathyContactListStorePriv *priv;
553 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
555 priv = GET_PRIV (store);
557 return priv->show_avatars;
561 empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
562 gboolean show_avatars)
564 EmpathyContactListStorePriv *priv;
567 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
569 priv = GET_PRIV (store);
571 priv->show_avatars = show_avatars;
573 model = GTK_TREE_MODEL (store);
575 gtk_tree_model_foreach (model,
576 (GtkTreeModelForeachFunc)
577 contact_list_store_update_list_mode_foreach,
580 g_object_notify (G_OBJECT (store), "show-avatars");
585 empathy_contact_list_store_get_show_protocols (EmpathyContactListStore *store)
587 EmpathyContactListStorePriv *priv;
589 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
591 priv = GET_PRIV (store);
593 return priv->show_protocols;
597 empathy_contact_list_store_set_show_protocols (EmpathyContactListStore *store,
598 gboolean show_protocols)
600 EmpathyContactListStorePriv *priv;
603 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
605 priv = GET_PRIV (store);
607 priv->show_protocols = show_protocols;
609 model = GTK_TREE_MODEL (store);
611 gtk_tree_model_foreach (model,
612 (GtkTreeModelForeachFunc)
613 contact_list_store_update_list_mode_foreach,
616 g_object_notify (G_OBJECT (store), "show-protocols");
620 empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
622 EmpathyContactListStorePriv *priv;
624 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
626 priv = GET_PRIV (store);
628 return priv->show_groups;
632 empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
633 gboolean show_groups)
635 EmpathyContactListStorePriv *priv;
637 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
639 priv = GET_PRIV (store);
641 if (priv->show_groups == show_groups) {
645 priv->show_groups = show_groups;
647 if (priv->setup_idle_id == 0) {
648 /* Remove all contacts and add them back, not optimized but
649 * that's the easy way :)
651 * This is only done if there's not a pending setup idle
652 * callback, otherwise it will race and the contacts will get
656 gtk_tree_store_clear (GTK_TREE_STORE (store));
658 /* Also clear the cache */
659 g_hash_table_remove_all (priv->empathy_contact_cache);
660 g_hash_table_remove_all (priv->empathy_group_cache);
662 contacts = empathy_contact_list_get_members (priv->list);
663 for (l = contacts; l; l = l->next) {
664 contact_list_store_members_changed_cb (priv->list,
670 g_object_unref (l->data);
672 g_list_free (contacts);
675 g_object_notify (G_OBJECT (store), "show-groups");
679 empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store)
681 EmpathyContactListStorePriv *priv;
683 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
685 priv = GET_PRIV (store);
687 return priv->is_compact;
691 empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
694 EmpathyContactListStorePriv *priv;
697 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
699 priv = GET_PRIV (store);
701 priv->is_compact = is_compact;
703 model = GTK_TREE_MODEL (store);
705 gtk_tree_model_foreach (model,
706 (GtkTreeModelForeachFunc)
707 contact_list_store_update_list_mode_foreach,
710 g_object_notify (G_OBJECT (store), "is-compact");
713 EmpathyContactListStoreSort
714 empathy_contact_list_store_get_sort_criterium (EmpathyContactListStore *store)
716 EmpathyContactListStorePriv *priv;
718 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), 0);
720 priv = GET_PRIV (store);
722 return priv->sort_criterium;
726 empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *store,
727 EmpathyContactListStoreSort sort_criterium)
729 EmpathyContactListStorePriv *priv;
731 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
733 priv = GET_PRIV (store);
735 priv->sort_criterium = sort_criterium;
737 switch (sort_criterium) {
738 case EMPATHY_CONTACT_LIST_STORE_SORT_STATE:
739 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
740 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
744 case EMPATHY_CONTACT_LIST_STORE_SORT_NAME:
745 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
746 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
751 g_assert_not_reached ();
754 g_object_notify (G_OBJECT (store), "sort-criterium");
758 empathy_contact_list_store_row_separator_func (GtkTreeModel *model,
762 gboolean is_separator = FALSE;
764 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
766 gtk_tree_model_get (model, iter,
767 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
774 empathy_contact_list_store_get_parent_group (GtkTreeModel *model,
776 gboolean *path_is_group,
777 gboolean *is_fake_group)
779 GtkTreeIter parent_iter, iter;
784 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
787 *path_is_group = FALSE;
790 if (!gtk_tree_model_get_iter (model, &iter, path)) {
794 gtk_tree_model_get (model, &iter,
795 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
796 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
803 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter)) {
809 gtk_tree_model_get (model, &iter,
810 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
811 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
812 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake,
821 *path_is_group = TRUE;
824 if (is_fake_group != NULL)
825 *is_fake_group = fake;
831 contact_list_store_setup (EmpathyContactListStore *store)
833 EmpathyContactListStorePriv *priv;
835 GDK_TYPE_PIXBUF, /* Status pixbuf */
836 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
837 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
838 G_TYPE_STRING, /* Name */
839 G_TYPE_UINT, /* Presence type */
840 G_TYPE_STRING, /* Status string */
841 G_TYPE_BOOLEAN, /* Compact view */
842 EMPATHY_TYPE_CONTACT, /* Contact type */
843 G_TYPE_BOOLEAN, /* Is group */
844 G_TYPE_BOOLEAN, /* Is active */
845 G_TYPE_BOOLEAN, /* Is online */
846 G_TYPE_BOOLEAN, /* Is separator */
847 G_TYPE_BOOLEAN, /* Can make audio calls */
848 G_TYPE_BOOLEAN, /* Can make video calls */
849 EMPATHY_TYPE_CONTACT_LIST_FLAGS, /* Flags */
850 G_TYPE_BOOLEAN, /* Is a fake group */
853 priv = GET_PRIV (store);
855 gtk_tree_store_set_column_types (GTK_TREE_STORE (store),
856 EMPATHY_CONTACT_LIST_STORE_COL_COUNT,
860 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
861 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
862 contact_list_store_name_sort_func,
864 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
865 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
866 contact_list_store_state_sort_func,
869 priv->sort_criterium = EMPATHY_CONTACT_LIST_STORE_SORT_NAME;
870 empathy_contact_list_store_set_sort_criterium (store, priv->sort_criterium);
874 contact_list_store_inibit_active_cb (EmpathyContactListStore *store)
876 EmpathyContactListStorePriv *priv;
878 priv = GET_PRIV (store);
880 priv->show_active = TRUE;
881 priv->inhibit_active = 0;
887 contact_list_store_add_contact_and_connect (EmpathyContactListStore *store, EmpathyContact *contact)
889 g_signal_connect (contact, "notify::presence",
890 G_CALLBACK (contact_list_store_contact_updated_cb),
892 g_signal_connect (contact, "notify::presence-message",
893 G_CALLBACK (contact_list_store_contact_updated_cb),
895 g_signal_connect (contact, "notify::name",
896 G_CALLBACK (contact_list_store_contact_updated_cb),
898 g_signal_connect (contact, "notify::avatar",
899 G_CALLBACK (contact_list_store_contact_updated_cb),
901 g_signal_connect (contact, "notify::capabilities",
902 G_CALLBACK (contact_list_store_contact_updated_cb),
905 contact_list_store_add_contact (store, contact);
909 contact_list_store_remove_contact_and_disconnect (EmpathyContactListStore *store, EmpathyContact *contact)
911 g_signal_handlers_disconnect_by_func (contact,
912 G_CALLBACK (contact_list_store_contact_updated_cb),
915 contact_list_store_remove_contact (store, contact);
919 contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
920 EmpathyContact *contact,
921 EmpathyContact *actor,
925 EmpathyContactListStore *store)
927 DEBUG ("Contact %s (%d) %s",
928 empathy_contact_get_id (contact),
929 empathy_contact_get_handle (contact),
930 is_member ? "added" : "removed");
933 contact_list_store_add_contact_and_connect (store, contact);
935 contact_list_store_remove_contact_and_disconnect (store, contact);
940 contact_list_store_favourites_changed_cb (EmpathyContactList *list_iface,
941 EmpathyContact *contact,
942 gboolean is_favourite,
943 EmpathyContactListStore *store)
945 DEBUG ("Contact %s (%d) is %s a favourite",
946 empathy_contact_get_id (contact),
947 empathy_contact_get_handle (contact),
948 is_favourite ? "now" : "no longer");
950 contact_list_store_remove_contact (store, contact);
951 contact_list_store_add_contact (store, contact);
955 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
956 EmpathyContact *old_contact,
957 EmpathyContact *new_contact,
960 EmpathyContactListStore *store)
962 DEBUG ("Contact %s (%d) renamed to %s (%d)",
963 empathy_contact_get_id (old_contact),
964 empathy_contact_get_handle (old_contact),
965 empathy_contact_get_id (new_contact),
966 empathy_contact_get_handle (new_contact));
968 /* add the new contact */
969 contact_list_store_add_contact_and_connect (store, new_contact);
971 /* remove old contact */
972 contact_list_store_remove_contact_and_disconnect (store, old_contact);
976 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
977 EmpathyContact *contact,
980 EmpathyContactListStore *store)
982 EmpathyContactListStorePriv *priv;
983 gboolean show_active;
985 priv = GET_PRIV (store);
987 DEBUG ("Updating groups for contact %s (%d)",
988 empathy_contact_get_id (contact),
989 empathy_contact_get_handle (contact));
991 /* We do this to make sure the groups are correct, if not, we
992 * would have to check the groups already set up for each
993 * contact and then see what has been updated.
995 show_active = priv->show_active;
996 priv->show_active = FALSE;
997 contact_list_store_remove_contact (store, contact);
998 contact_list_store_add_contact (store, contact);
999 priv->show_active = show_active;
1003 add_contact_to_store (GtkTreeStore *store,
1005 GtkTreeIter *parent,
1006 EmpathyContact *contact,
1007 EmpathyContactListFlags flags)
1009 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1012 gtk_tree_store_insert_with_values (store, iter, parent, 0,
1013 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_alias (contact),
1014 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
1015 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1016 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1017 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1018 empathy_contact_get_capabilities (contact) &
1019 EMPATHY_CAPABILITIES_AUDIO,
1020 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1021 empathy_contact_get_capabilities (contact) &
1022 EMPATHY_CAPABILITIES_VIDEO,
1023 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1026 queue = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1028 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
1030 queue = g_queue_new ();
1031 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
1032 g_hash_table_insert (priv->empathy_contact_cache, contact,
1038 contact_list_store_add_contact (EmpathyContactListStore *store,
1039 EmpathyContact *contact)
1041 EmpathyContactListStorePriv *priv;
1043 GList *groups = NULL, *l;
1044 TpConnection *connection;
1045 EmpathyContactListFlags flags = 0;
1046 char *protocol_name;
1048 priv = GET_PRIV (store);
1050 if (EMP_STR_EMPTY (empathy_contact_get_alias (contact)) ||
1051 (!priv->show_offline && !empathy_contact_is_online (contact))) {
1055 if (priv->show_groups) {
1056 groups = empathy_contact_list_get_groups (priv->list, contact);
1059 connection = empathy_contact_get_connection (contact);
1060 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
1061 flags = empathy_contact_manager_get_flags_for_connection (
1062 EMPATHY_CONTACT_MANAGER (priv->list), connection);
1065 tp_connection_parse_object_path (connection, &protocol_name, NULL);
1068 GtkTreeIter iter_group, *parent;
1070 parent = &iter_group;
1072 if (!priv->show_groups) {
1074 } else if (!tp_strdiff (protocol_name, "local-xmpp")) {
1075 /* these are People Nearby */
1076 contact_list_store_get_group (store,
1077 EMPATHY_CONTACT_LIST_STORE_PEOPLE_NEARBY,
1078 &iter_group, NULL, NULL, TRUE);
1080 contact_list_store_get_group (store,
1081 EMPATHY_CONTACT_LIST_STORE_UNGROUPED,
1082 &iter_group, NULL, NULL, TRUE);
1085 add_contact_to_store (GTK_TREE_STORE (store), &iter, parent,
1089 g_free (protocol_name);
1091 /* Else add to each group. */
1092 for (l = groups; l; l = l->next) {
1093 GtkTreeIter iter_group;
1095 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL, FALSE);
1097 add_contact_to_store (GTK_TREE_STORE (store), &iter, &iter_group, contact, flags);
1100 g_list_free (groups);
1102 if (priv->show_groups &&
1103 empathy_contact_list_is_favourite (priv->list, contact)) {
1104 /* Add contact to the fake 'Favorites' group */
1105 GtkTreeIter iter_group;
1107 contact_list_store_get_group (store, EMPATHY_CONTACT_LIST_STORE_FAVORITE,
1108 &iter_group, NULL, NULL, TRUE);
1110 add_contact_to_store (GTK_TREE_STORE (store), &iter, &iter_group, contact, flags);
1113 contact_list_store_contact_update (store, contact);
1117 contact_list_store_remove_contact (EmpathyContactListStore *store,
1118 EmpathyContact *contact)
1120 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1121 GtkTreeModel *model;
1125 row_refs = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1130 /* Clean up model */
1131 model = GTK_TREE_MODEL (store);
1133 for (l = g_queue_peek_head_link (row_refs); l; l = l->next) {
1134 GtkTreeIter *iter = l->data;
1137 /* NOTE: it is only <= 2 here because we have
1138 * separators after the group name, otherwise it
1141 if (gtk_tree_model_iter_parent (model, &parent, iter) &&
1142 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1144 gtk_tree_model_get (model, &parent,
1145 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &group_name,
1147 g_hash_table_remove (priv->empathy_group_cache,
1149 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1151 gtk_tree_store_remove (GTK_TREE_STORE (store), iter);
1155 g_hash_table_remove (priv->empathy_contact_cache, 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_alias (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_alias (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_alias (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_alias (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_ICON_STATUS, pixbuf_status,
1274 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1275 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1276 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_alias (contact),
1277 EMPATHY_CONTACT_LIST_STORE_COL_PRESENCE_TYPE,
1278 empathy_contact_get_presence (contact),
1279 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
1280 empathy_contact_get_presence_message (contact),
1281 EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
1282 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1283 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1284 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1285 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1286 empathy_contact_get_capabilities (contact) &
1287 EMPATHY_CAPABILITIES_AUDIO,
1288 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1289 empathy_contact_get_capabilities (contact) &
1290 EMPATHY_CAPABILITIES_VIDEO,
1294 if (pixbuf_avatar) {
1295 g_object_unref (pixbuf_avatar);
1298 if (priv->show_active && do_set_active) {
1299 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1301 if (do_set_active) {
1302 data = contact_list_store_contact_active_new (store, contact, do_remove);
1303 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1304 (GSourceFunc) contact_list_store_contact_active_cb,
1309 /* FIXME: when someone goes online then offline quickly, the
1310 * first timeout sets the user to be inactive and the second
1311 * timeout removes the user from the contact list, really we
1312 * should remove the first timeout.
1314 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1315 g_list_free (iters);
1319 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1321 EmpathyContactListStore *store)
1323 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1324 empathy_contact_get_alias (contact));
1326 contact_list_store_contact_update (store, contact);
1330 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1331 EmpathyContact *contact,
1333 gboolean set_changed)
1335 GtkTreeModel *model;
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_alias (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_alias (data->contact));
1403 contact_list_store_remove_contact (data->store, data->contact);
1406 DEBUG ("Contact:'%s' no longer active",
1407 empathy_contact_get_alias (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 (EmpathyContactListStore *store,
1422 GtkTreeIter *iter_group_to_set,
1423 GtkTreeIter *iter_separator_to_set,
1425 gboolean is_fake_group)
1427 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1428 GtkTreeModel *model;
1429 GtkTreeIter iter_group;
1430 GtkTreeIter iter_separator;
1433 model = GTK_TREE_MODEL (store);
1434 iter = g_hash_table_lookup (priv->empathy_group_cache, name);
1441 gtk_tree_store_insert_with_values (GTK_TREE_STORE (store), &iter_group, NULL, 0,
1442 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1443 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1444 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1445 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1446 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1447 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, is_fake_group,
1450 g_hash_table_insert (priv->empathy_group_cache,
1451 g_strdup (name), gtk_tree_iter_copy (&iter_group));
1453 if (iter_group_to_set) {
1454 *iter_group_to_set = iter_group;
1457 gtk_tree_store_insert_with_values (GTK_TREE_STORE (store), &iter_separator, &iter_group, 0,
1458 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1461 if (iter_separator_to_set) {
1462 *iter_separator_to_set = iter_separator;
1469 if (iter_group_to_set) {
1470 *iter_group_to_set = *iter;
1473 iter_separator = *iter;
1475 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1476 gboolean is_separator;
1478 gtk_tree_model_get (model, &iter_separator,
1479 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1482 if (is_separator && iter_separator_to_set) {
1483 *iter_separator_to_set = iter_separator;
1490 get_position (const char **strv,
1495 for (i = 0; strv[i] != NULL; i++) {
1496 if (!tp_strdiff (strv[i], str))
1504 compare_separator_and_groups (gboolean is_separator_a,
1505 gboolean is_separator_b,
1506 const gchar *name_a,
1507 const gchar *name_b,
1508 EmpathyContact *contact_a,
1509 EmpathyContact *contact_b,
1510 gboolean fake_group_a,
1511 gboolean fake_group_b)
1513 /* these two lists are the sorted list of fake groups to include at the
1514 * top and bottom of the roster */
1515 const char *top_groups[] = {
1516 EMPATHY_CONTACT_LIST_STORE_FAVORITE,
1520 const char *bottom_groups[] = {
1521 EMPATHY_CONTACT_LIST_STORE_UNGROUPED,
1525 if (is_separator_a || is_separator_b) {
1526 /* We have at least one separator */
1527 if (is_separator_a) {
1529 } else if (is_separator_b) {
1534 /* One group and one contact */
1535 if (!contact_a && contact_b) {
1537 } else if (contact_a && !contact_b) {
1539 } else if (!contact_a && !contact_b) {
1540 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1542 a_in_top = fake_group_a &&
1543 tp_strv_contains (top_groups, name_a);
1544 b_in_top = fake_group_b &&
1545 tp_strv_contains (top_groups, name_b);
1546 a_in_bottom = fake_group_a &&
1547 tp_strv_contains (bottom_groups, name_a);
1548 b_in_bottom = fake_group_b &&
1549 tp_strv_contains (bottom_groups, name_b);
1551 if (a_in_top && b_in_top) {
1552 /* compare positions */
1553 return CLAMP (get_position (top_groups, name_a) -
1554 get_position (top_groups, name_b),
1556 } else if (a_in_bottom && b_in_bottom) {
1557 /* compare positions */
1558 return CLAMP (get_position (bottom_groups, name_a) -
1559 get_position (bottom_groups, name_b),
1561 } else if (a_in_top || b_in_bottom) {
1563 } else if (b_in_top || a_in_bottom) {
1566 return g_utf8_collate (name_a, name_b);
1570 /* Two contacts, ordering depends of the sorting policy */
1575 contact_list_store_contact_sort (EmpathyContact *contact_a,
1576 EmpathyContact *contact_b)
1578 TpAccount *account_a, *account_b;
1581 g_return_val_if_fail (contact_a != NULL || contact_b != NULL, 0);
1584 ret_val = g_utf8_collate (empathy_contact_get_alias (contact_a),
1585 empathy_contact_get_alias (contact_b));
1591 ret_val = g_utf8_collate (empathy_contact_get_id (contact_a),
1592 empathy_contact_get_id (contact_b));
1597 account_a = empathy_contact_get_account (contact_a);
1598 account_b = empathy_contact_get_account (contact_b);
1601 ret_val = strcmp (tp_account_get_protocol (account_a),
1602 tp_account_get_protocol (account_b));
1608 ret_val = strcmp (tp_proxy_get_object_path (account_a),
1609 tp_proxy_get_object_path (account_b));
1616 contact_list_store_state_sort_func (GtkTreeModel *model,
1617 GtkTreeIter *iter_a,
1618 GtkTreeIter *iter_b,
1622 gchar *name_a, *name_b;
1623 gboolean is_separator_a, is_separator_b;
1624 EmpathyContact *contact_a, *contact_b;
1625 gboolean fake_group_a, fake_group_b;
1627 gtk_tree_model_get (model, iter_a,
1628 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1629 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1630 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1631 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_a,
1633 gtk_tree_model_get (model, iter_b,
1634 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1635 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1636 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1637 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_b,
1640 if (contact_a == NULL || contact_b == NULL) {
1641 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1642 name_a, name_b, contact_a, contact_b, fake_group_a, fake_group_b);
1646 /* If we managed to get this far, we can start looking at
1649 ret_val = -tp_connection_presence_type_cmp_availability (
1650 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1651 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1654 /* Fallback: compare by name et al. */
1655 ret_val = contact_list_store_contact_sort (contact_a, contact_b);
1663 g_object_unref (contact_a);
1667 g_object_unref (contact_b);
1674 contact_list_store_name_sort_func (GtkTreeModel *model,
1675 GtkTreeIter *iter_a,
1676 GtkTreeIter *iter_b,
1679 gchar *name_a, *name_b;
1680 EmpathyContact *contact_a, *contact_b;
1681 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1683 gboolean fake_group_a, fake_group_b;
1685 gtk_tree_model_get (model, iter_a,
1686 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1687 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1688 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1689 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_a,
1691 gtk_tree_model_get (model, iter_b,
1692 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1693 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1694 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1695 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_b,
1698 if (contact_a == NULL || contact_b == NULL)
1699 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1700 name_a, name_b, contact_a, contact_b, fake_group_a, fake_group_b);
1702 ret_val = contact_list_store_contact_sort (contact_a, contact_b);
1705 g_object_unref (contact_a);
1709 g_object_unref (contact_b);
1716 contact_list_store_find_contact (EmpathyContactListStore *store,
1717 EmpathyContact *contact)
1719 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1720 GQueue *row_refs_queue;
1722 GList *iters_list = NULL;
1724 row_refs_queue = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1725 if (!row_refs_queue)
1728 for (i = g_queue_peek_head_link (row_refs_queue) ; i != NULL ;
1730 GtkTreeIter *iter = i->data;
1732 iters_list = g_list_prepend
1733 (iters_list, gtk_tree_iter_copy (iter));
1740 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1743 EmpathyContactListStore *store)
1745 EmpathyContactListStorePriv *priv;
1746 gboolean show_avatar = FALSE;
1747 EmpathyContact *contact;
1748 GdkPixbuf *pixbuf_status;
1750 priv = GET_PRIV (store);
1752 if (priv->show_avatars && !priv->is_compact) {
1756 gtk_tree_model_get (model, iter,
1757 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1760 if (contact == NULL){
1763 /* get icon from hash_table */
1764 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1766 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1767 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1768 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1769 EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
1776 contact_list_store_get_contact_status_icon_with_icon_name (
1777 EmpathyContactListStore *store,
1778 EmpathyContact *contact,
1779 const gchar *status_icon_name)
1781 GdkPixbuf *pixbuf_status = NULL;
1782 EmpathyContactListStorePriv *priv;
1783 const gchar *protocol_name = NULL;
1784 gchar *icon_name = NULL;
1786 priv = GET_PRIV (store);
1788 if (priv->show_protocols) {
1789 protocol_name = empathy_protocol_name_for_contact (contact);
1790 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1792 icon_name = g_strdup_printf ("%s", status_icon_name);
1794 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1795 if (pixbuf_status == NULL) {
1796 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1798 priv->show_protocols);
1799 if (pixbuf_status != NULL) {
1800 g_hash_table_insert (priv->status_icons,
1801 g_strdup (icon_name),
1807 return pixbuf_status;
1811 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1812 EmpathyContact *contact)
1814 GdkPixbuf *pixbuf_status = NULL;
1815 EmpathyContactListStorePriv *priv;
1816 const gchar *status_icon_name = NULL;
1817 gboolean composing = FALSE;
1819 priv = GET_PRIV (store);
1821 if (EMPATHY_IS_TP_CHAT (priv->list)) {
1822 if (empathy_tp_chat_get_chat_state (EMPATHY_TP_CHAT (priv->list),
1824 TP_CHANNEL_CHAT_STATE_COMPOSING)
1829 status_icon_name = EMPATHY_IMAGE_TYPING;
1831 status_icon_name = empathy_icon_name_for_contact (contact);
1834 if (status_icon_name == NULL)
1837 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1842 return pixbuf_status;