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;
158 add_individual_to_store (GtkTreeStore *self,
161 FolksIndividual *individual,
162 EmpathyIndividualManagerFlags flags)
164 gboolean can_audio_call, can_video_call;
166 individual_can_audio_video_call (individual, &can_audio_call,
169 gtk_tree_store_insert_with_values (self, iter, parent, 0,
170 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
171 folks_individual_get_alias (individual),
172 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
173 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
174 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
175 EMPATHY_INDIVIDUAL_STORE_COL_FLAGS, flags,
176 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
177 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
182 individual_store_get_group_foreach (GtkTreeModel *model,
190 /* Groups are only at the top level. */
191 if (gtk_tree_path_get_depth (path) != 1)
194 gtk_tree_model_get (model, iter,
195 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
196 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
198 if (is_group && !tp_strdiff (str, fg->name))
210 individual_store_get_group (EmpathyIndividualStore *self,
212 GtkTreeIter *iter_group_to_set,
213 GtkTreeIter *iter_separator_to_set,
215 gboolean is_fake_group)
217 EmpathyIndividualStorePriv *priv;
219 GtkTreeIter iter_group;
220 GtkTreeIter iter_separator;
223 priv = GET_PRIV (self);
225 memset (&fg, 0, sizeof (fg));
229 model = GTK_TREE_MODEL (self);
230 gtk_tree_model_foreach (model,
231 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
238 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
240 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
241 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
242 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
243 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
244 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
245 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
248 if (iter_group_to_set)
249 *iter_group_to_set = iter_group;
251 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
253 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
256 if (iter_separator_to_set)
257 *iter_separator_to_set = iter_separator;
264 if (iter_group_to_set)
265 *iter_group_to_set = fg.iter;
267 iter_separator = fg.iter;
269 if (gtk_tree_model_iter_next (model, &iter_separator))
271 gboolean is_separator;
273 gtk_tree_model_get (model, &iter_separator,
274 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
276 if (is_separator && iter_separator_to_set)
277 *iter_separator_to_set = iter_separator;
283 individual_store_find_contact_foreach (GtkTreeModel *model,
288 FolksIndividual *individual;
290 gtk_tree_model_get (model, iter,
291 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
293 if (individual == fc->individual)
296 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
299 tp_clear_object (&individual);
305 individual_store_find_contact (EmpathyIndividualStore *self,
306 FolksIndividual *individual)
308 EmpathyIndividualStorePriv *priv;
313 priv = GET_PRIV (self);
315 memset (&fc, 0, sizeof (fc));
317 fc.individual = individual;
319 model = GTK_TREE_MODEL (self);
320 gtk_tree_model_foreach (model,
321 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
330 individual_store_remove_individual (EmpathyIndividualStore *self,
331 FolksIndividual *individual)
333 EmpathyIndividualStorePriv *priv;
337 priv = GET_PRIV (self);
339 iters = individual_store_find_contact (self, individual);
344 model = GTK_TREE_MODEL (self);
346 for (l = iters; l; l = l->next)
350 /* NOTE: it is only <= 2 here because we have
351 * separators after the group name, otherwise it
354 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
355 gtk_tree_model_iter_n_children (model, &parent) <= 2)
357 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
361 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
365 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
370 individual_store_add_individual (EmpathyIndividualStore *self,
371 FolksIndividual *individual)
373 EmpathyIndividualStorePriv *priv;
375 GHashTable *group_set = NULL;
376 GList *groups = NULL, *l;
377 EmpathyContact *contact;
378 TpConnection *connection;
379 EmpathyIndividualManagerFlags flags = 0;
380 gchar *protocol_name;
382 priv = GET_PRIV (self);
384 if (EMP_STR_EMPTY (folks_individual_get_alias (individual)))
387 if (priv->show_groups)
389 group_set = folks_individual_get_groups (individual);
390 groups = g_hash_table_get_keys (group_set);
393 contact = empathy_contact_dup_from_folks_individual (individual);
394 connection = empathy_contact_get_connection (contact);
395 flags = empathy_individual_manager_get_flags_for_connection (priv->manager,
398 tp_connection_parse_object_path (connection, &protocol_name, NULL);
402 GtkTreeIter iter_group, *parent;
404 parent = &iter_group;
406 if (!priv->show_groups)
408 else if (!tp_strdiff (protocol_name, "local-xmpp"))
410 /* these are People Nearby */
411 individual_store_get_group (self,
412 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
417 individual_store_get_group (self,
418 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
419 &iter_group, NULL, NULL, TRUE);
422 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
426 g_free (protocol_name);
428 /* Else add to each group. */
429 for (l = groups; l; l = l->next)
431 GtkTreeIter iter_group;
433 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
436 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
439 g_list_free (groups);
440 if (group_set != NULL)
441 g_hash_table_unref (group_set);
443 if (priv->show_groups &&
444 folks_favourite_get_is_favourite (FOLKS_FAVOURITE (individual)))
446 /* Add contact to the fake 'Favorites' group */
447 GtkTreeIter iter_group;
449 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
450 &iter_group, NULL, NULL, TRUE);
452 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
456 individual_store_contact_update (self, individual);
458 tp_clear_object (&contact);
462 individual_store_contact_set_active (EmpathyIndividualStore *self,
463 FolksIndividual *individual,
465 gboolean set_changed)
467 EmpathyIndividualStorePriv *priv;
471 priv = GET_PRIV (self);
472 model = GTK_TREE_MODEL (self);
474 iters = individual_store_find_contact (self, individual);
475 for (l = iters; l; l = l->next)
479 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
480 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
483 DEBUG ("Set item %s", active ? "active" : "inactive");
487 path = gtk_tree_model_get_path (model, l->data);
488 gtk_tree_model_row_changed (model, path, l->data);
489 gtk_tree_path_free (path);
493 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
498 static void individual_store_contact_active_free (ShowActiveData *data);
501 individual_store_contact_active_invalidated (ShowActiveData *data,
504 /* Remove the timeout and free the struct, since the individual or individual
505 * store has disappeared. */
506 g_source_remove (data->timeout);
508 if (old_object == (GObject *) data->self)
510 else if (old_object == (GObject *) data->individual)
511 data->individual = NULL;
513 g_assert_not_reached ();
515 individual_store_contact_active_free (data);
518 static ShowActiveData *
519 individual_store_contact_active_new (EmpathyIndividualStore *self,
520 FolksIndividual *individual,
523 ShowActiveData *data;
525 DEBUG ("Individual'%s' now active, and %s be removed",
526 folks_individual_get_alias (individual), remove_ ? "WILL" : "WILL NOT");
528 data = g_slice_new0 (ShowActiveData);
530 /* We don't actually want to force either the IndividualStore or the
531 * Individual to stay alive, since the user could quit Empathy or disable
532 * the account before the contact_active timeout is fired. */
533 g_object_weak_ref (G_OBJECT (self),
534 (GWeakNotify) individual_store_contact_active_invalidated, data);
535 g_object_weak_ref (G_OBJECT (individual),
536 (GWeakNotify) individual_store_contact_active_invalidated, data);
539 data->individual = individual;
540 data->remove = remove_;
547 individual_store_contact_active_free (ShowActiveData *data)
549 if (data->self != NULL)
551 g_object_weak_unref (G_OBJECT (data->self),
552 (GWeakNotify) individual_store_contact_active_invalidated, data);
555 if (data->individual != NULL)
557 g_object_weak_unref (G_OBJECT (data->individual),
558 (GWeakNotify) individual_store_contact_active_invalidated, data);
561 g_slice_free (ShowActiveData, data);
565 individual_store_contact_active_cb (ShowActiveData *data)
569 DEBUG ("Individual'%s' active timeout, removing item",
570 folks_individual_get_alias (data->individual));
571 individual_store_remove_individual (data->self, data->individual);
574 DEBUG ("Individual'%s' no longer active",
575 folks_individual_get_alias (data->individual));
577 individual_store_contact_set_active (data->self,
578 data->individual, FALSE, TRUE);
580 individual_store_contact_active_free (data);
586 EmpathyIndividualStore *store; /* weak */
587 GCancellable *cancellable; /* owned */
591 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
592 GAsyncResult *result,
593 LoadAvatarData *data)
595 GError *error = NULL;
598 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
603 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
604 folks_individual_get_alias (individual),
606 g_clear_error (&error);
608 else if (data->store != NULL)
612 iters = individual_store_find_contact (data->store, individual);
613 for (l = iters; l; l = l->next)
615 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
616 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
622 if (data->store != NULL)
624 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
626 g_object_remove_weak_pointer (G_OBJECT (data->store),
627 (gpointer *) &data->store);
628 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
632 g_object_unref (data->cancellable);
633 g_slice_free (LoadAvatarData, data);
637 individual_store_contact_update (EmpathyIndividualStore *self,
638 FolksIndividual *individual)
640 EmpathyIndividualStorePriv *priv;
641 ShowActiveData *data;
645 gboolean was_online = TRUE;
646 gboolean now_online = FALSE;
647 gboolean set_model = FALSE;
648 gboolean do_remove = FALSE;
649 gboolean do_set_active = FALSE;
650 gboolean do_set_refresh = FALSE;
651 gboolean show_avatar = FALSE;
652 GdkPixbuf *pixbuf_status;
653 LoadAvatarData *load_avatar_data;
655 priv = GET_PRIV (self);
657 model = GTK_TREE_MODEL (self);
659 iters = individual_store_find_contact (self, individual);
669 /* Get online state now. */
670 now_online = folks_individual_is_online (individual);
674 DEBUG ("Individual'%s' in list:NO, should be:YES",
675 folks_individual_get_alias (individual));
677 individual_store_add_individual (self, individual);
679 if (priv->show_active)
681 do_set_active = TRUE;
683 DEBUG ("Set active (individual added)");
688 DEBUG ("Individual'%s' in list:YES, should be:YES",
689 folks_individual_get_alias (individual));
691 /* Get online state before. */
692 if (iters && g_list_length (iters) > 0)
694 gtk_tree_model_get (model, iters->data,
695 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
698 /* Is this really an update or an online/offline. */
699 if (priv->show_active)
701 if (was_online != now_online)
703 do_set_active = TRUE;
704 do_set_refresh = TRUE;
706 DEBUG ("Set active (individual updated %s)",
707 was_online ? "online -> offline" : "offline -> online");
711 /* Was TRUE for presence updates. */
712 /* do_set_active = FALSE; */
713 do_set_refresh = TRUE;
715 DEBUG ("Set active (individual updated)");
722 if (priv->show_avatars && !priv->is_compact)
727 /* Load the avatar asynchronously */
728 load_avatar_data = g_slice_new (LoadAvatarData);
729 load_avatar_data->store = self;
730 g_object_add_weak_pointer (G_OBJECT (self),
731 (gpointer *) &load_avatar_data->store);
732 load_avatar_data->cancellable = g_cancellable_new ();
734 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
735 load_avatar_data->cancellable);
736 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
737 load_avatar_data->cancellable,
738 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
742 empathy_individual_store_get_individual_status_icon (self, individual);
744 for (l = iters; l && set_model; l = l->next)
746 gboolean can_audio_call, can_video_call;
748 individual_can_audio_video_call (individual, &can_audio_call,
751 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
752 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
753 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
754 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
755 folks_individual_get_alias (individual),
756 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
757 folks_individual_get_presence_type (individual),
758 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
759 folks_individual_get_presence_message (individual),
760 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
761 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
762 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
763 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
764 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
765 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
769 if (priv->show_active && do_set_active)
771 individual_store_contact_set_active (self, individual, do_set_active,
777 individual_store_contact_active_new (self, individual,
779 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
780 (GSourceFunc) individual_store_contact_active_cb, data);
784 /* FIXME: when someone goes online then offline quickly, the
785 * first timeout sets the user to be inactive and the second
786 * timeout removes the user from the contact list, really we
787 * should remove the first timeout.
789 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
794 individual_store_individual_updated_cb (FolksIndividual *individual,
796 EmpathyIndividualStore *self)
798 DEBUG ("Individual'%s' updated, checking roster is in sync...",
799 folks_individual_get_alias (individual));
801 individual_store_contact_update (self, individual);
805 individual_store_contact_updated_cb (EmpathyContact *contact,
807 EmpathyIndividualStore *self)
809 FolksIndividual *individual;
811 DEBUG ("Contact '%s' updated, checking roster is in sync...",
812 empathy_contact_get_alias (contact));
814 individual = g_object_get_data (G_OBJECT (contact), "individual");
815 if (individual == NULL)
818 individual_store_contact_update (self, individual);
822 individual_personas_changed_cb (FolksIndividual *individual,
825 EmpathyIndividualStore *self)
829 DEBUG ("Individual '%s' personas-changed.",
830 folks_individual_get_id (individual));
832 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
833 * through the EmpathyContacts for them. */
834 for (l = removed; l != NULL; l = l->next)
836 TpContact *tp_contact;
837 EmpathyContact *contact;
839 if (!TPF_IS_PERSONA (l->data))
842 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
843 contact = empathy_contact_dup_from_tp_contact (tp_contact);
844 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
846 g_object_set_data (G_OBJECT (contact), "individual", NULL);
847 g_signal_handlers_disconnect_by_func (contact,
848 (GCallback) individual_store_contact_updated_cb, self);
850 g_object_unref (contact);
853 for (l = added; l != NULL; l = l->next)
855 TpContact *tp_contact;
856 EmpathyContact *contact;
858 if (!TPF_IS_PERSONA (l->data))
861 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
862 contact = empathy_contact_dup_from_tp_contact (tp_contact);
863 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
865 g_object_set_data (G_OBJECT (contact), "individual", individual);
866 g_signal_connect (contact, "notify::capabilities",
867 (GCallback) individual_store_contact_updated_cb, self);
869 g_object_unref (contact);
874 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
875 FolksIndividual *individual)
877 individual_store_add_individual (self, individual);
879 g_signal_connect (individual, "notify::avatar",
880 (GCallback) individual_store_individual_updated_cb, self);
881 g_signal_connect (individual, "notify::presence-type",
882 (GCallback) individual_store_individual_updated_cb, self);
883 g_signal_connect (individual, "notify::presence-message",
884 (GCallback) individual_store_individual_updated_cb, self);
885 g_signal_connect (individual, "notify::alias",
886 (GCallback) individual_store_individual_updated_cb, self);
887 g_signal_connect (individual, "personas-changed",
888 (GCallback) individual_personas_changed_cb, self);
890 individual_personas_changed_cb (individual,
891 folks_individual_get_personas (individual), NULL, self);
895 individual_store_disconnect_individual (EmpathyIndividualStore *self,
896 FolksIndividual *individual)
898 individual_personas_changed_cb (individual, NULL,
899 folks_individual_get_personas (individual), self);
901 g_signal_handlers_disconnect_by_func (individual,
902 (GCallback) individual_store_individual_updated_cb, self);
903 g_signal_handlers_disconnect_by_func (individual,
904 (GCallback) individual_personas_changed_cb, self);
908 individual_store_remove_individual_and_disconnect (
909 EmpathyIndividualStore *self,
910 FolksIndividual *individual)
912 individual_store_disconnect_individual (self, individual);
913 individual_store_remove_individual (self, individual);
917 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
918 const gchar *message,
922 EmpathyIndividualStore *self)
926 for (l = added; l; l = l->next)
928 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
930 individual_store_add_individual_and_connect (self, l->data);
932 for (l = removed; l; l = l->next)
934 DEBUG ("Individual %s %s",
935 folks_individual_get_id (l->data), "removed");
937 individual_store_remove_individual_and_disconnect (self, l->data);
942 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
943 FolksIndividual *individual,
944 gboolean is_favourite,
945 EmpathyIndividualStore *self)
947 EmpathyIndividualStorePriv *priv;
949 priv = GET_PRIV (self);
951 DEBUG ("Individual %s is %s a favourite",
952 folks_individual_get_id (individual),
953 is_favourite ? "now" : "no longer");
955 individual_store_remove_individual (self, individual);
956 individual_store_add_individual (self, individual);
960 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
961 FolksIndividual *individual,
964 EmpathyIndividualStore *self)
966 EmpathyIndividualStorePriv *priv;
967 gboolean show_active;
969 priv = GET_PRIV (self);
971 DEBUG ("Updating groups for individual %s",
972 folks_individual_get_id (individual));
974 /* We do this to make sure the groups are correct, if not, we
975 * would have to check the groups already set up for each
976 * contact and then see what has been updated.
978 show_active = priv->show_active;
979 priv->show_active = FALSE;
980 individual_store_remove_individual (self, individual);
981 individual_store_add_individual (self, individual);
982 priv->show_active = show_active;
986 individual_store_manager_setup (gpointer user_data)
988 EmpathyIndividualStore *self = user_data;
989 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
992 /* Signal connection. */
994 /* TODO: implement */
995 DEBUG ("handling individual renames unimplemented");
997 g_signal_connect (priv->manager,
999 G_CALLBACK (individual_store_members_changed_cb), self);
1001 g_signal_connect (priv->manager,
1002 "favourites-changed",
1003 G_CALLBACK (individual_store_favourites_changed_cb), self);
1005 g_signal_connect (priv->manager,
1007 G_CALLBACK (individual_store_groups_changed_cb), self);
1009 /* Add contacts already created. */
1010 individuals = empathy_individual_manager_get_members (priv->manager);
1011 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1013 individual_store_members_changed_cb (priv->manager, "initial add",
1014 individuals, NULL, 0, self);
1015 g_list_free (individuals);
1018 priv->setup_idle_id = 0;
1023 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1024 EmpathyIndividualManager *manager)
1026 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1028 priv->manager = g_object_ref (manager);
1030 /* Let a chance to have all properties set before populating */
1031 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1035 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1036 FolksIndividual *old_individual,
1037 FolksIndividual *new_individual,
1039 const gchar *message,
1040 EmpathyIndividualStore *self)
1042 EmpathyIndividualStorePriv *priv;
1044 priv = GET_PRIV (self);
1046 DEBUG ("Individual %s renamed to %s",
1047 folks_individual_get_id (old_individual),
1048 folks_individual_get_id (new_individual));
1050 /* add the new contact */
1051 individual_store_add_individual_and_connect (self, new_individual);
1053 /* remove old contact */
1054 individual_store_remove_individual_and_disconnect (self, old_individual);
1058 individual_store_dispose (GObject *object)
1060 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1061 GList *individuals, *l;
1063 if (priv->dispose_has_run)
1065 priv->dispose_has_run = TRUE;
1067 /* Cancel any pending avatar load operations */
1068 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1070 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1071 g_cancellable_cancel (G_CANCELLABLE (l->data));
1073 g_list_free (priv->avatar_cancellables);
1075 individuals = empathy_individual_manager_get_members (priv->manager);
1076 for (l = individuals; l; l = l->next)
1078 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1079 FOLKS_INDIVIDUAL (l->data));
1081 g_list_free (individuals);
1083 g_signal_handlers_disconnect_by_func (priv->manager,
1084 G_CALLBACK (individual_store_member_renamed_cb), object);
1085 g_signal_handlers_disconnect_by_func (priv->manager,
1086 G_CALLBACK (individual_store_members_changed_cb), object);
1087 g_signal_handlers_disconnect_by_func (priv->manager,
1088 G_CALLBACK (individual_store_favourites_changed_cb), object);
1089 g_signal_handlers_disconnect_by_func (priv->manager,
1090 G_CALLBACK (individual_store_groups_changed_cb), object);
1091 g_object_unref (priv->manager);
1093 if (priv->inhibit_active)
1095 g_source_remove (priv->inhibit_active);
1098 if (priv->setup_idle_id != 0)
1100 g_source_remove (priv->setup_idle_id);
1103 g_hash_table_destroy (priv->status_icons);
1104 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1108 individual_store_get_property (GObject *object,
1113 EmpathyIndividualStorePriv *priv;
1115 priv = GET_PRIV (object);
1119 case PROP_INDIVIDUAL_MANAGER:
1120 g_value_set_object (value, priv->manager);
1122 case PROP_SHOW_AVATARS:
1123 g_value_set_boolean (value, priv->show_avatars);
1125 case PROP_SHOW_PROTOCOLS:
1126 g_value_set_boolean (value, priv->show_protocols);
1128 case PROP_SHOW_GROUPS:
1129 g_value_set_boolean (value, priv->show_groups);
1131 case PROP_IS_COMPACT:
1132 g_value_set_boolean (value, priv->is_compact);
1134 case PROP_SORT_CRITERIUM:
1135 g_value_set_enum (value, priv->sort_criterium);
1138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1144 individual_store_set_property (GObject *object,
1146 const GValue *value,
1149 EmpathyIndividualStorePriv *priv;
1151 priv = GET_PRIV (object);
1155 case PROP_INDIVIDUAL_MANAGER:
1156 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1157 (object), g_value_get_object (value));
1159 case PROP_SHOW_AVATARS:
1160 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1161 (object), g_value_get_boolean (value));
1163 case PROP_SHOW_PROTOCOLS:
1164 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1165 (object), g_value_get_boolean (value));
1167 case PROP_SHOW_GROUPS:
1168 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1169 (object), g_value_get_boolean (value));
1171 case PROP_IS_COMPACT:
1172 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1173 (object), g_value_get_boolean (value));
1175 case PROP_SORT_CRITERIUM:
1176 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1177 (object), g_value_get_enum (value));
1180 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1186 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1188 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1190 object_class->dispose = individual_store_dispose;
1191 object_class->get_property = individual_store_get_property;
1192 object_class->set_property = individual_store_set_property;
1194 g_object_class_install_property (object_class,
1195 PROP_INDIVIDUAL_MANAGER,
1196 g_param_spec_object ("individual-manager",
1197 "The individual manager",
1198 "The individual manager",
1199 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1200 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1201 g_object_class_install_property (object_class,
1203 g_param_spec_boolean ("show-avatars",
1205 "Whether contact list should display "
1206 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1207 g_object_class_install_property (object_class,
1208 PROP_SHOW_PROTOCOLS,
1209 g_param_spec_boolean ("show-protocols",
1211 "Whether contact list should display "
1212 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1213 g_object_class_install_property (object_class,
1215 g_param_spec_boolean ("show-groups",
1217 "Whether contact list should display "
1218 "contact groups", TRUE, G_PARAM_READWRITE));
1219 g_object_class_install_property (object_class,
1221 g_param_spec_boolean ("is-compact",
1223 "Whether the contact list is in compact mode or not",
1224 FALSE, G_PARAM_READWRITE));
1226 g_object_class_install_property (object_class,
1227 PROP_SORT_CRITERIUM,
1228 g_param_spec_enum ("sort-criterium",
1230 "The sort criterium to use for sorting the contact list",
1231 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1232 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1234 g_type_class_add_private (object_class,
1235 sizeof (EmpathyIndividualStorePriv));
1239 get_position (const char **strv,
1244 for (i = 0; strv[i] != NULL; i++)
1246 if (!tp_strdiff (strv[i], str))
1254 compare_separator_and_groups (gboolean is_separator_a,
1255 gboolean is_separator_b,
1256 const gchar *name_a,
1257 const gchar *name_b,
1258 FolksIndividual *individual_a,
1259 FolksIndividual *individual_b,
1260 gboolean fake_group_a,
1261 gboolean fake_group_b)
1263 /* these two lists are the sorted list of fake groups to include at the
1264 * top and bottom of the roster */
1265 const char *top_groups[] = {
1266 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1270 const char *bottom_groups[] = {
1271 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1275 if (is_separator_a || is_separator_b)
1277 /* We have at least one separator */
1282 else if (is_separator_b)
1288 /* One group and one contact */
1289 if (!individual_a && individual_b)
1293 else if (individual_a && !individual_b)
1297 else if (!individual_a && !individual_b)
1299 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1301 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1302 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1303 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1304 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1306 if (a_in_top && b_in_top)
1308 /* compare positions */
1309 return CLAMP (get_position (top_groups, name_a) -
1310 get_position (top_groups, name_b), -1, 1);
1312 else if (a_in_bottom && b_in_bottom)
1314 /* compare positions */
1315 return CLAMP (get_position (bottom_groups, name_a) -
1316 get_position (bottom_groups, name_b), -1, 1);
1318 else if (a_in_top || b_in_bottom)
1322 else if (b_in_top || a_in_bottom)
1328 return g_utf8_collate (name_a, name_b);
1332 /* Two contacts, ordering depends of the sorting policy */
1337 individual_store_contact_sort (FolksIndividual *individual_a,
1338 FolksIndividual *individual_b)
1341 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1342 TpAccount *account_a, *account_b;
1344 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1347 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1348 folks_individual_get_alias (individual_b));
1353 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1354 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1355 account_a = empathy_contact_get_account (contact_a);
1356 account_b = empathy_contact_get_account (contact_b);
1359 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1360 tp_account_get_protocol (account_b));
1366 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1367 tp_proxy_get_object_path (account_b));
1373 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1374 folks_individual_get_id (individual_b));
1377 tp_clear_object (&contact_a);
1378 tp_clear_object (&contact_b);
1384 individual_store_state_sort_func (GtkTreeModel *model,
1385 GtkTreeIter *iter_a,
1386 GtkTreeIter *iter_b,
1390 FolksIndividual *individual_a, *individual_b;
1391 gchar *name_a, *name_b;
1392 gboolean is_separator_a, is_separator_b;
1393 gboolean fake_group_a, fake_group_b;
1394 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1395 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1397 gtk_tree_model_get (model, iter_a,
1398 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1399 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1400 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1401 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1402 gtk_tree_model_get (model, iter_b,
1403 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1404 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1405 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1406 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1408 if (individual_a == NULL || individual_b == NULL)
1410 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1411 name_a, name_b, individual_a, individual_b, fake_group_a,
1416 /* If we managed to get this far, we can start looking at
1419 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1420 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1421 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1422 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1424 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1429 /* Fallback: compare by name et al. */
1430 ret_val = individual_store_contact_sort (individual_a, individual_b);
1436 tp_clear_object (&individual_a);
1437 tp_clear_object (&individual_b);
1443 individual_store_name_sort_func (GtkTreeModel *model,
1444 GtkTreeIter *iter_a,
1445 GtkTreeIter *iter_b,
1448 gchar *name_a, *name_b;
1449 FolksIndividual *individual_a, *individual_b;
1450 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1452 gboolean fake_group_a, fake_group_b;
1454 gtk_tree_model_get (model, iter_a,
1455 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1456 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1457 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1458 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1459 gtk_tree_model_get (model, iter_b,
1460 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1461 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1462 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1463 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1465 if (individual_a == NULL || individual_b == NULL)
1466 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1467 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1469 ret_val = individual_store_contact_sort (individual_a, individual_b);
1471 tp_clear_object (&individual_a);
1472 tp_clear_object (&individual_b);
1478 individual_store_setup (EmpathyIndividualStore *self)
1480 EmpathyIndividualStorePriv *priv;
1482 GDK_TYPE_PIXBUF, /* Status pixbuf */
1483 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1484 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1485 G_TYPE_STRING, /* Name */
1486 G_TYPE_UINT, /* Presence type */
1487 G_TYPE_STRING, /* Status string */
1488 G_TYPE_BOOLEAN, /* Compact view */
1489 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1490 G_TYPE_BOOLEAN, /* Is group */
1491 G_TYPE_BOOLEAN, /* Is active */
1492 G_TYPE_BOOLEAN, /* Is online */
1493 G_TYPE_BOOLEAN, /* Is separator */
1494 G_TYPE_BOOLEAN, /* Can make audio calls */
1495 G_TYPE_BOOLEAN, /* Can make video calls */
1496 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1497 G_TYPE_BOOLEAN, /* Is a fake group */
1500 priv = GET_PRIV (self);
1502 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1503 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1505 /* Set up sorting */
1506 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1507 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1508 individual_store_name_sort_func, self, NULL);
1509 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1510 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1511 individual_store_state_sort_func, self, NULL);
1513 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1514 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1518 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1520 EmpathyIndividualStorePriv *priv;
1522 priv = GET_PRIV (self);
1524 priv->show_active = TRUE;
1525 priv->inhibit_active = 0;
1531 empathy_individual_store_init (EmpathyIndividualStore *self)
1533 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1534 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1537 priv->show_avatars = TRUE;
1538 priv->show_groups = TRUE;
1539 priv->show_protocols = FALSE;
1540 priv->inhibit_active =
1541 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1542 (GSourceFunc) individual_store_inhibit_active_cb, self);
1543 priv->status_icons =
1544 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1545 individual_store_setup (self);
1548 EmpathyIndividualStore *
1549 empathy_individual_store_new (EmpathyIndividualManager *manager)
1551 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1553 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1554 "individual-manager", manager, NULL);
1557 EmpathyIndividualManager *
1558 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1560 EmpathyIndividualStorePriv *priv;
1562 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1564 priv = GET_PRIV (self);
1566 return priv->manager;
1570 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1572 EmpathyIndividualStorePriv *priv;
1574 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1576 priv = GET_PRIV (self);
1578 return priv->show_avatars;
1582 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1585 EmpathyIndividualStore *self)
1587 EmpathyIndividualStorePriv *priv;
1588 gboolean show_avatar = FALSE;
1589 FolksIndividual *individual;
1590 GdkPixbuf *pixbuf_status;
1592 priv = GET_PRIV (self);
1594 if (priv->show_avatars && !priv->is_compact)
1599 gtk_tree_model_get (model, iter,
1600 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1602 if (individual == NULL)
1606 /* get icon from hash_table */
1608 empathy_individual_store_get_individual_status_icon (self, individual);
1610 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1611 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1612 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1613 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1615 g_object_unref (individual);
1621 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1622 gboolean show_avatars)
1624 EmpathyIndividualStorePriv *priv;
1625 GtkTreeModel *model;
1627 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1629 priv = GET_PRIV (self);
1631 priv->show_avatars = show_avatars;
1633 model = GTK_TREE_MODEL (self);
1635 gtk_tree_model_foreach (model,
1636 (GtkTreeModelForeachFunc)
1637 individual_store_update_list_mode_foreach, self);
1639 g_object_notify (G_OBJECT (self), "show-avatars");
1643 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1645 EmpathyIndividualStorePriv *priv;
1647 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1649 priv = GET_PRIV (self);
1651 return priv->show_protocols;
1655 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1656 gboolean show_protocols)
1658 EmpathyIndividualStorePriv *priv;
1659 GtkTreeModel *model;
1661 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1663 priv = GET_PRIV (self);
1665 priv->show_protocols = show_protocols;
1667 model = GTK_TREE_MODEL (self);
1669 gtk_tree_model_foreach (model,
1670 (GtkTreeModelForeachFunc)
1671 individual_store_update_list_mode_foreach, self);
1673 g_object_notify (G_OBJECT (self), "show-protocols");
1677 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1679 EmpathyIndividualStorePriv *priv;
1681 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1683 priv = GET_PRIV (self);
1685 return priv->show_groups;
1689 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1690 gboolean show_groups)
1692 EmpathyIndividualStorePriv *priv;
1694 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1696 priv = GET_PRIV (self);
1698 if (priv->show_groups == show_groups)
1703 priv->show_groups = show_groups;
1705 if (priv->setup_idle_id == 0)
1707 /* Remove all contacts and add them back, not optimized but
1708 * that's the easy way :)
1710 * This is only done if there's not a pending setup idle
1711 * callback, otherwise it will race and the contacts will get
1715 gtk_tree_store_clear (GTK_TREE_STORE (self));
1716 contacts = empathy_individual_manager_get_members (priv->manager);
1718 individual_store_members_changed_cb (priv->manager,
1719 "re-adding members: toggled group visibility",
1720 contacts, NULL, 0, self);
1721 g_list_free (contacts);
1724 g_object_notify (G_OBJECT (self), "show-groups");
1728 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1730 EmpathyIndividualStorePriv *priv;
1732 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1734 priv = GET_PRIV (self);
1736 return priv->is_compact;
1740 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1741 gboolean is_compact)
1743 EmpathyIndividualStorePriv *priv;
1744 GtkTreeModel *model;
1746 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1748 priv = GET_PRIV (self);
1750 priv->is_compact = is_compact;
1752 model = GTK_TREE_MODEL (self);
1754 gtk_tree_model_foreach (model,
1755 (GtkTreeModelForeachFunc)
1756 individual_store_update_list_mode_foreach, self);
1758 g_object_notify (G_OBJECT (self), "is-compact");
1761 EmpathyIndividualStoreSort
1762 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1764 EmpathyIndividualStorePriv *priv;
1766 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1768 priv = GET_PRIV (self);
1770 return priv->sort_criterium;
1774 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1775 EmpathyIndividualStoreSort sort_criterium)
1777 EmpathyIndividualStorePriv *priv;
1779 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1781 priv = GET_PRIV (self);
1783 priv->sort_criterium = sort_criterium;
1785 switch (sort_criterium)
1787 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1788 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1789 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1792 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1793 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1794 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1798 g_assert_not_reached ();
1801 g_object_notify (G_OBJECT (self), "sort-criterium");
1805 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1809 gboolean is_separator = FALSE;
1811 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1813 gtk_tree_model_get (model, iter,
1814 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1816 return is_separator;
1820 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1822 gboolean *path_is_group,
1823 gboolean *is_fake_group)
1825 GtkTreeIter parent_iter, iter;
1830 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1834 *path_is_group = FALSE;
1837 if (!gtk_tree_model_get_iter (model, &iter, path))
1842 gtk_tree_model_get (model, &iter,
1843 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1844 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1851 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1858 gtk_tree_model_get (model, &iter,
1859 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1860 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1861 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1871 *path_is_group = TRUE;
1874 if (is_fake_group != NULL)
1875 *is_fake_group = fake;
1881 individual_store_get_individual_status_icon_with_icon_name (
1882 EmpathyIndividualStore *self,
1883 FolksIndividual *individual,
1884 const gchar *status_icon_name)
1886 GdkPixbuf *pixbuf_status = NULL;
1887 EmpathyIndividualStorePriv *priv;
1888 const gchar *protocol_name = NULL;
1889 gchar *icon_name = NULL;
1890 GList *personas, *l;
1891 guint contact_count;
1892 EmpathyContact *contact = NULL;
1893 gboolean show_protocols_here;
1895 priv = GET_PRIV (self);
1897 personas = folks_individual_get_personas (individual);
1898 for (l = personas, contact_count = 0; l; l = l->next)
1900 if (TPF_IS_PERSONA (l->data))
1903 if (contact_count > 1)
1907 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1908 if (show_protocols_here)
1910 contact = empathy_contact_dup_from_folks_individual (individual);
1911 protocol_name = empathy_protocol_name_for_contact (contact);
1912 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1916 icon_name = g_strdup_printf ("%s", status_icon_name);
1918 if (pixbuf_status == NULL)
1921 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1922 status_icon_name, show_protocols_here);
1923 if (pixbuf_status != NULL)
1925 g_hash_table_insert (priv->status_icons,
1926 g_strdup (icon_name), pixbuf_status);
1931 tp_clear_object (&contact);
1933 return pixbuf_status;
1937 empathy_individual_store_get_individual_status_icon (
1938 EmpathyIndividualStore *self,
1939 FolksIndividual *individual)
1941 GdkPixbuf *pixbuf_status = NULL;
1942 const gchar *status_icon_name = NULL;
1944 status_icon_name = empathy_icon_name_for_individual (individual);
1945 if (status_icon_name == NULL)
1949 individual_store_get_individual_status_icon_with_icon_name (self,
1950 individual, status_icon_name);
1952 return pixbuf_status;