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 } EmpathyIndividualStorePriv;
87 FolksIndividual *individual;
94 EmpathyIndividualStore *self;
95 FolksIndividual *individual;
103 PROP_INDIVIDUAL_MANAGER,
111 /* prototypes to break cycles */
112 static void individual_store_contact_update (EmpathyIndividualStore *self,
113 FolksIndividual *individual);
115 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
116 GTK_TYPE_TREE_STORE);
118 /* Calculate whether the Individual can do audio or video calls.
119 * FIXME: We can remove this once libfolks has grown capabilities support
120 * again: bgo#626179. */
122 individual_can_audio_video_call (FolksIndividual *individual,
123 gboolean *can_audio_call,
124 gboolean *can_video_call)
128 gboolean can_audio = FALSE, can_video = FALSE;
130 personas = folks_individual_get_personas (individual);
131 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
132 while (gee_iterator_next (iter))
134 FolksPersona *persona = gee_iterator_get (iter);
135 TpContact *tp_contact;
136 EmpathyContact *contact;
138 if (!empathy_folks_persona_is_interesting (persona))
141 tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
142 contact = empathy_contact_dup_from_tp_contact (tp_contact);
143 empathy_contact_set_persona (contact, persona);
145 can_audio = can_audio || empathy_contact_get_capabilities (contact) &
146 EMPATHY_CAPABILITIES_AUDIO;
147 can_video = can_video || empathy_contact_get_capabilities (contact) &
148 EMPATHY_CAPABILITIES_VIDEO;
150 g_object_unref (contact);
152 g_clear_object (&persona);
154 if (can_audio && can_video)
157 g_clear_object (&iter);
159 *can_audio_call = can_audio;
160 *can_video_call = can_video;
163 static const gchar * const *
164 individual_get_client_types (FolksIndividual *individual)
168 const gchar * const *types = NULL;
169 FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
171 personas = folks_individual_get_personas (individual);
172 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
173 while (gee_iterator_next (iter))
175 FolksPresenceDetails *presence;
176 FolksPersona *persona = gee_iterator_get (iter);
178 /* We only want personas which have presence and a TpContact */
179 if (!empathy_folks_persona_is_interesting (persona))
182 presence = FOLKS_PRESENCE_DETAILS (persona);
184 if (folks_presence_details_typecmp (
185 folks_presence_details_get_presence_type (presence),
188 TpContact *tp_contact;
190 presence_type = folks_presence_details_get_presence_type (presence);
192 tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
193 types = tp_contact_get_client_types (tp_contact);
197 g_clear_object (&persona);
199 g_clear_object (&iter);
205 add_individual_to_store (GtkTreeStore *self,
208 FolksIndividual *individual)
210 gboolean can_audio_call, can_video_call;
211 const gchar * const *types;
213 individual_can_audio_video_call (individual, &can_audio_call,
216 types = individual_get_client_types (individual);
218 gtk_tree_store_insert_with_values (self, iter, parent, 0,
219 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
220 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
221 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
222 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
223 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
224 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
225 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
226 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
231 individual_store_get_group_foreach (GtkTreeModel *model,
239 /* Groups are only at the top level. */
240 if (gtk_tree_path_get_depth (path) != 1)
243 gtk_tree_model_get (model, iter,
244 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
245 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
247 if (is_group && !tp_strdiff (str, fg->name))
259 individual_store_get_group (EmpathyIndividualStore *self,
261 GtkTreeIter *iter_group_to_set,
262 GtkTreeIter *iter_separator_to_set,
264 gboolean is_fake_group)
267 GtkTreeIter iter_group;
268 GtkTreeIter iter_separator;
271 memset (&fg, 0, sizeof (fg));
275 model = GTK_TREE_MODEL (self);
276 gtk_tree_model_foreach (model,
277 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
284 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
286 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
287 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
288 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
289 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
290 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
291 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
294 if (iter_group_to_set)
295 *iter_group_to_set = iter_group;
297 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
299 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
302 if (iter_separator_to_set)
303 *iter_separator_to_set = iter_separator;
310 if (iter_group_to_set)
311 *iter_group_to_set = fg.iter;
313 iter_separator = fg.iter;
315 if (gtk_tree_model_iter_next (model, &iter_separator))
317 gboolean is_separator;
319 gtk_tree_model_get (model, &iter_separator,
320 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
322 if (is_separator && iter_separator_to_set)
323 *iter_separator_to_set = iter_separator;
329 individual_store_find_contact_foreach (GtkTreeModel *model,
334 FolksIndividual *individual;
336 gtk_tree_model_get (model, iter,
337 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
339 if (individual == fc->individual)
342 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
345 tp_clear_object (&individual);
351 individual_store_find_contact (EmpathyIndividualStore *self,
352 FolksIndividual *individual)
358 memset (&fc, 0, sizeof (fc));
360 fc.individual = individual;
362 model = GTK_TREE_MODEL (self);
363 gtk_tree_model_foreach (model,
364 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
373 free_iters (GList *iters)
375 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
380 individual_store_remove_individual (EmpathyIndividualStore *self,
381 FolksIndividual *individual)
386 iters = individual_store_find_contact (self, individual);
391 model = GTK_TREE_MODEL (self);
393 for (l = iters; l; l = l->next)
397 /* NOTE: it is only <= 2 here because we have
398 * separators after the group name, otherwise it
401 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
402 gtk_tree_model_iter_n_children (model, &parent) <= 2)
404 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
408 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
416 individual_store_add_individual (EmpathyIndividualStore *self,
417 FolksIndividual *individual)
419 EmpathyIndividualStorePriv *priv;
421 GeeIterator *group_iter = NULL;
423 priv = GET_PRIV (self);
425 if (EMP_STR_EMPTY (folks_alias_details_get_alias (
426 FOLKS_ALIAS_DETAILS (individual))))
429 if (priv->show_groups)
431 GeeSet *group_set = NULL;
433 group_set = folks_group_details_get_groups (
434 FOLKS_GROUP_DETAILS (individual));
436 if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
437 group_iter = gee_iterable_iterator (GEE_ITERABLE (group_set));
440 /* fall-back groups, in case there are no named groups */
441 if (group_iter == NULL)
443 GtkTreeIter iter_group, *parent;
444 EmpathyContact *contact;
445 TpConnection *connection;
446 gchar *protocol_name = NULL;
448 parent = &iter_group;
450 contact = empathy_contact_dup_from_folks_individual (individual);
453 connection = empathy_contact_get_connection (contact);
454 tp_connection_parse_object_path (connection, &protocol_name, NULL);
457 if (!priv->show_groups)
459 else if (!tp_strdiff (protocol_name, "local-xmpp"))
461 /* these are People Nearby */
462 individual_store_get_group (self,
463 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
468 individual_store_get_group (self,
469 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
470 &iter_group, NULL, NULL, TRUE);
473 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
476 g_free (protocol_name);
477 g_clear_object (&contact);
480 /* Else add to each group. */
481 while (group_iter != NULL && gee_iterator_next (group_iter))
483 gchar *group_name = gee_iterator_get (group_iter);
484 GtkTreeIter iter_group;
486 individual_store_get_group (self, group_name, &iter_group, NULL, NULL,
489 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
494 g_clear_object (&group_iter);
496 if (priv->show_groups &&
497 folks_favourite_details_get_is_favourite (
498 FOLKS_FAVOURITE_DETAILS (individual)))
500 /* Add contact to the fake 'Favorites' group */
501 GtkTreeIter iter_group;
503 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
504 &iter_group, NULL, NULL, TRUE);
506 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
510 individual_store_contact_update (self, individual);
514 individual_store_contact_set_active (EmpathyIndividualStore *self,
515 FolksIndividual *individual,
517 gboolean set_changed)
522 model = GTK_TREE_MODEL (self);
524 iters = individual_store_find_contact (self, individual);
525 for (l = iters; l; l = l->next)
529 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
530 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
533 DEBUG ("Set item %s", active ? "active" : "inactive");
537 path = gtk_tree_model_get_path (model, l->data);
538 gtk_tree_model_row_changed (model, path, l->data);
539 gtk_tree_path_free (path);
546 static void individual_store_contact_active_free (ShowActiveData *data);
549 individual_store_contact_active_invalidated (ShowActiveData *data,
552 /* Remove the timeout and free the struct, since the individual or individual
553 * store has disappeared. */
554 g_source_remove (data->timeout);
556 if (old_object == (GObject *) data->self)
558 else if (old_object == (GObject *) data->individual)
559 data->individual = NULL;
561 g_assert_not_reached ();
563 individual_store_contact_active_free (data);
566 static ShowActiveData *
567 individual_store_contact_active_new (EmpathyIndividualStore *self,
568 FolksIndividual *individual,
571 ShowActiveData *data;
573 DEBUG ("Individual'%s' now active, and %s be removed",
574 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
575 remove_ ? "WILL" : "WILL NOT");
577 data = g_slice_new0 (ShowActiveData);
579 /* We don't actually want to force either the IndividualStore or the
580 * Individual to stay alive, since the user could quit Empathy or disable
581 * the account before the contact_active timeout is fired. */
582 g_object_weak_ref (G_OBJECT (self),
583 (GWeakNotify) individual_store_contact_active_invalidated, data);
584 g_object_weak_ref (G_OBJECT (individual),
585 (GWeakNotify) individual_store_contact_active_invalidated, data);
588 data->individual = individual;
589 data->remove = remove_;
596 individual_store_contact_active_free (ShowActiveData *data)
598 if (data->self != NULL)
600 g_object_weak_unref (G_OBJECT (data->self),
601 (GWeakNotify) individual_store_contact_active_invalidated, data);
604 if (data->individual != NULL)
606 g_object_weak_unref (G_OBJECT (data->individual),
607 (GWeakNotify) individual_store_contact_active_invalidated, data);
610 g_slice_free (ShowActiveData, data);
614 individual_store_contact_active_cb (ShowActiveData *data)
618 DEBUG ("Individual'%s' active timeout, removing item",
619 folks_alias_details_get_alias (
620 FOLKS_ALIAS_DETAILS (data->individual)));
621 individual_store_remove_individual (data->self, data->individual);
624 DEBUG ("Individual'%s' no longer active",
625 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
627 individual_store_contact_set_active (data->self,
628 data->individual, FALSE, TRUE);
630 individual_store_contact_active_free (data);
636 EmpathyIndividualStore *store; /* weak */
637 GCancellable *cancellable; /* owned */
641 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
642 GAsyncResult *result,
643 LoadAvatarData *data)
645 GError *error = NULL;
648 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
653 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
654 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
656 g_clear_error (&error);
658 else if (data->store != NULL)
662 iters = individual_store_find_contact (data->store, individual);
663 for (l = iters; l; l = l->next)
665 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
666 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
674 if (data->store != NULL)
676 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
678 g_object_remove_weak_pointer (G_OBJECT (data->store),
679 (gpointer *) &data->store);
680 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
684 tp_clear_object (&pixbuf);
685 g_object_unref (data->cancellable);
686 g_slice_free (LoadAvatarData, data);
690 individual_store_contact_update (EmpathyIndividualStore *self,
691 FolksIndividual *individual)
693 EmpathyIndividualStorePriv *priv;
694 ShowActiveData *data;
698 gboolean was_online = TRUE;
699 gboolean now_online = FALSE;
700 gboolean set_model = FALSE;
701 gboolean do_remove = FALSE;
702 gboolean do_set_active = FALSE;
703 gboolean do_set_refresh = FALSE;
704 gboolean show_avatar = FALSE;
705 GdkPixbuf *pixbuf_status;
706 LoadAvatarData *load_avatar_data;
708 priv = GET_PRIV (self);
710 model = GTK_TREE_MODEL (self);
712 iters = individual_store_find_contact (self, individual);
722 /* Get online state now. */
723 now_online = folks_presence_details_is_online (
724 FOLKS_PRESENCE_DETAILS (individual));
728 DEBUG ("Individual'%s' in list:NO, should be:YES",
729 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
731 individual_store_add_individual (self, individual);
733 if (priv->show_active)
735 do_set_active = TRUE;
737 DEBUG ("Set active (individual added)");
742 DEBUG ("Individual'%s' in list:YES, should be:YES",
743 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
745 /* Get online state before. */
746 if (iters && g_list_length (iters) > 0)
748 gtk_tree_model_get (model, iters->data,
749 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
752 /* Is this really an update or an online/offline. */
753 if (priv->show_active)
755 if (was_online != now_online)
757 do_set_active = TRUE;
758 do_set_refresh = TRUE;
760 DEBUG ("Set active (individual updated %s)",
761 was_online ? "online -> offline" : "offline -> online");
765 /* Was TRUE for presence updates. */
766 /* do_set_active = FALSE; */
767 do_set_refresh = TRUE;
769 DEBUG ("Set active (individual updated)");
776 if (priv->show_avatars && !priv->is_compact)
781 /* Load the avatar asynchronously */
782 load_avatar_data = g_slice_new (LoadAvatarData);
783 load_avatar_data->store = self;
784 g_object_add_weak_pointer (G_OBJECT (self),
785 (gpointer *) &load_avatar_data->store);
786 load_avatar_data->cancellable = g_cancellable_new ();
788 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
789 load_avatar_data->cancellable);
790 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
791 load_avatar_data->cancellable,
792 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
796 empathy_individual_store_get_individual_status_icon (self, individual);
798 for (l = iters; l && set_model; l = l->next)
800 gboolean can_audio_call, can_video_call;
801 const gchar * const *types;
803 individual_can_audio_video_call (individual, &can_audio_call,
806 types = individual_get_client_types (individual);
808 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
809 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
810 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
811 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
812 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
813 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
814 folks_presence_details_get_presence_type (
815 FOLKS_PRESENCE_DETAILS (individual)),
816 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
817 folks_presence_details_get_presence_message (
818 FOLKS_PRESENCE_DETAILS (individual)),
819 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
820 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
821 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
822 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
823 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
824 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
825 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
829 if (priv->show_active && do_set_active)
831 individual_store_contact_set_active (self, individual, do_set_active,
837 individual_store_contact_active_new (self, individual,
839 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
840 (GSourceFunc) individual_store_contact_active_cb, data);
844 /* FIXME: when someone goes online then offline quickly, the
845 * first timeout sets the user to be inactive and the second
846 * timeout removes the user from the contact list, really we
847 * should remove the first timeout.
853 individual_store_individual_updated_cb (FolksIndividual *individual,
855 EmpathyIndividualStore *self)
857 DEBUG ("Individual'%s' updated, checking roster is in sync...",
858 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
860 individual_store_contact_update (self, individual);
864 individual_store_contact_updated_cb (EmpathyContact *contact,
866 EmpathyIndividualStore *self)
868 FolksIndividual *individual;
870 DEBUG ("Contact '%s' updated, checking roster is in sync...",
871 empathy_contact_get_alias (contact));
873 individual = g_object_get_data (G_OBJECT (contact), "individual");
874 if (individual == NULL)
877 individual_store_contact_update (self, individual);
881 individual_personas_changed_cb (FolksIndividual *individual,
884 EmpathyIndividualStore *self)
888 DEBUG ("Individual '%s' personas-changed.",
889 folks_individual_get_id (individual));
891 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
892 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
893 * through the EmpathyContacts for them. */
894 while (gee_iterator_next (iter))
896 TpfPersona *persona = gee_iterator_get (iter);
897 TpContact *tp_contact;
898 EmpathyContact *contact;
900 if (TPF_IS_PERSONA (persona))
902 tp_contact = tpf_persona_get_contact (persona);
903 contact = empathy_contact_dup_from_tp_contact (tp_contact);
904 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
906 g_object_set_data (G_OBJECT (contact), "individual", NULL);
907 g_signal_handlers_disconnect_by_func (contact,
908 (GCallback) individual_store_contact_updated_cb, self);
910 g_object_unref (contact);
913 g_clear_object (&persona);
915 g_clear_object (&iter);
917 iter = gee_iterable_iterator (GEE_ITERABLE (added));
918 while (gee_iterator_next (iter))
920 TpfPersona *persona = gee_iterator_get (iter);
921 TpContact *tp_contact;
922 EmpathyContact *contact;
924 if (TPF_IS_PERSONA (persona))
926 tp_contact = tpf_persona_get_contact (persona);
927 contact = empathy_contact_dup_from_tp_contact (tp_contact);
928 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
930 g_object_set_data (G_OBJECT (contact), "individual", individual);
931 g_signal_connect (contact, "notify::capabilities",
932 (GCallback) individual_store_contact_updated_cb, self);
933 g_signal_connect (contact, "notify::client-types",
934 (GCallback) individual_store_contact_updated_cb, self);
936 g_object_unref (contact);
939 g_clear_object (&persona);
941 g_clear_object (&iter);
945 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
946 FolksIndividual *individual)
948 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
950 individual_store_add_individual (self, individual);
952 g_signal_connect (individual, "notify::avatar",
953 (GCallback) individual_store_individual_updated_cb, self);
954 g_signal_connect (individual, "notify::presence-type",
955 (GCallback) individual_store_individual_updated_cb, self);
956 g_signal_connect (individual, "notify::presence-message",
957 (GCallback) individual_store_individual_updated_cb, self);
958 g_signal_connect (individual, "notify::alias",
959 (GCallback) individual_store_individual_updated_cb, self);
960 g_signal_connect (individual, "personas-changed",
961 (GCallback) individual_personas_changed_cb, self);
963 /* provide an empty set so the callback can assume non-NULL sets */
964 individual_personas_changed_cb (individual,
965 folks_individual_get_personas (individual), empty_set, self);
966 g_clear_object (&empty_set);
970 individual_store_disconnect_individual (EmpathyIndividualStore *self,
971 FolksIndividual *individual)
973 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
975 /* provide an empty set so the callback can assume non-NULL sets */
976 individual_personas_changed_cb (individual, empty_set,
977 folks_individual_get_personas (individual), self);
978 g_clear_object (&empty_set);
980 g_signal_handlers_disconnect_by_func (individual,
981 (GCallback) individual_store_individual_updated_cb, self);
982 g_signal_handlers_disconnect_by_func (individual,
983 (GCallback) individual_personas_changed_cb, self);
987 individual_store_remove_individual_and_disconnect (
988 EmpathyIndividualStore *self,
989 FolksIndividual *individual)
991 individual_store_disconnect_individual (self, individual);
992 individual_store_remove_individual (self, individual);
996 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
997 const gchar *message,
1001 EmpathyIndividualStore *self)
1005 for (l = added; l; l = l->next)
1007 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
1009 individual_store_add_individual_and_connect (self, l->data);
1011 for (l = removed; l; l = l->next)
1013 DEBUG ("Individual %s %s",
1014 folks_individual_get_id (l->data), "removed");
1016 individual_store_remove_individual_and_disconnect (self, l->data);
1021 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
1022 FolksIndividual *individual,
1023 gboolean is_favourite,
1024 EmpathyIndividualStore *self)
1026 DEBUG ("Individual %s is %s a favourite",
1027 folks_individual_get_id (individual),
1028 is_favourite ? "now" : "no longer");
1030 individual_store_remove_individual (self, individual);
1031 individual_store_add_individual (self, individual);
1035 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
1036 FolksIndividual *individual,
1039 EmpathyIndividualStore *self)
1041 EmpathyIndividualStorePriv *priv;
1042 gboolean show_active;
1044 priv = GET_PRIV (self);
1046 DEBUG ("Updating groups for individual %s",
1047 folks_individual_get_id (individual));
1049 /* We do this to make sure the groups are correct, if not, we
1050 * would have to check the groups already set up for each
1051 * contact and then see what has been updated.
1053 show_active = priv->show_active;
1054 priv->show_active = FALSE;
1055 individual_store_remove_individual (self, individual);
1056 individual_store_add_individual (self, individual);
1057 priv->show_active = show_active;
1061 individual_store_manager_setup (gpointer user_data)
1063 EmpathyIndividualStore *self = user_data;
1064 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1067 /* Signal connection. */
1069 /* TODO: implement */
1070 DEBUG ("handling individual renames unimplemented");
1072 g_signal_connect (priv->manager,
1074 G_CALLBACK (individual_store_members_changed_cb), self);
1076 g_signal_connect (priv->manager,
1077 "favourites-changed",
1078 G_CALLBACK (individual_store_favourites_changed_cb), self);
1080 g_signal_connect (priv->manager,
1082 G_CALLBACK (individual_store_groups_changed_cb), self);
1084 /* Add contacts already created. */
1085 individuals = empathy_individual_manager_get_members (priv->manager);
1086 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1088 individual_store_members_changed_cb (priv->manager, "initial add",
1089 individuals, NULL, 0, self);
1090 g_list_free (individuals);
1093 priv->setup_idle_id = 0;
1098 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1099 EmpathyIndividualManager *manager)
1101 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1103 priv->manager = g_object_ref (manager);
1105 /* Let a chance to have all properties set before populating */
1106 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1110 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1111 FolksIndividual *old_individual,
1112 FolksIndividual *new_individual,
1114 const gchar *message,
1115 EmpathyIndividualStore *self)
1117 DEBUG ("Individual %s renamed to %s",
1118 folks_individual_get_id (old_individual),
1119 folks_individual_get_id (new_individual));
1121 /* add the new contact */
1122 individual_store_add_individual_and_connect (self, new_individual);
1124 /* remove old contact */
1125 individual_store_remove_individual_and_disconnect (self, old_individual);
1129 individual_store_dispose (GObject *object)
1131 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1132 GList *individuals, *l;
1134 if (priv->dispose_has_run)
1136 priv->dispose_has_run = TRUE;
1138 /* Cancel any pending avatar load operations */
1139 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1141 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1142 g_cancellable_cancel (G_CANCELLABLE (l->data));
1144 g_list_free (priv->avatar_cancellables);
1146 individuals = empathy_individual_manager_get_members (priv->manager);
1147 for (l = individuals; l; l = l->next)
1149 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1150 FOLKS_INDIVIDUAL (l->data));
1152 g_list_free (individuals);
1154 g_signal_handlers_disconnect_by_func (priv->manager,
1155 G_CALLBACK (individual_store_member_renamed_cb), object);
1156 g_signal_handlers_disconnect_by_func (priv->manager,
1157 G_CALLBACK (individual_store_members_changed_cb), object);
1158 g_signal_handlers_disconnect_by_func (priv->manager,
1159 G_CALLBACK (individual_store_favourites_changed_cb), object);
1160 g_signal_handlers_disconnect_by_func (priv->manager,
1161 G_CALLBACK (individual_store_groups_changed_cb), object);
1162 g_object_unref (priv->manager);
1164 if (priv->inhibit_active)
1166 g_source_remove (priv->inhibit_active);
1169 if (priv->setup_idle_id != 0)
1171 g_source_remove (priv->setup_idle_id);
1174 g_hash_table_destroy (priv->status_icons);
1175 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1179 individual_store_get_property (GObject *object,
1184 EmpathyIndividualStorePriv *priv;
1186 priv = GET_PRIV (object);
1190 case PROP_INDIVIDUAL_MANAGER:
1191 g_value_set_object (value, priv->manager);
1193 case PROP_SHOW_AVATARS:
1194 g_value_set_boolean (value, priv->show_avatars);
1196 case PROP_SHOW_PROTOCOLS:
1197 g_value_set_boolean (value, priv->show_protocols);
1199 case PROP_SHOW_GROUPS:
1200 g_value_set_boolean (value, priv->show_groups);
1202 case PROP_IS_COMPACT:
1203 g_value_set_boolean (value, priv->is_compact);
1205 case PROP_SORT_CRITERIUM:
1206 g_value_set_enum (value, priv->sort_criterium);
1209 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1215 individual_store_set_property (GObject *object,
1217 const GValue *value,
1222 case PROP_INDIVIDUAL_MANAGER:
1223 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1224 (object), g_value_get_object (value));
1226 case PROP_SHOW_AVATARS:
1227 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1228 (object), g_value_get_boolean (value));
1230 case PROP_SHOW_PROTOCOLS:
1231 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1232 (object), g_value_get_boolean (value));
1234 case PROP_SHOW_GROUPS:
1235 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1236 (object), g_value_get_boolean (value));
1238 case PROP_IS_COMPACT:
1239 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1240 (object), g_value_get_boolean (value));
1242 case PROP_SORT_CRITERIUM:
1243 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1244 (object), g_value_get_enum (value));
1247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1253 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1255 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1257 object_class->dispose = individual_store_dispose;
1258 object_class->get_property = individual_store_get_property;
1259 object_class->set_property = individual_store_set_property;
1261 g_object_class_install_property (object_class,
1262 PROP_INDIVIDUAL_MANAGER,
1263 g_param_spec_object ("individual-manager",
1264 "The individual manager",
1265 "The individual manager",
1266 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1267 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1268 g_object_class_install_property (object_class,
1270 g_param_spec_boolean ("show-avatars",
1272 "Whether contact list should display "
1273 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1274 g_object_class_install_property (object_class,
1275 PROP_SHOW_PROTOCOLS,
1276 g_param_spec_boolean ("show-protocols",
1278 "Whether contact list should display "
1279 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1280 g_object_class_install_property (object_class,
1282 g_param_spec_boolean ("show-groups",
1284 "Whether contact list should display "
1285 "contact groups", TRUE, G_PARAM_READWRITE));
1286 g_object_class_install_property (object_class,
1288 g_param_spec_boolean ("is-compact",
1290 "Whether the contact list is in compact mode or not",
1291 FALSE, G_PARAM_READWRITE));
1293 g_object_class_install_property (object_class,
1294 PROP_SORT_CRITERIUM,
1295 g_param_spec_enum ("sort-criterium",
1297 "The sort criterium to use for sorting the contact list",
1298 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1299 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1301 g_type_class_add_private (object_class,
1302 sizeof (EmpathyIndividualStorePriv));
1306 get_position (const char **strv,
1311 for (i = 0; strv[i] != NULL; i++)
1313 if (!tp_strdiff (strv[i], str))
1321 compare_separator_and_groups (gboolean is_separator_a,
1322 gboolean is_separator_b,
1323 const gchar *name_a,
1324 const gchar *name_b,
1325 FolksIndividual *individual_a,
1326 FolksIndividual *individual_b,
1327 gboolean fake_group_a,
1328 gboolean fake_group_b)
1330 /* these two lists are the sorted list of fake groups to include at the
1331 * top and bottom of the roster */
1332 const char *top_groups[] = {
1333 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1337 const char *bottom_groups[] = {
1338 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1342 if (is_separator_a || is_separator_b)
1344 /* We have at least one separator */
1349 else if (is_separator_b)
1355 /* One group and one contact */
1356 if (!individual_a && individual_b)
1360 else if (individual_a && !individual_b)
1364 else if (!individual_a && !individual_b)
1366 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1368 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1369 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1370 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1371 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1373 if (a_in_top && b_in_top)
1375 /* compare positions */
1376 return CLAMP (get_position (top_groups, name_a) -
1377 get_position (top_groups, name_b), -1, 1);
1379 else if (a_in_bottom && b_in_bottom)
1381 /* compare positions */
1382 return CLAMP (get_position (bottom_groups, name_a) -
1383 get_position (bottom_groups, name_b), -1, 1);
1385 else if (a_in_top || b_in_bottom)
1389 else if (b_in_top || a_in_bottom)
1395 return g_utf8_collate (name_a, name_b);
1399 /* Two contacts, ordering depends of the sorting policy */
1404 individual_store_contact_sort (FolksIndividual *individual_a,
1405 FolksIndividual *individual_b)
1408 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1409 TpAccount *account_a, *account_b;
1411 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1414 ret_val = g_utf8_collate (
1415 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1416 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1421 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1422 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1423 account_a = empathy_contact_get_account (contact_a);
1424 account_b = empathy_contact_get_account (contact_b);
1426 g_assert (account_a != NULL);
1427 g_assert (account_b != NULL);
1430 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1431 tp_account_get_protocol (account_b));
1437 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1438 tp_proxy_get_object_path (account_b));
1444 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1445 folks_individual_get_id (individual_b));
1448 tp_clear_object (&contact_a);
1449 tp_clear_object (&contact_b);
1455 individual_store_state_sort_func (GtkTreeModel *model,
1456 GtkTreeIter *iter_a,
1457 GtkTreeIter *iter_b,
1461 FolksIndividual *individual_a, *individual_b;
1462 gchar *name_a, *name_b;
1463 gboolean is_separator_a, is_separator_b;
1464 gboolean fake_group_a, fake_group_b;
1465 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1466 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1468 gtk_tree_model_get (model, iter_a,
1469 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1470 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1471 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1472 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1473 gtk_tree_model_get (model, iter_b,
1474 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1475 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1476 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1477 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1479 if (individual_a == NULL || individual_b == NULL)
1481 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1482 name_a, name_b, individual_a, individual_b, fake_group_a,
1487 /* If we managed to get this far, we can start looking at
1490 folks_presence_type_a =
1491 folks_presence_details_get_presence_type (
1492 FOLKS_PRESENCE_DETAILS (individual_a));
1493 folks_presence_type_b =
1494 folks_presence_details_get_presence_type (
1495 FOLKS_PRESENCE_DETAILS (individual_b));
1496 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1497 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1499 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1504 /* Fallback: compare by name et al. */
1505 ret_val = individual_store_contact_sort (individual_a, individual_b);
1511 tp_clear_object (&individual_a);
1512 tp_clear_object (&individual_b);
1518 individual_store_name_sort_func (GtkTreeModel *model,
1519 GtkTreeIter *iter_a,
1520 GtkTreeIter *iter_b,
1523 gchar *name_a, *name_b;
1524 FolksIndividual *individual_a, *individual_b;
1525 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1527 gboolean fake_group_a, fake_group_b;
1529 gtk_tree_model_get (model, iter_a,
1530 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1531 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1532 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1533 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1534 gtk_tree_model_get (model, iter_b,
1535 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1536 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1537 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1538 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1540 if (individual_a == NULL || individual_b == NULL)
1541 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1542 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1544 ret_val = individual_store_contact_sort (individual_a, individual_b);
1546 tp_clear_object (&individual_a);
1547 tp_clear_object (&individual_b);
1555 individual_store_setup (EmpathyIndividualStore *self)
1557 EmpathyIndividualStorePriv *priv;
1559 GDK_TYPE_PIXBUF, /* Status pixbuf */
1560 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1561 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1562 G_TYPE_STRING, /* Name */
1563 G_TYPE_UINT, /* Presence type */
1564 G_TYPE_STRING, /* Status string */
1565 G_TYPE_BOOLEAN, /* Compact view */
1566 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1567 G_TYPE_BOOLEAN, /* Is group */
1568 G_TYPE_BOOLEAN, /* Is active */
1569 G_TYPE_BOOLEAN, /* Is online */
1570 G_TYPE_BOOLEAN, /* Is separator */
1571 G_TYPE_BOOLEAN, /* Can make audio calls */
1572 G_TYPE_BOOLEAN, /* Can make video calls */
1573 G_TYPE_BOOLEAN, /* Is a fake group */
1574 G_TYPE_STRV, /* Client types */
1575 G_TYPE_UINT, /* Event count */
1578 priv = GET_PRIV (self);
1580 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1581 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1583 /* Set up sorting */
1584 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1585 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1586 individual_store_name_sort_func, self, NULL);
1587 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1588 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1589 individual_store_state_sort_func, self, NULL);
1591 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1592 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1596 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1598 EmpathyIndividualStorePriv *priv;
1600 priv = GET_PRIV (self);
1602 priv->show_active = TRUE;
1603 priv->inhibit_active = 0;
1609 empathy_individual_store_init (EmpathyIndividualStore *self)
1611 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1612 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1615 priv->show_avatars = TRUE;
1616 priv->show_groups = TRUE;
1617 priv->show_protocols = FALSE;
1618 priv->inhibit_active =
1619 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1620 (GSourceFunc) individual_store_inhibit_active_cb, self);
1621 priv->status_icons =
1622 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1623 individual_store_setup (self);
1626 EmpathyIndividualStore *
1627 empathy_individual_store_new (EmpathyIndividualManager *manager)
1629 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1631 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1632 "individual-manager", manager, NULL);
1635 EmpathyIndividualManager *
1636 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1638 EmpathyIndividualStorePriv *priv;
1640 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1642 priv = GET_PRIV (self);
1644 return priv->manager;
1648 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1650 EmpathyIndividualStorePriv *priv;
1652 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1654 priv = GET_PRIV (self);
1656 return priv->show_avatars;
1660 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1663 EmpathyIndividualStore *self)
1665 EmpathyIndividualStorePriv *priv;
1666 gboolean show_avatar = FALSE;
1667 FolksIndividual *individual;
1668 GdkPixbuf *pixbuf_status;
1670 priv = GET_PRIV (self);
1672 if (priv->show_avatars && !priv->is_compact)
1677 gtk_tree_model_get (model, iter,
1678 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1680 if (individual == NULL)
1684 /* get icon from hash_table */
1686 empathy_individual_store_get_individual_status_icon (self, individual);
1688 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1689 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1690 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1691 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1693 g_object_unref (individual);
1699 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1700 gboolean show_avatars)
1702 EmpathyIndividualStorePriv *priv;
1703 GtkTreeModel *model;
1705 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1707 priv = GET_PRIV (self);
1709 priv->show_avatars = show_avatars;
1711 model = GTK_TREE_MODEL (self);
1713 gtk_tree_model_foreach (model,
1714 (GtkTreeModelForeachFunc)
1715 individual_store_update_list_mode_foreach, self);
1717 g_object_notify (G_OBJECT (self), "show-avatars");
1721 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1723 EmpathyIndividualStorePriv *priv;
1725 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1727 priv = GET_PRIV (self);
1729 return priv->show_protocols;
1733 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1734 gboolean show_protocols)
1736 EmpathyIndividualStorePriv *priv;
1737 GtkTreeModel *model;
1739 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1741 priv = GET_PRIV (self);
1743 priv->show_protocols = show_protocols;
1745 model = GTK_TREE_MODEL (self);
1747 gtk_tree_model_foreach (model,
1748 (GtkTreeModelForeachFunc)
1749 individual_store_update_list_mode_foreach, self);
1751 g_object_notify (G_OBJECT (self), "show-protocols");
1755 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1757 EmpathyIndividualStorePriv *priv;
1759 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1761 priv = GET_PRIV (self);
1763 return priv->show_groups;
1767 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1768 gboolean show_groups)
1770 EmpathyIndividualStorePriv *priv;
1772 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1774 priv = GET_PRIV (self);
1776 if (priv->show_groups == show_groups)
1781 priv->show_groups = show_groups;
1783 if (priv->setup_idle_id == 0)
1785 /* Remove all contacts and add them back, not optimized but
1786 * that's the easy way :)
1788 * This is only done if there's not a pending setup idle
1789 * callback, otherwise it will race and the contacts will get
1793 gtk_tree_store_clear (GTK_TREE_STORE (self));
1794 contacts = empathy_individual_manager_get_members (priv->manager);
1796 individual_store_members_changed_cb (priv->manager,
1797 "re-adding members: toggled group visibility",
1798 contacts, NULL, 0, self);
1799 g_list_free (contacts);
1802 g_object_notify (G_OBJECT (self), "show-groups");
1806 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1808 EmpathyIndividualStorePriv *priv;
1810 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1812 priv = GET_PRIV (self);
1814 return priv->is_compact;
1818 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1819 gboolean is_compact)
1821 EmpathyIndividualStorePriv *priv;
1822 GtkTreeModel *model;
1824 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1826 priv = GET_PRIV (self);
1828 priv->is_compact = is_compact;
1830 model = GTK_TREE_MODEL (self);
1832 gtk_tree_model_foreach (model,
1833 (GtkTreeModelForeachFunc)
1834 individual_store_update_list_mode_foreach, self);
1836 g_object_notify (G_OBJECT (self), "is-compact");
1839 EmpathyIndividualStoreSort
1840 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1842 EmpathyIndividualStorePriv *priv;
1844 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1846 priv = GET_PRIV (self);
1848 return priv->sort_criterium;
1852 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1853 EmpathyIndividualStoreSort sort_criterium)
1855 EmpathyIndividualStorePriv *priv;
1857 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1859 priv = GET_PRIV (self);
1861 priv->sort_criterium = sort_criterium;
1863 switch (sort_criterium)
1865 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1866 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1867 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1870 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1871 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1872 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1876 g_assert_not_reached ();
1879 g_object_notify (G_OBJECT (self), "sort-criterium");
1883 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1887 gboolean is_separator = FALSE;
1889 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1891 gtk_tree_model_get (model, iter,
1892 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1894 return is_separator;
1898 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1900 gboolean *path_is_group,
1901 gboolean *is_fake_group)
1903 GtkTreeIter parent_iter, iter;
1906 gboolean fake = FALSE;
1908 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1912 *path_is_group = FALSE;
1915 if (!gtk_tree_model_get_iter (model, &iter, path))
1920 gtk_tree_model_get (model, &iter,
1921 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1922 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1929 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1936 gtk_tree_model_get (model, &iter,
1937 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1938 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1939 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1949 *path_is_group = TRUE;
1952 if (is_fake_group != NULL)
1953 *is_fake_group = fake;
1959 individual_store_get_individual_status_icon_with_icon_name (
1960 EmpathyIndividualStore *self,
1961 FolksIndividual *individual,
1962 const gchar *status_icon_name)
1964 GdkPixbuf *pixbuf_status;
1965 EmpathyIndividualStorePriv *priv;
1966 const gchar *protocol_name = NULL;
1967 gchar *icon_name = NULL;
1970 guint contact_count = 0;
1971 EmpathyContact *contact = NULL;
1972 gboolean show_protocols_here;
1974 priv = GET_PRIV (self);
1976 personas = folks_individual_get_personas (individual);
1977 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1978 while (gee_iterator_next (iter))
1980 FolksPersona *persona = gee_iterator_get (iter);
1981 if (empathy_folks_persona_is_interesting (persona))
1984 g_clear_object (&persona);
1986 if (contact_count > 1)
1989 g_clear_object (&iter);
1991 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1992 if (show_protocols_here)
1994 contact = empathy_contact_dup_from_folks_individual (individual);
1995 protocol_name = empathy_protocol_name_for_contact (contact);
1996 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
2000 icon_name = g_strdup_printf ("%s", status_icon_name);
2003 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
2005 if (pixbuf_status == NULL)
2008 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
2009 status_icon_name, show_protocols_here);
2011 if (pixbuf_status != NULL)
2013 /* pass the reference to the hash table */
2014 g_hash_table_insert (priv->status_icons,
2015 g_strdup (icon_name), pixbuf_status);
2020 tp_clear_object (&contact);
2022 return pixbuf_status;
2026 empathy_individual_store_get_individual_status_icon (
2027 EmpathyIndividualStore *self,
2028 FolksIndividual *individual)
2030 GdkPixbuf *pixbuf_status = NULL;
2031 const gchar *status_icon_name = NULL;
2033 status_icon_name = empathy_icon_name_for_individual (individual);
2034 if (status_icon_name == NULL)
2038 individual_store_get_individual_status_icon_with_icon_name (self,
2039 individual, status_icon_name);
2041 return pixbuf_status;