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)
334 GeeIterator *group_iter = NULL;
336 if (EMP_STR_EMPTY (folks_alias_details_get_alias (
337 FOLKS_ALIAS_DETAILS (individual))))
340 if (self->priv->show_groups)
342 GeeSet *group_set = NULL;
344 group_set = folks_group_details_get_groups (
345 FOLKS_GROUP_DETAILS (individual));
347 if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
348 group_iter = gee_iterable_iterator (GEE_ITERABLE (group_set));
351 /* fall-back groups, in case there are no named groups */
352 if (group_iter == NULL)
354 GtkTreeIter iter_group, *parent;
355 EmpathyContact *contact;
356 TpConnection *connection;
357 gchar *protocol_name = NULL;
359 parent = &iter_group;
361 contact = empathy_contact_dup_from_folks_individual (individual);
364 connection = empathy_contact_get_connection (contact);
365 tp_connection_parse_object_path (connection, &protocol_name, NULL);
368 if (!self->priv->show_groups)
370 else if (!tp_strdiff (protocol_name, "local-xmpp"))
372 /* these are People Nearby */
373 individual_store_get_group (self,
374 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
379 individual_store_get_group (self,
380 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
381 &iter_group, NULL, NULL, TRUE);
384 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
387 g_free (protocol_name);
388 g_clear_object (&contact);
391 /* Else add to each group. */
392 while (group_iter != NULL && gee_iterator_next (group_iter))
394 gchar *group_name = gee_iterator_get (group_iter);
395 GtkTreeIter iter_group;
397 individual_store_get_group (self, group_name, &iter_group, NULL, NULL,
400 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
405 g_clear_object (&group_iter);
407 if (self->priv->show_groups &&
408 folks_favourite_details_get_is_favourite (
409 FOLKS_FAVOURITE_DETAILS (individual)))
411 /* Add contact to the fake 'Favorites' group */
412 GtkTreeIter iter_group;
414 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
415 &iter_group, NULL, NULL, TRUE);
417 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
421 individual_store_contact_update (self, individual);
425 individual_store_contact_set_active (EmpathyIndividualStore *self,
426 FolksIndividual *individual,
428 gboolean set_changed)
433 model = GTK_TREE_MODEL (self);
435 iters = individual_store_find_contact (self, individual);
436 for (l = iters; l; l = l->next)
440 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
441 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
444 DEBUG ("Set item %s", active ? "active" : "inactive");
448 path = gtk_tree_model_get_path (model, l->data);
449 gtk_tree_model_row_changed (model, path, l->data);
450 gtk_tree_path_free (path);
457 static void individual_store_contact_active_free (ShowActiveData *data);
460 individual_store_contact_active_invalidated (ShowActiveData *data,
463 /* Remove the timeout and free the struct, since the individual or individual
464 * store has disappeared. */
465 g_source_remove (data->timeout);
467 if (old_object == (GObject *) data->self)
469 else if (old_object == (GObject *) data->individual)
470 data->individual = NULL;
472 g_assert_not_reached ();
474 individual_store_contact_active_free (data);
477 static ShowActiveData *
478 individual_store_contact_active_new (EmpathyIndividualStore *self,
479 FolksIndividual *individual,
482 ShowActiveData *data;
484 DEBUG ("Individual'%s' now active, and %s be removed",
485 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
486 remove_ ? "WILL" : "WILL NOT");
488 data = g_slice_new0 (ShowActiveData);
490 /* We don't actually want to force either the IndividualStore or the
491 * Individual to stay alive, since the user could quit Empathy or disable
492 * the account before the contact_active timeout is fired. */
493 g_object_weak_ref (G_OBJECT (self),
494 (GWeakNotify) individual_store_contact_active_invalidated, data);
495 g_object_weak_ref (G_OBJECT (individual),
496 (GWeakNotify) individual_store_contact_active_invalidated, data);
499 data->individual = individual;
500 data->remove = remove_;
507 individual_store_contact_active_free (ShowActiveData *data)
509 if (data->self != NULL)
511 g_object_weak_unref (G_OBJECT (data->self),
512 (GWeakNotify) individual_store_contact_active_invalidated, data);
515 if (data->individual != NULL)
517 g_object_weak_unref (G_OBJECT (data->individual),
518 (GWeakNotify) individual_store_contact_active_invalidated, data);
521 g_slice_free (ShowActiveData, data);
525 individual_store_contact_active_cb (ShowActiveData *data)
529 DEBUG ("Individual'%s' active timeout, removing item",
530 folks_alias_details_get_alias (
531 FOLKS_ALIAS_DETAILS (data->individual)));
532 empathy_individual_store_remove_individual (data->self, data->individual);
535 DEBUG ("Individual'%s' no longer active",
536 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
538 individual_store_contact_set_active (data->self,
539 data->individual, FALSE, TRUE);
541 individual_store_contact_active_free (data);
547 EmpathyIndividualStore *store; /* weak */
548 GCancellable *cancellable; /* owned */
552 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
553 GAsyncResult *result,
554 LoadAvatarData *data)
556 GError *error = NULL;
559 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
564 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
565 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
567 g_clear_error (&error);
569 else if (data->store != NULL)
573 iters = individual_store_find_contact (data->store, individual);
574 for (l = iters; l; l = l->next)
576 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
577 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
585 if (data->store != NULL)
587 g_object_remove_weak_pointer (G_OBJECT (data->store),
588 (gpointer *) &data->store);
589 data->store->priv->avatar_cancellables = g_list_remove (
590 data->store->priv->avatar_cancellables, data->cancellable);
593 tp_clear_object (&pixbuf);
594 g_object_unref (data->cancellable);
595 g_slice_free (LoadAvatarData, data);
599 individual_store_contact_update (EmpathyIndividualStore *self,
600 FolksIndividual *individual)
602 ShowActiveData *data;
606 gboolean was_online = TRUE;
607 gboolean now_online = FALSE;
608 gboolean set_model = FALSE;
609 gboolean do_remove = FALSE;
610 gboolean do_set_active = FALSE;
611 gboolean do_set_refresh = FALSE;
612 gboolean show_avatar = FALSE;
613 GdkPixbuf *pixbuf_status;
614 LoadAvatarData *load_avatar_data;
616 model = GTK_TREE_MODEL (self);
618 iters = individual_store_find_contact (self, individual);
628 /* Get online state now. */
629 now_online = folks_presence_details_is_online (
630 FOLKS_PRESENCE_DETAILS (individual));
634 DEBUG ("Individual'%s' in list:NO, should be:YES",
635 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
637 empathy_individual_store_add_individual (self, individual);
639 if (self->priv->show_active)
641 do_set_active = TRUE;
643 DEBUG ("Set active (individual added)");
648 DEBUG ("Individual'%s' in list:YES, should be:YES",
649 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
651 /* Get online state before. */
652 if (iters && g_list_length (iters) > 0)
654 gtk_tree_model_get (model, iters->data,
655 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
658 /* Is this really an update or an online/offline. */
659 if (self->priv->show_active)
661 if (was_online != now_online)
663 do_set_active = TRUE;
664 do_set_refresh = TRUE;
666 DEBUG ("Set active (individual updated %s)",
667 was_online ? "online -> offline" : "offline -> online");
671 /* Was TRUE for presence updates. */
672 /* do_set_active = FALSE; */
673 do_set_refresh = TRUE;
675 DEBUG ("Set active (individual updated)");
682 if (self->priv->show_avatars && !self->priv->is_compact)
687 /* Load the avatar asynchronously */
688 load_avatar_data = g_slice_new (LoadAvatarData);
689 load_avatar_data->store = self;
690 g_object_add_weak_pointer (G_OBJECT (self),
691 (gpointer *) &load_avatar_data->store);
692 load_avatar_data->cancellable = g_cancellable_new ();
694 self->priv->avatar_cancellables = g_list_prepend (
695 self->priv->avatar_cancellables, load_avatar_data->cancellable);
697 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
698 load_avatar_data->cancellable,
699 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
703 empathy_individual_store_get_individual_status_icon (self, individual);
705 for (l = iters; l && set_model; l = l->next)
707 gboolean can_audio_call, can_video_call;
708 const gchar * const *types;
710 empathy_individual_can_audio_video_call (individual, &can_audio_call,
711 &can_video_call, NULL);
713 types = individual_get_client_types (individual);
715 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
716 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
717 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
718 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
719 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
720 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
721 folks_presence_details_get_presence_type (
722 FOLKS_PRESENCE_DETAILS (individual)),
723 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
724 folks_presence_details_get_presence_message (
725 FOLKS_PRESENCE_DETAILS (individual)),
726 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, self->priv->is_compact,
727 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
728 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
729 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
730 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
731 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
732 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
736 if (self->priv->show_active && do_set_active)
738 individual_store_contact_set_active (self, individual, do_set_active,
744 individual_store_contact_active_new (self, individual,
746 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
747 (GSourceFunc) individual_store_contact_active_cb, data);
751 /* FIXME: when someone goes online then offline quickly, the
752 * first timeout sets the user to be inactive and the second
753 * timeout removes the user from the contact list, really we
754 * should remove the first timeout.
760 individual_store_individual_updated_cb (FolksIndividual *individual,
762 EmpathyIndividualStore *self)
764 DEBUG ("Individual'%s' updated, checking roster is in sync...",
765 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
767 individual_store_contact_update (self, individual);
771 individual_store_contact_updated_cb (EmpathyContact *contact,
773 EmpathyIndividualStore *self)
775 FolksIndividual *individual;
777 DEBUG ("Contact '%s' updated, checking roster is in sync...",
778 empathy_contact_get_alias (contact));
780 individual = g_object_get_data (G_OBJECT (contact), "individual");
781 if (individual == NULL)
784 individual_store_contact_update (self, individual);
788 individual_personas_changed_cb (FolksIndividual *individual,
791 EmpathyIndividualStore *self)
795 DEBUG ("Individual '%s' personas-changed.",
796 folks_individual_get_id (individual));
798 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
799 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
800 * through the EmpathyContacts for them. */
801 while (gee_iterator_next (iter))
803 TpfPersona *persona = gee_iterator_get (iter);
804 TpContact *tp_contact;
805 EmpathyContact *contact;
807 if (TPF_IS_PERSONA (persona))
809 tp_contact = tpf_persona_get_contact (persona);
810 if (tp_contact != NULL)
812 contact = empathy_contact_dup_from_tp_contact (tp_contact);
813 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
815 g_object_set_data (G_OBJECT (contact), "individual", NULL);
816 g_signal_handlers_disconnect_by_func (contact,
817 (GCallback) individual_store_contact_updated_cb, self);
819 g_object_unref (contact);
823 g_clear_object (&persona);
825 g_clear_object (&iter);
827 iter = gee_iterable_iterator (GEE_ITERABLE (added));
828 while (gee_iterator_next (iter))
830 TpfPersona *persona = gee_iterator_get (iter);
831 TpContact *tp_contact;
832 EmpathyContact *contact;
834 if (TPF_IS_PERSONA (persona))
836 tp_contact = tpf_persona_get_contact (persona);
837 if (tp_contact != NULL)
839 contact = empathy_contact_dup_from_tp_contact (tp_contact);
840 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
842 g_object_set_data (G_OBJECT (contact), "individual", individual);
843 g_signal_connect (contact, "notify::capabilities",
844 (GCallback) individual_store_contact_updated_cb, self);
845 g_signal_connect (contact, "notify::client-types",
846 (GCallback) individual_store_contact_updated_cb, self);
848 g_object_unref (contact);
852 g_clear_object (&persona);
854 g_clear_object (&iter);
858 individual_store_favourites_changed_cb (FolksIndividual *individual,
860 EmpathyIndividualStore *self)
862 DEBUG ("Individual %s is %s a favourite",
863 folks_individual_get_id (individual),
864 folks_favourite_details_get_is_favourite (
865 FOLKS_FAVOURITE_DETAILS (individual)) ? "now" : "no longer");
867 empathy_individual_store_remove_individual (self, individual);
868 empathy_individual_store_add_individual (self, individual);
872 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
873 FolksIndividual *individual)
875 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
877 empathy_individual_store_add_individual (self, individual);
879 g_signal_connect (individual, "notify::avatar",
880 (GCallback) individual_store_individual_updated_cb, self);
881 g_signal_connect (individual, "notify::presence-type",
882 (GCallback) individual_store_individual_updated_cb, self);
883 g_signal_connect (individual, "notify::presence-message",
884 (GCallback) individual_store_individual_updated_cb, self);
885 g_signal_connect (individual, "notify::alias",
886 (GCallback) individual_store_individual_updated_cb, self);
887 g_signal_connect (individual, "personas-changed",
888 (GCallback) individual_personas_changed_cb, self);
889 g_signal_connect (individual, "notify::is-favourite",
890 (GCallback) individual_store_favourites_changed_cb, self);
892 /* provide an empty set so the callback can assume non-NULL sets */
893 individual_personas_changed_cb (individual,
894 folks_individual_get_personas (individual), empty_set, self);
895 g_clear_object (&empty_set);
899 empathy_individual_store_disconnect_individual (EmpathyIndividualStore *self,
900 FolksIndividual *individual)
902 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
904 /* provide an empty set so the callback can assume non-NULL sets */
905 individual_personas_changed_cb (individual, empty_set,
906 folks_individual_get_personas (individual), self);
907 g_clear_object (&empty_set);
909 g_signal_handlers_disconnect_by_func (individual,
910 (GCallback) individual_store_individual_updated_cb, self);
911 g_signal_handlers_disconnect_by_func (individual,
912 (GCallback) individual_personas_changed_cb, self);
913 g_signal_handlers_disconnect_by_func (individual,
914 (GCallback) individual_store_favourites_changed_cb, self);
918 individual_store_remove_individual_and_disconnect (
919 EmpathyIndividualStore *self,
920 FolksIndividual *individual)
922 empathy_individual_store_disconnect_individual (self, individual);
923 empathy_individual_store_remove_individual (self, individual);
927 individual_store_dispose (GObject *object)
929 EmpathyIndividualStore *self = EMPATHY_INDIVIDUAL_STORE (object);
932 if (self->priv->dispose_has_run)
934 self->priv->dispose_has_run = TRUE;
936 /* Cancel any pending avatar load operations */
937 for (l = self->priv->avatar_cancellables; l != NULL; l = l->next)
939 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
940 g_cancellable_cancel (G_CANCELLABLE (l->data));
942 g_list_free (self->priv->avatar_cancellables);
944 if (self->priv->inhibit_active)
946 g_source_remove (self->priv->inhibit_active);
949 if (self->setup_idle_id != 0)
951 g_source_remove (self->setup_idle_id);
954 g_hash_table_unref (self->priv->status_icons);
955 g_hash_table_unref (self->priv->folks_individual_cache);
956 g_hash_table_unref (self->priv->empathy_group_cache);
957 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
961 individual_store_get_property (GObject *object,
966 EmpathyIndividualStore *self = EMPATHY_INDIVIDUAL_STORE (object);
970 case PROP_SHOW_AVATARS:
971 g_value_set_boolean (value, self->priv->show_avatars);
973 case PROP_SHOW_PROTOCOLS:
974 g_value_set_boolean (value, self->priv->show_protocols);
976 case PROP_SHOW_GROUPS:
977 g_value_set_boolean (value, self->priv->show_groups);
979 case PROP_IS_COMPACT:
980 g_value_set_boolean (value, self->priv->is_compact);
982 case PROP_SORT_CRITERIUM:
983 g_value_set_enum (value, self->priv->sort_criterium);
986 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
992 individual_store_set_property (GObject *object,
999 case PROP_SHOW_AVATARS:
1000 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1001 (object), g_value_get_boolean (value));
1003 case PROP_SHOW_PROTOCOLS:
1004 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1005 (object), g_value_get_boolean (value));
1007 case PROP_SHOW_GROUPS:
1008 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1009 (object), g_value_get_boolean (value));
1011 case PROP_IS_COMPACT:
1012 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1013 (object), g_value_get_boolean (value));
1015 case PROP_SORT_CRITERIUM:
1016 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1017 (object), g_value_get_enum (value));
1020 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1026 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1028 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1030 object_class->dispose = individual_store_dispose;
1031 object_class->get_property = individual_store_get_property;
1032 object_class->set_property = individual_store_set_property;
1034 g_object_class_install_property (object_class,
1036 g_param_spec_boolean ("show-avatars",
1038 "Whether contact list should display "
1039 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1040 g_object_class_install_property (object_class,
1041 PROP_SHOW_PROTOCOLS,
1042 g_param_spec_boolean ("show-protocols",
1044 "Whether contact list should display "
1045 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1046 g_object_class_install_property (object_class,
1048 g_param_spec_boolean ("show-groups",
1050 "Whether contact list should display "
1051 "contact groups", TRUE, G_PARAM_READWRITE));
1052 g_object_class_install_property (object_class,
1054 g_param_spec_boolean ("is-compact",
1056 "Whether the contact list is in compact mode or not",
1057 FALSE, G_PARAM_READWRITE));
1059 g_object_class_install_property (object_class,
1060 PROP_SORT_CRITERIUM,
1061 g_param_spec_enum ("sort-criterium",
1063 "The sort criterium to use for sorting the contact list",
1064 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1065 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1067 g_type_class_add_private (object_class,
1068 sizeof (EmpathyIndividualStorePriv));
1072 get_position (const char **strv,
1077 for (i = 0; strv[i] != NULL; i++)
1079 if (!tp_strdiff (strv[i], str))
1087 compare_separator_and_groups (gboolean is_separator_a,
1088 gboolean is_separator_b,
1089 const gchar *name_a,
1090 const gchar *name_b,
1091 FolksIndividual *individual_a,
1092 FolksIndividual *individual_b,
1093 gboolean fake_group_a,
1094 gboolean fake_group_b)
1096 /* these two lists are the sorted list of fake groups to include at the
1097 * top and bottom of the roster */
1098 const char *top_groups[] = {
1099 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1103 const char *bottom_groups[] = {
1104 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1108 if (is_separator_a || is_separator_b)
1110 /* We have at least one separator */
1115 else if (is_separator_b)
1121 /* One group and one contact */
1122 if (!individual_a && individual_b)
1126 else if (individual_a && !individual_b)
1130 else if (!individual_a && !individual_b)
1132 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1134 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1135 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1136 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1137 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1139 if (a_in_top && b_in_top)
1141 /* compare positions */
1142 return CLAMP (get_position (top_groups, name_a) -
1143 get_position (top_groups, name_b), -1, 1);
1145 else if (a_in_bottom && b_in_bottom)
1147 /* compare positions */
1148 return CLAMP (get_position (bottom_groups, name_a) -
1149 get_position (bottom_groups, name_b), -1, 1);
1151 else if (a_in_top || b_in_bottom)
1155 else if (b_in_top || a_in_bottom)
1161 return g_utf8_collate (name_a, name_b);
1165 /* Two contacts, ordering depends of the sorting policy */
1170 individual_store_contact_sort (FolksIndividual *individual_a,
1171 FolksIndividual *individual_b)
1174 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1175 TpAccount *account_a, *account_b;
1177 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1180 ret_val = g_utf8_collate (
1181 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1182 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1187 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1188 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1189 if (contact_a != NULL && contact_b != NULL)
1191 account_a = empathy_contact_get_account (contact_a);
1192 account_b = empathy_contact_get_account (contact_b);
1194 g_assert (account_a != NULL);
1195 g_assert (account_b != NULL);
1198 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1199 tp_account_get_protocol (account_b));
1205 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1206 tp_proxy_get_object_path (account_b));
1213 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1214 folks_individual_get_id (individual_b));
1217 tp_clear_object (&contact_a);
1218 tp_clear_object (&contact_b);
1224 individual_store_state_sort_func (GtkTreeModel *model,
1225 GtkTreeIter *iter_a,
1226 GtkTreeIter *iter_b,
1230 FolksIndividual *individual_a, *individual_b;
1231 gchar *name_a, *name_b;
1232 gboolean is_separator_a, is_separator_b;
1233 gboolean fake_group_a, fake_group_b;
1234 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1235 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1237 gtk_tree_model_get (model, iter_a,
1238 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1239 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1240 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1241 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1242 gtk_tree_model_get (model, iter_b,
1243 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1244 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1245 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1246 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1248 if (individual_a == NULL || individual_b == NULL)
1250 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1251 name_a, name_b, individual_a, individual_b, fake_group_a,
1256 /* If we managed to get this far, we can start looking at
1259 folks_presence_type_a =
1260 folks_presence_details_get_presence_type (
1261 FOLKS_PRESENCE_DETAILS (individual_a));
1262 folks_presence_type_b =
1263 folks_presence_details_get_presence_type (
1264 FOLKS_PRESENCE_DETAILS (individual_b));
1265 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1266 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1268 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1273 /* Fallback: compare by name et al. */
1274 ret_val = individual_store_contact_sort (individual_a, individual_b);
1280 tp_clear_object (&individual_a);
1281 tp_clear_object (&individual_b);
1287 individual_store_name_sort_func (GtkTreeModel *model,
1288 GtkTreeIter *iter_a,
1289 GtkTreeIter *iter_b,
1292 gchar *name_a, *name_b;
1293 FolksIndividual *individual_a, *individual_b;
1294 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1296 gboolean fake_group_a, fake_group_b;
1298 gtk_tree_model_get (model, iter_a,
1299 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1300 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1301 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1302 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1303 gtk_tree_model_get (model, iter_b,
1304 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1305 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1306 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1307 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1309 if (individual_a == NULL || individual_b == NULL)
1310 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1311 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1313 ret_val = individual_store_contact_sort (individual_a, individual_b);
1315 tp_clear_object (&individual_a);
1316 tp_clear_object (&individual_b);
1324 individual_store_setup (EmpathyIndividualStore *self)
1327 GDK_TYPE_PIXBUF, /* Status pixbuf */
1328 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1329 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1330 G_TYPE_STRING, /* Name */
1331 G_TYPE_UINT, /* Presence type */
1332 G_TYPE_STRING, /* Status string */
1333 G_TYPE_BOOLEAN, /* Compact view */
1334 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1335 G_TYPE_BOOLEAN, /* Is group */
1336 G_TYPE_BOOLEAN, /* Is active */
1337 G_TYPE_BOOLEAN, /* Is online */
1338 G_TYPE_BOOLEAN, /* Is separator */
1339 G_TYPE_BOOLEAN, /* Can make audio calls */
1340 G_TYPE_BOOLEAN, /* Can make video calls */
1341 G_TYPE_BOOLEAN, /* Is a fake group */
1342 G_TYPE_STRV, /* Client types */
1343 G_TYPE_UINT, /* Event count */
1346 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1347 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1349 /* Set up sorting */
1350 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1351 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1352 individual_store_name_sort_func, self, NULL);
1353 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1354 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1355 individual_store_state_sort_func, self, NULL);
1357 self->priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1359 empathy_individual_store_set_sort_criterium (self,
1360 self->priv->sort_criterium);
1364 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1366 self->priv->show_active = TRUE;
1367 self->priv->inhibit_active = 0;
1373 g_queue_free_full_iter (gpointer data)
1375 GQueue *queue = (GQueue *) data;
1376 g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
1377 g_queue_free (queue);
1381 empathy_individual_store_init (EmpathyIndividualStore *self)
1383 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1384 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1386 self->priv->show_avatars = TRUE;
1387 self->priv->show_groups = TRUE;
1388 self->priv->show_protocols = FALSE;
1389 self->priv->inhibit_active =
1390 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1391 (GSourceFunc) individual_store_inhibit_active_cb, self);
1392 self->priv->status_icons =
1393 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1394 self->priv->folks_individual_cache = g_hash_table_new_full (NULL, NULL, NULL,
1395 g_queue_free_full_iter);
1396 self->priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
1397 g_str_equal, g_free, (GDestroyNotify) gtk_tree_iter_free);
1398 individual_store_setup (self);
1402 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1404 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1406 return self->priv->show_avatars;
1410 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1413 EmpathyIndividualStore *self)
1415 gboolean show_avatar = FALSE;
1416 FolksIndividual *individual;
1417 GdkPixbuf *pixbuf_status;
1419 if (self->priv->show_avatars && !self->priv->is_compact)
1424 gtk_tree_model_get (model, iter,
1425 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1427 if (individual == NULL)
1431 /* get icon from hash_table */
1433 empathy_individual_store_get_individual_status_icon (self, individual);
1435 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1436 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1437 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1438 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, self->priv->is_compact, -1);
1440 g_object_unref (individual);
1446 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1447 gboolean show_avatars)
1449 GtkTreeModel *model;
1451 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1453 self->priv->show_avatars = show_avatars;
1455 model = GTK_TREE_MODEL (self);
1457 gtk_tree_model_foreach (model,
1458 (GtkTreeModelForeachFunc)
1459 individual_store_update_list_mode_foreach, self);
1461 g_object_notify (G_OBJECT (self), "show-avatars");
1465 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1467 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1469 return self->priv->show_protocols;
1473 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1474 gboolean show_protocols)
1476 GtkTreeModel *model;
1478 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1480 self->priv->show_protocols = show_protocols;
1482 model = GTK_TREE_MODEL (self);
1484 gtk_tree_model_foreach (model,
1485 (GtkTreeModelForeachFunc)
1486 individual_store_update_list_mode_foreach, self);
1488 g_object_notify (G_OBJECT (self), "show-protocols");
1492 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1494 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1496 return self->priv->show_groups;
1500 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1501 gboolean show_groups)
1503 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1505 if (self->priv->show_groups == show_groups)
1510 self->priv->show_groups = show_groups;
1512 if (self->setup_idle_id == 0)
1514 /* Remove all contacts and add them back, not optimized but
1515 * that's the easy way :)
1517 * This is only done if there's not a pending setup idle
1518 * callback, otherwise it will race and the contacts will get
1520 EmpathyIndividualStoreClass *klass = EMPATHY_INDIVIDUAL_STORE_GET_CLASS (
1523 gtk_tree_store_clear (GTK_TREE_STORE (self));
1524 /* Also clear the cache */
1525 g_hash_table_remove_all (self->priv->folks_individual_cache);
1526 g_hash_table_remove_all (self->priv->empathy_group_cache);
1528 klass->reload_individuals (self);
1531 g_object_notify (G_OBJECT (self), "show-groups");
1535 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1537 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1539 return self->priv->is_compact;
1543 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1544 gboolean is_compact)
1546 GtkTreeModel *model;
1548 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1550 self->priv->is_compact = is_compact;
1552 model = GTK_TREE_MODEL (self);
1554 gtk_tree_model_foreach (model,
1555 (GtkTreeModelForeachFunc)
1556 individual_store_update_list_mode_foreach, self);
1558 g_object_notify (G_OBJECT (self), "is-compact");
1561 EmpathyIndividualStoreSort
1562 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1564 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1566 return self->priv->sort_criterium;
1570 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1571 EmpathyIndividualStoreSort sort_criterium)
1573 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1575 self->priv->sort_criterium = sort_criterium;
1577 switch (sort_criterium)
1579 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1580 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1581 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1584 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1585 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1586 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1590 g_assert_not_reached ();
1593 g_object_notify (G_OBJECT (self), "sort-criterium");
1597 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1601 gboolean is_separator = FALSE;
1603 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1605 gtk_tree_model_get (model, iter,
1606 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1608 return is_separator;
1612 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1614 gboolean *path_is_group,
1615 gboolean *is_fake_group)
1617 GtkTreeIter parent_iter, iter;
1620 gboolean fake = FALSE;
1622 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1626 *path_is_group = FALSE;
1629 if (!gtk_tree_model_get_iter (model, &iter, path))
1634 gtk_tree_model_get (model, &iter,
1635 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1636 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1643 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1650 gtk_tree_model_get (model, &iter,
1651 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1652 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1653 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1663 *path_is_group = TRUE;
1666 if (is_fake_group != NULL)
1667 *is_fake_group = fake;
1673 individual_store_get_individual_status_icon_with_icon_name (
1674 EmpathyIndividualStore *self,
1675 FolksIndividual *individual,
1676 const gchar *status_icon_name)
1678 GdkPixbuf *pixbuf_status;
1679 const gchar *protocol_name = NULL;
1680 gchar *icon_name = NULL;
1683 guint contact_count = 0;
1684 EmpathyContact *contact = NULL;
1685 gboolean show_protocols_here;
1687 personas = folks_individual_get_personas (individual);
1688 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1689 while (gee_iterator_next (iter))
1691 FolksPersona *persona = gee_iterator_get (iter);
1692 if (empathy_folks_persona_is_interesting (persona))
1695 g_clear_object (&persona);
1697 if (contact_count > 1)
1700 g_clear_object (&iter);
1702 show_protocols_here = (self->priv->show_protocols && (contact_count == 1));
1703 if (show_protocols_here)
1705 contact = empathy_contact_dup_from_folks_individual (individual);
1706 if (contact != NULL)
1708 protocol_name = empathy_protocol_name_for_contact (contact);
1709 icon_name = g_strdup_printf ("%s-%s", status_icon_name,
1714 g_warning ("Cannot retrieve contact from individual '%s'",
1715 folks_alias_details_get_alias (
1716 FOLKS_ALIAS_DETAILS (individual)));
1723 icon_name = g_strdup_printf ("%s", status_icon_name);
1726 pixbuf_status = g_hash_table_lookup (self->priv->status_icons, icon_name);
1728 if (pixbuf_status == NULL)
1731 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1732 status_icon_name, show_protocols_here);
1734 if (pixbuf_status != NULL)
1736 /* pass the reference to the hash table */
1737 g_hash_table_insert (self->priv->status_icons,
1738 g_strdup (icon_name), pixbuf_status);
1743 tp_clear_object (&contact);
1745 return pixbuf_status;
1749 empathy_individual_store_get_individual_status_icon (
1750 EmpathyIndividualStore *self,
1751 FolksIndividual *individual)
1753 GdkPixbuf *pixbuf_status = NULL;
1754 const gchar *status_icon_name = NULL;
1756 status_icon_name = empathy_icon_name_for_individual (individual);
1757 if (status_icon_name == NULL)
1761 individual_store_get_individual_status_icon_with_icon_name (self,
1762 individual, status_icon_name);
1764 return pixbuf_status;
1768 empathy_individual_store_refresh_individual (EmpathyIndividualStore *self,
1769 FolksIndividual *individual)
1771 gboolean show_active;
1773 show_active = self->priv->show_active;
1774 self->priv->show_active = FALSE;
1775 empathy_individual_store_remove_individual (self, individual);
1776 empathy_individual_store_add_individual (self, individual);
1777 self->priv->show_active = show_active;