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)
127 gboolean can_audio = FALSE, can_video = FALSE;
129 personas = folks_individual_get_personas (individual);
130 for (l = personas; l != NULL; l = l->next)
132 TpContact *tp_contact;
133 EmpathyContact *contact;
135 if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
138 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
139 contact = empathy_contact_dup_from_tp_contact (tp_contact);
140 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
142 can_audio = can_audio || empathy_contact_get_capabilities (contact) &
143 EMPATHY_CAPABILITIES_AUDIO;
144 can_video = can_video || empathy_contact_get_capabilities (contact) &
145 EMPATHY_CAPABILITIES_VIDEO;
147 g_object_unref (contact);
149 if (can_audio && can_video)
153 *can_audio_call = can_audio;
154 *can_video_call = can_video;
157 static const gchar * const *
158 individual_get_client_types (FolksIndividual *individual)
161 const gchar * const *types = NULL;
162 FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
164 personas = folks_individual_get_personas (individual);
165 for (l = personas; l != NULL; l = l->next)
167 FolksPresenceOwner *presence;
169 /* We only want personas which implement FolksPresenceOwner */
170 if (!FOLKS_IS_PRESENCE_OWNER (l->data))
173 presence = FOLKS_PRESENCE_OWNER (l->data);
175 if (folks_presence_owner_typecmp (
176 folks_presence_owner_get_presence_type (presence),
179 TpContact *tp_contact;
181 presence_type = folks_presence_owner_get_presence_type (presence);
183 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
184 types = tp_contact_get_client_types (tp_contact);
192 add_individual_to_store (GtkTreeStore *self,
195 FolksIndividual *individual)
197 gboolean can_audio_call, can_video_call;
198 const gchar * const *types;
200 individual_can_audio_video_call (individual, &can_audio_call,
203 types = individual_get_client_types (individual);
205 gtk_tree_store_insert_with_values (self, iter, parent, 0,
206 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
207 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
208 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
209 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
210 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
211 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
212 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
213 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
218 individual_store_get_group_foreach (GtkTreeModel *model,
226 /* Groups are only at the top level. */
227 if (gtk_tree_path_get_depth (path) != 1)
230 gtk_tree_model_get (model, iter,
231 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
232 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
234 if (is_group && !tp_strdiff (str, fg->name))
246 individual_store_get_group (EmpathyIndividualStore *self,
248 GtkTreeIter *iter_group_to_set,
249 GtkTreeIter *iter_separator_to_set,
251 gboolean is_fake_group)
253 EmpathyIndividualStorePriv *priv;
255 GtkTreeIter iter_group;
256 GtkTreeIter iter_separator;
259 priv = GET_PRIV (self);
261 memset (&fg, 0, sizeof (fg));
265 model = GTK_TREE_MODEL (self);
266 gtk_tree_model_foreach (model,
267 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
274 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
276 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
277 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
278 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
279 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
280 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
281 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
284 if (iter_group_to_set)
285 *iter_group_to_set = iter_group;
287 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
289 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
292 if (iter_separator_to_set)
293 *iter_separator_to_set = iter_separator;
300 if (iter_group_to_set)
301 *iter_group_to_set = fg.iter;
303 iter_separator = fg.iter;
305 if (gtk_tree_model_iter_next (model, &iter_separator))
307 gboolean is_separator;
309 gtk_tree_model_get (model, &iter_separator,
310 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
312 if (is_separator && iter_separator_to_set)
313 *iter_separator_to_set = iter_separator;
319 individual_store_find_contact_foreach (GtkTreeModel *model,
324 FolksIndividual *individual;
326 gtk_tree_model_get (model, iter,
327 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
329 if (individual == fc->individual)
332 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
335 tp_clear_object (&individual);
341 individual_store_find_contact (EmpathyIndividualStore *self,
342 FolksIndividual *individual)
344 EmpathyIndividualStorePriv *priv;
349 priv = GET_PRIV (self);
351 memset (&fc, 0, sizeof (fc));
353 fc.individual = individual;
355 model = GTK_TREE_MODEL (self);
356 gtk_tree_model_foreach (model,
357 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
366 free_iters (GList *iters)
368 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
373 individual_store_remove_individual (EmpathyIndividualStore *self,
374 FolksIndividual *individual)
376 EmpathyIndividualStorePriv *priv;
380 priv = GET_PRIV (self);
382 iters = individual_store_find_contact (self, individual);
387 model = GTK_TREE_MODEL (self);
389 for (l = iters; l; l = l->next)
393 /* NOTE: it is only <= 2 here because we have
394 * separators after the group name, otherwise it
397 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
398 gtk_tree_model_iter_n_children (model, &parent) <= 2)
400 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
404 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
412 individual_store_add_individual (EmpathyIndividualStore *self,
413 FolksIndividual *individual)
415 EmpathyIndividualStorePriv *priv;
417 GHashTable *group_set = NULL;
418 GList *groups = NULL, *l;
419 EmpathyContact *contact;
420 TpConnection *connection;
421 gchar *protocol_name;
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 group_set = folks_groupable_get_groups (FOLKS_GROUPABLE (individual));
432 groups = g_hash_table_get_keys (group_set);
435 contact = empathy_contact_dup_from_folks_individual (individual);
436 connection = empathy_contact_get_connection (contact);
438 tp_connection_parse_object_path (connection, &protocol_name, NULL);
442 GtkTreeIter iter_group, *parent;
444 parent = &iter_group;
446 if (!priv->show_groups)
448 else if (!tp_strdiff (protocol_name, "local-xmpp"))
450 /* these are People Nearby */
451 individual_store_get_group (self,
452 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
457 individual_store_get_group (self,
458 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
459 &iter_group, NULL, NULL, TRUE);
462 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
466 g_free (protocol_name);
468 /* Else add to each group. */
469 for (l = groups; l; l = l->next)
471 GtkTreeIter iter_group;
473 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
476 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
479 g_list_free (groups);
481 if (priv->show_groups &&
482 folks_favourite_details_get_is_favourite (
483 FOLKS_FAVOURITE_DETAILS (individual)))
485 /* Add contact to the fake 'Favorites' group */
486 GtkTreeIter iter_group;
488 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
489 &iter_group, NULL, NULL, TRUE);
491 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
495 individual_store_contact_update (self, individual);
497 tp_clear_object (&contact);
501 individual_store_contact_set_active (EmpathyIndividualStore *self,
502 FolksIndividual *individual,
504 gboolean set_changed)
506 EmpathyIndividualStorePriv *priv;
510 priv = GET_PRIV (self);
511 model = GTK_TREE_MODEL (self);
513 iters = individual_store_find_contact (self, individual);
514 for (l = iters; l; l = l->next)
518 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
519 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
522 DEBUG ("Set item %s", active ? "active" : "inactive");
526 path = gtk_tree_model_get_path (model, l->data);
527 gtk_tree_model_row_changed (model, path, l->data);
528 gtk_tree_path_free (path);
535 static void individual_store_contact_active_free (ShowActiveData *data);
538 individual_store_contact_active_invalidated (ShowActiveData *data,
541 /* Remove the timeout and free the struct, since the individual or individual
542 * store has disappeared. */
543 g_source_remove (data->timeout);
545 if (old_object == (GObject *) data->self)
547 else if (old_object == (GObject *) data->individual)
548 data->individual = NULL;
550 g_assert_not_reached ();
552 individual_store_contact_active_free (data);
555 static ShowActiveData *
556 individual_store_contact_active_new (EmpathyIndividualStore *self,
557 FolksIndividual *individual,
560 ShowActiveData *data;
562 DEBUG ("Individual'%s' now active, and %s be removed",
563 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
564 remove_ ? "WILL" : "WILL NOT");
566 data = g_slice_new0 (ShowActiveData);
568 /* We don't actually want to force either the IndividualStore or the
569 * Individual to stay alive, since the user could quit Empathy or disable
570 * the account before the contact_active timeout is fired. */
571 g_object_weak_ref (G_OBJECT (self),
572 (GWeakNotify) individual_store_contact_active_invalidated, data);
573 g_object_weak_ref (G_OBJECT (individual),
574 (GWeakNotify) individual_store_contact_active_invalidated, data);
577 data->individual = individual;
578 data->remove = remove_;
585 individual_store_contact_active_free (ShowActiveData *data)
587 if (data->self != NULL)
589 g_object_weak_unref (G_OBJECT (data->self),
590 (GWeakNotify) individual_store_contact_active_invalidated, data);
593 if (data->individual != NULL)
595 g_object_weak_unref (G_OBJECT (data->individual),
596 (GWeakNotify) individual_store_contact_active_invalidated, data);
599 g_slice_free (ShowActiveData, data);
603 individual_store_contact_active_cb (ShowActiveData *data)
607 DEBUG ("Individual'%s' active timeout, removing item",
608 folks_alias_details_get_alias (
609 FOLKS_ALIAS_DETAILS (data->individual)));
610 individual_store_remove_individual (data->self, data->individual);
613 DEBUG ("Individual'%s' no longer active",
614 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
616 individual_store_contact_set_active (data->self,
617 data->individual, FALSE, TRUE);
619 individual_store_contact_active_free (data);
625 EmpathyIndividualStore *store; /* weak */
626 GCancellable *cancellable; /* owned */
630 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
631 GAsyncResult *result,
632 LoadAvatarData *data)
634 GError *error = NULL;
637 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
642 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
643 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
645 g_clear_error (&error);
647 else if (data->store != NULL)
651 iters = individual_store_find_contact (data->store, individual);
652 for (l = iters; l; l = l->next)
654 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
655 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
663 if (data->store != NULL)
665 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
667 g_object_remove_weak_pointer (G_OBJECT (data->store),
668 (gpointer *) &data->store);
669 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
673 tp_clear_object (&pixbuf);
674 g_object_unref (data->cancellable);
675 g_slice_free (LoadAvatarData, data);
679 individual_store_contact_update (EmpathyIndividualStore *self,
680 FolksIndividual *individual)
682 EmpathyIndividualStorePriv *priv;
683 ShowActiveData *data;
687 gboolean was_online = TRUE;
688 gboolean now_online = FALSE;
689 gboolean set_model = FALSE;
690 gboolean do_remove = FALSE;
691 gboolean do_set_active = FALSE;
692 gboolean do_set_refresh = FALSE;
693 gboolean show_avatar = FALSE;
694 GdkPixbuf *pixbuf_status;
695 LoadAvatarData *load_avatar_data;
697 priv = GET_PRIV (self);
699 model = GTK_TREE_MODEL (self);
701 iters = individual_store_find_contact (self, individual);
711 /* Get online state now. */
712 now_online = folks_presence_owner_is_online (
713 FOLKS_PRESENCE_OWNER (individual));
717 DEBUG ("Individual'%s' in list:NO, should be:YES",
718 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
720 individual_store_add_individual (self, individual);
722 if (priv->show_active)
724 do_set_active = TRUE;
726 DEBUG ("Set active (individual added)");
731 DEBUG ("Individual'%s' in list:YES, should be:YES",
732 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
734 /* Get online state before. */
735 if (iters && g_list_length (iters) > 0)
737 gtk_tree_model_get (model, iters->data,
738 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
741 /* Is this really an update or an online/offline. */
742 if (priv->show_active)
744 if (was_online != now_online)
746 do_set_active = TRUE;
747 do_set_refresh = TRUE;
749 DEBUG ("Set active (individual updated %s)",
750 was_online ? "online -> offline" : "offline -> online");
754 /* Was TRUE for presence updates. */
755 /* do_set_active = FALSE; */
756 do_set_refresh = TRUE;
758 DEBUG ("Set active (individual updated)");
765 if (priv->show_avatars && !priv->is_compact)
770 /* Load the avatar asynchronously */
771 load_avatar_data = g_slice_new (LoadAvatarData);
772 load_avatar_data->store = self;
773 g_object_add_weak_pointer (G_OBJECT (self),
774 (gpointer *) &load_avatar_data->store);
775 load_avatar_data->cancellable = g_cancellable_new ();
777 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
778 load_avatar_data->cancellable);
779 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
780 load_avatar_data->cancellable,
781 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
785 empathy_individual_store_get_individual_status_icon (self, individual);
787 for (l = iters; l && set_model; l = l->next)
789 gboolean can_audio_call, can_video_call;
790 const gchar * const *types;
792 individual_can_audio_video_call (individual, &can_audio_call,
795 types = individual_get_client_types (individual);
797 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
798 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
799 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
800 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
801 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
802 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
803 folks_presence_owner_get_presence_type (
804 FOLKS_PRESENCE_OWNER (individual)),
805 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
806 folks_presence_owner_get_presence_message (
807 FOLKS_PRESENCE_OWNER (individual)),
808 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
809 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
810 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
811 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
812 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
813 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
814 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
818 if (priv->show_active && do_set_active)
820 individual_store_contact_set_active (self, individual, do_set_active,
826 individual_store_contact_active_new (self, individual,
828 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
829 (GSourceFunc) individual_store_contact_active_cb, data);
833 /* FIXME: when someone goes online then offline quickly, the
834 * first timeout sets the user to be inactive and the second
835 * timeout removes the user from the contact list, really we
836 * should remove the first timeout.
842 individual_store_individual_updated_cb (FolksIndividual *individual,
844 EmpathyIndividualStore *self)
846 DEBUG ("Individual'%s' updated, checking roster is in sync...",
847 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
849 individual_store_contact_update (self, individual);
853 individual_store_contact_updated_cb (EmpathyContact *contact,
855 EmpathyIndividualStore *self)
857 FolksIndividual *individual;
859 DEBUG ("Contact '%s' updated, checking roster is in sync...",
860 empathy_contact_get_alias (contact));
862 individual = g_object_get_data (G_OBJECT (contact), "individual");
863 if (individual == NULL)
866 individual_store_contact_update (self, individual);
870 individual_personas_changed_cb (FolksIndividual *individual,
873 EmpathyIndividualStore *self)
877 DEBUG ("Individual '%s' personas-changed.",
878 folks_individual_get_id (individual));
880 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
881 * through the EmpathyContacts for them. */
882 for (l = removed; l != NULL; l = l->next)
884 TpContact *tp_contact;
885 EmpathyContact *contact;
887 if (!TPF_IS_PERSONA (l->data))
890 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
891 contact = empathy_contact_dup_from_tp_contact (tp_contact);
892 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
894 g_object_set_data (G_OBJECT (contact), "individual", NULL);
895 g_signal_handlers_disconnect_by_func (contact,
896 (GCallback) individual_store_contact_updated_cb, self);
898 g_object_unref (contact);
901 for (l = added; l != NULL; l = l->next)
903 TpContact *tp_contact;
904 EmpathyContact *contact;
906 if (!TPF_IS_PERSONA (l->data))
909 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
910 contact = empathy_contact_dup_from_tp_contact (tp_contact);
911 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
913 g_object_set_data (G_OBJECT (contact), "individual", individual);
914 g_signal_connect (contact, "notify::capabilities",
915 (GCallback) individual_store_contact_updated_cb, self);
916 g_signal_connect (contact, "notify::client-types",
917 (GCallback) individual_store_contact_updated_cb, self);
919 g_object_unref (contact);
924 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
925 FolksIndividual *individual)
927 individual_store_add_individual (self, individual);
929 g_signal_connect (individual, "notify::avatar",
930 (GCallback) individual_store_individual_updated_cb, self);
931 g_signal_connect (individual, "notify::presence-type",
932 (GCallback) individual_store_individual_updated_cb, self);
933 g_signal_connect (individual, "notify::presence-message",
934 (GCallback) individual_store_individual_updated_cb, self);
935 g_signal_connect (individual, "notify::alias",
936 (GCallback) individual_store_individual_updated_cb, self);
937 g_signal_connect (individual, "personas-changed",
938 (GCallback) individual_personas_changed_cb, self);
940 individual_personas_changed_cb (individual,
941 folks_individual_get_personas (individual), NULL, self);
945 individual_store_disconnect_individual (EmpathyIndividualStore *self,
946 FolksIndividual *individual)
948 individual_personas_changed_cb (individual, NULL,
949 folks_individual_get_personas (individual), self);
951 g_signal_handlers_disconnect_by_func (individual,
952 (GCallback) individual_store_individual_updated_cb, self);
953 g_signal_handlers_disconnect_by_func (individual,
954 (GCallback) individual_personas_changed_cb, self);
958 individual_store_remove_individual_and_disconnect (
959 EmpathyIndividualStore *self,
960 FolksIndividual *individual)
962 individual_store_disconnect_individual (self, individual);
963 individual_store_remove_individual (self, individual);
967 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
968 const gchar *message,
972 EmpathyIndividualStore *self)
976 for (l = added; l; l = l->next)
978 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
980 individual_store_add_individual_and_connect (self, l->data);
982 for (l = removed; l; l = l->next)
984 DEBUG ("Individual %s %s",
985 folks_individual_get_id (l->data), "removed");
987 individual_store_remove_individual_and_disconnect (self, l->data);
992 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
993 FolksIndividual *individual,
994 gboolean is_favourite,
995 EmpathyIndividualStore *self)
997 EmpathyIndividualStorePriv *priv;
999 priv = GET_PRIV (self);
1001 DEBUG ("Individual %s is %s a favourite",
1002 folks_individual_get_id (individual),
1003 is_favourite ? "now" : "no longer");
1005 individual_store_remove_individual (self, individual);
1006 individual_store_add_individual (self, individual);
1010 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
1011 FolksIndividual *individual,
1014 EmpathyIndividualStore *self)
1016 EmpathyIndividualStorePriv *priv;
1017 gboolean show_active;
1019 priv = GET_PRIV (self);
1021 DEBUG ("Updating groups for individual %s",
1022 folks_individual_get_id (individual));
1024 /* We do this to make sure the groups are correct, if not, we
1025 * would have to check the groups already set up for each
1026 * contact and then see what has been updated.
1028 show_active = priv->show_active;
1029 priv->show_active = FALSE;
1030 individual_store_remove_individual (self, individual);
1031 individual_store_add_individual (self, individual);
1032 priv->show_active = show_active;
1036 individual_store_manager_setup (gpointer user_data)
1038 EmpathyIndividualStore *self = user_data;
1039 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1042 /* Signal connection. */
1044 /* TODO: implement */
1045 DEBUG ("handling individual renames unimplemented");
1047 g_signal_connect (priv->manager,
1049 G_CALLBACK (individual_store_members_changed_cb), self);
1051 g_signal_connect (priv->manager,
1052 "favourites-changed",
1053 G_CALLBACK (individual_store_favourites_changed_cb), self);
1055 g_signal_connect (priv->manager,
1057 G_CALLBACK (individual_store_groups_changed_cb), self);
1059 /* Add contacts already created. */
1060 individuals = empathy_individual_manager_get_members (priv->manager);
1061 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1063 individual_store_members_changed_cb (priv->manager, "initial add",
1064 individuals, NULL, 0, self);
1065 g_list_free (individuals);
1068 priv->setup_idle_id = 0;
1073 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1074 EmpathyIndividualManager *manager)
1076 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1078 priv->manager = g_object_ref (manager);
1080 /* Let a chance to have all properties set before populating */
1081 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1085 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1086 FolksIndividual *old_individual,
1087 FolksIndividual *new_individual,
1089 const gchar *message,
1090 EmpathyIndividualStore *self)
1092 EmpathyIndividualStorePriv *priv;
1094 priv = GET_PRIV (self);
1096 DEBUG ("Individual %s renamed to %s",
1097 folks_individual_get_id (old_individual),
1098 folks_individual_get_id (new_individual));
1100 /* add the new contact */
1101 individual_store_add_individual_and_connect (self, new_individual);
1103 /* remove old contact */
1104 individual_store_remove_individual_and_disconnect (self, old_individual);
1108 individual_store_dispose (GObject *object)
1110 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1111 GList *individuals, *l;
1113 if (priv->dispose_has_run)
1115 priv->dispose_has_run = TRUE;
1117 /* Cancel any pending avatar load operations */
1118 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1120 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1121 g_cancellable_cancel (G_CANCELLABLE (l->data));
1123 g_list_free (priv->avatar_cancellables);
1125 individuals = empathy_individual_manager_get_members (priv->manager);
1126 for (l = individuals; l; l = l->next)
1128 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1129 FOLKS_INDIVIDUAL (l->data));
1131 g_list_free (individuals);
1133 g_signal_handlers_disconnect_by_func (priv->manager,
1134 G_CALLBACK (individual_store_member_renamed_cb), object);
1135 g_signal_handlers_disconnect_by_func (priv->manager,
1136 G_CALLBACK (individual_store_members_changed_cb), object);
1137 g_signal_handlers_disconnect_by_func (priv->manager,
1138 G_CALLBACK (individual_store_favourites_changed_cb), object);
1139 g_signal_handlers_disconnect_by_func (priv->manager,
1140 G_CALLBACK (individual_store_groups_changed_cb), object);
1141 g_object_unref (priv->manager);
1143 if (priv->inhibit_active)
1145 g_source_remove (priv->inhibit_active);
1148 if (priv->setup_idle_id != 0)
1150 g_source_remove (priv->setup_idle_id);
1153 g_hash_table_destroy (priv->status_icons);
1154 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1158 individual_store_get_property (GObject *object,
1163 EmpathyIndividualStorePriv *priv;
1165 priv = GET_PRIV (object);
1169 case PROP_INDIVIDUAL_MANAGER:
1170 g_value_set_object (value, priv->manager);
1172 case PROP_SHOW_AVATARS:
1173 g_value_set_boolean (value, priv->show_avatars);
1175 case PROP_SHOW_PROTOCOLS:
1176 g_value_set_boolean (value, priv->show_protocols);
1178 case PROP_SHOW_GROUPS:
1179 g_value_set_boolean (value, priv->show_groups);
1181 case PROP_IS_COMPACT:
1182 g_value_set_boolean (value, priv->is_compact);
1184 case PROP_SORT_CRITERIUM:
1185 g_value_set_enum (value, priv->sort_criterium);
1188 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1194 individual_store_set_property (GObject *object,
1196 const GValue *value,
1199 EmpathyIndividualStorePriv *priv;
1201 priv = GET_PRIV (object);
1205 case PROP_INDIVIDUAL_MANAGER:
1206 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1207 (object), g_value_get_object (value));
1209 case PROP_SHOW_AVATARS:
1210 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1211 (object), g_value_get_boolean (value));
1213 case PROP_SHOW_PROTOCOLS:
1214 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1215 (object), g_value_get_boolean (value));
1217 case PROP_SHOW_GROUPS:
1218 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1219 (object), g_value_get_boolean (value));
1221 case PROP_IS_COMPACT:
1222 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1223 (object), g_value_get_boolean (value));
1225 case PROP_SORT_CRITERIUM:
1226 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1227 (object), g_value_get_enum (value));
1230 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1236 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1238 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1240 object_class->dispose = individual_store_dispose;
1241 object_class->get_property = individual_store_get_property;
1242 object_class->set_property = individual_store_set_property;
1244 g_object_class_install_property (object_class,
1245 PROP_INDIVIDUAL_MANAGER,
1246 g_param_spec_object ("individual-manager",
1247 "The individual manager",
1248 "The individual manager",
1249 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1250 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1251 g_object_class_install_property (object_class,
1253 g_param_spec_boolean ("show-avatars",
1255 "Whether contact list should display "
1256 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1257 g_object_class_install_property (object_class,
1258 PROP_SHOW_PROTOCOLS,
1259 g_param_spec_boolean ("show-protocols",
1261 "Whether contact list should display "
1262 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1263 g_object_class_install_property (object_class,
1265 g_param_spec_boolean ("show-groups",
1267 "Whether contact list should display "
1268 "contact groups", TRUE, G_PARAM_READWRITE));
1269 g_object_class_install_property (object_class,
1271 g_param_spec_boolean ("is-compact",
1273 "Whether the contact list is in compact mode or not",
1274 FALSE, G_PARAM_READWRITE));
1276 g_object_class_install_property (object_class,
1277 PROP_SORT_CRITERIUM,
1278 g_param_spec_enum ("sort-criterium",
1280 "The sort criterium to use for sorting the contact list",
1281 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1282 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1284 g_type_class_add_private (object_class,
1285 sizeof (EmpathyIndividualStorePriv));
1289 get_position (const char **strv,
1294 for (i = 0; strv[i] != NULL; i++)
1296 if (!tp_strdiff (strv[i], str))
1304 compare_separator_and_groups (gboolean is_separator_a,
1305 gboolean is_separator_b,
1306 const gchar *name_a,
1307 const gchar *name_b,
1308 FolksIndividual *individual_a,
1309 FolksIndividual *individual_b,
1310 gboolean fake_group_a,
1311 gboolean fake_group_b)
1313 /* these two lists are the sorted list of fake groups to include at the
1314 * top and bottom of the roster */
1315 const char *top_groups[] = {
1316 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1320 const char *bottom_groups[] = {
1321 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1325 if (is_separator_a || is_separator_b)
1327 /* We have at least one separator */
1332 else if (is_separator_b)
1338 /* One group and one contact */
1339 if (!individual_a && individual_b)
1343 else if (individual_a && !individual_b)
1347 else if (!individual_a && !individual_b)
1349 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1351 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1352 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1353 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1354 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1356 if (a_in_top && b_in_top)
1358 /* compare positions */
1359 return CLAMP (get_position (top_groups, name_a) -
1360 get_position (top_groups, name_b), -1, 1);
1362 else if (a_in_bottom && b_in_bottom)
1364 /* compare positions */
1365 return CLAMP (get_position (bottom_groups, name_a) -
1366 get_position (bottom_groups, name_b), -1, 1);
1368 else if (a_in_top || b_in_bottom)
1372 else if (b_in_top || a_in_bottom)
1378 return g_utf8_collate (name_a, name_b);
1382 /* Two contacts, ordering depends of the sorting policy */
1387 individual_store_contact_sort (FolksIndividual *individual_a,
1388 FolksIndividual *individual_b)
1391 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1392 TpAccount *account_a, *account_b;
1394 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1397 ret_val = g_utf8_collate (
1398 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1399 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1404 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1405 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1406 account_a = empathy_contact_get_account (contact_a);
1407 account_b = empathy_contact_get_account (contact_b);
1409 g_assert (account_a != NULL);
1410 g_assert (account_b != NULL);
1413 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1414 tp_account_get_protocol (account_b));
1420 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1421 tp_proxy_get_object_path (account_b));
1427 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1428 folks_individual_get_id (individual_b));
1431 tp_clear_object (&contact_a);
1432 tp_clear_object (&contact_b);
1438 individual_store_state_sort_func (GtkTreeModel *model,
1439 GtkTreeIter *iter_a,
1440 GtkTreeIter *iter_b,
1444 FolksIndividual *individual_a, *individual_b;
1445 gchar *name_a, *name_b;
1446 gboolean is_separator_a, is_separator_b;
1447 gboolean fake_group_a, fake_group_b;
1448 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1449 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1451 gtk_tree_model_get (model, iter_a,
1452 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1453 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1454 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1455 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1456 gtk_tree_model_get (model, iter_b,
1457 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1458 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1459 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1460 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1462 if (individual_a == NULL || individual_b == NULL)
1464 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1465 name_a, name_b, individual_a, individual_b, fake_group_a,
1470 /* If we managed to get this far, we can start looking at
1473 folks_presence_type_a =
1474 folks_presence_owner_get_presence_type (
1475 FOLKS_PRESENCE_OWNER (individual_a));
1476 folks_presence_type_b =
1477 folks_presence_owner_get_presence_type (
1478 FOLKS_PRESENCE_OWNER (individual_b));
1479 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1480 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1482 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1487 /* Fallback: compare by name et al. */
1488 ret_val = individual_store_contact_sort (individual_a, individual_b);
1494 tp_clear_object (&individual_a);
1495 tp_clear_object (&individual_b);
1501 individual_store_name_sort_func (GtkTreeModel *model,
1502 GtkTreeIter *iter_a,
1503 GtkTreeIter *iter_b,
1506 gchar *name_a, *name_b;
1507 FolksIndividual *individual_a, *individual_b;
1508 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1510 gboolean fake_group_a, fake_group_b;
1512 gtk_tree_model_get (model, iter_a,
1513 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1514 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1515 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1516 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1517 gtk_tree_model_get (model, iter_b,
1518 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1519 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1520 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1521 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1523 if (individual_a == NULL || individual_b == NULL)
1524 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1525 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1527 ret_val = individual_store_contact_sort (individual_a, individual_b);
1529 tp_clear_object (&individual_a);
1530 tp_clear_object (&individual_b);
1538 individual_store_setup (EmpathyIndividualStore *self)
1540 EmpathyIndividualStorePriv *priv;
1542 GDK_TYPE_PIXBUF, /* Status pixbuf */
1543 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1544 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1545 G_TYPE_STRING, /* Name */
1546 G_TYPE_UINT, /* Presence type */
1547 G_TYPE_STRING, /* Status string */
1548 G_TYPE_BOOLEAN, /* Compact view */
1549 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1550 G_TYPE_BOOLEAN, /* Is group */
1551 G_TYPE_BOOLEAN, /* Is active */
1552 G_TYPE_BOOLEAN, /* Is online */
1553 G_TYPE_BOOLEAN, /* Is separator */
1554 G_TYPE_BOOLEAN, /* Can make audio calls */
1555 G_TYPE_BOOLEAN, /* Can make video calls */
1556 G_TYPE_BOOLEAN, /* Is a fake group */
1557 G_TYPE_STRV, /* Client types */
1560 priv = GET_PRIV (self);
1562 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1563 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1565 /* Set up sorting */
1566 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1567 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1568 individual_store_name_sort_func, self, NULL);
1569 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1570 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1571 individual_store_state_sort_func, self, NULL);
1573 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1574 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1578 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1580 EmpathyIndividualStorePriv *priv;
1582 priv = GET_PRIV (self);
1584 priv->show_active = TRUE;
1585 priv->inhibit_active = 0;
1591 empathy_individual_store_init (EmpathyIndividualStore *self)
1593 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1594 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1597 priv->show_avatars = TRUE;
1598 priv->show_groups = TRUE;
1599 priv->show_protocols = FALSE;
1600 priv->inhibit_active =
1601 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1602 (GSourceFunc) individual_store_inhibit_active_cb, self);
1603 priv->status_icons =
1604 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1605 individual_store_setup (self);
1608 EmpathyIndividualStore *
1609 empathy_individual_store_new (EmpathyIndividualManager *manager)
1611 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1613 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1614 "individual-manager", manager, NULL);
1617 EmpathyIndividualManager *
1618 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1620 EmpathyIndividualStorePriv *priv;
1622 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1624 priv = GET_PRIV (self);
1626 return priv->manager;
1630 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1632 EmpathyIndividualStorePriv *priv;
1634 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1636 priv = GET_PRIV (self);
1638 return priv->show_avatars;
1642 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1645 EmpathyIndividualStore *self)
1647 EmpathyIndividualStorePriv *priv;
1648 gboolean show_avatar = FALSE;
1649 FolksIndividual *individual;
1650 GdkPixbuf *pixbuf_status;
1652 priv = GET_PRIV (self);
1654 if (priv->show_avatars && !priv->is_compact)
1659 gtk_tree_model_get (model, iter,
1660 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1662 if (individual == NULL)
1666 /* get icon from hash_table */
1668 empathy_individual_store_get_individual_status_icon (self, individual);
1670 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1671 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1672 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1673 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1675 g_object_unref (individual);
1681 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1682 gboolean show_avatars)
1684 EmpathyIndividualStorePriv *priv;
1685 GtkTreeModel *model;
1687 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1689 priv = GET_PRIV (self);
1691 priv->show_avatars = show_avatars;
1693 model = GTK_TREE_MODEL (self);
1695 gtk_tree_model_foreach (model,
1696 (GtkTreeModelForeachFunc)
1697 individual_store_update_list_mode_foreach, self);
1699 g_object_notify (G_OBJECT (self), "show-avatars");
1703 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1705 EmpathyIndividualStorePriv *priv;
1707 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1709 priv = GET_PRIV (self);
1711 return priv->show_protocols;
1715 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1716 gboolean show_protocols)
1718 EmpathyIndividualStorePriv *priv;
1719 GtkTreeModel *model;
1721 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1723 priv = GET_PRIV (self);
1725 priv->show_protocols = show_protocols;
1727 model = GTK_TREE_MODEL (self);
1729 gtk_tree_model_foreach (model,
1730 (GtkTreeModelForeachFunc)
1731 individual_store_update_list_mode_foreach, self);
1733 g_object_notify (G_OBJECT (self), "show-protocols");
1737 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1739 EmpathyIndividualStorePriv *priv;
1741 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1743 priv = GET_PRIV (self);
1745 return priv->show_groups;
1749 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1750 gboolean show_groups)
1752 EmpathyIndividualStorePriv *priv;
1754 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1756 priv = GET_PRIV (self);
1758 if (priv->show_groups == show_groups)
1763 priv->show_groups = show_groups;
1765 if (priv->setup_idle_id == 0)
1767 /* Remove all contacts and add them back, not optimized but
1768 * that's the easy way :)
1770 * This is only done if there's not a pending setup idle
1771 * callback, otherwise it will race and the contacts will get
1775 gtk_tree_store_clear (GTK_TREE_STORE (self));
1776 contacts = empathy_individual_manager_get_members (priv->manager);
1778 individual_store_members_changed_cb (priv->manager,
1779 "re-adding members: toggled group visibility",
1780 contacts, NULL, 0, self);
1781 g_list_free (contacts);
1784 g_object_notify (G_OBJECT (self), "show-groups");
1788 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1790 EmpathyIndividualStorePriv *priv;
1792 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1794 priv = GET_PRIV (self);
1796 return priv->is_compact;
1800 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1801 gboolean is_compact)
1803 EmpathyIndividualStorePriv *priv;
1804 GtkTreeModel *model;
1806 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1808 priv = GET_PRIV (self);
1810 priv->is_compact = is_compact;
1812 model = GTK_TREE_MODEL (self);
1814 gtk_tree_model_foreach (model,
1815 (GtkTreeModelForeachFunc)
1816 individual_store_update_list_mode_foreach, self);
1818 g_object_notify (G_OBJECT (self), "is-compact");
1821 EmpathyIndividualStoreSort
1822 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1824 EmpathyIndividualStorePriv *priv;
1826 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1828 priv = GET_PRIV (self);
1830 return priv->sort_criterium;
1834 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1835 EmpathyIndividualStoreSort sort_criterium)
1837 EmpathyIndividualStorePriv *priv;
1839 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1841 priv = GET_PRIV (self);
1843 priv->sort_criterium = sort_criterium;
1845 switch (sort_criterium)
1847 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1848 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1849 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1852 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1853 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1854 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1858 g_assert_not_reached ();
1861 g_object_notify (G_OBJECT (self), "sort-criterium");
1865 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1869 gboolean is_separator = FALSE;
1871 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1873 gtk_tree_model_get (model, iter,
1874 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1876 return is_separator;
1880 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1882 gboolean *path_is_group,
1883 gboolean *is_fake_group)
1885 GtkTreeIter parent_iter, iter;
1888 gboolean fake = FALSE;
1890 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1894 *path_is_group = FALSE;
1897 if (!gtk_tree_model_get_iter (model, &iter, path))
1902 gtk_tree_model_get (model, &iter,
1903 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1904 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1911 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1918 gtk_tree_model_get (model, &iter,
1919 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1920 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1921 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1931 *path_is_group = TRUE;
1934 if (is_fake_group != NULL)
1935 *is_fake_group = fake;
1941 individual_store_get_individual_status_icon_with_icon_name (
1942 EmpathyIndividualStore *self,
1943 FolksIndividual *individual,
1944 const gchar *status_icon_name)
1946 GdkPixbuf *pixbuf_status = NULL;
1947 EmpathyIndividualStorePriv *priv;
1948 const gchar *protocol_name = NULL;
1949 gchar *icon_name = NULL;
1950 GList *personas, *l;
1951 guint contact_count;
1952 EmpathyContact *contact = NULL;
1953 gboolean show_protocols_here;
1955 priv = GET_PRIV (self);
1957 personas = folks_individual_get_personas (individual);
1958 for (l = personas, contact_count = 0; l; l = l->next)
1960 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
1963 if (contact_count > 1)
1967 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1968 if (show_protocols_here)
1970 contact = empathy_contact_dup_from_folks_individual (individual);
1971 protocol_name = empathy_protocol_name_for_contact (contact);
1972 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1976 icon_name = g_strdup_printf ("%s", status_icon_name);
1978 if (pixbuf_status == NULL)
1981 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1982 status_icon_name, show_protocols_here);
1983 if (pixbuf_status != NULL)
1985 g_hash_table_insert (priv->status_icons,
1986 g_strdup (icon_name), pixbuf_status);
1991 tp_clear_object (&contact);
1993 return pixbuf_status;
1997 empathy_individual_store_get_individual_status_icon (
1998 EmpathyIndividualStore *self,
1999 FolksIndividual *individual)
2001 GdkPixbuf *pixbuf_status = NULL;
2002 const gchar *status_icon_name = NULL;
2004 status_icon_name = empathy_icon_name_for_individual (individual);
2005 if (status_icon_name == NULL)
2009 individual_store_get_individual_status_icon_with_icon_name (self,
2010 individual, status_icon_name);
2012 return pixbuf_status;