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-2010 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>
24 * Travis Reitter <travis.reitter@collabora.co.uk>
32 #include <glib/gi18n-lib.h>
35 #include <folks/folks.h>
36 #include <folks/folks-telepathy.h>
37 #include <telepathy-glib/util.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-enum-types.h>
42 #include "empathy-individual-store.h"
43 #include "empathy-ui-utils.h"
44 #include "empathy-gtk-enum-types.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 struct _EmpathyIndividualStorePriv
61 gboolean show_avatars;
64 gboolean show_protocols;
65 EmpathyIndividualStoreSort sort_criterium;
67 gboolean dispose_has_run;
68 GHashTable *status_icons;
69 /* List of owned GCancellables for each pending avatar load operation */
70 GList *avatar_cancellables;
71 /* Hash: FolksIndividual* -> GQueue (GtkTreeIter *) */
72 GHashTable *folks_individual_cache;
73 /* Hash: char *groupname -> GtkTreeIter * */
74 GHashTable *empathy_group_cache;
80 EmpathyIndividualStore *self;
81 FolksIndividual *individual;
96 /* prototypes to break cycles */
97 static void individual_store_contact_update (EmpathyIndividualStore *self,
98 FolksIndividual *individual);
100 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
101 GTK_TYPE_TREE_STORE);
103 static const gchar * const *
104 individual_get_client_types (FolksIndividual *individual)
108 const gchar * const *types = NULL;
109 FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
111 personas = folks_individual_get_personas (individual);
112 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
113 while (gee_iterator_next (iter))
115 FolksPresenceDetails *presence;
116 FolksPersona *persona = gee_iterator_get (iter);
118 /* We only want personas which have presence and a TpContact */
119 if (!empathy_folks_persona_is_interesting (persona))
122 presence = FOLKS_PRESENCE_DETAILS (persona);
124 if (folks_presence_details_typecmp (
125 folks_presence_details_get_presence_type (presence),
128 TpContact *tp_contact;
130 presence_type = folks_presence_details_get_presence_type (presence);
132 tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
133 if (tp_contact != NULL)
134 types = tp_contact_get_client_types (tp_contact);
138 g_clear_object (&persona);
140 g_clear_object (&iter);
146 add_individual_to_store (GtkTreeStore *store,
149 FolksIndividual *individual)
151 EmpathyIndividualStore *self = EMPATHY_INDIVIDUAL_STORE (store);
152 gboolean can_audio_call, can_video_call;
153 const gchar * const *types;
156 empathy_individual_can_audio_video_call (individual, &can_audio_call,
157 &can_video_call, NULL);
159 types = individual_get_client_types (individual);
161 gtk_tree_store_insert_with_values (store, iter, parent, 0,
162 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
163 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
164 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
165 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
166 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
167 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
168 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
169 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
172 queue = g_hash_table_lookup (self->priv->folks_individual_cache, individual);
175 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
179 queue = g_queue_new ();
180 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
181 g_hash_table_insert (self->priv->folks_individual_cache, individual,
187 individual_store_get_group (EmpathyIndividualStore *self,
189 GtkTreeIter *iter_group_to_set,
190 GtkTreeIter *iter_separator_to_set,
192 gboolean is_fake_group)
195 GtkTreeIter iter_group;
196 GtkTreeIter iter_separator;
199 model = GTK_TREE_MODEL (self);
200 iter = g_hash_table_lookup (self->priv->empathy_group_cache, name);
207 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
209 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
210 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
211 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
212 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
213 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
214 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
217 g_hash_table_insert (self->priv->empathy_group_cache, g_strdup (name),
218 gtk_tree_iter_copy (&iter_group));
220 if (iter_group_to_set)
221 *iter_group_to_set = iter_group;
223 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
225 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
228 if (iter_separator_to_set)
229 *iter_separator_to_set = iter_separator;
236 if (iter_group_to_set)
237 *iter_group_to_set = *iter;
239 iter_separator = *iter;
241 if (gtk_tree_model_iter_next (model, &iter_separator))
243 gboolean is_separator;
245 gtk_tree_model_get (model, &iter_separator,
246 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
248 if (is_separator && iter_separator_to_set)
249 *iter_separator_to_set = iter_separator;
255 individual_store_find_contact (EmpathyIndividualStore *self,
256 FolksIndividual *individual)
258 GQueue *row_refs_queue;
260 GList *iters_list = NULL;
262 row_refs_queue = g_hash_table_lookup (self->priv->folks_individual_cache,
267 for (i = g_queue_peek_head_link (row_refs_queue) ; i != NULL ; i = i->next)
269 GtkTreeIter *iter = i->data;
271 iters_list = g_list_prepend (iters_list, gtk_tree_iter_copy (iter));
278 free_iters (GList *iters)
280 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
285 empathy_individual_store_remove_individual (EmpathyIndividualStore *self,
286 FolksIndividual *individual)
292 row_refs = g_hash_table_lookup (self->priv->folks_individual_cache,
298 model = GTK_TREE_MODEL (self);
300 for (l = g_queue_peek_head_link (row_refs); l; l = l->next)
302 GtkTreeIter *iter = l->data;
305 /* NOTE: it is only <= 2 here because we have
306 * separators after the group name, otherwise it
309 if (gtk_tree_model_iter_parent (model, &parent, iter) &&
310 gtk_tree_model_iter_n_children (model, &parent) <= 2)
313 gtk_tree_model_get (model, &parent,
314 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &group_name,
316 g_hash_table_remove (self->priv->empathy_group_cache,
318 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
322 gtk_tree_store_remove (GTK_TREE_STORE (self), iter);
326 g_hash_table_remove (self->priv->folks_individual_cache, individual);
330 empathy_individual_store_add_individual (EmpathyIndividualStore *self,
331 FolksIndividual *individual)
333 GtkTreeIter iter, iter_group;
334 GeeSet *group_set = NULL;
335 gboolean grouped = FALSE;
337 if (EMP_STR_EMPTY (folks_alias_details_get_alias (
338 FOLKS_ALIAS_DETAILS (individual))))
341 if (!self->priv->show_groups)
343 /* add our individual to the toplevel of the store */
344 add_individual_to_store (GTK_TREE_STORE (self), &iter, NULL,
350 group_set = folks_group_details_get_groups (
351 FOLKS_GROUP_DETAILS (individual));
353 if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
355 /* add the contact to its groups */
356 GeeIterator *group_iter =
357 gee_iterable_iterator (GEE_ITERABLE (group_set));
359 while (group_iter != NULL && gee_iterator_next (group_iter))
361 gchar *group_name = gee_iterator_get (group_iter);
363 individual_store_get_group (self, group_name, &iter_group,
366 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
373 g_clear_object (&group_iter);
377 /* fall-back groups, in case there are no named groups */
378 EmpathyContact *contact;
379 TpConnection *connection;
380 const gchar *protocol_name = NULL;
382 contact = empathy_contact_dup_from_folks_individual (individual);
385 connection = empathy_contact_get_connection (contact);
386 protocol_name = tp_connection_get_protocol_name (connection);
389 if (!tp_strdiff (protocol_name, "local-xmpp"))
391 /* these are People Nearby */
392 individual_store_get_group (self,
393 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
395 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
400 g_clear_object (&contact);
403 if (folks_favourite_details_get_is_favourite (
404 FOLKS_FAVOURITE_DETAILS (individual)))
406 /* Add contact to the fake 'Favorites' group */
407 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
408 &iter_group, NULL, NULL, TRUE);
410 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
417 /* Else add the contact to 'Ungrouped' */
418 individual_store_get_group (self,
419 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
420 &iter_group, NULL, NULL, TRUE);
421 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
427 individual_store_contact_update (self, individual);
431 individual_store_contact_set_active (EmpathyIndividualStore *self,
432 FolksIndividual *individual,
434 gboolean set_changed)
439 model = GTK_TREE_MODEL (self);
441 iters = individual_store_find_contact (self, individual);
442 for (l = iters; l; l = l->next)
446 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
447 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
450 DEBUG ("Set item %s", active ? "active" : "inactive");
454 path = gtk_tree_model_get_path (model, l->data);
455 gtk_tree_model_row_changed (model, path, l->data);
456 gtk_tree_path_free (path);
463 static void individual_store_contact_active_free (ShowActiveData *data);
466 individual_store_contact_active_invalidated (ShowActiveData *data,
469 /* Remove the timeout and free the struct, since the individual or individual
470 * store has disappeared. */
471 g_source_remove (data->timeout);
473 if (old_object == (GObject *) data->self)
475 else if (old_object == (GObject *) data->individual)
476 data->individual = NULL;
478 g_assert_not_reached ();
480 individual_store_contact_active_free (data);
483 static ShowActiveData *
484 individual_store_contact_active_new (EmpathyIndividualStore *self,
485 FolksIndividual *individual,
488 ShowActiveData *data;
490 DEBUG ("Individual'%s' now active, and %s be removed",
491 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
492 remove_ ? "WILL" : "WILL NOT");
494 data = g_slice_new0 (ShowActiveData);
496 /* We don't actually want to force either the IndividualStore or the
497 * Individual to stay alive, since the user could quit Empathy or disable
498 * the account before the contact_active timeout is fired. */
499 g_object_weak_ref (G_OBJECT (self),
500 (GWeakNotify) individual_store_contact_active_invalidated, data);
501 g_object_weak_ref (G_OBJECT (individual),
502 (GWeakNotify) individual_store_contact_active_invalidated, data);
505 data->individual = individual;
506 data->remove = remove_;
513 individual_store_contact_active_free (ShowActiveData *data)
515 if (data->self != NULL)
517 g_object_weak_unref (G_OBJECT (data->self),
518 (GWeakNotify) individual_store_contact_active_invalidated, data);
521 if (data->individual != NULL)
523 g_object_weak_unref (G_OBJECT (data->individual),
524 (GWeakNotify) individual_store_contact_active_invalidated, data);
527 g_slice_free (ShowActiveData, data);
531 individual_store_contact_active_cb (ShowActiveData *data)
535 DEBUG ("Individual'%s' active timeout, removing item",
536 folks_alias_details_get_alias (
537 FOLKS_ALIAS_DETAILS (data->individual)));
538 empathy_individual_store_remove_individual (data->self, data->individual);
541 DEBUG ("Individual'%s' no longer active",
542 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
544 individual_store_contact_set_active (data->self,
545 data->individual, FALSE, TRUE);
547 individual_store_contact_active_free (data);
553 EmpathyIndividualStore *store; /* weak */
554 GCancellable *cancellable; /* owned */
558 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
559 GAsyncResult *result,
560 LoadAvatarData *data)
562 GError *error = NULL;
565 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
570 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
571 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
573 g_clear_error (&error);
575 else if (data->store != NULL)
579 iters = individual_store_find_contact (data->store, individual);
580 for (l = iters; l; l = l->next)
582 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
583 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
591 if (data->store != NULL)
593 g_object_remove_weak_pointer (G_OBJECT (data->store),
594 (gpointer *) &data->store);
595 data->store->priv->avatar_cancellables = g_list_remove (
596 data->store->priv->avatar_cancellables, data->cancellable);
599 tp_clear_object (&pixbuf);
600 g_object_unref (data->cancellable);
601 g_slice_free (LoadAvatarData, data);
605 individual_store_contact_update (EmpathyIndividualStore *self,
606 FolksIndividual *individual)
608 ShowActiveData *data;
612 gboolean was_online = TRUE;
613 gboolean now_online = FALSE;
614 gboolean set_model = FALSE;
615 gboolean do_remove = FALSE;
616 gboolean do_set_active = FALSE;
617 gboolean do_set_refresh = FALSE;
618 gboolean show_avatar = FALSE;
619 GdkPixbuf *pixbuf_status;
620 LoadAvatarData *load_avatar_data;
622 model = GTK_TREE_MODEL (self);
624 iters = individual_store_find_contact (self, individual);
634 /* Get online state now. */
635 now_online = folks_presence_details_is_online (
636 FOLKS_PRESENCE_DETAILS (individual));
640 DEBUG ("Individual'%s' in list:NO, should be:YES",
641 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
643 empathy_individual_store_add_individual (self, individual);
645 if (self->priv->show_active)
647 do_set_active = TRUE;
649 DEBUG ("Set active (individual added)");
654 DEBUG ("Individual'%s' in list:YES, should be:YES",
655 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
657 /* Get online state before. */
658 if (iters && g_list_length (iters) > 0)
660 gtk_tree_model_get (model, iters->data,
661 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
664 /* Is this really an update or an online/offline. */
665 if (self->priv->show_active)
667 if (was_online != now_online)
669 do_set_active = TRUE;
670 do_set_refresh = TRUE;
672 DEBUG ("Set active (individual updated %s)",
673 was_online ? "online -> offline" : "offline -> online");
677 /* Was TRUE for presence updates. */
678 /* do_set_active = FALSE; */
679 do_set_refresh = TRUE;
681 DEBUG ("Set active (individual updated)");
688 if (self->priv->show_avatars && !self->priv->is_compact)
693 /* Load the avatar asynchronously */
694 load_avatar_data = g_slice_new (LoadAvatarData);
695 load_avatar_data->store = self;
696 g_object_add_weak_pointer (G_OBJECT (self),
697 (gpointer *) &load_avatar_data->store);
698 load_avatar_data->cancellable = g_cancellable_new ();
700 self->priv->avatar_cancellables = g_list_prepend (
701 self->priv->avatar_cancellables, load_avatar_data->cancellable);
703 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
704 load_avatar_data->cancellable,
705 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
709 empathy_individual_store_get_individual_status_icon (self, individual);
711 for (l = iters; l && set_model; l = l->next)
713 gboolean can_audio_call, can_video_call;
714 const gchar * const *types;
716 empathy_individual_can_audio_video_call (individual, &can_audio_call,
717 &can_video_call, NULL);
719 types = individual_get_client_types (individual);
721 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
722 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
723 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
724 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
725 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
726 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
727 folks_presence_details_get_presence_type (
728 FOLKS_PRESENCE_DETAILS (individual)),
729 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
730 folks_presence_details_get_presence_message (
731 FOLKS_PRESENCE_DETAILS (individual)),
732 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, self->priv->is_compact,
733 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
734 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
735 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
736 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
737 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
738 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
742 if (self->priv->show_active && do_set_active)
744 individual_store_contact_set_active (self, individual, do_set_active,
750 individual_store_contact_active_new (self, individual,
752 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
753 (GSourceFunc) individual_store_contact_active_cb, data);
757 /* FIXME: when someone goes online then offline quickly, the
758 * first timeout sets the user to be inactive and the second
759 * timeout removes the user from the contact list, really we
760 * should remove the first timeout.
766 individual_store_individual_updated_cb (FolksIndividual *individual,
768 EmpathyIndividualStore *self)
770 DEBUG ("Individual'%s' updated, checking roster is in sync...",
771 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
773 individual_store_contact_update (self, individual);
777 individual_store_contact_updated_cb (EmpathyContact *contact,
779 EmpathyIndividualStore *self)
781 FolksIndividual *individual;
783 DEBUG ("Contact '%s' updated, checking roster is in sync...",
784 empathy_contact_get_alias (contact));
786 individual = g_object_get_data (G_OBJECT (contact), "individual");
787 if (individual == NULL)
790 individual_store_contact_update (self, individual);
794 individual_personas_changed_cb (FolksIndividual *individual,
797 EmpathyIndividualStore *self)
801 DEBUG ("Individual '%s' personas-changed.",
802 folks_individual_get_id (individual));
804 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
805 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
806 * through the EmpathyContacts for them. */
807 while (gee_iterator_next (iter))
809 TpfPersona *persona = gee_iterator_get (iter);
810 TpContact *tp_contact;
811 EmpathyContact *contact;
813 if (TPF_IS_PERSONA (persona))
815 tp_contact = tpf_persona_get_contact (persona);
816 if (tp_contact != NULL)
818 contact = empathy_contact_dup_from_tp_contact (tp_contact);
819 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
821 g_object_set_data (G_OBJECT (contact), "individual", NULL);
822 g_signal_handlers_disconnect_by_func (contact,
823 (GCallback) individual_store_contact_updated_cb, self);
825 g_object_unref (contact);
829 g_clear_object (&persona);
831 g_clear_object (&iter);
833 iter = gee_iterable_iterator (GEE_ITERABLE (added));
834 while (gee_iterator_next (iter))
836 TpfPersona *persona = gee_iterator_get (iter);
837 TpContact *tp_contact;
838 EmpathyContact *contact;
840 if (TPF_IS_PERSONA (persona))
842 tp_contact = tpf_persona_get_contact (persona);
843 if (tp_contact != NULL)
845 contact = empathy_contact_dup_from_tp_contact (tp_contact);
846 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
848 g_object_set_data (G_OBJECT (contact), "individual", individual);
849 g_signal_connect (contact, "notify::capabilities",
850 (GCallback) individual_store_contact_updated_cb, self);
851 g_signal_connect (contact, "notify::client-types",
852 (GCallback) individual_store_contact_updated_cb, self);
854 g_object_unref (contact);
858 g_clear_object (&persona);
860 g_clear_object (&iter);
864 individual_store_favourites_changed_cb (FolksIndividual *individual,
866 EmpathyIndividualStore *self)
868 DEBUG ("Individual %s is %s a favourite",
869 folks_individual_get_id (individual),
870 folks_favourite_details_get_is_favourite (
871 FOLKS_FAVOURITE_DETAILS (individual)) ? "now" : "no longer");
873 empathy_individual_store_remove_individual (self, individual);
874 empathy_individual_store_add_individual (self, individual);
878 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
879 FolksIndividual *individual)
881 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
883 empathy_individual_store_add_individual (self, individual);
885 g_signal_connect (individual, "notify::avatar",
886 (GCallback) individual_store_individual_updated_cb, self);
887 g_signal_connect (individual, "notify::presence-type",
888 (GCallback) individual_store_individual_updated_cb, self);
889 g_signal_connect (individual, "notify::presence-message",
890 (GCallback) individual_store_individual_updated_cb, self);
891 g_signal_connect (individual, "notify::alias",
892 (GCallback) individual_store_individual_updated_cb, self);
893 g_signal_connect (individual, "personas-changed",
894 (GCallback) individual_personas_changed_cb, self);
895 g_signal_connect (individual, "notify::is-favourite",
896 (GCallback) individual_store_favourites_changed_cb, self);
898 /* provide an empty set so the callback can assume non-NULL sets */
899 individual_personas_changed_cb (individual,
900 folks_individual_get_personas (individual), empty_set, self);
901 g_clear_object (&empty_set);
905 empathy_individual_store_disconnect_individual (EmpathyIndividualStore *self,
906 FolksIndividual *individual)
908 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
910 /* provide an empty set so the callback can assume non-NULL sets */
911 individual_personas_changed_cb (individual, empty_set,
912 folks_individual_get_personas (individual), self);
913 g_clear_object (&empty_set);
915 g_signal_handlers_disconnect_by_func (individual,
916 (GCallback) individual_store_individual_updated_cb, self);
917 g_signal_handlers_disconnect_by_func (individual,
918 (GCallback) individual_personas_changed_cb, self);
919 g_signal_handlers_disconnect_by_func (individual,
920 (GCallback) individual_store_favourites_changed_cb, self);
924 individual_store_remove_individual_and_disconnect (
925 EmpathyIndividualStore *self,
926 FolksIndividual *individual)
928 empathy_individual_store_disconnect_individual (self, individual);
929 empathy_individual_store_remove_individual (self, individual);
933 individual_store_dispose (GObject *object)
935 EmpathyIndividualStore *self = EMPATHY_INDIVIDUAL_STORE (object);
938 if (self->priv->dispose_has_run)
940 self->priv->dispose_has_run = TRUE;
942 /* Cancel any pending avatar load operations */
943 for (l = self->priv->avatar_cancellables; l != NULL; l = l->next)
945 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
946 g_cancellable_cancel (G_CANCELLABLE (l->data));
948 g_list_free (self->priv->avatar_cancellables);
950 if (self->priv->inhibit_active)
952 g_source_remove (self->priv->inhibit_active);
955 g_hash_table_unref (self->priv->status_icons);
956 g_hash_table_unref (self->priv->folks_individual_cache);
957 g_hash_table_unref (self->priv->empathy_group_cache);
958 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
962 individual_store_get_property (GObject *object,
967 EmpathyIndividualStore *self = EMPATHY_INDIVIDUAL_STORE (object);
971 case PROP_SHOW_AVATARS:
972 g_value_set_boolean (value, self->priv->show_avatars);
974 case PROP_SHOW_PROTOCOLS:
975 g_value_set_boolean (value, self->priv->show_protocols);
977 case PROP_SHOW_GROUPS:
978 g_value_set_boolean (value, self->priv->show_groups);
980 case PROP_IS_COMPACT:
981 g_value_set_boolean (value, self->priv->is_compact);
983 case PROP_SORT_CRITERIUM:
984 g_value_set_enum (value, self->priv->sort_criterium);
987 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
993 individual_store_set_property (GObject *object,
1000 case PROP_SHOW_AVATARS:
1001 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1002 (object), g_value_get_boolean (value));
1004 case PROP_SHOW_PROTOCOLS:
1005 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1006 (object), g_value_get_boolean (value));
1008 case PROP_SHOW_GROUPS:
1009 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1010 (object), g_value_get_boolean (value));
1012 case PROP_IS_COMPACT:
1013 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1014 (object), g_value_get_boolean (value));
1016 case PROP_SORT_CRITERIUM:
1017 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1018 (object), g_value_get_enum (value));
1021 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1027 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1029 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1031 object_class->dispose = individual_store_dispose;
1032 object_class->get_property = individual_store_get_property;
1033 object_class->set_property = individual_store_set_property;
1035 g_object_class_install_property (object_class,
1037 g_param_spec_boolean ("show-avatars",
1039 "Whether contact list should display "
1040 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1041 g_object_class_install_property (object_class,
1042 PROP_SHOW_PROTOCOLS,
1043 g_param_spec_boolean ("show-protocols",
1045 "Whether contact list should display "
1046 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1047 g_object_class_install_property (object_class,
1049 g_param_spec_boolean ("show-groups",
1051 "Whether contact list should display "
1052 "contact groups", TRUE, G_PARAM_READWRITE));
1053 g_object_class_install_property (object_class,
1055 g_param_spec_boolean ("is-compact",
1057 "Whether the contact list is in compact mode or not",
1058 FALSE, G_PARAM_READWRITE));
1060 g_object_class_install_property (object_class,
1061 PROP_SORT_CRITERIUM,
1062 g_param_spec_enum ("sort-criterium",
1064 "The sort criterium to use for sorting the contact list",
1065 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1066 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1068 g_type_class_add_private (object_class,
1069 sizeof (EmpathyIndividualStorePriv));
1073 get_position (const char **strv,
1078 for (i = 0; strv[i] != NULL; i++)
1080 if (!tp_strdiff (strv[i], str))
1088 compare_separator_and_groups (gboolean is_separator_a,
1089 gboolean is_separator_b,
1090 const gchar *name_a,
1091 const gchar *name_b,
1092 FolksIndividual *individual_a,
1093 FolksIndividual *individual_b,
1094 gboolean fake_group_a,
1095 gboolean fake_group_b)
1097 /* these two lists are the sorted list of fake groups to include at the
1098 * top and bottom of the roster */
1099 const char *top_groups[] = {
1100 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1104 const char *bottom_groups[] = {
1105 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1109 if (is_separator_a || is_separator_b)
1111 /* We have at least one separator */
1116 else if (is_separator_b)
1122 /* One group and one contact */
1123 if (!individual_a && individual_b)
1127 else if (individual_a && !individual_b)
1131 else if (!individual_a && !individual_b)
1133 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1135 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1136 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1137 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1138 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1140 if (a_in_top && b_in_top)
1142 /* compare positions */
1143 return CLAMP (get_position (top_groups, name_a) -
1144 get_position (top_groups, name_b), -1, 1);
1146 else if (a_in_bottom && b_in_bottom)
1148 /* compare positions */
1149 return CLAMP (get_position (bottom_groups, name_a) -
1150 get_position (bottom_groups, name_b), -1, 1);
1152 else if (a_in_top || b_in_bottom)
1156 else if (b_in_top || a_in_bottom)
1162 return g_utf8_collate (name_a, name_b);
1166 /* Two contacts, ordering depends of the sorting policy */
1171 individual_store_contact_sort (FolksIndividual *individual_a,
1172 FolksIndividual *individual_b)
1175 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1176 TpAccount *account_a, *account_b;
1178 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1181 ret_val = g_utf8_collate (
1182 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1183 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1188 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1189 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1190 if (contact_a != NULL && contact_b != NULL)
1192 account_a = empathy_contact_get_account (contact_a);
1193 account_b = empathy_contact_get_account (contact_b);
1195 g_assert (account_a != NULL);
1196 g_assert (account_b != NULL);
1199 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1200 tp_account_get_protocol (account_b));
1206 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1207 tp_proxy_get_object_path (account_b));
1214 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1215 folks_individual_get_id (individual_b));
1218 tp_clear_object (&contact_a);
1219 tp_clear_object (&contact_b);
1225 individual_store_state_sort_func (GtkTreeModel *model,
1226 GtkTreeIter *iter_a,
1227 GtkTreeIter *iter_b,
1231 FolksIndividual *individual_a, *individual_b;
1232 gchar *name_a, *name_b;
1233 gboolean is_separator_a, is_separator_b;
1234 gboolean fake_group_a, fake_group_b;
1235 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1236 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1238 gtk_tree_model_get (model, iter_a,
1239 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1240 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1241 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1242 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1243 gtk_tree_model_get (model, iter_b,
1244 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1245 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1246 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1247 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1249 if (individual_a == NULL || individual_b == NULL)
1251 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1252 name_a, name_b, individual_a, individual_b, fake_group_a,
1257 /* If we managed to get this far, we can start looking at
1260 folks_presence_type_a =
1261 folks_presence_details_get_presence_type (
1262 FOLKS_PRESENCE_DETAILS (individual_a));
1263 folks_presence_type_b =
1264 folks_presence_details_get_presence_type (
1265 FOLKS_PRESENCE_DETAILS (individual_b));
1266 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1267 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1269 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1274 /* Fallback: compare by name et al. */
1275 ret_val = individual_store_contact_sort (individual_a, individual_b);
1281 tp_clear_object (&individual_a);
1282 tp_clear_object (&individual_b);
1288 individual_store_name_sort_func (GtkTreeModel *model,
1289 GtkTreeIter *iter_a,
1290 GtkTreeIter *iter_b,
1293 gchar *name_a, *name_b;
1294 FolksIndividual *individual_a, *individual_b;
1295 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1297 gboolean fake_group_a, fake_group_b;
1299 gtk_tree_model_get (model, iter_a,
1300 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1301 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1302 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1303 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1304 gtk_tree_model_get (model, iter_b,
1305 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1306 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1307 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1308 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1310 if (individual_a == NULL || individual_b == NULL)
1311 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1312 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1314 ret_val = individual_store_contact_sort (individual_a, individual_b);
1316 tp_clear_object (&individual_a);
1317 tp_clear_object (&individual_b);
1325 individual_store_setup (EmpathyIndividualStore *self)
1328 GDK_TYPE_PIXBUF, /* Status pixbuf */
1329 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1330 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1331 G_TYPE_STRING, /* Name */
1332 G_TYPE_UINT, /* Presence type */
1333 G_TYPE_STRING, /* Status string */
1334 G_TYPE_BOOLEAN, /* Compact view */
1335 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1336 G_TYPE_BOOLEAN, /* Is group */
1337 G_TYPE_BOOLEAN, /* Is active */
1338 G_TYPE_BOOLEAN, /* Is online */
1339 G_TYPE_BOOLEAN, /* Is separator */
1340 G_TYPE_BOOLEAN, /* Can make audio calls */
1341 G_TYPE_BOOLEAN, /* Can make video calls */
1342 G_TYPE_BOOLEAN, /* Is a fake group */
1343 G_TYPE_STRV, /* Client types */
1344 G_TYPE_UINT, /* Event count */
1347 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1348 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1350 /* Set up sorting */
1351 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1352 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1353 individual_store_name_sort_func, self, NULL);
1354 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1355 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1356 individual_store_state_sort_func, self, NULL);
1358 self->priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1360 empathy_individual_store_set_sort_criterium (self,
1361 self->priv->sort_criterium);
1365 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1367 self->priv->show_active = TRUE;
1368 self->priv->inhibit_active = 0;
1374 g_queue_free_full_iter (gpointer data)
1376 GQueue *queue = (GQueue *) data;
1377 g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
1378 g_queue_free (queue);
1382 empathy_individual_store_init (EmpathyIndividualStore *self)
1384 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1385 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1387 self->priv->show_avatars = TRUE;
1388 self->priv->show_groups = TRUE;
1389 self->priv->show_protocols = FALSE;
1390 self->priv->inhibit_active =
1391 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1392 (GSourceFunc) individual_store_inhibit_active_cb, self);
1393 self->priv->status_icons =
1394 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1395 self->priv->folks_individual_cache = g_hash_table_new_full (NULL, NULL, NULL,
1396 g_queue_free_full_iter);
1397 self->priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
1398 g_str_equal, g_free, (GDestroyNotify) gtk_tree_iter_free);
1399 individual_store_setup (self);
1403 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1405 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1407 return self->priv->show_avatars;
1411 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1414 EmpathyIndividualStore *self)
1416 gboolean show_avatar = FALSE;
1417 FolksIndividual *individual;
1418 GdkPixbuf *pixbuf_status;
1420 if (self->priv->show_avatars && !self->priv->is_compact)
1425 gtk_tree_model_get (model, iter,
1426 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1428 if (individual == NULL)
1432 /* get icon from hash_table */
1434 empathy_individual_store_get_individual_status_icon (self, individual);
1436 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1437 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1438 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1439 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, self->priv->is_compact, -1);
1441 g_object_unref (individual);
1447 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1448 gboolean show_avatars)
1450 GtkTreeModel *model;
1452 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1454 self->priv->show_avatars = show_avatars;
1456 model = GTK_TREE_MODEL (self);
1458 gtk_tree_model_foreach (model,
1459 (GtkTreeModelForeachFunc)
1460 individual_store_update_list_mode_foreach, self);
1462 g_object_notify (G_OBJECT (self), "show-avatars");
1466 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1468 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1470 return self->priv->show_protocols;
1474 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1475 gboolean show_protocols)
1477 GtkTreeModel *model;
1479 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1481 self->priv->show_protocols = show_protocols;
1483 model = GTK_TREE_MODEL (self);
1485 gtk_tree_model_foreach (model,
1486 (GtkTreeModelForeachFunc)
1487 individual_store_update_list_mode_foreach, self);
1489 g_object_notify (G_OBJECT (self), "show-protocols");
1493 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1495 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1497 return self->priv->show_groups;
1501 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1502 gboolean show_groups)
1504 EmpathyIndividualStoreClass *klass;
1506 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1508 klass = EMPATHY_INDIVIDUAL_STORE_GET_CLASS ( self);
1510 if (self->priv->show_groups == show_groups)
1515 self->priv->show_groups = show_groups;
1517 if (!klass->initial_loading (self))
1519 /* Remove all contacts and add them back, not optimized but
1520 * that's the easy way :)
1522 * This is only done if there's not a pending setup idle
1523 * callback, otherwise it will race and the contacts will get
1526 gtk_tree_store_clear (GTK_TREE_STORE (self));
1527 /* Also clear the cache */
1528 g_hash_table_remove_all (self->priv->folks_individual_cache);
1529 g_hash_table_remove_all (self->priv->empathy_group_cache);
1531 klass->reload_individuals (self);
1534 g_object_notify (G_OBJECT (self), "show-groups");
1538 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1540 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1542 return self->priv->is_compact;
1546 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1547 gboolean is_compact)
1549 GtkTreeModel *model;
1551 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1553 self->priv->is_compact = is_compact;
1555 model = GTK_TREE_MODEL (self);
1557 gtk_tree_model_foreach (model,
1558 (GtkTreeModelForeachFunc)
1559 individual_store_update_list_mode_foreach, self);
1561 g_object_notify (G_OBJECT (self), "is-compact");
1564 EmpathyIndividualStoreSort
1565 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1567 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1569 return self->priv->sort_criterium;
1573 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1574 EmpathyIndividualStoreSort sort_criterium)
1576 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1578 self->priv->sort_criterium = sort_criterium;
1580 switch (sort_criterium)
1582 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1583 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1584 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1587 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1588 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1589 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1593 g_assert_not_reached ();
1596 g_object_notify (G_OBJECT (self), "sort-criterium");
1600 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1604 gboolean is_separator = FALSE;
1606 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1608 gtk_tree_model_get (model, iter,
1609 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1611 return is_separator;
1615 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1617 gboolean *path_is_group,
1618 gboolean *is_fake_group)
1620 GtkTreeIter parent_iter, iter;
1623 gboolean fake = FALSE;
1625 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1629 *path_is_group = FALSE;
1632 if (!gtk_tree_model_get_iter (model, &iter, path))
1637 gtk_tree_model_get (model, &iter,
1638 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1639 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1646 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1653 gtk_tree_model_get (model, &iter,
1654 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1655 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1656 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1666 *path_is_group = TRUE;
1669 if (is_fake_group != NULL)
1670 *is_fake_group = fake;
1676 individual_store_get_individual_status_icon_with_icon_name (
1677 EmpathyIndividualStore *self,
1678 FolksIndividual *individual,
1679 const gchar *status_icon_name)
1681 GdkPixbuf *pixbuf_status;
1682 const gchar *protocol_name = NULL;
1683 gchar *icon_name = NULL;
1686 guint contact_count = 0;
1687 EmpathyContact *contact = NULL;
1688 gboolean show_protocols_here;
1690 personas = folks_individual_get_personas (individual);
1691 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1692 while (gee_iterator_next (iter))
1694 FolksPersona *persona = gee_iterator_get (iter);
1695 if (empathy_folks_persona_is_interesting (persona))
1698 g_clear_object (&persona);
1700 if (contact_count > 1)
1703 g_clear_object (&iter);
1705 show_protocols_here = (self->priv->show_protocols && (contact_count == 1));
1706 if (show_protocols_here)
1708 contact = empathy_contact_dup_from_folks_individual (individual);
1709 if (contact != NULL)
1711 protocol_name = empathy_protocol_name_for_contact (contact);
1712 icon_name = g_strdup_printf ("%s-%s", status_icon_name,
1717 g_warning ("Cannot retrieve contact from individual '%s'",
1718 folks_alias_details_get_alias (
1719 FOLKS_ALIAS_DETAILS (individual)));
1726 icon_name = g_strdup_printf ("%s", status_icon_name);
1729 pixbuf_status = g_hash_table_lookup (self->priv->status_icons, icon_name);
1731 if (pixbuf_status == NULL)
1734 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1735 status_icon_name, show_protocols_here);
1737 if (pixbuf_status != NULL)
1739 /* pass the reference to the hash table */
1740 g_hash_table_insert (self->priv->status_icons,
1741 g_strdup (icon_name), pixbuf_status);
1746 tp_clear_object (&contact);
1748 return pixbuf_status;
1752 empathy_individual_store_get_individual_status_icon (
1753 EmpathyIndividualStore *self,
1754 FolksIndividual *individual)
1756 GdkPixbuf *pixbuf_status = NULL;
1757 const gchar *status_icon_name = NULL;
1759 status_icon_name = empathy_icon_name_for_individual (individual);
1760 if (status_icon_name == NULL)
1764 individual_store_get_individual_status_icon_with_icon_name (self,
1765 individual, status_icon_name);
1767 return pixbuf_status;
1771 empathy_individual_store_refresh_individual (EmpathyIndividualStore *self,
1772 FolksIndividual *individual)
1774 gboolean show_active;
1776 show_active = self->priv->show_active;
1777 self->priv->show_active = FALSE;
1778 empathy_individual_store_remove_individual (self, individual);
1779 empathy_individual_store_add_individual (self, individual);
1780 self->priv->show_active = show_active;