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>
41 #include <libempathy/empathy-individual-manager.h>
43 #include "empathy-individual-store.h"
44 #include "empathy-ui-utils.h"
45 #include "empathy-gtk-enum-types.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
48 #include <libempathy/empathy-debug.h>
50 /* Active users are those which have recently changed state
51 * (e.g. online, offline or from normal to a busy state).
54 /* Time in seconds user is shown as active */
55 #define ACTIVE_USER_SHOW_TIME 7
57 /* Time in seconds after connecting which we wait before active users are enabled */
58 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualStore)
63 EmpathyIndividualManager *manager;
64 gboolean show_avatars;
67 gboolean show_protocols;
69 EmpathyIndividualStoreSort sort_criterium;
72 gboolean dispose_has_run;
73 GHashTable *status_icons;
74 /* List of owned GCancellables for each pending avatar load operation */
75 GList *avatar_cancellables;
76 /* Hash: FolksIndividual* -> GQueue (GtkTreeIter *) */
77 GHashTable *folks_individual_cache;
78 /* Hash: char *groupname -> GtkTreeIter * */
79 GHashTable *empathy_group_cache;
80 } EmpathyIndividualStorePriv;
84 EmpathyIndividualStore *self;
85 FolksIndividual *individual;
93 PROP_INDIVIDUAL_MANAGER,
101 /* prototypes to break cycles */
102 static void individual_store_contact_update (EmpathyIndividualStore *self,
103 FolksIndividual *individual);
105 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
106 GTK_TYPE_TREE_STORE);
108 static const gchar * const *
109 individual_get_client_types (FolksIndividual *individual)
113 const gchar * const *types = NULL;
114 FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
116 personas = folks_individual_get_personas (individual);
117 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
118 while (gee_iterator_next (iter))
120 FolksPresenceDetails *presence;
121 FolksPersona *persona = gee_iterator_get (iter);
123 /* We only want personas which have presence and a TpContact */
124 if (!empathy_folks_persona_is_interesting (persona))
127 presence = FOLKS_PRESENCE_DETAILS (persona);
129 if (folks_presence_details_typecmp (
130 folks_presence_details_get_presence_type (presence),
133 TpContact *tp_contact;
135 presence_type = folks_presence_details_get_presence_type (presence);
137 tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
138 if (tp_contact != NULL)
139 types = tp_contact_get_client_types (tp_contact);
143 g_clear_object (&persona);
145 g_clear_object (&iter);
151 add_individual_to_store (GtkTreeStore *self,
154 FolksIndividual *individual)
156 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
157 gboolean can_audio_call, can_video_call;
158 const gchar * const *types;
161 empathy_individual_can_audio_video_call (individual, &can_audio_call,
162 &can_video_call, NULL);
164 types = individual_get_client_types (individual);
166 gtk_tree_store_insert_with_values (self, iter, parent, 0,
167 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
168 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
169 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
170 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
171 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
172 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
173 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
174 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
177 queue = g_hash_table_lookup (priv->folks_individual_cache, individual);
180 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
184 queue = g_queue_new ();
185 g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
186 g_hash_table_insert (priv->folks_individual_cache, individual,
192 individual_store_get_group (EmpathyIndividualStore *self,
194 GtkTreeIter *iter_group_to_set,
195 GtkTreeIter *iter_separator_to_set,
197 gboolean is_fake_group)
199 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
201 GtkTreeIter iter_group;
202 GtkTreeIter iter_separator;
205 model = GTK_TREE_MODEL (self);
206 iter = g_hash_table_lookup (priv->empathy_group_cache, name);
213 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
215 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
216 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
217 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
218 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
219 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
220 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
223 g_hash_table_insert (priv->empathy_group_cache, g_strdup (name),
224 gtk_tree_iter_copy (&iter_group));
226 if (iter_group_to_set)
227 *iter_group_to_set = iter_group;
229 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
231 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
234 if (iter_separator_to_set)
235 *iter_separator_to_set = iter_separator;
242 if (iter_group_to_set)
243 *iter_group_to_set = *iter;
245 iter_separator = *iter;
247 if (gtk_tree_model_iter_next (model, &iter_separator))
249 gboolean is_separator;
251 gtk_tree_model_get (model, &iter_separator,
252 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
254 if (is_separator && iter_separator_to_set)
255 *iter_separator_to_set = iter_separator;
261 individual_store_find_contact (EmpathyIndividualStore *self,
262 FolksIndividual *individual)
264 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
265 GQueue *row_refs_queue;
267 GList *iters_list = NULL;
269 row_refs_queue = g_hash_table_lookup (priv->folks_individual_cache,
274 for (i = g_queue_peek_head_link (row_refs_queue) ; i != NULL ; i = i->next)
276 GtkTreeIter *iter = i->data;
278 iters_list = g_list_prepend (iters_list, gtk_tree_iter_copy (iter));
285 free_iters (GList *iters)
287 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
292 individual_store_remove_individual (EmpathyIndividualStore *self,
293 FolksIndividual *individual)
295 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
300 row_refs = g_hash_table_lookup (priv->folks_individual_cache, individual);
305 model = GTK_TREE_MODEL (self);
307 for (l = g_queue_peek_head_link (row_refs); l; l = l->next)
309 GtkTreeIter *iter = l->data;
312 /* NOTE: it is only <= 2 here because we have
313 * separators after the group name, otherwise it
316 if (gtk_tree_model_iter_parent (model, &parent, iter) &&
317 gtk_tree_model_iter_n_children (model, &parent) <= 2)
320 gtk_tree_model_get (model, &parent,
321 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &group_name,
323 g_hash_table_remove (priv->empathy_group_cache,
325 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
329 gtk_tree_store_remove (GTK_TREE_STORE (self), iter);
333 g_hash_table_remove (priv->folks_individual_cache, individual);
337 individual_store_add_individual (EmpathyIndividualStore *self,
338 FolksIndividual *individual)
340 EmpathyIndividualStorePriv *priv;
342 GeeIterator *group_iter = NULL;
344 priv = GET_PRIV (self);
346 if (EMP_STR_EMPTY (folks_alias_details_get_alias (
347 FOLKS_ALIAS_DETAILS (individual))))
350 if (priv->show_groups)
352 GeeSet *group_set = NULL;
354 group_set = folks_group_details_get_groups (
355 FOLKS_GROUP_DETAILS (individual));
357 if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
358 group_iter = gee_iterable_iterator (GEE_ITERABLE (group_set));
361 /* fall-back groups, in case there are no named groups */
362 if (group_iter == NULL)
364 GtkTreeIter iter_group, *parent;
365 EmpathyContact *contact;
366 TpConnection *connection;
367 gchar *protocol_name = NULL;
369 parent = &iter_group;
371 contact = empathy_contact_dup_from_folks_individual (individual);
374 connection = empathy_contact_get_connection (contact);
375 tp_connection_parse_object_path (connection, &protocol_name, NULL);
378 if (!priv->show_groups)
380 else if (!tp_strdiff (protocol_name, "local-xmpp"))
382 /* these are People Nearby */
383 individual_store_get_group (self,
384 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
389 individual_store_get_group (self,
390 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
391 &iter_group, NULL, NULL, TRUE);
394 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
397 g_free (protocol_name);
398 g_clear_object (&contact);
401 /* Else add to each group. */
402 while (group_iter != NULL && gee_iterator_next (group_iter))
404 gchar *group_name = gee_iterator_get (group_iter);
405 GtkTreeIter iter_group;
407 individual_store_get_group (self, group_name, &iter_group, NULL, NULL,
410 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
415 g_clear_object (&group_iter);
417 if (priv->show_groups &&
418 folks_favourite_details_get_is_favourite (
419 FOLKS_FAVOURITE_DETAILS (individual)))
421 /* Add contact to the fake 'Favorites' group */
422 GtkTreeIter iter_group;
424 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
425 &iter_group, NULL, NULL, TRUE);
427 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
431 individual_store_contact_update (self, individual);
435 individual_store_contact_set_active (EmpathyIndividualStore *self,
436 FolksIndividual *individual,
438 gboolean set_changed)
443 model = GTK_TREE_MODEL (self);
445 iters = individual_store_find_contact (self, individual);
446 for (l = iters; l; l = l->next)
450 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
451 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
454 DEBUG ("Set item %s", active ? "active" : "inactive");
458 path = gtk_tree_model_get_path (model, l->data);
459 gtk_tree_model_row_changed (model, path, l->data);
460 gtk_tree_path_free (path);
467 static void individual_store_contact_active_free (ShowActiveData *data);
470 individual_store_contact_active_invalidated (ShowActiveData *data,
473 /* Remove the timeout and free the struct, since the individual or individual
474 * store has disappeared. */
475 g_source_remove (data->timeout);
477 if (old_object == (GObject *) data->self)
479 else if (old_object == (GObject *) data->individual)
480 data->individual = NULL;
482 g_assert_not_reached ();
484 individual_store_contact_active_free (data);
487 static ShowActiveData *
488 individual_store_contact_active_new (EmpathyIndividualStore *self,
489 FolksIndividual *individual,
492 ShowActiveData *data;
494 DEBUG ("Individual'%s' now active, and %s be removed",
495 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
496 remove_ ? "WILL" : "WILL NOT");
498 data = g_slice_new0 (ShowActiveData);
500 /* We don't actually want to force either the IndividualStore or the
501 * Individual to stay alive, since the user could quit Empathy or disable
502 * the account before the contact_active timeout is fired. */
503 g_object_weak_ref (G_OBJECT (self),
504 (GWeakNotify) individual_store_contact_active_invalidated, data);
505 g_object_weak_ref (G_OBJECT (individual),
506 (GWeakNotify) individual_store_contact_active_invalidated, data);
509 data->individual = individual;
510 data->remove = remove_;
517 individual_store_contact_active_free (ShowActiveData *data)
519 if (data->self != NULL)
521 g_object_weak_unref (G_OBJECT (data->self),
522 (GWeakNotify) individual_store_contact_active_invalidated, data);
525 if (data->individual != NULL)
527 g_object_weak_unref (G_OBJECT (data->individual),
528 (GWeakNotify) individual_store_contact_active_invalidated, data);
531 g_slice_free (ShowActiveData, data);
535 individual_store_contact_active_cb (ShowActiveData *data)
539 DEBUG ("Individual'%s' active timeout, removing item",
540 folks_alias_details_get_alias (
541 FOLKS_ALIAS_DETAILS (data->individual)));
542 individual_store_remove_individual (data->self, data->individual);
545 DEBUG ("Individual'%s' no longer active",
546 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
548 individual_store_contact_set_active (data->self,
549 data->individual, FALSE, TRUE);
551 individual_store_contact_active_free (data);
557 EmpathyIndividualStore *store; /* weak */
558 GCancellable *cancellable; /* owned */
562 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
563 GAsyncResult *result,
564 LoadAvatarData *data)
566 GError *error = NULL;
569 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
574 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
575 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
577 g_clear_error (&error);
579 else if (data->store != NULL)
583 iters = individual_store_find_contact (data->store, individual);
584 for (l = iters; l; l = l->next)
586 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
587 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
595 if (data->store != NULL)
597 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
599 g_object_remove_weak_pointer (G_OBJECT (data->store),
600 (gpointer *) &data->store);
601 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
605 tp_clear_object (&pixbuf);
606 g_object_unref (data->cancellable);
607 g_slice_free (LoadAvatarData, data);
611 individual_store_contact_update (EmpathyIndividualStore *self,
612 FolksIndividual *individual)
614 EmpathyIndividualStorePriv *priv;
615 ShowActiveData *data;
619 gboolean was_online = TRUE;
620 gboolean now_online = FALSE;
621 gboolean set_model = FALSE;
622 gboolean do_remove = FALSE;
623 gboolean do_set_active = FALSE;
624 gboolean do_set_refresh = FALSE;
625 gboolean show_avatar = FALSE;
626 GdkPixbuf *pixbuf_status;
627 LoadAvatarData *load_avatar_data;
629 priv = GET_PRIV (self);
631 model = GTK_TREE_MODEL (self);
633 iters = individual_store_find_contact (self, individual);
643 /* Get online state now. */
644 now_online = folks_presence_details_is_online (
645 FOLKS_PRESENCE_DETAILS (individual));
649 DEBUG ("Individual'%s' in list:NO, should be:YES",
650 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
652 individual_store_add_individual (self, individual);
654 if (priv->show_active)
656 do_set_active = TRUE;
658 DEBUG ("Set active (individual added)");
663 DEBUG ("Individual'%s' in list:YES, should be:YES",
664 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
666 /* Get online state before. */
667 if (iters && g_list_length (iters) > 0)
669 gtk_tree_model_get (model, iters->data,
670 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
673 /* Is this really an update or an online/offline. */
674 if (priv->show_active)
676 if (was_online != now_online)
678 do_set_active = TRUE;
679 do_set_refresh = TRUE;
681 DEBUG ("Set active (individual updated %s)",
682 was_online ? "online -> offline" : "offline -> online");
686 /* Was TRUE for presence updates. */
687 /* do_set_active = FALSE; */
688 do_set_refresh = TRUE;
690 DEBUG ("Set active (individual updated)");
697 if (priv->show_avatars && !priv->is_compact)
702 /* Load the avatar asynchronously */
703 load_avatar_data = g_slice_new (LoadAvatarData);
704 load_avatar_data->store = self;
705 g_object_add_weak_pointer (G_OBJECT (self),
706 (gpointer *) &load_avatar_data->store);
707 load_avatar_data->cancellable = g_cancellable_new ();
709 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
710 load_avatar_data->cancellable);
711 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
712 load_avatar_data->cancellable,
713 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
717 empathy_individual_store_get_individual_status_icon (self, individual);
719 for (l = iters; l && set_model; l = l->next)
721 gboolean can_audio_call, can_video_call;
722 const gchar * const *types;
724 empathy_individual_can_audio_video_call (individual, &can_audio_call,
725 &can_video_call, NULL);
727 types = individual_get_client_types (individual);
729 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
730 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
731 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
732 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
733 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
734 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
735 folks_presence_details_get_presence_type (
736 FOLKS_PRESENCE_DETAILS (individual)),
737 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
738 folks_presence_details_get_presence_message (
739 FOLKS_PRESENCE_DETAILS (individual)),
740 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
741 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
742 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
743 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
744 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
745 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
746 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
750 if (priv->show_active && do_set_active)
752 individual_store_contact_set_active (self, individual, do_set_active,
758 individual_store_contact_active_new (self, individual,
760 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
761 (GSourceFunc) individual_store_contact_active_cb, data);
765 /* FIXME: when someone goes online then offline quickly, the
766 * first timeout sets the user to be inactive and the second
767 * timeout removes the user from the contact list, really we
768 * should remove the first timeout.
774 individual_store_individual_updated_cb (FolksIndividual *individual,
776 EmpathyIndividualStore *self)
778 DEBUG ("Individual'%s' updated, checking roster is in sync...",
779 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
781 individual_store_contact_update (self, individual);
785 individual_store_contact_updated_cb (EmpathyContact *contact,
787 EmpathyIndividualStore *self)
789 FolksIndividual *individual;
791 DEBUG ("Contact '%s' updated, checking roster is in sync...",
792 empathy_contact_get_alias (contact));
794 individual = g_object_get_data (G_OBJECT (contact), "individual");
795 if (individual == NULL)
798 individual_store_contact_update (self, individual);
802 individual_personas_changed_cb (FolksIndividual *individual,
805 EmpathyIndividualStore *self)
809 DEBUG ("Individual '%s' personas-changed.",
810 folks_individual_get_id (individual));
812 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
813 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
814 * through the EmpathyContacts for them. */
815 while (gee_iterator_next (iter))
817 TpfPersona *persona = gee_iterator_get (iter);
818 TpContact *tp_contact;
819 EmpathyContact *contact;
821 if (TPF_IS_PERSONA (persona))
823 tp_contact = tpf_persona_get_contact (persona);
824 if (tp_contact != NULL)
826 contact = empathy_contact_dup_from_tp_contact (tp_contact);
827 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
829 g_object_set_data (G_OBJECT (contact), "individual", NULL);
830 g_signal_handlers_disconnect_by_func (contact,
831 (GCallback) individual_store_contact_updated_cb, self);
833 g_object_unref (contact);
837 g_clear_object (&persona);
839 g_clear_object (&iter);
841 iter = gee_iterable_iterator (GEE_ITERABLE (added));
842 while (gee_iterator_next (iter))
844 TpfPersona *persona = gee_iterator_get (iter);
845 TpContact *tp_contact;
846 EmpathyContact *contact;
848 if (TPF_IS_PERSONA (persona))
850 tp_contact = tpf_persona_get_contact (persona);
851 if (tp_contact != NULL)
853 contact = empathy_contact_dup_from_tp_contact (tp_contact);
854 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
856 g_object_set_data (G_OBJECT (contact), "individual", individual);
857 g_signal_connect (contact, "notify::capabilities",
858 (GCallback) individual_store_contact_updated_cb, self);
859 g_signal_connect (contact, "notify::client-types",
860 (GCallback) individual_store_contact_updated_cb, self);
862 g_object_unref (contact);
866 g_clear_object (&persona);
868 g_clear_object (&iter);
872 individual_store_favourites_changed_cb (FolksIndividual *individual,
874 EmpathyIndividualStore *self)
876 DEBUG ("Individual %s is %s a favourite",
877 folks_individual_get_id (individual),
878 folks_favourite_details_get_is_favourite (
879 FOLKS_FAVOURITE_DETAILS (individual)) ? "now" : "no longer");
881 individual_store_remove_individual (self, individual);
882 individual_store_add_individual (self, individual);
886 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
887 FolksIndividual *individual)
889 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
891 individual_store_add_individual (self, individual);
893 g_signal_connect (individual, "notify::avatar",
894 (GCallback) individual_store_individual_updated_cb, self);
895 g_signal_connect (individual, "notify::presence-type",
896 (GCallback) individual_store_individual_updated_cb, self);
897 g_signal_connect (individual, "notify::presence-message",
898 (GCallback) individual_store_individual_updated_cb, self);
899 g_signal_connect (individual, "notify::alias",
900 (GCallback) individual_store_individual_updated_cb, self);
901 g_signal_connect (individual, "personas-changed",
902 (GCallback) individual_personas_changed_cb, self);
903 g_signal_connect (individual, "notify::is-favourite",
904 (GCallback) individual_store_favourites_changed_cb, self);
906 /* provide an empty set so the callback can assume non-NULL sets */
907 individual_personas_changed_cb (individual,
908 folks_individual_get_personas (individual), empty_set, self);
909 g_clear_object (&empty_set);
913 individual_store_disconnect_individual (EmpathyIndividualStore *self,
914 FolksIndividual *individual)
916 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
918 /* provide an empty set so the callback can assume non-NULL sets */
919 individual_personas_changed_cb (individual, empty_set,
920 folks_individual_get_personas (individual), self);
921 g_clear_object (&empty_set);
923 g_signal_handlers_disconnect_by_func (individual,
924 (GCallback) individual_store_individual_updated_cb, self);
925 g_signal_handlers_disconnect_by_func (individual,
926 (GCallback) individual_personas_changed_cb, self);
927 g_signal_handlers_disconnect_by_func (individual,
928 (GCallback) individual_store_favourites_changed_cb, self);
932 individual_store_remove_individual_and_disconnect (
933 EmpathyIndividualStore *self,
934 FolksIndividual *individual)
936 individual_store_disconnect_individual (self, individual);
937 individual_store_remove_individual (self, individual);
941 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
942 const gchar *message,
946 EmpathyIndividualStore *self)
950 for (l = added; l; l = l->next)
952 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
954 individual_store_add_individual_and_connect (self, l->data);
956 for (l = removed; l; l = l->next)
958 DEBUG ("Individual %s %s",
959 folks_individual_get_id (l->data), "removed");
961 individual_store_remove_individual_and_disconnect (self, l->data);
966 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
967 FolksIndividual *individual,
970 EmpathyIndividualStore *self)
972 EmpathyIndividualStorePriv *priv;
973 gboolean show_active;
975 priv = GET_PRIV (self);
977 DEBUG ("Updating groups for individual %s",
978 folks_individual_get_id (individual));
980 /* We do this to make sure the groups are correct, if not, we
981 * would have to check the groups already set up for each
982 * contact and then see what has been updated.
984 show_active = priv->show_active;
985 priv->show_active = FALSE;
986 individual_store_remove_individual (self, individual);
987 individual_store_add_individual (self, individual);
988 priv->show_active = show_active;
992 individual_store_manager_setup (gpointer user_data)
994 EmpathyIndividualStore *self = user_data;
995 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
998 /* Signal connection. */
1000 /* TODO: implement */
1001 DEBUG ("handling individual renames unimplemented");
1003 g_signal_connect (priv->manager,
1005 G_CALLBACK (individual_store_members_changed_cb), self);
1007 g_signal_connect (priv->manager,
1009 G_CALLBACK (individual_store_groups_changed_cb), self);
1011 /* Add contacts already created. */
1012 individuals = empathy_individual_manager_get_members (priv->manager);
1013 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1015 individual_store_members_changed_cb (priv->manager, "initial add",
1016 individuals, NULL, 0, self);
1017 g_list_free (individuals);
1020 priv->setup_idle_id = 0;
1025 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1026 EmpathyIndividualManager *manager)
1028 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1030 priv->manager = g_object_ref (manager);
1032 /* Let a chance to have all properties set before populating */
1033 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1037 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1038 FolksIndividual *old_individual,
1039 FolksIndividual *new_individual,
1041 const gchar *message,
1042 EmpathyIndividualStore *self)
1044 DEBUG ("Individual %s renamed to %s",
1045 folks_individual_get_id (old_individual),
1046 folks_individual_get_id (new_individual));
1048 /* add the new contact */
1049 individual_store_add_individual_and_connect (self, new_individual);
1051 /* remove old contact */
1052 individual_store_remove_individual_and_disconnect (self, old_individual);
1056 individual_store_dispose (GObject *object)
1058 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1059 GList *individuals, *l;
1061 if (priv->dispose_has_run)
1063 priv->dispose_has_run = TRUE;
1065 /* Cancel any pending avatar load operations */
1066 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1068 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1069 g_cancellable_cancel (G_CANCELLABLE (l->data));
1071 g_list_free (priv->avatar_cancellables);
1073 individuals = empathy_individual_manager_get_members (priv->manager);
1074 for (l = individuals; l; l = l->next)
1076 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1077 FOLKS_INDIVIDUAL (l->data));
1079 g_list_free (individuals);
1081 g_signal_handlers_disconnect_by_func (priv->manager,
1082 G_CALLBACK (individual_store_member_renamed_cb), object);
1083 g_signal_handlers_disconnect_by_func (priv->manager,
1084 G_CALLBACK (individual_store_members_changed_cb), object);
1085 g_signal_handlers_disconnect_by_func (priv->manager,
1086 G_CALLBACK (individual_store_groups_changed_cb), object);
1087 g_object_unref (priv->manager);
1089 if (priv->inhibit_active)
1091 g_source_remove (priv->inhibit_active);
1094 if (priv->setup_idle_id != 0)
1096 g_source_remove (priv->setup_idle_id);
1099 g_hash_table_destroy (priv->status_icons);
1100 g_hash_table_destroy (priv->folks_individual_cache);
1101 g_hash_table_destroy (priv->empathy_group_cache);
1102 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1106 individual_store_get_property (GObject *object,
1111 EmpathyIndividualStorePriv *priv;
1113 priv = GET_PRIV (object);
1117 case PROP_INDIVIDUAL_MANAGER:
1118 g_value_set_object (value, priv->manager);
1120 case PROP_SHOW_AVATARS:
1121 g_value_set_boolean (value, priv->show_avatars);
1123 case PROP_SHOW_PROTOCOLS:
1124 g_value_set_boolean (value, priv->show_protocols);
1126 case PROP_SHOW_GROUPS:
1127 g_value_set_boolean (value, priv->show_groups);
1129 case PROP_IS_COMPACT:
1130 g_value_set_boolean (value, priv->is_compact);
1132 case PROP_SORT_CRITERIUM:
1133 g_value_set_enum (value, priv->sort_criterium);
1136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1142 individual_store_set_property (GObject *object,
1144 const GValue *value,
1149 case PROP_INDIVIDUAL_MANAGER:
1150 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1151 (object), g_value_get_object (value));
1153 case PROP_SHOW_AVATARS:
1154 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1155 (object), g_value_get_boolean (value));
1157 case PROP_SHOW_PROTOCOLS:
1158 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1159 (object), g_value_get_boolean (value));
1161 case PROP_SHOW_GROUPS:
1162 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1163 (object), g_value_get_boolean (value));
1165 case PROP_IS_COMPACT:
1166 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1167 (object), g_value_get_boolean (value));
1169 case PROP_SORT_CRITERIUM:
1170 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1171 (object), g_value_get_enum (value));
1174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1180 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1182 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1184 object_class->dispose = individual_store_dispose;
1185 object_class->get_property = individual_store_get_property;
1186 object_class->set_property = individual_store_set_property;
1188 g_object_class_install_property (object_class,
1189 PROP_INDIVIDUAL_MANAGER,
1190 g_param_spec_object ("individual-manager",
1191 "The individual manager",
1192 "The individual manager",
1193 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1194 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1195 g_object_class_install_property (object_class,
1197 g_param_spec_boolean ("show-avatars",
1199 "Whether contact list should display "
1200 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1201 g_object_class_install_property (object_class,
1202 PROP_SHOW_PROTOCOLS,
1203 g_param_spec_boolean ("show-protocols",
1205 "Whether contact list should display "
1206 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1207 g_object_class_install_property (object_class,
1209 g_param_spec_boolean ("show-groups",
1211 "Whether contact list should display "
1212 "contact groups", TRUE, G_PARAM_READWRITE));
1213 g_object_class_install_property (object_class,
1215 g_param_spec_boolean ("is-compact",
1217 "Whether the contact list is in compact mode or not",
1218 FALSE, G_PARAM_READWRITE));
1220 g_object_class_install_property (object_class,
1221 PROP_SORT_CRITERIUM,
1222 g_param_spec_enum ("sort-criterium",
1224 "The sort criterium to use for sorting the contact list",
1225 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1226 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1228 g_type_class_add_private (object_class,
1229 sizeof (EmpathyIndividualStorePriv));
1233 get_position (const char **strv,
1238 for (i = 0; strv[i] != NULL; i++)
1240 if (!tp_strdiff (strv[i], str))
1248 compare_separator_and_groups (gboolean is_separator_a,
1249 gboolean is_separator_b,
1250 const gchar *name_a,
1251 const gchar *name_b,
1252 FolksIndividual *individual_a,
1253 FolksIndividual *individual_b,
1254 gboolean fake_group_a,
1255 gboolean fake_group_b)
1257 /* these two lists are the sorted list of fake groups to include at the
1258 * top and bottom of the roster */
1259 const char *top_groups[] = {
1260 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1264 const char *bottom_groups[] = {
1265 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1269 if (is_separator_a || is_separator_b)
1271 /* We have at least one separator */
1276 else if (is_separator_b)
1282 /* One group and one contact */
1283 if (!individual_a && individual_b)
1287 else if (individual_a && !individual_b)
1291 else if (!individual_a && !individual_b)
1293 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1295 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1296 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1297 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1298 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1300 if (a_in_top && b_in_top)
1302 /* compare positions */
1303 return CLAMP (get_position (top_groups, name_a) -
1304 get_position (top_groups, name_b), -1, 1);
1306 else if (a_in_bottom && b_in_bottom)
1308 /* compare positions */
1309 return CLAMP (get_position (bottom_groups, name_a) -
1310 get_position (bottom_groups, name_b), -1, 1);
1312 else if (a_in_top || b_in_bottom)
1316 else if (b_in_top || a_in_bottom)
1322 return g_utf8_collate (name_a, name_b);
1326 /* Two contacts, ordering depends of the sorting policy */
1331 individual_store_contact_sort (FolksIndividual *individual_a,
1332 FolksIndividual *individual_b)
1335 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1336 TpAccount *account_a, *account_b;
1338 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1341 ret_val = g_utf8_collate (
1342 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1343 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1348 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1349 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1350 if (contact_a != NULL && contact_b != NULL)
1352 account_a = empathy_contact_get_account (contact_a);
1353 account_b = empathy_contact_get_account (contact_b);
1355 g_assert (account_a != NULL);
1356 g_assert (account_b != NULL);
1359 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1360 tp_account_get_protocol (account_b));
1366 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1367 tp_proxy_get_object_path (account_b));
1374 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1375 folks_individual_get_id (individual_b));
1378 tp_clear_object (&contact_a);
1379 tp_clear_object (&contact_b);
1385 individual_store_state_sort_func (GtkTreeModel *model,
1386 GtkTreeIter *iter_a,
1387 GtkTreeIter *iter_b,
1391 FolksIndividual *individual_a, *individual_b;
1392 gchar *name_a, *name_b;
1393 gboolean is_separator_a, is_separator_b;
1394 gboolean fake_group_a, fake_group_b;
1395 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1396 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1398 gtk_tree_model_get (model, iter_a,
1399 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1400 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1401 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1402 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1403 gtk_tree_model_get (model, iter_b,
1404 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1405 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1406 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1407 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1409 if (individual_a == NULL || individual_b == NULL)
1411 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1412 name_a, name_b, individual_a, individual_b, fake_group_a,
1417 /* If we managed to get this far, we can start looking at
1420 folks_presence_type_a =
1421 folks_presence_details_get_presence_type (
1422 FOLKS_PRESENCE_DETAILS (individual_a));
1423 folks_presence_type_b =
1424 folks_presence_details_get_presence_type (
1425 FOLKS_PRESENCE_DETAILS (individual_b));
1426 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1427 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1429 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1434 /* Fallback: compare by name et al. */
1435 ret_val = individual_store_contact_sort (individual_a, individual_b);
1441 tp_clear_object (&individual_a);
1442 tp_clear_object (&individual_b);
1448 individual_store_name_sort_func (GtkTreeModel *model,
1449 GtkTreeIter *iter_a,
1450 GtkTreeIter *iter_b,
1453 gchar *name_a, *name_b;
1454 FolksIndividual *individual_a, *individual_b;
1455 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1457 gboolean fake_group_a, fake_group_b;
1459 gtk_tree_model_get (model, iter_a,
1460 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1461 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1462 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1463 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1464 gtk_tree_model_get (model, iter_b,
1465 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1466 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1467 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1468 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1470 if (individual_a == NULL || individual_b == NULL)
1471 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1472 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1474 ret_val = individual_store_contact_sort (individual_a, individual_b);
1476 tp_clear_object (&individual_a);
1477 tp_clear_object (&individual_b);
1485 individual_store_setup (EmpathyIndividualStore *self)
1487 EmpathyIndividualStorePriv *priv;
1489 GDK_TYPE_PIXBUF, /* Status pixbuf */
1490 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1491 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1492 G_TYPE_STRING, /* Name */
1493 G_TYPE_UINT, /* Presence type */
1494 G_TYPE_STRING, /* Status string */
1495 G_TYPE_BOOLEAN, /* Compact view */
1496 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1497 G_TYPE_BOOLEAN, /* Is group */
1498 G_TYPE_BOOLEAN, /* Is active */
1499 G_TYPE_BOOLEAN, /* Is online */
1500 G_TYPE_BOOLEAN, /* Is separator */
1501 G_TYPE_BOOLEAN, /* Can make audio calls */
1502 G_TYPE_BOOLEAN, /* Can make video calls */
1503 G_TYPE_BOOLEAN, /* Is a fake group */
1504 G_TYPE_STRV, /* Client types */
1505 G_TYPE_UINT, /* Event count */
1508 priv = GET_PRIV (self);
1510 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1511 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1513 /* Set up sorting */
1514 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1515 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1516 individual_store_name_sort_func, self, NULL);
1517 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1518 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1519 individual_store_state_sort_func, self, NULL);
1521 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1522 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1526 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1528 EmpathyIndividualStorePriv *priv;
1530 priv = GET_PRIV (self);
1532 priv->show_active = TRUE;
1533 priv->inhibit_active = 0;
1539 g_queue_free_full_iter (gpointer data)
1541 GQueue *queue = (GQueue *) data;
1542 g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
1543 g_queue_free (queue);
1547 empathy_individual_store_init (EmpathyIndividualStore *self)
1549 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1550 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1553 priv->show_avatars = TRUE;
1554 priv->show_groups = TRUE;
1555 priv->show_protocols = FALSE;
1556 priv->inhibit_active =
1557 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1558 (GSourceFunc) individual_store_inhibit_active_cb, self);
1559 priv->status_icons =
1560 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1561 priv->folks_individual_cache = g_hash_table_new_full (NULL, NULL, NULL,
1562 g_queue_free_full_iter);
1563 priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
1564 g_str_equal, g_free, (GDestroyNotify) gtk_tree_iter_free);
1565 individual_store_setup (self);
1568 EmpathyIndividualStore *
1569 empathy_individual_store_new (EmpathyIndividualManager *manager)
1571 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1573 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1574 "individual-manager", manager, NULL);
1577 EmpathyIndividualManager *
1578 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1580 EmpathyIndividualStorePriv *priv;
1582 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1584 priv = GET_PRIV (self);
1586 return priv->manager;
1590 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1592 EmpathyIndividualStorePriv *priv;
1594 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1596 priv = GET_PRIV (self);
1598 return priv->show_avatars;
1602 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1605 EmpathyIndividualStore *self)
1607 EmpathyIndividualStorePriv *priv;
1608 gboolean show_avatar = FALSE;
1609 FolksIndividual *individual;
1610 GdkPixbuf *pixbuf_status;
1612 priv = GET_PRIV (self);
1614 if (priv->show_avatars && !priv->is_compact)
1619 gtk_tree_model_get (model, iter,
1620 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1622 if (individual == NULL)
1626 /* get icon from hash_table */
1628 empathy_individual_store_get_individual_status_icon (self, individual);
1630 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1631 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1632 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1633 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1635 g_object_unref (individual);
1641 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1642 gboolean show_avatars)
1644 EmpathyIndividualStorePriv *priv;
1645 GtkTreeModel *model;
1647 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1649 priv = GET_PRIV (self);
1651 priv->show_avatars = show_avatars;
1653 model = GTK_TREE_MODEL (self);
1655 gtk_tree_model_foreach (model,
1656 (GtkTreeModelForeachFunc)
1657 individual_store_update_list_mode_foreach, self);
1659 g_object_notify (G_OBJECT (self), "show-avatars");
1663 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1665 EmpathyIndividualStorePriv *priv;
1667 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1669 priv = GET_PRIV (self);
1671 return priv->show_protocols;
1675 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1676 gboolean show_protocols)
1678 EmpathyIndividualStorePriv *priv;
1679 GtkTreeModel *model;
1681 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1683 priv = GET_PRIV (self);
1685 priv->show_protocols = show_protocols;
1687 model = GTK_TREE_MODEL (self);
1689 gtk_tree_model_foreach (model,
1690 (GtkTreeModelForeachFunc)
1691 individual_store_update_list_mode_foreach, self);
1693 g_object_notify (G_OBJECT (self), "show-protocols");
1697 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1699 EmpathyIndividualStorePriv *priv;
1701 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1703 priv = GET_PRIV (self);
1705 return priv->show_groups;
1709 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1710 gboolean show_groups)
1712 EmpathyIndividualStorePriv *priv;
1714 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1716 priv = GET_PRIV (self);
1718 if (priv->show_groups == show_groups)
1723 priv->show_groups = show_groups;
1725 if (priv->setup_idle_id == 0)
1727 /* Remove all contacts and add them back, not optimized but
1728 * that's the easy way :)
1730 * This is only done if there's not a pending setup idle
1731 * callback, otherwise it will race and the contacts will get
1735 gtk_tree_store_clear (GTK_TREE_STORE (self));
1736 /* Also clear the cache */
1737 g_hash_table_remove_all (priv->folks_individual_cache);
1738 g_hash_table_remove_all (priv->empathy_group_cache);
1740 contacts = empathy_individual_manager_get_members (priv->manager);
1742 individual_store_members_changed_cb (priv->manager,
1743 "re-adding members: toggled group visibility",
1744 contacts, NULL, 0, self);
1745 g_list_free (contacts);
1748 g_object_notify (G_OBJECT (self), "show-groups");
1752 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1754 EmpathyIndividualStorePriv *priv;
1756 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1758 priv = GET_PRIV (self);
1760 return priv->is_compact;
1764 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1765 gboolean is_compact)
1767 EmpathyIndividualStorePriv *priv;
1768 GtkTreeModel *model;
1770 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1772 priv = GET_PRIV (self);
1774 priv->is_compact = is_compact;
1776 model = GTK_TREE_MODEL (self);
1778 gtk_tree_model_foreach (model,
1779 (GtkTreeModelForeachFunc)
1780 individual_store_update_list_mode_foreach, self);
1782 g_object_notify (G_OBJECT (self), "is-compact");
1785 EmpathyIndividualStoreSort
1786 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1788 EmpathyIndividualStorePriv *priv;
1790 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1792 priv = GET_PRIV (self);
1794 return priv->sort_criterium;
1798 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1799 EmpathyIndividualStoreSort sort_criterium)
1801 EmpathyIndividualStorePriv *priv;
1803 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1805 priv = GET_PRIV (self);
1807 priv->sort_criterium = sort_criterium;
1809 switch (sort_criterium)
1811 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1812 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1813 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1816 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1817 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1818 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1822 g_assert_not_reached ();
1825 g_object_notify (G_OBJECT (self), "sort-criterium");
1829 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1833 gboolean is_separator = FALSE;
1835 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1837 gtk_tree_model_get (model, iter,
1838 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1840 return is_separator;
1844 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1846 gboolean *path_is_group,
1847 gboolean *is_fake_group)
1849 GtkTreeIter parent_iter, iter;
1852 gboolean fake = FALSE;
1854 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1858 *path_is_group = FALSE;
1861 if (!gtk_tree_model_get_iter (model, &iter, path))
1866 gtk_tree_model_get (model, &iter,
1867 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1868 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1875 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1882 gtk_tree_model_get (model, &iter,
1883 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1884 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1885 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1895 *path_is_group = TRUE;
1898 if (is_fake_group != NULL)
1899 *is_fake_group = fake;
1905 individual_store_get_individual_status_icon_with_icon_name (
1906 EmpathyIndividualStore *self,
1907 FolksIndividual *individual,
1908 const gchar *status_icon_name)
1910 GdkPixbuf *pixbuf_status;
1911 EmpathyIndividualStorePriv *priv;
1912 const gchar *protocol_name = NULL;
1913 gchar *icon_name = NULL;
1916 guint contact_count = 0;
1917 EmpathyContact *contact = NULL;
1918 gboolean show_protocols_here;
1920 priv = GET_PRIV (self);
1922 personas = folks_individual_get_personas (individual);
1923 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1924 while (gee_iterator_next (iter))
1926 FolksPersona *persona = gee_iterator_get (iter);
1927 if (empathy_folks_persona_is_interesting (persona))
1930 g_clear_object (&persona);
1932 if (contact_count > 1)
1935 g_clear_object (&iter);
1937 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1938 if (show_protocols_here)
1940 contact = empathy_contact_dup_from_folks_individual (individual);
1941 if (contact != NULL)
1943 protocol_name = empathy_protocol_name_for_contact (contact);
1944 icon_name = g_strdup_printf ("%s-%s", status_icon_name,
1949 g_warning ("Cannot retrieve contact from individual '%s'",
1950 folks_alias_details_get_alias (
1951 FOLKS_ALIAS_DETAILS (individual)));
1958 icon_name = g_strdup_printf ("%s", status_icon_name);
1961 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1963 if (pixbuf_status == NULL)
1966 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1967 status_icon_name, show_protocols_here);
1969 if (pixbuf_status != NULL)
1971 /* pass the reference to the hash table */
1972 g_hash_table_insert (priv->status_icons,
1973 g_strdup (icon_name), pixbuf_status);
1978 tp_clear_object (&contact);
1980 return pixbuf_status;
1984 empathy_individual_store_get_individual_status_icon (
1985 EmpathyIndividualStore *self,
1986 FolksIndividual *individual)
1988 GdkPixbuf *pixbuf_status = NULL;
1989 const gchar *status_icon_name = NULL;
1991 status_icon_name = empathy_icon_name_for_individual (individual);
1992 if (status_icon_name == NULL)
1996 individual_store_get_individual_status_icon_with_icon_name (self,
1997 individual, status_icon_name);
1999 return pixbuf_status;