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_member_renamed_cb (EmpathyContactList *list_iface,
104 EmpathyContact *old_contact,
105 EmpathyContact *new_contact,
108 EmpathyContactListStore *store);
109 static void contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
110 EmpathyContact *contact,
113 EmpathyContactListStore *store);
114 static void contact_list_store_add_contact (EmpathyContactListStore *store,
115 EmpathyContact *contact);
116 static void contact_list_store_remove_contact (EmpathyContactListStore *store,
117 EmpathyContact *contact);
118 static void contact_list_store_contact_update (EmpathyContactListStore *store,
119 EmpathyContact *contact);
120 static void contact_list_store_contact_updated_cb (EmpathyContact *contact,
122 EmpathyContactListStore *store);
123 static void contact_list_store_contact_set_active (EmpathyContactListStore *store,
124 EmpathyContact *contact,
126 gboolean set_changed);
127 static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store,
128 EmpathyContact *contact,
130 static void contact_list_store_contact_active_free (ShowActiveData *data);
131 static gboolean contact_list_store_contact_active_cb (ShowActiveData *data);
132 static void contact_list_store_get_group (EmpathyContactListStore *store,
134 GtkTreeIter *iter_group_to_set,
135 GtkTreeIter *iter_separator_to_set,
137 gboolean is_fake_group);
138 static gint contact_list_store_state_sort_func (GtkTreeModel *model,
142 static gint contact_list_store_name_sort_func (GtkTreeModel *model,
146 static GList * contact_list_store_find_contact (EmpathyContactListStore *store,
147 EmpathyContact *contact);
148 static gboolean contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
151 EmpathyContactListStore *store);
164 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
167 contact_list_store_chat_state_changed_cb (TpChannel *self,
168 guint contact_handle,
172 EmpathyContactListStorePriv *priv = GET_PRIV (store);
175 contacts = empathy_contact_list_get_members (priv->list);
177 for (l = contacts; l != NULL; l = l->next) {
178 EmpathyContact *contact = EMPATHY_CONTACT (l->data);
180 if (empathy_contact_get_handle (contact) == contact_handle) {
181 contact_list_store_contact_update (store, contact);
186 g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
187 g_list_free (contacts);
191 contact_list_store_iface_setup (gpointer user_data)
193 EmpathyContactListStore *store = user_data;
194 EmpathyContactListStorePriv *priv = GET_PRIV (store);
197 /* Signal connection. */
198 g_signal_connect (priv->list,
200 G_CALLBACK (contact_list_store_member_renamed_cb),
202 g_signal_connect (priv->list,
204 G_CALLBACK (contact_list_store_members_changed_cb),
206 g_signal_connect (priv->list,
208 G_CALLBACK (contact_list_store_groups_changed_cb),
211 if (EMPATHY_IS_TP_CHAT (priv->list)) {
212 g_signal_connect (priv->list,
213 "chat-state-changed",
214 G_CALLBACK (contact_list_store_chat_state_changed_cb),
218 /* Add contacts already created. */
219 contacts = empathy_contact_list_get_members (priv->list);
220 for (l = contacts; l; l = l->next) {
221 contact_list_store_members_changed_cb (priv->list, l->data,
226 g_object_unref (l->data);
228 g_list_free (contacts);
230 priv->setup_idle_id = 0;
236 contact_list_store_set_contact_list (EmpathyContactListStore *store,
237 EmpathyContactList *list_iface)
239 EmpathyContactListStorePriv *priv = GET_PRIV (store);
241 priv->list = g_object_ref (list_iface);
243 /* Let a chance to have all properties set before populating */
244 priv->setup_idle_id = g_idle_add (contact_list_store_iface_setup, store);
248 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
250 GObjectClass *object_class = G_OBJECT_CLASS (klass);
252 object_class->dispose = contact_list_store_dispose;
253 object_class->get_property = contact_list_store_get_property;
254 object_class->set_property = contact_list_store_set_property;
256 g_object_class_install_property (object_class,
258 g_param_spec_object ("contact-list",
259 "The contact list iface",
260 "The contact list iface",
261 EMPATHY_TYPE_CONTACT_LIST,
262 G_PARAM_CONSTRUCT_ONLY |
264 g_object_class_install_property (object_class,
266 g_param_spec_boolean ("show-offline",
268 "Whether contact list should display "
272 g_object_class_install_property (object_class,
274 g_param_spec_boolean ("show-avatars",
276 "Whether contact list should display "
277 "avatars for contacts",
280 g_object_class_install_property (object_class,
282 g_param_spec_boolean ("show-protocols",
284 "Whether contact list should display "
285 "protocols for contacts",
288 g_object_class_install_property (object_class,
290 g_param_spec_boolean ("show-groups",
292 "Whether contact list should display "
296 g_object_class_install_property (object_class,
298 g_param_spec_boolean ("is-compact",
300 "Whether the contact list is in compact mode or not",
304 g_object_class_install_property (object_class,
306 g_param_spec_enum ("sort-criterium",
308 "The sort criterium to use for sorting the contact list",
309 EMPATHY_TYPE_CONTACT_LIST_STORE_SORT,
310 EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
313 g_type_class_add_private (object_class, sizeof (EmpathyContactListStorePriv));
317 g_queue_free_full_iter (gpointer data)
319 GQueue *queue = (GQueue *) data;
320 g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
321 g_queue_free (queue);
326 empathy_contact_list_store_init (EmpathyContactListStore *store)
328 EmpathyContactListStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
329 EMPATHY_TYPE_CONTACT_LIST_STORE, EmpathyContactListStorePriv);
332 priv->show_avatars = TRUE;
333 priv->show_groups = TRUE;
334 priv->show_protocols = FALSE;
335 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
336 (GSourceFunc) contact_list_store_inibit_active_cb,
338 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
339 priv->empathy_contact_cache = g_hash_table_new_full (NULL, NULL, NULL,
340 g_queue_free_full_iter);
341 priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
343 (GDestroyNotify) gtk_tree_iter_free);
344 contact_list_store_setup (store);
348 contact_list_store_dispose (GObject *object)
350 EmpathyContactListStorePriv *priv = GET_PRIV (object);
353 if (priv->dispose_has_run)
355 priv->dispose_has_run = TRUE;
357 contacts = empathy_contact_list_get_members (priv->list);
358 for (l = contacts; l; l = l->next) {
359 g_signal_handlers_disconnect_by_func (l->data,
360 G_CALLBACK (contact_list_store_contact_updated_cb),
363 g_object_unref (l->data);
365 g_list_free (contacts);
367 g_signal_handlers_disconnect_by_func (priv->list,
368 G_CALLBACK (contact_list_store_member_renamed_cb),
370 g_signal_handlers_disconnect_by_func (priv->list,
371 G_CALLBACK (contact_list_store_members_changed_cb),
373 g_signal_handlers_disconnect_by_func (priv->list,
374 G_CALLBACK (contact_list_store_groups_changed_cb),
376 g_object_unref (priv->list);
378 if (priv->inhibit_active != 0) {
379 g_source_remove (priv->inhibit_active);
380 priv->inhibit_active = 0;
383 if (priv->setup_idle_id != 0) {
384 g_source_remove (priv->setup_idle_id);
385 priv->setup_idle_id = 0;
388 g_hash_table_destroy (priv->status_icons);
389 g_hash_table_destroy (priv->empathy_contact_cache);
390 g_hash_table_destroy (priv->empathy_group_cache);
391 G_OBJECT_CLASS (empathy_contact_list_store_parent_class)->dispose (object);
395 contact_list_store_get_property (GObject *object,
400 EmpathyContactListStorePriv *priv;
402 priv = GET_PRIV (object);
405 case PROP_CONTACT_LIST:
406 g_value_set_object (value, priv->list);
408 case PROP_SHOW_OFFLINE:
409 g_value_set_boolean (value, priv->show_offline);
411 case PROP_SHOW_AVATARS:
412 g_value_set_boolean (value, priv->show_avatars);
414 case PROP_SHOW_PROTOCOLS:
415 g_value_set_boolean (value, priv->show_protocols);
417 case PROP_SHOW_GROUPS:
418 g_value_set_boolean (value, priv->show_groups);
420 case PROP_IS_COMPACT:
421 g_value_set_boolean (value, priv->is_compact);
423 case PROP_SORT_CRITERIUM:
424 g_value_set_enum (value, priv->sort_criterium);
427 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
433 contact_list_store_set_property (GObject *object,
439 case PROP_CONTACT_LIST:
440 contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
441 g_value_get_object (value));
443 case PROP_SHOW_OFFLINE:
444 empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
445 g_value_get_boolean (value));
447 case PROP_SHOW_AVATARS:
448 empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
449 g_value_get_boolean (value));
451 case PROP_SHOW_PROTOCOLS:
452 empathy_contact_list_store_set_show_protocols (EMPATHY_CONTACT_LIST_STORE (object),
453 g_value_get_boolean (value));
455 case PROP_SHOW_GROUPS:
456 empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
457 g_value_get_boolean (value));
459 case PROP_IS_COMPACT:
460 empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
461 g_value_get_boolean (value));
463 case PROP_SORT_CRITERIUM:
464 empathy_contact_list_store_set_sort_criterium (EMPATHY_CONTACT_LIST_STORE (object),
465 g_value_get_enum (value));
468 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
473 EmpathyContactListStore *
474 empathy_contact_list_store_new (EmpathyContactList *list_iface)
476 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
478 return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
479 "contact-list", list_iface,
484 empathy_contact_list_store_get_list_iface (EmpathyContactListStore *store)
486 EmpathyContactListStorePriv *priv;
488 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
490 priv = GET_PRIV (store);
496 empathy_contact_list_store_get_show_offline (EmpathyContactListStore *store)
498 EmpathyContactListStorePriv *priv;
500 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), FALSE);
502 priv = GET_PRIV (store);
504 return priv->show_offline;
508 empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
509 gboolean show_offline)
511 EmpathyContactListStorePriv *priv;
513 gboolean show_active;
515 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
517 priv = GET_PRIV (store);
519 priv->show_offline = show_offline;
520 show_active = priv->show_active;
522 /* Disable temporarily. */
523 priv->show_active = FALSE;
525 contacts = empathy_contact_list_get_members (priv->list);
526 for (l = contacts; l; l = l->next) {
527 contact_list_store_contact_update (store, l->data);
529 g_object_unref (l->data);
531 g_list_free (contacts);
533 /* Restore to original setting. */
534 priv->show_active = show_active;
536 g_object_notify (G_OBJECT (store), "show-offline");
540 empathy_contact_list_store_get_show_avatars (EmpathyContactListStore *store)
542 EmpathyContactListStorePriv *priv;
544 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
546 priv = GET_PRIV (store);
548 return priv->show_avatars;
552 empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
553 gboolean show_avatars)
555 EmpathyContactListStorePriv *priv;
558 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
560 priv = GET_PRIV (store);
562 priv->show_avatars = show_avatars;
564 model = GTK_TREE_MODEL (store);
566 gtk_tree_model_foreach (model,
567 (GtkTreeModelForeachFunc)
568 contact_list_store_update_list_mode_foreach,
571 g_object_notify (G_OBJECT (store), "show-avatars");
576 empathy_contact_list_store_get_show_protocols (EmpathyContactListStore *store)
578 EmpathyContactListStorePriv *priv;
580 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
582 priv = GET_PRIV (store);
584 return priv->show_protocols;
588 empathy_contact_list_store_set_show_protocols (EmpathyContactListStore *store,
589 gboolean show_protocols)
591 EmpathyContactListStorePriv *priv;
594 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
596 priv = GET_PRIV (store);
598 priv->show_protocols = show_protocols;
600 model = GTK_TREE_MODEL (store);
602 gtk_tree_model_foreach (model,
603 (GtkTreeModelForeachFunc)
604 contact_list_store_update_list_mode_foreach,
607 g_object_notify (G_OBJECT (store), "show-protocols");
611 empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
613 EmpathyContactListStorePriv *priv;
615 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
617 priv = GET_PRIV (store);
619 return priv->show_groups;
623 empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
624 gboolean show_groups)
626 EmpathyContactListStorePriv *priv;
628 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
630 priv = GET_PRIV (store);
632 if (priv->show_groups == show_groups) {
636 priv->show_groups = show_groups;
638 if (priv->setup_idle_id == 0) {
639 /* Remove all contacts and add them back, not optimized but
640 * that's the easy way :)
642 * This is only done if there's not a pending setup idle
643 * callback, otherwise it will race and the contacts will get
647 gtk_tree_store_clear (GTK_TREE_STORE (store));
649 /* Also clear the cache */
650 g_hash_table_remove_all (priv->empathy_contact_cache);
651 g_hash_table_remove_all (priv->empathy_group_cache);
653 contacts = empathy_contact_list_get_members (priv->list);
654 for (l = contacts; l; l = l->next) {
655 contact_list_store_members_changed_cb (priv->list,
661 g_object_unref (l->data);
663 g_list_free (contacts);
666 g_object_notify (G_OBJECT (store), "show-groups");
670 empathy_contact_list_store_get_is_compact (EmpathyContactListStore *store)
672 EmpathyContactListStorePriv *priv;
674 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
676 priv = GET_PRIV (store);
678 return priv->is_compact;
682 empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
685 EmpathyContactListStorePriv *priv;
688 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
690 priv = GET_PRIV (store);
692 priv->is_compact = is_compact;
694 model = GTK_TREE_MODEL (store);
696 gtk_tree_model_foreach (model,
697 (GtkTreeModelForeachFunc)
698 contact_list_store_update_list_mode_foreach,
701 g_object_notify (G_OBJECT (store), "is-compact");
704 EmpathyContactListStoreSort
705 empathy_contact_list_store_get_sort_criterium (EmpathyContactListStore *store)
707 EmpathyContactListStorePriv *priv;
709 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), 0);
711 priv = GET_PRIV (store);
713 return priv->sort_criterium;
717 empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore *store,
718 EmpathyContactListStoreSort sort_criterium)
720 EmpathyContactListStorePriv *priv;
722 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
724 priv = GET_PRIV (store);
726 priv->sort_criterium = sort_criterium;
728 switch (sort_criterium) {
729 case EMPATHY_CONTACT_LIST_STORE_SORT_STATE:
730 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
731 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
735 case EMPATHY_CONTACT_LIST_STORE_SORT_NAME:
736 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
737 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
742 g_assert_not_reached ();
745 g_object_notify (G_OBJECT (store), "sort-criterium");
749 empathy_contact_list_store_row_separator_func (GtkTreeModel *model,
753 gboolean is_separator = FALSE;
755 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
757 gtk_tree_model_get (model, iter,
758 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
765 empathy_contact_list_store_get_parent_group (GtkTreeModel *model,
767 gboolean *path_is_group,
768 gboolean *is_fake_group)
770 GtkTreeIter parent_iter, iter;
775 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
778 *path_is_group = FALSE;
781 if (!gtk_tree_model_get_iter (model, &iter, path)) {
785 gtk_tree_model_get (model, &iter,
786 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
787 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
794 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter)) {
800 gtk_tree_model_get (model, &iter,
801 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
802 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
803 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake,
812 *path_is_group = TRUE;
815 if (is_fake_group != NULL)
816 *is_fake_group = fake;
822 contact_list_store_setup (EmpathyContactListStore *store)
824 EmpathyContactListStorePriv *priv;
826 GDK_TYPE_PIXBUF, /* Status pixbuf */
827 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
828 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
829 G_TYPE_STRING, /* Name */
830 G_TYPE_UINT, /* Presence type */
831 G_TYPE_STRING, /* Status string */
832 G_TYPE_BOOLEAN, /* Compact view */
833 EMPATHY_TYPE_CONTACT, /* Contact type */
834 G_TYPE_BOOLEAN, /* Is group */
835 G_TYPE_BOOLEAN, /* Is active */
836 G_TYPE_BOOLEAN, /* Is online */
837 G_TYPE_BOOLEAN, /* Is separator */
838 G_TYPE_BOOLEAN, /* Can make audio calls */
839 G_TYPE_BOOLEAN, /* Can make video calls */
840 EMPATHY_TYPE_CONTACT_LIST_FLAGS, /* Flags */
841 G_TYPE_BOOLEAN, /* Is a fake group */
844 priv = GET_PRIV (store);
846 gtk_tree_store_set_column_types (GTK_TREE_STORE (store),
847 EMPATHY_CONTACT_LIST_STORE_COL_COUNT,
851 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
852 EMPATHY_CONTACT_LIST_STORE_COL_NAME,
853 contact_list_store_name_sort_func,
855 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
856 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
857 contact_list_store_state_sort_func,
860 priv->sort_criterium = EMPATHY_CONTACT_LIST_STORE_SORT_NAME;
861 empathy_contact_list_store_set_sort_criterium (store, priv->sort_criterium);
865 contact_list_store_inibit_active_cb (EmpathyContactListStore *store)
867 EmpathyContactListStorePriv *priv;
869 priv = GET_PRIV (store);
871 priv->show_active = TRUE;
872 priv->inhibit_active = 0;
878 contact_list_store_add_contact_and_connect (EmpathyContactListStore *store, EmpathyContact *contact)
880 g_signal_connect (contact, "notify::presence",
881 G_CALLBACK (contact_list_store_contact_updated_cb),
883 g_signal_connect (contact, "notify::presence-message",
884 G_CALLBACK (contact_list_store_contact_updated_cb),
886 g_signal_connect (contact, "notify::name",
887 G_CALLBACK (contact_list_store_contact_updated_cb),
889 g_signal_connect (contact, "notify::avatar",
890 G_CALLBACK (contact_list_store_contact_updated_cb),
892 g_signal_connect (contact, "notify::capabilities",
893 G_CALLBACK (contact_list_store_contact_updated_cb),
896 contact_list_store_add_contact (store, contact);
900 contact_list_store_remove_contact_and_disconnect (EmpathyContactListStore *store, EmpathyContact *contact)
902 g_signal_handlers_disconnect_by_func (contact,
903 G_CALLBACK (contact_list_store_contact_updated_cb),
906 contact_list_store_remove_contact (store, contact);
910 contact_list_store_members_changed_cb (EmpathyContactList *list_iface,
911 EmpathyContact *contact,
912 EmpathyContact *actor,
916 EmpathyContactListStore *store)
918 DEBUG ("Contact %s (%d) %s",
919 empathy_contact_get_id (contact),
920 empathy_contact_get_handle (contact),
921 is_member ? "added" : "removed");
924 contact_list_store_add_contact_and_connect (store, contact);
926 contact_list_store_remove_contact_and_disconnect (store, contact);
931 contact_list_store_member_renamed_cb (EmpathyContactList *list_iface,
932 EmpathyContact *old_contact,
933 EmpathyContact *new_contact,
936 EmpathyContactListStore *store)
938 DEBUG ("Contact %s (%d) renamed to %s (%d)",
939 empathy_contact_get_id (old_contact),
940 empathy_contact_get_handle (old_contact),
941 empathy_contact_get_id (new_contact),
942 empathy_contact_get_handle (new_contact));
944 /* add the new contact */
945 contact_list_store_add_contact_and_connect (store, new_contact);
947 /* remove old contact */
948 contact_list_store_remove_contact_and_disconnect (store, old_contact);
952 contact_list_store_groups_changed_cb (EmpathyContactList *list_iface,
953 EmpathyContact *contact,
956 EmpathyContactListStore *store)
958 EmpathyContactListStorePriv *priv;
959 gboolean show_active;
961 priv = GET_PRIV (store);
963 DEBUG ("Updating groups for contact %s (%d)",
964 empathy_contact_get_id (contact),
965 empathy_contact_get_handle (contact));
967 /* We do this to make sure the groups are correct, if not, we
968 * would have to check the groups already set up for each
969 * contact and then see what has been updated.
971 show_active = priv->show_active;
972 priv->show_active = FALSE;
973 contact_list_store_remove_contact (store, contact);
974 contact_list_store_add_contact (store, contact);
975 priv->show_active = show_active;
979 add_contact_to_store (GtkTreeStore *store,
982 EmpathyContact *contact,
983 EmpathyContactListFlags flags)
985 EmpathyContactListStorePriv *priv = GET_PRIV (store);
988 gtk_tree_store_insert_with_values (store, iter, parent, 0,
989 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_alias (contact),
990 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
991 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
992 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
993 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
994 empathy_contact_get_capabilities (contact) &
995 EMPATHY_CAPABILITIES_AUDIO,
996 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
997 empathy_contact_get_capabilities (contact) &
998 EMPATHY_CAPABILITIES_VIDEO,
999 EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
1002 queue = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1004 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
1006 queue = g_queue_new ();
1007 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
1008 g_hash_table_insert (priv->empathy_contact_cache, contact,
1014 contact_list_store_add_contact (EmpathyContactListStore *store,
1015 EmpathyContact *contact)
1017 EmpathyContactListStorePriv *priv;
1019 GList *groups = NULL, *l;
1020 TpConnection *connection;
1021 EmpathyContactListFlags flags = 0;
1022 char *protocol_name;
1024 priv = GET_PRIV (store);
1026 if (EMP_STR_EMPTY (empathy_contact_get_alias (contact)) ||
1027 (!priv->show_offline && !empathy_contact_is_online (contact))) {
1031 if (priv->show_groups) {
1032 groups = empathy_contact_list_get_groups (priv->list, contact);
1035 connection = empathy_contact_get_connection (contact);
1036 if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
1037 flags = empathy_contact_manager_get_flags_for_connection (
1038 EMPATHY_CONTACT_MANAGER (priv->list), connection);
1041 tp_connection_parse_object_path (connection, &protocol_name, NULL);
1044 GtkTreeIter iter_group, *parent;
1046 parent = &iter_group;
1048 if (!priv->show_groups) {
1052 add_contact_to_store (GTK_TREE_STORE (store), &iter, parent,
1056 g_free (protocol_name);
1058 /* Else add to each group. */
1059 for (l = groups; l; l = l->next) {
1060 GtkTreeIter iter_group;
1062 contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL, FALSE);
1064 add_contact_to_store (GTK_TREE_STORE (store), &iter, &iter_group, contact, flags);
1067 g_list_free (groups);
1069 contact_list_store_contact_update (store, contact);
1073 contact_list_store_remove_contact (EmpathyContactListStore *store,
1074 EmpathyContact *contact)
1076 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1077 GtkTreeModel *model;
1081 row_refs = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1086 /* Clean up model */
1087 model = GTK_TREE_MODEL (store);
1089 for (l = g_queue_peek_head_link (row_refs); l; l = l->next) {
1090 GtkTreeIter *iter = l->data;
1093 /* NOTE: it is only <= 2 here because we have
1094 * separators after the group name, otherwise it
1097 if (gtk_tree_model_iter_parent (model, &parent, iter) &&
1098 gtk_tree_model_iter_n_children (model, &parent) <= 2) {
1100 gtk_tree_model_get (model, &parent,
1101 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &group_name,
1103 g_hash_table_remove (priv->empathy_group_cache,
1105 gtk_tree_store_remove (GTK_TREE_STORE (store), &parent);
1107 gtk_tree_store_remove (GTK_TREE_STORE (store), iter);
1111 g_hash_table_remove (priv->empathy_contact_cache, contact);
1115 contact_list_store_contact_update (EmpathyContactListStore *store,
1116 EmpathyContact *contact)
1118 EmpathyContactListStorePriv *priv;
1119 ShowActiveData *data;
1120 GtkTreeModel *model;
1123 gboolean should_be_in_list;
1124 gboolean was_online = TRUE;
1125 gboolean now_online = FALSE;
1126 gboolean set_model = FALSE;
1127 gboolean do_remove = FALSE;
1128 gboolean do_set_active = FALSE;
1129 gboolean do_set_refresh = FALSE;
1130 gboolean show_avatar = FALSE;
1131 GdkPixbuf *pixbuf_avatar;
1132 GdkPixbuf *pixbuf_status;
1134 priv = GET_PRIV (store);
1136 model = GTK_TREE_MODEL (store);
1138 iters = contact_list_store_find_contact (store, contact);
1145 /* Get online state now. */
1146 now_online = empathy_contact_is_online (contact);
1148 if (priv->show_offline || now_online) {
1149 should_be_in_list = TRUE;
1151 should_be_in_list = FALSE;
1154 if (!in_list && !should_be_in_list) {
1155 /* Nothing to do. */
1156 DEBUG ("Contact:'%s' in list:NO, should be:NO",
1157 empathy_contact_get_alias (contact));
1159 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1160 g_list_free (iters);
1163 else if (in_list && !should_be_in_list) {
1164 DEBUG ("Contact:'%s' in list:YES, should be:NO",
1165 empathy_contact_get_alias (contact));
1167 if (priv->show_active) {
1169 do_set_active = TRUE;
1170 do_set_refresh = TRUE;
1173 DEBUG ("Remove item (after timeout)");
1175 DEBUG ("Remove item (now)!");
1176 contact_list_store_remove_contact (store, contact);
1179 else if (!in_list && should_be_in_list) {
1180 DEBUG ("Contact:'%s' in list:NO, should be:YES",
1181 empathy_contact_get_alias (contact));
1183 contact_list_store_add_contact (store, contact);
1185 if (priv->show_active) {
1186 do_set_active = TRUE;
1188 DEBUG ("Set active (contact added)");
1191 DEBUG ("Contact:'%s' in list:YES, should be:YES",
1192 empathy_contact_get_alias (contact));
1194 /* Get online state before. */
1195 if (iters && g_list_length (iters) > 0) {
1196 gtk_tree_model_get (model, iters->data,
1197 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online,
1201 /* Is this really an update or an online/offline. */
1202 if (priv->show_active) {
1203 if (was_online != now_online) {
1204 do_set_active = TRUE;
1205 do_set_refresh = TRUE;
1207 DEBUG ("Set active (contact updated %s)",
1208 was_online ? "online -> offline" :
1209 "offline -> online");
1211 /* Was TRUE for presence updates. */
1212 /* do_set_active = FALSE; */
1213 do_set_refresh = TRUE;
1215 DEBUG ("Set active (contact updated)");
1222 if (priv->show_avatars && !priv->is_compact) {
1225 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
1226 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1227 for (l = iters; l && set_model; l = l->next) {
1228 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1229 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1230 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
1231 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1232 EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_alias (contact),
1233 EMPATHY_CONTACT_LIST_STORE_COL_PRESENCE_TYPE,
1234 empathy_contact_get_presence (contact),
1235 EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
1236 empathy_contact_get_presence_message (contact),
1237 EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
1238 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
1239 EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
1240 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1241 EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
1242 empathy_contact_get_capabilities (contact) &
1243 EMPATHY_CAPABILITIES_AUDIO,
1244 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
1245 empathy_contact_get_capabilities (contact) &
1246 EMPATHY_CAPABILITIES_VIDEO,
1250 if (pixbuf_avatar) {
1251 g_object_unref (pixbuf_avatar);
1254 if (priv->show_active && do_set_active) {
1255 contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);
1257 if (do_set_active) {
1258 data = contact_list_store_contact_active_new (store, contact, do_remove);
1259 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
1260 (GSourceFunc) contact_list_store_contact_active_cb,
1265 /* FIXME: when someone goes online then offline quickly, the
1266 * first timeout sets the user to be inactive and the second
1267 * timeout removes the user from the contact list, really we
1268 * should remove the first timeout.
1270 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1271 g_list_free (iters);
1275 contact_list_store_contact_updated_cb (EmpathyContact *contact,
1277 EmpathyContactListStore *store)
1279 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
1280 empathy_contact_get_alias (contact));
1282 contact_list_store_contact_update (store, contact);
1286 contact_list_store_contact_set_active (EmpathyContactListStore *store,
1287 EmpathyContact *contact,
1289 gboolean set_changed)
1291 GtkTreeModel *model;
1294 model = GTK_TREE_MODEL (store);
1296 iters = contact_list_store_find_contact (store, contact);
1297 for (l = iters; l; l = l->next) {
1300 gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
1301 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, active,
1304 DEBUG ("Set item %s", active ? "active" : "inactive");
1307 path = gtk_tree_model_get_path (model, l->data);
1308 gtk_tree_model_row_changed (model, path, l->data);
1309 gtk_tree_path_free (path);
1313 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
1314 g_list_free (iters);
1318 static ShowActiveData *
1319 contact_list_store_contact_active_new (EmpathyContactListStore *store,
1320 EmpathyContact *contact,
1323 ShowActiveData *data;
1325 DEBUG ("Contact:'%s' now active, and %s be removed",
1326 empathy_contact_get_alias (contact),
1327 remove_ ? "WILL" : "WILL NOT");
1329 data = g_slice_new0 (ShowActiveData);
1331 data->store = g_object_ref (store);
1332 data->contact = g_object_ref (contact);
1333 data->remove = remove_;
1339 contact_list_store_contact_active_free (ShowActiveData *data)
1341 g_object_unref (data->contact);
1342 g_object_unref (data->store);
1344 g_slice_free (ShowActiveData, data);
1348 contact_list_store_contact_active_cb (ShowActiveData *data)
1350 EmpathyContactListStorePriv *priv;
1352 priv = GET_PRIV (data->store);
1355 !priv->show_offline &&
1356 !empathy_contact_is_online (data->contact)) {
1357 DEBUG ("Contact:'%s' active timeout, removing item",
1358 empathy_contact_get_alias (data->contact));
1359 contact_list_store_remove_contact (data->store, data->contact);
1362 DEBUG ("Contact:'%s' no longer active",
1363 empathy_contact_get_alias (data->contact));
1365 contact_list_store_contact_set_active (data->store,
1370 contact_list_store_contact_active_free (data);
1376 contact_list_store_get_group (EmpathyContactListStore *store,
1378 GtkTreeIter *iter_group_to_set,
1379 GtkTreeIter *iter_separator_to_set,
1381 gboolean is_fake_group)
1383 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1384 GtkTreeModel *model;
1385 GtkTreeIter iter_group;
1386 GtkTreeIter iter_separator;
1389 model = GTK_TREE_MODEL (store);
1390 iter = g_hash_table_lookup (priv->empathy_group_cache, name);
1397 gtk_tree_store_insert_with_values (GTK_TREE_STORE (store), &iter_group, NULL, 0,
1398 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, NULL,
1399 EMPATHY_CONTACT_LIST_STORE_COL_NAME, name,
1400 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, TRUE,
1401 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, FALSE,
1402 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
1403 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, is_fake_group,
1406 g_hash_table_insert (priv->empathy_group_cache,
1407 g_strdup (name), gtk_tree_iter_copy (&iter_group));
1409 if (iter_group_to_set) {
1410 *iter_group_to_set = iter_group;
1413 gtk_tree_store_insert_with_values (GTK_TREE_STORE (store), &iter_separator, &iter_group, 0,
1414 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, TRUE,
1417 if (iter_separator_to_set) {
1418 *iter_separator_to_set = iter_separator;
1425 if (iter_group_to_set) {
1426 *iter_group_to_set = *iter;
1429 iter_separator = *iter;
1431 if (gtk_tree_model_iter_next (model, &iter_separator)) {
1432 gboolean is_separator;
1434 gtk_tree_model_get (model, &iter_separator,
1435 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator,
1438 if (is_separator && iter_separator_to_set) {
1439 *iter_separator_to_set = iter_separator;
1446 compare_separator_and_groups (gboolean is_separator_a,
1447 gboolean is_separator_b,
1448 const gchar *name_a,
1449 const gchar *name_b,
1450 EmpathyContact *contact_a,
1451 EmpathyContact *contact_b,
1452 gboolean fake_group_a,
1453 gboolean fake_group_b)
1455 if (is_separator_a || is_separator_b) {
1456 /* We have at least one separator */
1457 if (is_separator_a) {
1459 } else if (is_separator_b) {
1464 /* One group and one contact */
1465 if (!contact_a && contact_b) {
1467 } else if (contact_a && !contact_b) {
1469 } else if (!contact_a && !contact_b) {
1470 return g_utf8_collate (name_a, name_b);
1473 /* Two contacts, ordering depends of the sorting policy */
1478 contact_list_store_contact_sort (EmpathyContact *contact_a,
1479 EmpathyContact *contact_b)
1481 TpAccount *account_a, *account_b;
1484 g_return_val_if_fail (contact_a != NULL || contact_b != NULL, 0);
1487 ret_val = g_utf8_collate (empathy_contact_get_alias (contact_a),
1488 empathy_contact_get_alias (contact_b));
1494 ret_val = g_utf8_collate (empathy_contact_get_id (contact_a),
1495 empathy_contact_get_id (contact_b));
1500 account_a = empathy_contact_get_account (contact_a);
1501 account_b = empathy_contact_get_account (contact_b);
1504 ret_val = strcmp (tp_account_get_protocol (account_a),
1505 tp_account_get_protocol (account_b));
1511 ret_val = strcmp (tp_proxy_get_object_path (account_a),
1512 tp_proxy_get_object_path (account_b));
1519 contact_list_store_state_sort_func (GtkTreeModel *model,
1520 GtkTreeIter *iter_a,
1521 GtkTreeIter *iter_b,
1525 gchar *name_a, *name_b;
1526 gboolean is_separator_a, is_separator_b;
1527 EmpathyContact *contact_a, *contact_b;
1528 gboolean fake_group_a, fake_group_b;
1530 gtk_tree_model_get (model, iter_a,
1531 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1532 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1533 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1534 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_a,
1536 gtk_tree_model_get (model, iter_b,
1537 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1538 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1539 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1540 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_b,
1543 if (contact_a == NULL || contact_b == NULL) {
1544 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1545 name_a, name_b, contact_a, contact_b, fake_group_a, fake_group_b);
1549 /* If we managed to get this far, we can start looking at
1552 ret_val = -tp_connection_presence_type_cmp_availability (
1553 empathy_contact_get_presence (EMPATHY_CONTACT (contact_a)),
1554 empathy_contact_get_presence (EMPATHY_CONTACT (contact_b)));
1557 /* Fallback: compare by name et al. */
1558 ret_val = contact_list_store_contact_sort (contact_a, contact_b);
1566 g_object_unref (contact_a);
1570 g_object_unref (contact_b);
1577 contact_list_store_name_sort_func (GtkTreeModel *model,
1578 GtkTreeIter *iter_a,
1579 GtkTreeIter *iter_b,
1582 gchar *name_a, *name_b;
1583 EmpathyContact *contact_a, *contact_b;
1584 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1586 gboolean fake_group_a, fake_group_b;
1588 gtk_tree_model_get (model, iter_a,
1589 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_a,
1590 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_a,
1591 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_a,
1592 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_a,
1594 gtk_tree_model_get (model, iter_b,
1595 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name_b,
1596 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact_b,
1597 EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, &is_separator_b,
1598 EMPATHY_CONTACT_LIST_STORE_COL_IS_FAKE_GROUP, &fake_group_b,
1601 if (contact_a == NULL || contact_b == NULL)
1602 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1603 name_a, name_b, contact_a, contact_b, fake_group_a, fake_group_b);
1605 ret_val = contact_list_store_contact_sort (contact_a, contact_b);
1608 g_object_unref (contact_a);
1612 g_object_unref (contact_b);
1619 contact_list_store_find_contact (EmpathyContactListStore *store,
1620 EmpathyContact *contact)
1622 EmpathyContactListStorePriv *priv = GET_PRIV (store);
1623 GQueue *row_refs_queue;
1625 GList *iters_list = NULL;
1627 row_refs_queue = g_hash_table_lookup (priv->empathy_contact_cache, contact);
1628 if (!row_refs_queue)
1631 for (i = g_queue_peek_head_link (row_refs_queue) ; i != NULL ;
1633 GtkTreeIter *iter = i->data;
1635 iters_list = g_list_prepend
1636 (iters_list, gtk_tree_iter_copy (iter));
1643 contact_list_store_update_list_mode_foreach (GtkTreeModel *model,
1646 EmpathyContactListStore *store)
1648 EmpathyContactListStorePriv *priv;
1649 gboolean show_avatar = FALSE;
1650 EmpathyContact *contact;
1651 GdkPixbuf *pixbuf_status;
1653 priv = GET_PRIV (store);
1655 if (priv->show_avatars && !priv->is_compact) {
1659 gtk_tree_model_get (model, iter,
1660 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1663 if (contact == NULL){
1666 /* get icon from hash_table */
1667 pixbuf_status = contact_list_store_get_contact_status_icon (store, contact);
1669 gtk_tree_store_set (GTK_TREE_STORE (store), iter,
1670 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
1671 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1672 EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
1679 contact_list_store_get_contact_status_icon_with_icon_name (
1680 EmpathyContactListStore *store,
1681 EmpathyContact *contact,
1682 const gchar *status_icon_name)
1684 GdkPixbuf *pixbuf_status = NULL;
1685 EmpathyContactListStorePriv *priv;
1686 const gchar *protocol_name = NULL;
1687 gchar *icon_name = NULL;
1689 priv = GET_PRIV (store);
1691 if (priv->show_protocols) {
1692 protocol_name = empathy_protocol_name_for_contact (contact);
1693 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1695 icon_name = g_strdup_printf ("%s", status_icon_name);
1697 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1698 if (pixbuf_status == NULL) {
1699 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1701 priv->show_protocols);
1702 if (pixbuf_status != NULL) {
1703 g_hash_table_insert (priv->status_icons,
1704 g_strdup (icon_name),
1710 return pixbuf_status;
1714 contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
1715 EmpathyContact *contact)
1717 GdkPixbuf *pixbuf_status = NULL;
1718 EmpathyContactListStorePriv *priv;
1719 const gchar *status_icon_name = NULL;
1720 gboolean composing = FALSE;
1722 priv = GET_PRIV (store);
1724 if (EMPATHY_IS_TP_CHAT (priv->list)) {
1725 if (empathy_tp_chat_get_chat_state (EMPATHY_TP_CHAT (priv->list),
1727 TP_CHANNEL_CHAT_STATE_COMPOSING)
1732 status_icon_name = EMPATHY_IMAGE_TYPING;
1734 status_icon_name = empathy_icon_name_for_contact (contact);
1737 if (status_icon_name == NULL)
1740 pixbuf_status = contact_list_store_get_contact_status_icon_with_icon_name (
1745 return pixbuf_status;