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 (!TPF_IS_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 FolksHasPresence *presence;
169 /* We only want personas which implement FolksHasPresence */
170 if (!FOLKS_IS_HAS_PRESENCE (l->data))
173 presence = FOLKS_HAS_PRESENCE (l->data);
175 if (folks_has_presence_typecmp (
176 folks_has_presence_get_presence_type (presence),
179 TpContact *tp_contact;
181 presence_type = folks_has_presence_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_aliasable_get_alias (FOLKS_ALIASABLE (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_aliasable_get_alias (FOLKS_ALIASABLE (individual))))
428 if (priv->show_groups)
430 group_set = folks_groupable_get_groups (FOLKS_GROUPABLE (individual));
431 groups = g_hash_table_get_keys (group_set);
434 contact = empathy_contact_dup_from_folks_individual (individual);
435 connection = empathy_contact_get_connection (contact);
437 tp_connection_parse_object_path (connection, &protocol_name, NULL);
441 GtkTreeIter iter_group, *parent;
443 parent = &iter_group;
445 if (!priv->show_groups)
447 else if (!tp_strdiff (protocol_name, "local-xmpp"))
449 /* these are People Nearby */
450 individual_store_get_group (self,
451 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
456 individual_store_get_group (self,
457 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
458 &iter_group, NULL, NULL, TRUE);
461 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
465 g_free (protocol_name);
467 /* Else add to each group. */
468 for (l = groups; l; l = l->next)
470 GtkTreeIter iter_group;
472 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
475 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
478 g_list_free (groups);
480 if (priv->show_groups &&
481 folks_favouritable_get_is_favourite (FOLKS_FAVOURITABLE (individual)))
483 /* Add contact to the fake 'Favorites' group */
484 GtkTreeIter iter_group;
486 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
487 &iter_group, NULL, NULL, TRUE);
489 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
493 individual_store_contact_update (self, individual);
495 tp_clear_object (&contact);
499 individual_store_contact_set_active (EmpathyIndividualStore *self,
500 FolksIndividual *individual,
502 gboolean set_changed)
504 EmpathyIndividualStorePriv *priv;
508 priv = GET_PRIV (self);
509 model = GTK_TREE_MODEL (self);
511 iters = individual_store_find_contact (self, individual);
512 for (l = iters; l; l = l->next)
516 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
517 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
520 DEBUG ("Set item %s", active ? "active" : "inactive");
524 path = gtk_tree_model_get_path (model, l->data);
525 gtk_tree_model_row_changed (model, path, l->data);
526 gtk_tree_path_free (path);
533 static void individual_store_contact_active_free (ShowActiveData *data);
536 individual_store_contact_active_invalidated (ShowActiveData *data,
539 /* Remove the timeout and free the struct, since the individual or individual
540 * store has disappeared. */
541 g_source_remove (data->timeout);
543 if (old_object == (GObject *) data->self)
545 else if (old_object == (GObject *) data->individual)
546 data->individual = NULL;
548 g_assert_not_reached ();
550 individual_store_contact_active_free (data);
553 static ShowActiveData *
554 individual_store_contact_active_new (EmpathyIndividualStore *self,
555 FolksIndividual *individual,
558 ShowActiveData *data;
560 DEBUG ("Individual'%s' now active, and %s be removed",
561 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)),
562 remove_ ? "WILL" : "WILL NOT");
564 data = g_slice_new0 (ShowActiveData);
566 /* We don't actually want to force either the IndividualStore or the
567 * Individual to stay alive, since the user could quit Empathy or disable
568 * the account before the contact_active timeout is fired. */
569 g_object_weak_ref (G_OBJECT (self),
570 (GWeakNotify) individual_store_contact_active_invalidated, data);
571 g_object_weak_ref (G_OBJECT (individual),
572 (GWeakNotify) individual_store_contact_active_invalidated, data);
575 data->individual = individual;
576 data->remove = remove_;
583 individual_store_contact_active_free (ShowActiveData *data)
585 if (data->self != NULL)
587 g_object_weak_unref (G_OBJECT (data->self),
588 (GWeakNotify) individual_store_contact_active_invalidated, data);
591 if (data->individual != NULL)
593 g_object_weak_unref (G_OBJECT (data->individual),
594 (GWeakNotify) individual_store_contact_active_invalidated, data);
597 g_slice_free (ShowActiveData, data);
601 individual_store_contact_active_cb (ShowActiveData *data)
605 DEBUG ("Individual'%s' active timeout, removing item",
606 folks_aliasable_get_alias (FOLKS_ALIASABLE (data->individual)));
607 individual_store_remove_individual (data->self, data->individual);
610 DEBUG ("Individual'%s' no longer active",
611 folks_aliasable_get_alias (FOLKS_ALIASABLE (data->individual)));
613 individual_store_contact_set_active (data->self,
614 data->individual, FALSE, TRUE);
616 individual_store_contact_active_free (data);
622 EmpathyIndividualStore *store; /* weak */
623 GCancellable *cancellable; /* owned */
627 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
628 GAsyncResult *result,
629 LoadAvatarData *data)
631 GError *error = NULL;
634 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
639 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
640 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)),
642 g_clear_error (&error);
644 else if (data->store != NULL)
648 iters = individual_store_find_contact (data->store, individual);
649 for (l = iters; l; l = l->next)
651 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
652 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
660 if (data->store != NULL)
662 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
664 g_object_remove_weak_pointer (G_OBJECT (data->store),
665 (gpointer *) &data->store);
666 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
670 tp_clear_object (&pixbuf);
671 g_object_unref (data->cancellable);
672 g_slice_free (LoadAvatarData, data);
676 individual_store_contact_update (EmpathyIndividualStore *self,
677 FolksIndividual *individual)
679 EmpathyIndividualStorePriv *priv;
680 ShowActiveData *data;
684 gboolean was_online = TRUE;
685 gboolean now_online = FALSE;
686 gboolean set_model = FALSE;
687 gboolean do_remove = FALSE;
688 gboolean do_set_active = FALSE;
689 gboolean do_set_refresh = FALSE;
690 gboolean show_avatar = FALSE;
691 GdkPixbuf *pixbuf_status;
692 LoadAvatarData *load_avatar_data;
694 priv = GET_PRIV (self);
696 model = GTK_TREE_MODEL (self);
698 iters = individual_store_find_contact (self, individual);
708 /* Get online state now. */
709 now_online = folks_has_presence_is_online (FOLKS_HAS_PRESENCE (individual));
713 DEBUG ("Individual'%s' in list:NO, should be:YES",
714 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
716 individual_store_add_individual (self, individual);
718 if (priv->show_active)
720 do_set_active = TRUE;
722 DEBUG ("Set active (individual added)");
727 DEBUG ("Individual'%s' in list:YES, should be:YES",
728 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
730 /* Get online state before. */
731 if (iters && g_list_length (iters) > 0)
733 gtk_tree_model_get (model, iters->data,
734 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
737 /* Is this really an update or an online/offline. */
738 if (priv->show_active)
740 if (was_online != now_online)
742 do_set_active = TRUE;
743 do_set_refresh = TRUE;
745 DEBUG ("Set active (individual updated %s)",
746 was_online ? "online -> offline" : "offline -> online");
750 /* Was TRUE for presence updates. */
751 /* do_set_active = FALSE; */
752 do_set_refresh = TRUE;
754 DEBUG ("Set active (individual updated)");
761 if (priv->show_avatars && !priv->is_compact)
766 /* Load the avatar asynchronously */
767 load_avatar_data = g_slice_new (LoadAvatarData);
768 load_avatar_data->store = self;
769 g_object_add_weak_pointer (G_OBJECT (self),
770 (gpointer *) &load_avatar_data->store);
771 load_avatar_data->cancellable = g_cancellable_new ();
773 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
774 load_avatar_data->cancellable);
775 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
776 load_avatar_data->cancellable,
777 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
781 empathy_individual_store_get_individual_status_icon (self, individual);
783 for (l = iters; l && set_model; l = l->next)
785 gboolean can_audio_call, can_video_call;
786 const gchar * const *types;
788 individual_can_audio_video_call (individual, &can_audio_call,
791 types = individual_get_client_types (individual);
793 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
794 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
795 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
796 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
797 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)),
798 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
799 folks_has_presence_get_presence_type (
800 FOLKS_HAS_PRESENCE (individual)),
801 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
802 folks_has_presence_get_presence_message (
803 FOLKS_HAS_PRESENCE (individual)),
804 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
805 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
806 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
807 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
808 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
809 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
810 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
814 if (priv->show_active && do_set_active)
816 individual_store_contact_set_active (self, individual, do_set_active,
822 individual_store_contact_active_new (self, individual,
824 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
825 (GSourceFunc) individual_store_contact_active_cb, data);
829 /* FIXME: when someone goes online then offline quickly, the
830 * first timeout sets the user to be inactive and the second
831 * timeout removes the user from the contact list, really we
832 * should remove the first timeout.
838 individual_store_individual_updated_cb (FolksIndividual *individual,
840 EmpathyIndividualStore *self)
842 DEBUG ("Individual'%s' updated, checking roster is in sync...",
843 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
845 individual_store_contact_update (self, individual);
849 individual_store_contact_updated_cb (EmpathyContact *contact,
851 EmpathyIndividualStore *self)
853 FolksIndividual *individual;
855 DEBUG ("Contact '%s' updated, checking roster is in sync...",
856 empathy_contact_get_alias (contact));
858 individual = g_object_get_data (G_OBJECT (contact), "individual");
859 if (individual == NULL)
862 individual_store_contact_update (self, individual);
866 individual_personas_changed_cb (FolksIndividual *individual,
869 EmpathyIndividualStore *self)
873 DEBUG ("Individual '%s' personas-changed.",
874 folks_individual_get_id (individual));
876 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
877 * through the EmpathyContacts for them. */
878 for (l = removed; l != NULL; l = l->next)
880 TpContact *tp_contact;
881 EmpathyContact *contact;
883 if (!TPF_IS_PERSONA (l->data))
886 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
887 contact = empathy_contact_dup_from_tp_contact (tp_contact);
888 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
890 g_object_set_data (G_OBJECT (contact), "individual", NULL);
891 g_signal_handlers_disconnect_by_func (contact,
892 (GCallback) individual_store_contact_updated_cb, self);
894 g_object_unref (contact);
897 for (l = added; l != NULL; l = l->next)
899 TpContact *tp_contact;
900 EmpathyContact *contact;
902 if (!TPF_IS_PERSONA (l->data))
905 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
906 contact = empathy_contact_dup_from_tp_contact (tp_contact);
907 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
909 g_object_set_data (G_OBJECT (contact), "individual", individual);
910 g_signal_connect (contact, "notify::capabilities",
911 (GCallback) individual_store_contact_updated_cb, self);
912 g_signal_connect (contact, "notify::client-types",
913 (GCallback) individual_store_contact_updated_cb, self);
915 g_object_unref (contact);
920 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
921 FolksIndividual *individual)
923 individual_store_add_individual (self, individual);
925 g_signal_connect (individual, "notify::avatar",
926 (GCallback) individual_store_individual_updated_cb, self);
927 g_signal_connect (individual, "notify::presence-type",
928 (GCallback) individual_store_individual_updated_cb, self);
929 g_signal_connect (individual, "notify::presence-message",
930 (GCallback) individual_store_individual_updated_cb, self);
931 g_signal_connect (individual, "notify::alias",
932 (GCallback) individual_store_individual_updated_cb, self);
933 g_signal_connect (individual, "personas-changed",
934 (GCallback) individual_personas_changed_cb, self);
936 individual_personas_changed_cb (individual,
937 folks_individual_get_personas (individual), NULL, self);
941 individual_store_disconnect_individual (EmpathyIndividualStore *self,
942 FolksIndividual *individual)
944 individual_personas_changed_cb (individual, NULL,
945 folks_individual_get_personas (individual), self);
947 g_signal_handlers_disconnect_by_func (individual,
948 (GCallback) individual_store_individual_updated_cb, self);
949 g_signal_handlers_disconnect_by_func (individual,
950 (GCallback) individual_personas_changed_cb, self);
954 individual_store_remove_individual_and_disconnect (
955 EmpathyIndividualStore *self,
956 FolksIndividual *individual)
958 individual_store_disconnect_individual (self, individual);
959 individual_store_remove_individual (self, individual);
963 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
964 const gchar *message,
968 EmpathyIndividualStore *self)
972 for (l = added; l; l = l->next)
974 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
976 individual_store_add_individual_and_connect (self, l->data);
978 for (l = removed; l; l = l->next)
980 DEBUG ("Individual %s %s",
981 folks_individual_get_id (l->data), "removed");
983 individual_store_remove_individual_and_disconnect (self, l->data);
988 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
989 FolksIndividual *individual,
990 gboolean is_favourite,
991 EmpathyIndividualStore *self)
993 EmpathyIndividualStorePriv *priv;
995 priv = GET_PRIV (self);
997 DEBUG ("Individual %s is %s a favourite",
998 folks_individual_get_id (individual),
999 is_favourite ? "now" : "no longer");
1001 individual_store_remove_individual (self, individual);
1002 individual_store_add_individual (self, individual);
1006 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
1007 FolksIndividual *individual,
1010 EmpathyIndividualStore *self)
1012 EmpathyIndividualStorePriv *priv;
1013 gboolean show_active;
1015 priv = GET_PRIV (self);
1017 DEBUG ("Updating groups for individual %s",
1018 folks_individual_get_id (individual));
1020 /* We do this to make sure the groups are correct, if not, we
1021 * would have to check the groups already set up for each
1022 * contact and then see what has been updated.
1024 show_active = priv->show_active;
1025 priv->show_active = FALSE;
1026 individual_store_remove_individual (self, individual);
1027 individual_store_add_individual (self, individual);
1028 priv->show_active = show_active;
1032 individual_store_manager_setup (gpointer user_data)
1034 EmpathyIndividualStore *self = user_data;
1035 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1038 /* Signal connection. */
1040 /* TODO: implement */
1041 DEBUG ("handling individual renames unimplemented");
1043 g_signal_connect (priv->manager,
1045 G_CALLBACK (individual_store_members_changed_cb), self);
1047 g_signal_connect (priv->manager,
1048 "favourites-changed",
1049 G_CALLBACK (individual_store_favourites_changed_cb), self);
1051 g_signal_connect (priv->manager,
1053 G_CALLBACK (individual_store_groups_changed_cb), self);
1055 /* Add contacts already created. */
1056 individuals = empathy_individual_manager_get_members (priv->manager);
1057 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1059 individual_store_members_changed_cb (priv->manager, "initial add",
1060 individuals, NULL, 0, self);
1061 g_list_free (individuals);
1064 priv->setup_idle_id = 0;
1069 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1070 EmpathyIndividualManager *manager)
1072 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1074 priv->manager = g_object_ref (manager);
1076 /* Let a chance to have all properties set before populating */
1077 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1081 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1082 FolksIndividual *old_individual,
1083 FolksIndividual *new_individual,
1085 const gchar *message,
1086 EmpathyIndividualStore *self)
1088 EmpathyIndividualStorePriv *priv;
1090 priv = GET_PRIV (self);
1092 DEBUG ("Individual %s renamed to %s",
1093 folks_individual_get_id (old_individual),
1094 folks_individual_get_id (new_individual));
1096 /* add the new contact */
1097 individual_store_add_individual_and_connect (self, new_individual);
1099 /* remove old contact */
1100 individual_store_remove_individual_and_disconnect (self, old_individual);
1104 individual_store_dispose (GObject *object)
1106 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1107 GList *individuals, *l;
1109 if (priv->dispose_has_run)
1111 priv->dispose_has_run = TRUE;
1113 /* Cancel any pending avatar load operations */
1114 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1116 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1117 g_cancellable_cancel (G_CANCELLABLE (l->data));
1119 g_list_free (priv->avatar_cancellables);
1121 individuals = empathy_individual_manager_get_members (priv->manager);
1122 for (l = individuals; l; l = l->next)
1124 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1125 FOLKS_INDIVIDUAL (l->data));
1127 g_list_free (individuals);
1129 g_signal_handlers_disconnect_by_func (priv->manager,
1130 G_CALLBACK (individual_store_member_renamed_cb), object);
1131 g_signal_handlers_disconnect_by_func (priv->manager,
1132 G_CALLBACK (individual_store_members_changed_cb), object);
1133 g_signal_handlers_disconnect_by_func (priv->manager,
1134 G_CALLBACK (individual_store_favourites_changed_cb), object);
1135 g_signal_handlers_disconnect_by_func (priv->manager,
1136 G_CALLBACK (individual_store_groups_changed_cb), object);
1137 g_object_unref (priv->manager);
1139 if (priv->inhibit_active)
1141 g_source_remove (priv->inhibit_active);
1144 if (priv->setup_idle_id != 0)
1146 g_source_remove (priv->setup_idle_id);
1149 g_hash_table_destroy (priv->status_icons);
1150 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1154 individual_store_get_property (GObject *object,
1159 EmpathyIndividualStorePriv *priv;
1161 priv = GET_PRIV (object);
1165 case PROP_INDIVIDUAL_MANAGER:
1166 g_value_set_object (value, priv->manager);
1168 case PROP_SHOW_AVATARS:
1169 g_value_set_boolean (value, priv->show_avatars);
1171 case PROP_SHOW_PROTOCOLS:
1172 g_value_set_boolean (value, priv->show_protocols);
1174 case PROP_SHOW_GROUPS:
1175 g_value_set_boolean (value, priv->show_groups);
1177 case PROP_IS_COMPACT:
1178 g_value_set_boolean (value, priv->is_compact);
1180 case PROP_SORT_CRITERIUM:
1181 g_value_set_enum (value, priv->sort_criterium);
1184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1190 individual_store_set_property (GObject *object,
1192 const GValue *value,
1195 EmpathyIndividualStorePriv *priv;
1197 priv = GET_PRIV (object);
1201 case PROP_INDIVIDUAL_MANAGER:
1202 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1203 (object), g_value_get_object (value));
1205 case PROP_SHOW_AVATARS:
1206 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1207 (object), g_value_get_boolean (value));
1209 case PROP_SHOW_PROTOCOLS:
1210 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1211 (object), g_value_get_boolean (value));
1213 case PROP_SHOW_GROUPS:
1214 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1215 (object), g_value_get_boolean (value));
1217 case PROP_IS_COMPACT:
1218 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1219 (object), g_value_get_boolean (value));
1221 case PROP_SORT_CRITERIUM:
1222 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1223 (object), g_value_get_enum (value));
1226 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1232 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1234 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1236 object_class->dispose = individual_store_dispose;
1237 object_class->get_property = individual_store_get_property;
1238 object_class->set_property = individual_store_set_property;
1240 g_object_class_install_property (object_class,
1241 PROP_INDIVIDUAL_MANAGER,
1242 g_param_spec_object ("individual-manager",
1243 "The individual manager",
1244 "The individual manager",
1245 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1246 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1247 g_object_class_install_property (object_class,
1249 g_param_spec_boolean ("show-avatars",
1251 "Whether contact list should display "
1252 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1253 g_object_class_install_property (object_class,
1254 PROP_SHOW_PROTOCOLS,
1255 g_param_spec_boolean ("show-protocols",
1257 "Whether contact list should display "
1258 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1259 g_object_class_install_property (object_class,
1261 g_param_spec_boolean ("show-groups",
1263 "Whether contact list should display "
1264 "contact groups", TRUE, G_PARAM_READWRITE));
1265 g_object_class_install_property (object_class,
1267 g_param_spec_boolean ("is-compact",
1269 "Whether the contact list is in compact mode or not",
1270 FALSE, G_PARAM_READWRITE));
1272 g_object_class_install_property (object_class,
1273 PROP_SORT_CRITERIUM,
1274 g_param_spec_enum ("sort-criterium",
1276 "The sort criterium to use for sorting the contact list",
1277 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1278 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1280 g_type_class_add_private (object_class,
1281 sizeof (EmpathyIndividualStorePriv));
1285 get_position (const char **strv,
1290 for (i = 0; strv[i] != NULL; i++)
1292 if (!tp_strdiff (strv[i], str))
1300 compare_separator_and_groups (gboolean is_separator_a,
1301 gboolean is_separator_b,
1302 const gchar *name_a,
1303 const gchar *name_b,
1304 FolksIndividual *individual_a,
1305 FolksIndividual *individual_b,
1306 gboolean fake_group_a,
1307 gboolean fake_group_b)
1309 /* these two lists are the sorted list of fake groups to include at the
1310 * top and bottom of the roster */
1311 const char *top_groups[] = {
1312 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1316 const char *bottom_groups[] = {
1317 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1321 if (is_separator_a || is_separator_b)
1323 /* We have at least one separator */
1328 else if (is_separator_b)
1334 /* One group and one contact */
1335 if (!individual_a && individual_b)
1339 else if (individual_a && !individual_b)
1343 else if (!individual_a && !individual_b)
1345 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1347 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1348 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1349 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1350 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1352 if (a_in_top && b_in_top)
1354 /* compare positions */
1355 return CLAMP (get_position (top_groups, name_a) -
1356 get_position (top_groups, name_b), -1, 1);
1358 else if (a_in_bottom && b_in_bottom)
1360 /* compare positions */
1361 return CLAMP (get_position (bottom_groups, name_a) -
1362 get_position (bottom_groups, name_b), -1, 1);
1364 else if (a_in_top || b_in_bottom)
1368 else if (b_in_top || a_in_bottom)
1374 return g_utf8_collate (name_a, name_b);
1378 /* Two contacts, ordering depends of the sorting policy */
1383 individual_store_contact_sort (FolksIndividual *individual_a,
1384 FolksIndividual *individual_b)
1387 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1388 TpAccount *account_a, *account_b;
1390 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1393 ret_val = g_utf8_collate (
1394 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual_a)),
1395 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual_b)));
1400 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1401 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1402 account_a = empathy_contact_get_account (contact_a);
1403 account_b = empathy_contact_get_account (contact_b);
1405 g_assert (account_a != NULL);
1406 g_assert (account_b != NULL);
1409 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1410 tp_account_get_protocol (account_b));
1416 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1417 tp_proxy_get_object_path (account_b));
1423 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1424 folks_individual_get_id (individual_b));
1427 tp_clear_object (&contact_a);
1428 tp_clear_object (&contact_b);
1434 individual_store_state_sort_func (GtkTreeModel *model,
1435 GtkTreeIter *iter_a,
1436 GtkTreeIter *iter_b,
1440 FolksIndividual *individual_a, *individual_b;
1441 gchar *name_a, *name_b;
1442 gboolean is_separator_a, is_separator_b;
1443 gboolean fake_group_a, fake_group_b;
1444 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1445 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1447 gtk_tree_model_get (model, iter_a,
1448 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1449 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1450 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1451 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1452 gtk_tree_model_get (model, iter_b,
1453 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1454 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1455 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1456 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1458 if (individual_a == NULL || individual_b == NULL)
1460 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1461 name_a, name_b, individual_a, individual_b, fake_group_a,
1466 /* If we managed to get this far, we can start looking at
1469 folks_presence_type_a =
1470 folks_has_presence_get_presence_type (FOLKS_HAS_PRESENCE (individual_a));
1471 folks_presence_type_b =
1472 folks_has_presence_get_presence_type (FOLKS_HAS_PRESENCE (individual_b));
1473 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1474 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1476 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1481 /* Fallback: compare by name et al. */
1482 ret_val = individual_store_contact_sort (individual_a, individual_b);
1488 tp_clear_object (&individual_a);
1489 tp_clear_object (&individual_b);
1495 individual_store_name_sort_func (GtkTreeModel *model,
1496 GtkTreeIter *iter_a,
1497 GtkTreeIter *iter_b,
1500 gchar *name_a, *name_b;
1501 FolksIndividual *individual_a, *individual_b;
1502 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1504 gboolean fake_group_a, fake_group_b;
1506 gtk_tree_model_get (model, iter_a,
1507 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1508 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1509 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1510 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1511 gtk_tree_model_get (model, iter_b,
1512 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1513 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1514 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1515 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1517 if (individual_a == NULL || individual_b == NULL)
1518 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1519 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1521 ret_val = individual_store_contact_sort (individual_a, individual_b);
1523 tp_clear_object (&individual_a);
1524 tp_clear_object (&individual_b);
1532 individual_store_setup (EmpathyIndividualStore *self)
1534 EmpathyIndividualStorePriv *priv;
1536 GDK_TYPE_PIXBUF, /* Status pixbuf */
1537 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1538 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1539 G_TYPE_STRING, /* Name */
1540 G_TYPE_UINT, /* Presence type */
1541 G_TYPE_STRING, /* Status string */
1542 G_TYPE_BOOLEAN, /* Compact view */
1543 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1544 G_TYPE_BOOLEAN, /* Is group */
1545 G_TYPE_BOOLEAN, /* Is active */
1546 G_TYPE_BOOLEAN, /* Is online */
1547 G_TYPE_BOOLEAN, /* Is separator */
1548 G_TYPE_BOOLEAN, /* Can make audio calls */
1549 G_TYPE_BOOLEAN, /* Can make video calls */
1550 G_TYPE_BOOLEAN, /* Is a fake group */
1551 G_TYPE_STRV, /* Client types */
1554 priv = GET_PRIV (self);
1556 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1557 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1559 /* Set up sorting */
1560 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1561 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1562 individual_store_name_sort_func, self, NULL);
1563 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1564 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1565 individual_store_state_sort_func, self, NULL);
1567 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1568 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1572 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1574 EmpathyIndividualStorePriv *priv;
1576 priv = GET_PRIV (self);
1578 priv->show_active = TRUE;
1579 priv->inhibit_active = 0;
1585 empathy_individual_store_init (EmpathyIndividualStore *self)
1587 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1588 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1591 priv->show_avatars = TRUE;
1592 priv->show_groups = TRUE;
1593 priv->show_protocols = FALSE;
1594 priv->inhibit_active =
1595 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1596 (GSourceFunc) individual_store_inhibit_active_cb, self);
1597 priv->status_icons =
1598 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1599 individual_store_setup (self);
1602 EmpathyIndividualStore *
1603 empathy_individual_store_new (EmpathyIndividualManager *manager)
1605 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1607 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1608 "individual-manager", manager, NULL);
1611 EmpathyIndividualManager *
1612 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1614 EmpathyIndividualStorePriv *priv;
1616 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1618 priv = GET_PRIV (self);
1620 return priv->manager;
1624 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1626 EmpathyIndividualStorePriv *priv;
1628 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1630 priv = GET_PRIV (self);
1632 return priv->show_avatars;
1636 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1639 EmpathyIndividualStore *self)
1641 EmpathyIndividualStorePriv *priv;
1642 gboolean show_avatar = FALSE;
1643 FolksIndividual *individual;
1644 GdkPixbuf *pixbuf_status;
1646 priv = GET_PRIV (self);
1648 if (priv->show_avatars && !priv->is_compact)
1653 gtk_tree_model_get (model, iter,
1654 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1656 if (individual == NULL)
1660 /* get icon from hash_table */
1662 empathy_individual_store_get_individual_status_icon (self, individual);
1664 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1665 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1666 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1667 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1669 g_object_unref (individual);
1675 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1676 gboolean show_avatars)
1678 EmpathyIndividualStorePriv *priv;
1679 GtkTreeModel *model;
1681 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1683 priv = GET_PRIV (self);
1685 priv->show_avatars = show_avatars;
1687 model = GTK_TREE_MODEL (self);
1689 gtk_tree_model_foreach (model,
1690 (GtkTreeModelForeachFunc)
1691 individual_store_update_list_mode_foreach, self);
1693 g_object_notify (G_OBJECT (self), "show-avatars");
1697 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1699 EmpathyIndividualStorePriv *priv;
1701 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1703 priv = GET_PRIV (self);
1705 return priv->show_protocols;
1709 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1710 gboolean show_protocols)
1712 EmpathyIndividualStorePriv *priv;
1713 GtkTreeModel *model;
1715 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1717 priv = GET_PRIV (self);
1719 priv->show_protocols = show_protocols;
1721 model = GTK_TREE_MODEL (self);
1723 gtk_tree_model_foreach (model,
1724 (GtkTreeModelForeachFunc)
1725 individual_store_update_list_mode_foreach, self);
1727 g_object_notify (G_OBJECT (self), "show-protocols");
1731 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1733 EmpathyIndividualStorePriv *priv;
1735 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1737 priv = GET_PRIV (self);
1739 return priv->show_groups;
1743 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1744 gboolean show_groups)
1746 EmpathyIndividualStorePriv *priv;
1748 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1750 priv = GET_PRIV (self);
1752 if (priv->show_groups == show_groups)
1757 priv->show_groups = show_groups;
1759 if (priv->setup_idle_id == 0)
1761 /* Remove all contacts and add them back, not optimized but
1762 * that's the easy way :)
1764 * This is only done if there's not a pending setup idle
1765 * callback, otherwise it will race and the contacts will get
1769 gtk_tree_store_clear (GTK_TREE_STORE (self));
1770 contacts = empathy_individual_manager_get_members (priv->manager);
1772 individual_store_members_changed_cb (priv->manager,
1773 "re-adding members: toggled group visibility",
1774 contacts, NULL, 0, self);
1775 g_list_free (contacts);
1778 g_object_notify (G_OBJECT (self), "show-groups");
1782 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1784 EmpathyIndividualStorePriv *priv;
1786 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1788 priv = GET_PRIV (self);
1790 return priv->is_compact;
1794 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1795 gboolean is_compact)
1797 EmpathyIndividualStorePriv *priv;
1798 GtkTreeModel *model;
1800 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1802 priv = GET_PRIV (self);
1804 priv->is_compact = is_compact;
1806 model = GTK_TREE_MODEL (self);
1808 gtk_tree_model_foreach (model,
1809 (GtkTreeModelForeachFunc)
1810 individual_store_update_list_mode_foreach, self);
1812 g_object_notify (G_OBJECT (self), "is-compact");
1815 EmpathyIndividualStoreSort
1816 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1818 EmpathyIndividualStorePriv *priv;
1820 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1822 priv = GET_PRIV (self);
1824 return priv->sort_criterium;
1828 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1829 EmpathyIndividualStoreSort sort_criterium)
1831 EmpathyIndividualStorePriv *priv;
1833 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1835 priv = GET_PRIV (self);
1837 priv->sort_criterium = sort_criterium;
1839 switch (sort_criterium)
1841 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1842 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1843 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1846 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1847 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1848 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1852 g_assert_not_reached ();
1855 g_object_notify (G_OBJECT (self), "sort-criterium");
1859 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1863 gboolean is_separator = FALSE;
1865 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1867 gtk_tree_model_get (model, iter,
1868 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1870 return is_separator;
1874 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1876 gboolean *path_is_group,
1877 gboolean *is_fake_group)
1879 GtkTreeIter parent_iter, iter;
1882 gboolean fake = FALSE;
1884 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1888 *path_is_group = FALSE;
1891 if (!gtk_tree_model_get_iter (model, &iter, path))
1896 gtk_tree_model_get (model, &iter,
1897 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1898 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1905 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1912 gtk_tree_model_get (model, &iter,
1913 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1914 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1915 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1925 *path_is_group = TRUE;
1928 if (is_fake_group != NULL)
1929 *is_fake_group = fake;
1935 individual_store_get_individual_status_icon_with_icon_name (
1936 EmpathyIndividualStore *self,
1937 FolksIndividual *individual,
1938 const gchar *status_icon_name)
1940 GdkPixbuf *pixbuf_status = NULL;
1941 EmpathyIndividualStorePriv *priv;
1942 const gchar *protocol_name = NULL;
1943 gchar *icon_name = NULL;
1944 GList *personas, *l;
1945 guint contact_count;
1946 EmpathyContact *contact = NULL;
1947 gboolean show_protocols_here;
1949 priv = GET_PRIV (self);
1951 personas = folks_individual_get_personas (individual);
1952 for (l = personas, contact_count = 0; l; l = l->next)
1954 if (TPF_IS_PERSONA (l->data))
1957 if (contact_count > 1)
1961 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1962 if (show_protocols_here)
1964 contact = empathy_contact_dup_from_folks_individual (individual);
1965 protocol_name = empathy_protocol_name_for_contact (contact);
1966 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1970 icon_name = g_strdup_printf ("%s", status_icon_name);
1972 if (pixbuf_status == NULL)
1975 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1976 status_icon_name, show_protocols_here);
1977 if (pixbuf_status != NULL)
1979 g_hash_table_insert (priv->status_icons,
1980 g_strdup (icon_name), pixbuf_status);
1985 tp_clear_object (&contact);
1987 return pixbuf_status;
1991 empathy_individual_store_get_individual_status_icon (
1992 EmpathyIndividualStore *self,
1993 FolksIndividual *individual)
1995 GdkPixbuf *pixbuf_status = NULL;
1996 const gchar *status_icon_name = NULL;
1998 status_icon_name = empathy_icon_name_for_individual (individual);
1999 if (status_icon_name == NULL)
2003 individual_store_get_individual_status_icon_with_icon_name (self,
2004 individual, status_icon_name);
2006 return pixbuf_status;