1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2010 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
24 * Travis Reitter <travis.reitter@collabora.co.uk>
32 #include <glib/gi18n-lib.h>
35 #include <folks/folks.h>
36 #include <folks/folks-telepathy.h>
37 #include <telepathy-glib/util.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-enum-types.h>
41 #include <libempathy/empathy-individual-manager.h>
43 #include "empathy-individual-store.h"
44 #include "empathy-ui-utils.h"
45 #include "empathy-gtk-enum-types.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
48 #include <libempathy/empathy-debug.h>
50 /* Active users are those which have recently changed state
51 * (e.g. online, offline or from normal to a busy state).
54 /* Time in seconds user is shown as active */
55 #define ACTIVE_USER_SHOW_TIME 7
57 /* Time in seconds after connecting which we wait before active users are enabled */
58 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualStore)
63 EmpathyIndividualManager *manager;
64 gboolean show_avatars;
67 gboolean show_protocols;
69 EmpathyIndividualStoreSort sort_criterium;
72 gboolean dispose_has_run;
73 GHashTable *status_icons;
74 /* List of owned GCancellables for each pending avatar load operation */
75 GList *avatar_cancellables;
76 } EmpathyIndividualStorePriv;
87 FolksIndividual *individual;
94 EmpathyIndividualStore *self;
95 FolksIndividual *individual;
103 PROP_INDIVIDUAL_MANAGER,
111 /* prototypes to break cycles */
112 static void individual_store_contact_update (EmpathyIndividualStore *self,
113 FolksIndividual *individual);
115 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
116 GTK_TYPE_TREE_STORE);
118 /* Calculate whether the Individual can do audio or video calls.
119 * FIXME: We can remove this once libfolks has grown capabilities support
120 * again: bgo#626179. */
122 individual_can_audio_video_call (FolksIndividual *individual,
123 gboolean *can_audio_call,
124 gboolean *can_video_call)
128 gboolean can_audio = FALSE, can_video = FALSE;
130 personas = folks_individual_get_personas (individual);
131 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
132 while (gee_iterator_next (iter))
134 FolksPersona *persona = gee_iterator_get (iter);
135 TpContact *tp_contact;
136 EmpathyContact *contact;
138 if (!empathy_folks_persona_is_interesting (persona))
141 tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
142 contact = empathy_contact_dup_from_tp_contact (tp_contact);
143 empathy_contact_set_persona (contact, persona);
145 can_audio = can_audio || empathy_contact_get_capabilities (contact) &
146 EMPATHY_CAPABILITIES_AUDIO;
147 can_video = can_video || empathy_contact_get_capabilities (contact) &
148 EMPATHY_CAPABILITIES_VIDEO;
150 g_object_unref (contact);
152 g_clear_object (&persona);
154 if (can_audio && can_video)
157 g_clear_object (&iter);
159 *can_audio_call = can_audio;
160 *can_video_call = can_video;
163 static const gchar * const *
164 individual_get_client_types (FolksIndividual *individual)
168 const gchar * const *types = NULL;
169 FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
171 personas = folks_individual_get_personas (individual);
172 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
173 while (gee_iterator_next (iter))
175 FolksPresenceDetails *presence;
176 FolksPersona *persona = gee_iterator_get (iter);
178 /* We only want personas which have presence and a TpContact */
179 if (!empathy_folks_persona_is_interesting (persona))
182 presence = FOLKS_PRESENCE_DETAILS (persona);
184 if (folks_presence_details_typecmp (
185 folks_presence_details_get_presence_type (presence),
188 TpContact *tp_contact;
190 presence_type = folks_presence_details_get_presence_type (presence);
192 tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
193 types = tp_contact_get_client_types (tp_contact);
197 g_clear_object (&persona);
199 g_clear_object (&iter);
205 add_individual_to_store (GtkTreeStore *self,
208 FolksIndividual *individual)
210 gboolean can_audio_call, can_video_call;
211 const gchar * const *types;
213 individual_can_audio_video_call (individual, &can_audio_call,
216 types = individual_get_client_types (individual);
218 gtk_tree_store_insert_with_values (self, iter, parent, 0,
219 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
220 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
221 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
222 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
223 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
224 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
225 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
226 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
231 individual_store_get_group_foreach (GtkTreeModel *model,
239 /* Groups are only at the top level. */
240 if (gtk_tree_path_get_depth (path) != 1)
243 gtk_tree_model_get (model, iter,
244 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
245 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
247 if (is_group && !tp_strdiff (str, fg->name))
259 individual_store_get_group (EmpathyIndividualStore *self,
261 GtkTreeIter *iter_group_to_set,
262 GtkTreeIter *iter_separator_to_set,
264 gboolean is_fake_group)
267 GtkTreeIter iter_group;
268 GtkTreeIter iter_separator;
271 memset (&fg, 0, sizeof (fg));
275 model = GTK_TREE_MODEL (self);
276 gtk_tree_model_foreach (model,
277 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
284 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
286 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
287 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
288 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
289 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
290 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
291 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
294 if (iter_group_to_set)
295 *iter_group_to_set = iter_group;
297 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
299 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
302 if (iter_separator_to_set)
303 *iter_separator_to_set = iter_separator;
310 if (iter_group_to_set)
311 *iter_group_to_set = fg.iter;
313 iter_separator = fg.iter;
315 if (gtk_tree_model_iter_next (model, &iter_separator))
317 gboolean is_separator;
319 gtk_tree_model_get (model, &iter_separator,
320 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
322 if (is_separator && iter_separator_to_set)
323 *iter_separator_to_set = iter_separator;
329 individual_store_find_contact_foreach (GtkTreeModel *model,
334 FolksIndividual *individual;
336 gtk_tree_model_get (model, iter,
337 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
339 if (individual == fc->individual)
342 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
345 tp_clear_object (&individual);
351 individual_store_find_contact (EmpathyIndividualStore *self,
352 FolksIndividual *individual)
358 memset (&fc, 0, sizeof (fc));
360 fc.individual = individual;
362 model = GTK_TREE_MODEL (self);
363 gtk_tree_model_foreach (model,
364 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
373 free_iters (GList *iters)
375 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
380 individual_store_remove_individual (EmpathyIndividualStore *self,
381 FolksIndividual *individual)
386 iters = individual_store_find_contact (self, individual);
391 model = GTK_TREE_MODEL (self);
393 for (l = iters; l; l = l->next)
397 /* NOTE: it is only <= 2 here because we have
398 * separators after the group name, otherwise it
401 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
402 gtk_tree_model_iter_n_children (model, &parent) <= 2)
404 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
408 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
416 individual_store_add_individual (EmpathyIndividualStore *self,
417 FolksIndividual *individual)
419 EmpathyIndividualStorePriv *priv;
421 GHashTable *group_set = NULL;
422 GList *groups = NULL, *l;
423 EmpathyContact *contact;
424 TpConnection *connection;
425 gchar *protocol_name;
427 priv = GET_PRIV (self);
429 if (EMP_STR_EMPTY (folks_alias_details_get_alias (
430 FOLKS_ALIAS_DETAILS (individual))))
433 if (priv->show_groups)
435 group_set = folks_group_details_get_groups (
436 FOLKS_GROUP_DETAILS (individual));
437 groups = g_hash_table_get_keys (group_set);
440 contact = empathy_contact_dup_from_folks_individual (individual);
441 connection = empathy_contact_get_connection (contact);
443 tp_connection_parse_object_path (connection, &protocol_name, NULL);
447 GtkTreeIter iter_group, *parent;
449 parent = &iter_group;
451 if (!priv->show_groups)
453 else if (!tp_strdiff (protocol_name, "local-xmpp"))
455 /* these are People Nearby */
456 individual_store_get_group (self,
457 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
462 individual_store_get_group (self,
463 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
464 &iter_group, NULL, NULL, TRUE);
467 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
471 g_free (protocol_name);
473 /* Else add to each group. */
474 for (l = groups; l; l = l->next)
476 GtkTreeIter iter_group;
478 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
481 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
484 g_list_free (groups);
486 if (priv->show_groups &&
487 folks_favourite_details_get_is_favourite (
488 FOLKS_FAVOURITE_DETAILS (individual)))
490 /* Add contact to the fake 'Favorites' group */
491 GtkTreeIter iter_group;
493 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
494 &iter_group, NULL, NULL, TRUE);
496 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
500 individual_store_contact_update (self, individual);
502 tp_clear_object (&contact);
506 individual_store_contact_set_active (EmpathyIndividualStore *self,
507 FolksIndividual *individual,
509 gboolean set_changed)
514 model = GTK_TREE_MODEL (self);
516 iters = individual_store_find_contact (self, individual);
517 for (l = iters; l; l = l->next)
521 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
522 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
525 DEBUG ("Set item %s", active ? "active" : "inactive");
529 path = gtk_tree_model_get_path (model, l->data);
530 gtk_tree_model_row_changed (model, path, l->data);
531 gtk_tree_path_free (path);
538 static void individual_store_contact_active_free (ShowActiveData *data);
541 individual_store_contact_active_invalidated (ShowActiveData *data,
544 /* Remove the timeout and free the struct, since the individual or individual
545 * store has disappeared. */
546 g_source_remove (data->timeout);
548 if (old_object == (GObject *) data->self)
550 else if (old_object == (GObject *) data->individual)
551 data->individual = NULL;
553 g_assert_not_reached ();
555 individual_store_contact_active_free (data);
558 static ShowActiveData *
559 individual_store_contact_active_new (EmpathyIndividualStore *self,
560 FolksIndividual *individual,
563 ShowActiveData *data;
565 DEBUG ("Individual'%s' now active, and %s be removed",
566 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
567 remove_ ? "WILL" : "WILL NOT");
569 data = g_slice_new0 (ShowActiveData);
571 /* We don't actually want to force either the IndividualStore or the
572 * Individual to stay alive, since the user could quit Empathy or disable
573 * the account before the contact_active timeout is fired. */
574 g_object_weak_ref (G_OBJECT (self),
575 (GWeakNotify) individual_store_contact_active_invalidated, data);
576 g_object_weak_ref (G_OBJECT (individual),
577 (GWeakNotify) individual_store_contact_active_invalidated, data);
580 data->individual = individual;
581 data->remove = remove_;
588 individual_store_contact_active_free (ShowActiveData *data)
590 if (data->self != NULL)
592 g_object_weak_unref (G_OBJECT (data->self),
593 (GWeakNotify) individual_store_contact_active_invalidated, data);
596 if (data->individual != NULL)
598 g_object_weak_unref (G_OBJECT (data->individual),
599 (GWeakNotify) individual_store_contact_active_invalidated, data);
602 g_slice_free (ShowActiveData, data);
606 individual_store_contact_active_cb (ShowActiveData *data)
610 DEBUG ("Individual'%s' active timeout, removing item",
611 folks_alias_details_get_alias (
612 FOLKS_ALIAS_DETAILS (data->individual)));
613 individual_store_remove_individual (data->self, data->individual);
616 DEBUG ("Individual'%s' no longer active",
617 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
619 individual_store_contact_set_active (data->self,
620 data->individual, FALSE, TRUE);
622 individual_store_contact_active_free (data);
628 EmpathyIndividualStore *store; /* weak */
629 GCancellable *cancellable; /* owned */
633 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
634 GAsyncResult *result,
635 LoadAvatarData *data)
637 GError *error = NULL;
640 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
645 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
646 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
648 g_clear_error (&error);
650 else if (data->store != NULL)
654 iters = individual_store_find_contact (data->store, individual);
655 for (l = iters; l; l = l->next)
657 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
658 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
666 if (data->store != NULL)
668 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
670 g_object_remove_weak_pointer (G_OBJECT (data->store),
671 (gpointer *) &data->store);
672 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
676 tp_clear_object (&pixbuf);
677 g_object_unref (data->cancellable);
678 g_slice_free (LoadAvatarData, data);
682 individual_store_contact_update (EmpathyIndividualStore *self,
683 FolksIndividual *individual)
685 EmpathyIndividualStorePriv *priv;
686 ShowActiveData *data;
690 gboolean was_online = TRUE;
691 gboolean now_online = FALSE;
692 gboolean set_model = FALSE;
693 gboolean do_remove = FALSE;
694 gboolean do_set_active = FALSE;
695 gboolean do_set_refresh = FALSE;
696 gboolean show_avatar = FALSE;
697 GdkPixbuf *pixbuf_status;
698 LoadAvatarData *load_avatar_data;
700 priv = GET_PRIV (self);
702 model = GTK_TREE_MODEL (self);
704 iters = individual_store_find_contact (self, individual);
714 /* Get online state now. */
715 now_online = folks_presence_details_is_online (
716 FOLKS_PRESENCE_DETAILS (individual));
720 DEBUG ("Individual'%s' in list:NO, should be:YES",
721 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
723 individual_store_add_individual (self, individual);
725 if (priv->show_active)
727 do_set_active = TRUE;
729 DEBUG ("Set active (individual added)");
734 DEBUG ("Individual'%s' in list:YES, should be:YES",
735 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
737 /* Get online state before. */
738 if (iters && g_list_length (iters) > 0)
740 gtk_tree_model_get (model, iters->data,
741 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
744 /* Is this really an update or an online/offline. */
745 if (priv->show_active)
747 if (was_online != now_online)
749 do_set_active = TRUE;
750 do_set_refresh = TRUE;
752 DEBUG ("Set active (individual updated %s)",
753 was_online ? "online -> offline" : "offline -> online");
757 /* Was TRUE for presence updates. */
758 /* do_set_active = FALSE; */
759 do_set_refresh = TRUE;
761 DEBUG ("Set active (individual updated)");
768 if (priv->show_avatars && !priv->is_compact)
773 /* Load the avatar asynchronously */
774 load_avatar_data = g_slice_new (LoadAvatarData);
775 load_avatar_data->store = self;
776 g_object_add_weak_pointer (G_OBJECT (self),
777 (gpointer *) &load_avatar_data->store);
778 load_avatar_data->cancellable = g_cancellable_new ();
780 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
781 load_avatar_data->cancellable);
782 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
783 load_avatar_data->cancellable,
784 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
788 empathy_individual_store_get_individual_status_icon (self, individual);
790 for (l = iters; l && set_model; l = l->next)
792 gboolean can_audio_call, can_video_call;
793 const gchar * const *types;
795 individual_can_audio_video_call (individual, &can_audio_call,
798 types = individual_get_client_types (individual);
800 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
801 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
802 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
803 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
804 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
805 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
806 folks_presence_details_get_presence_type (
807 FOLKS_PRESENCE_DETAILS (individual)),
808 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
809 folks_presence_details_get_presence_message (
810 FOLKS_PRESENCE_DETAILS (individual)),
811 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
812 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
813 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
814 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
815 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
816 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
817 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
821 if (priv->show_active && do_set_active)
823 individual_store_contact_set_active (self, individual, do_set_active,
829 individual_store_contact_active_new (self, individual,
831 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
832 (GSourceFunc) individual_store_contact_active_cb, data);
836 /* FIXME: when someone goes online then offline quickly, the
837 * first timeout sets the user to be inactive and the second
838 * timeout removes the user from the contact list, really we
839 * should remove the first timeout.
845 individual_store_individual_updated_cb (FolksIndividual *individual,
847 EmpathyIndividualStore *self)
849 DEBUG ("Individual'%s' updated, checking roster is in sync...",
850 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
852 individual_store_contact_update (self, individual);
856 individual_store_contact_updated_cb (EmpathyContact *contact,
858 EmpathyIndividualStore *self)
860 FolksIndividual *individual;
862 DEBUG ("Contact '%s' updated, checking roster is in sync...",
863 empathy_contact_get_alias (contact));
865 individual = g_object_get_data (G_OBJECT (contact), "individual");
866 if (individual == NULL)
869 individual_store_contact_update (self, individual);
873 individual_personas_changed_cb (FolksIndividual *individual,
876 EmpathyIndividualStore *self)
880 DEBUG ("Individual '%s' personas-changed.",
881 folks_individual_get_id (individual));
883 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
884 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
885 * through the EmpathyContacts for them. */
886 while (gee_iterator_next (iter))
888 TpfPersona *persona = gee_iterator_get (iter);
889 TpContact *tp_contact;
890 EmpathyContact *contact;
892 if (TPF_IS_PERSONA (persona))
894 tp_contact = tpf_persona_get_contact (persona);
895 contact = empathy_contact_dup_from_tp_contact (tp_contact);
896 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
898 g_object_set_data (G_OBJECT (contact), "individual", NULL);
899 g_signal_handlers_disconnect_by_func (contact,
900 (GCallback) individual_store_contact_updated_cb, self);
902 g_object_unref (contact);
905 g_clear_object (&persona);
907 g_clear_object (&iter);
909 iter = gee_iterable_iterator (GEE_ITERABLE (added));
910 while (gee_iterator_next (iter))
912 TpfPersona *persona = gee_iterator_get (iter);
913 TpContact *tp_contact;
914 EmpathyContact *contact;
916 if (TPF_IS_PERSONA (persona))
918 tp_contact = tpf_persona_get_contact (persona);
919 contact = empathy_contact_dup_from_tp_contact (tp_contact);
920 empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
922 g_object_set_data (G_OBJECT (contact), "individual", individual);
923 g_signal_connect (contact, "notify::capabilities",
924 (GCallback) individual_store_contact_updated_cb, self);
925 g_signal_connect (contact, "notify::client-types",
926 (GCallback) individual_store_contact_updated_cb, self);
928 g_object_unref (contact);
931 g_clear_object (&persona);
933 g_clear_object (&iter);
937 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
938 FolksIndividual *individual)
940 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
942 individual_store_add_individual (self, individual);
944 g_signal_connect (individual, "notify::avatar",
945 (GCallback) individual_store_individual_updated_cb, self);
946 g_signal_connect (individual, "notify::presence-type",
947 (GCallback) individual_store_individual_updated_cb, self);
948 g_signal_connect (individual, "notify::presence-message",
949 (GCallback) individual_store_individual_updated_cb, self);
950 g_signal_connect (individual, "notify::alias",
951 (GCallback) individual_store_individual_updated_cb, self);
952 g_signal_connect (individual, "personas-changed",
953 (GCallback) individual_personas_changed_cb, self);
955 /* provide an empty set so the callback can assume non-NULL sets */
956 individual_personas_changed_cb (individual,
957 folks_individual_get_personas (individual), empty_set, self);
958 g_clear_object (&empty_set);
962 individual_store_disconnect_individual (EmpathyIndividualStore *self,
963 FolksIndividual *individual)
965 GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
967 /* provide an empty set so the callback can assume non-NULL sets */
968 individual_personas_changed_cb (individual, empty_set,
969 folks_individual_get_personas (individual), self);
970 g_clear_object (&empty_set);
972 g_signal_handlers_disconnect_by_func (individual,
973 (GCallback) individual_store_individual_updated_cb, self);
974 g_signal_handlers_disconnect_by_func (individual,
975 (GCallback) individual_personas_changed_cb, self);
979 individual_store_remove_individual_and_disconnect (
980 EmpathyIndividualStore *self,
981 FolksIndividual *individual)
983 individual_store_disconnect_individual (self, individual);
984 individual_store_remove_individual (self, individual);
988 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
989 const gchar *message,
993 EmpathyIndividualStore *self)
997 for (l = added; l; l = l->next)
999 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
1001 individual_store_add_individual_and_connect (self, l->data);
1003 for (l = removed; l; l = l->next)
1005 DEBUG ("Individual %s %s",
1006 folks_individual_get_id (l->data), "removed");
1008 individual_store_remove_individual_and_disconnect (self, l->data);
1013 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
1014 FolksIndividual *individual,
1015 gboolean is_favourite,
1016 EmpathyIndividualStore *self)
1018 DEBUG ("Individual %s is %s a favourite",
1019 folks_individual_get_id (individual),
1020 is_favourite ? "now" : "no longer");
1022 individual_store_remove_individual (self, individual);
1023 individual_store_add_individual (self, individual);
1027 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
1028 FolksIndividual *individual,
1031 EmpathyIndividualStore *self)
1033 EmpathyIndividualStorePriv *priv;
1034 gboolean show_active;
1036 priv = GET_PRIV (self);
1038 DEBUG ("Updating groups for individual %s",
1039 folks_individual_get_id (individual));
1041 /* We do this to make sure the groups are correct, if not, we
1042 * would have to check the groups already set up for each
1043 * contact and then see what has been updated.
1045 show_active = priv->show_active;
1046 priv->show_active = FALSE;
1047 individual_store_remove_individual (self, individual);
1048 individual_store_add_individual (self, individual);
1049 priv->show_active = show_active;
1053 individual_store_manager_setup (gpointer user_data)
1055 EmpathyIndividualStore *self = user_data;
1056 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1059 /* Signal connection. */
1061 /* TODO: implement */
1062 DEBUG ("handling individual renames unimplemented");
1064 g_signal_connect (priv->manager,
1066 G_CALLBACK (individual_store_members_changed_cb), self);
1068 g_signal_connect (priv->manager,
1069 "favourites-changed",
1070 G_CALLBACK (individual_store_favourites_changed_cb), self);
1072 g_signal_connect (priv->manager,
1074 G_CALLBACK (individual_store_groups_changed_cb), self);
1076 /* Add contacts already created. */
1077 individuals = empathy_individual_manager_get_members (priv->manager);
1078 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1080 individual_store_members_changed_cb (priv->manager, "initial add",
1081 individuals, NULL, 0, self);
1082 g_list_free (individuals);
1085 priv->setup_idle_id = 0;
1090 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1091 EmpathyIndividualManager *manager)
1093 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1095 priv->manager = g_object_ref (manager);
1097 /* Let a chance to have all properties set before populating */
1098 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1102 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1103 FolksIndividual *old_individual,
1104 FolksIndividual *new_individual,
1106 const gchar *message,
1107 EmpathyIndividualStore *self)
1109 DEBUG ("Individual %s renamed to %s",
1110 folks_individual_get_id (old_individual),
1111 folks_individual_get_id (new_individual));
1113 /* add the new contact */
1114 individual_store_add_individual_and_connect (self, new_individual);
1116 /* remove old contact */
1117 individual_store_remove_individual_and_disconnect (self, old_individual);
1121 individual_store_dispose (GObject *object)
1123 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1124 GList *individuals, *l;
1126 if (priv->dispose_has_run)
1128 priv->dispose_has_run = TRUE;
1130 /* Cancel any pending avatar load operations */
1131 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1133 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1134 g_cancellable_cancel (G_CANCELLABLE (l->data));
1136 g_list_free (priv->avatar_cancellables);
1138 individuals = empathy_individual_manager_get_members (priv->manager);
1139 for (l = individuals; l; l = l->next)
1141 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1142 FOLKS_INDIVIDUAL (l->data));
1144 g_list_free (individuals);
1146 g_signal_handlers_disconnect_by_func (priv->manager,
1147 G_CALLBACK (individual_store_member_renamed_cb), object);
1148 g_signal_handlers_disconnect_by_func (priv->manager,
1149 G_CALLBACK (individual_store_members_changed_cb), object);
1150 g_signal_handlers_disconnect_by_func (priv->manager,
1151 G_CALLBACK (individual_store_favourites_changed_cb), object);
1152 g_signal_handlers_disconnect_by_func (priv->manager,
1153 G_CALLBACK (individual_store_groups_changed_cb), object);
1154 g_object_unref (priv->manager);
1156 if (priv->inhibit_active)
1158 g_source_remove (priv->inhibit_active);
1161 if (priv->setup_idle_id != 0)
1163 g_source_remove (priv->setup_idle_id);
1166 g_hash_table_destroy (priv->status_icons);
1167 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1171 individual_store_get_property (GObject *object,
1176 EmpathyIndividualStorePriv *priv;
1178 priv = GET_PRIV (object);
1182 case PROP_INDIVIDUAL_MANAGER:
1183 g_value_set_object (value, priv->manager);
1185 case PROP_SHOW_AVATARS:
1186 g_value_set_boolean (value, priv->show_avatars);
1188 case PROP_SHOW_PROTOCOLS:
1189 g_value_set_boolean (value, priv->show_protocols);
1191 case PROP_SHOW_GROUPS:
1192 g_value_set_boolean (value, priv->show_groups);
1194 case PROP_IS_COMPACT:
1195 g_value_set_boolean (value, priv->is_compact);
1197 case PROP_SORT_CRITERIUM:
1198 g_value_set_enum (value, priv->sort_criterium);
1201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1207 individual_store_set_property (GObject *object,
1209 const GValue *value,
1214 case PROP_INDIVIDUAL_MANAGER:
1215 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1216 (object), g_value_get_object (value));
1218 case PROP_SHOW_AVATARS:
1219 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1220 (object), g_value_get_boolean (value));
1222 case PROP_SHOW_PROTOCOLS:
1223 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1224 (object), g_value_get_boolean (value));
1226 case PROP_SHOW_GROUPS:
1227 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1228 (object), g_value_get_boolean (value));
1230 case PROP_IS_COMPACT:
1231 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1232 (object), g_value_get_boolean (value));
1234 case PROP_SORT_CRITERIUM:
1235 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1236 (object), g_value_get_enum (value));
1239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1245 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1247 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1249 object_class->dispose = individual_store_dispose;
1250 object_class->get_property = individual_store_get_property;
1251 object_class->set_property = individual_store_set_property;
1253 g_object_class_install_property (object_class,
1254 PROP_INDIVIDUAL_MANAGER,
1255 g_param_spec_object ("individual-manager",
1256 "The individual manager",
1257 "The individual manager",
1258 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1259 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1260 g_object_class_install_property (object_class,
1262 g_param_spec_boolean ("show-avatars",
1264 "Whether contact list should display "
1265 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1266 g_object_class_install_property (object_class,
1267 PROP_SHOW_PROTOCOLS,
1268 g_param_spec_boolean ("show-protocols",
1270 "Whether contact list should display "
1271 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1272 g_object_class_install_property (object_class,
1274 g_param_spec_boolean ("show-groups",
1276 "Whether contact list should display "
1277 "contact groups", TRUE, G_PARAM_READWRITE));
1278 g_object_class_install_property (object_class,
1280 g_param_spec_boolean ("is-compact",
1282 "Whether the contact list is in compact mode or not",
1283 FALSE, G_PARAM_READWRITE));
1285 g_object_class_install_property (object_class,
1286 PROP_SORT_CRITERIUM,
1287 g_param_spec_enum ("sort-criterium",
1289 "The sort criterium to use for sorting the contact list",
1290 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1291 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1293 g_type_class_add_private (object_class,
1294 sizeof (EmpathyIndividualStorePriv));
1298 get_position (const char **strv,
1303 for (i = 0; strv[i] != NULL; i++)
1305 if (!tp_strdiff (strv[i], str))
1313 compare_separator_and_groups (gboolean is_separator_a,
1314 gboolean is_separator_b,
1315 const gchar *name_a,
1316 const gchar *name_b,
1317 FolksIndividual *individual_a,
1318 FolksIndividual *individual_b,
1319 gboolean fake_group_a,
1320 gboolean fake_group_b)
1322 /* these two lists are the sorted list of fake groups to include at the
1323 * top and bottom of the roster */
1324 const char *top_groups[] = {
1325 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1329 const char *bottom_groups[] = {
1330 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1334 if (is_separator_a || is_separator_b)
1336 /* We have at least one separator */
1341 else if (is_separator_b)
1347 /* One group and one contact */
1348 if (!individual_a && individual_b)
1352 else if (individual_a && !individual_b)
1356 else if (!individual_a && !individual_b)
1358 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1360 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1361 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1362 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1363 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1365 if (a_in_top && b_in_top)
1367 /* compare positions */
1368 return CLAMP (get_position (top_groups, name_a) -
1369 get_position (top_groups, name_b), -1, 1);
1371 else if (a_in_bottom && b_in_bottom)
1373 /* compare positions */
1374 return CLAMP (get_position (bottom_groups, name_a) -
1375 get_position (bottom_groups, name_b), -1, 1);
1377 else if (a_in_top || b_in_bottom)
1381 else if (b_in_top || a_in_bottom)
1387 return g_utf8_collate (name_a, name_b);
1391 /* Two contacts, ordering depends of the sorting policy */
1396 individual_store_contact_sort (FolksIndividual *individual_a,
1397 FolksIndividual *individual_b)
1400 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1401 TpAccount *account_a, *account_b;
1403 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1406 ret_val = g_utf8_collate (
1407 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1408 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1413 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1414 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1415 account_a = empathy_contact_get_account (contact_a);
1416 account_b = empathy_contact_get_account (contact_b);
1418 g_assert (account_a != NULL);
1419 g_assert (account_b != NULL);
1422 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1423 tp_account_get_protocol (account_b));
1429 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1430 tp_proxy_get_object_path (account_b));
1436 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1437 folks_individual_get_id (individual_b));
1440 tp_clear_object (&contact_a);
1441 tp_clear_object (&contact_b);
1447 individual_store_state_sort_func (GtkTreeModel *model,
1448 GtkTreeIter *iter_a,
1449 GtkTreeIter *iter_b,
1453 FolksIndividual *individual_a, *individual_b;
1454 gchar *name_a, *name_b;
1455 gboolean is_separator_a, is_separator_b;
1456 gboolean fake_group_a, fake_group_b;
1457 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1458 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1460 gtk_tree_model_get (model, iter_a,
1461 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1462 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1463 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1464 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1465 gtk_tree_model_get (model, iter_b,
1466 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1467 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1468 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1469 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1471 if (individual_a == NULL || individual_b == NULL)
1473 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1474 name_a, name_b, individual_a, individual_b, fake_group_a,
1479 /* If we managed to get this far, we can start looking at
1482 folks_presence_type_a =
1483 folks_presence_details_get_presence_type (
1484 FOLKS_PRESENCE_DETAILS (individual_a));
1485 folks_presence_type_b =
1486 folks_presence_details_get_presence_type (
1487 FOLKS_PRESENCE_DETAILS (individual_b));
1488 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1489 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1491 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1496 /* Fallback: compare by name et al. */
1497 ret_val = individual_store_contact_sort (individual_a, individual_b);
1503 tp_clear_object (&individual_a);
1504 tp_clear_object (&individual_b);
1510 individual_store_name_sort_func (GtkTreeModel *model,
1511 GtkTreeIter *iter_a,
1512 GtkTreeIter *iter_b,
1515 gchar *name_a, *name_b;
1516 FolksIndividual *individual_a, *individual_b;
1517 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1519 gboolean fake_group_a, fake_group_b;
1521 gtk_tree_model_get (model, iter_a,
1522 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1523 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1524 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1525 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1526 gtk_tree_model_get (model, iter_b,
1527 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1528 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1529 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1530 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1532 if (individual_a == NULL || individual_b == NULL)
1533 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1534 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1536 ret_val = individual_store_contact_sort (individual_a, individual_b);
1538 tp_clear_object (&individual_a);
1539 tp_clear_object (&individual_b);
1547 individual_store_setup (EmpathyIndividualStore *self)
1549 EmpathyIndividualStorePriv *priv;
1551 GDK_TYPE_PIXBUF, /* Status pixbuf */
1552 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1553 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1554 G_TYPE_STRING, /* Name */
1555 G_TYPE_UINT, /* Presence type */
1556 G_TYPE_STRING, /* Status string */
1557 G_TYPE_BOOLEAN, /* Compact view */
1558 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1559 G_TYPE_BOOLEAN, /* Is group */
1560 G_TYPE_BOOLEAN, /* Is active */
1561 G_TYPE_BOOLEAN, /* Is online */
1562 G_TYPE_BOOLEAN, /* Is separator */
1563 G_TYPE_BOOLEAN, /* Can make audio calls */
1564 G_TYPE_BOOLEAN, /* Can make video calls */
1565 G_TYPE_BOOLEAN, /* Is a fake group */
1566 G_TYPE_STRV, /* Client types */
1569 priv = GET_PRIV (self);
1571 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1572 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1574 /* Set up sorting */
1575 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1576 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1577 individual_store_name_sort_func, self, NULL);
1578 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1579 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1580 individual_store_state_sort_func, self, NULL);
1582 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1583 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1587 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1589 EmpathyIndividualStorePriv *priv;
1591 priv = GET_PRIV (self);
1593 priv->show_active = TRUE;
1594 priv->inhibit_active = 0;
1600 empathy_individual_store_init (EmpathyIndividualStore *self)
1602 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1603 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1606 priv->show_avatars = TRUE;
1607 priv->show_groups = TRUE;
1608 priv->show_protocols = FALSE;
1609 priv->inhibit_active =
1610 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1611 (GSourceFunc) individual_store_inhibit_active_cb, self);
1612 priv->status_icons =
1613 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1614 individual_store_setup (self);
1617 EmpathyIndividualStore *
1618 empathy_individual_store_new (EmpathyIndividualManager *manager)
1620 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1622 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1623 "individual-manager", manager, NULL);
1626 EmpathyIndividualManager *
1627 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1629 EmpathyIndividualStorePriv *priv;
1631 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1633 priv = GET_PRIV (self);
1635 return priv->manager;
1639 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1641 EmpathyIndividualStorePriv *priv;
1643 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1645 priv = GET_PRIV (self);
1647 return priv->show_avatars;
1651 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1654 EmpathyIndividualStore *self)
1656 EmpathyIndividualStorePriv *priv;
1657 gboolean show_avatar = FALSE;
1658 FolksIndividual *individual;
1659 GdkPixbuf *pixbuf_status;
1661 priv = GET_PRIV (self);
1663 if (priv->show_avatars && !priv->is_compact)
1668 gtk_tree_model_get (model, iter,
1669 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1671 if (individual == NULL)
1675 /* get icon from hash_table */
1677 empathy_individual_store_get_individual_status_icon (self, individual);
1679 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1680 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1681 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1682 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1684 g_object_unref (individual);
1690 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1691 gboolean show_avatars)
1693 EmpathyIndividualStorePriv *priv;
1694 GtkTreeModel *model;
1696 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1698 priv = GET_PRIV (self);
1700 priv->show_avatars = show_avatars;
1702 model = GTK_TREE_MODEL (self);
1704 gtk_tree_model_foreach (model,
1705 (GtkTreeModelForeachFunc)
1706 individual_store_update_list_mode_foreach, self);
1708 g_object_notify (G_OBJECT (self), "show-avatars");
1712 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1714 EmpathyIndividualStorePriv *priv;
1716 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1718 priv = GET_PRIV (self);
1720 return priv->show_protocols;
1724 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1725 gboolean show_protocols)
1727 EmpathyIndividualStorePriv *priv;
1728 GtkTreeModel *model;
1730 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1732 priv = GET_PRIV (self);
1734 priv->show_protocols = show_protocols;
1736 model = GTK_TREE_MODEL (self);
1738 gtk_tree_model_foreach (model,
1739 (GtkTreeModelForeachFunc)
1740 individual_store_update_list_mode_foreach, self);
1742 g_object_notify (G_OBJECT (self), "show-protocols");
1746 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1748 EmpathyIndividualStorePriv *priv;
1750 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1752 priv = GET_PRIV (self);
1754 return priv->show_groups;
1758 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1759 gboolean show_groups)
1761 EmpathyIndividualStorePriv *priv;
1763 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1765 priv = GET_PRIV (self);
1767 if (priv->show_groups == show_groups)
1772 priv->show_groups = show_groups;
1774 if (priv->setup_idle_id == 0)
1776 /* Remove all contacts and add them back, not optimized but
1777 * that's the easy way :)
1779 * This is only done if there's not a pending setup idle
1780 * callback, otherwise it will race and the contacts will get
1784 gtk_tree_store_clear (GTK_TREE_STORE (self));
1785 contacts = empathy_individual_manager_get_members (priv->manager);
1787 individual_store_members_changed_cb (priv->manager,
1788 "re-adding members: toggled group visibility",
1789 contacts, NULL, 0, self);
1790 g_list_free (contacts);
1793 g_object_notify (G_OBJECT (self), "show-groups");
1797 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1799 EmpathyIndividualStorePriv *priv;
1801 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1803 priv = GET_PRIV (self);
1805 return priv->is_compact;
1809 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1810 gboolean is_compact)
1812 EmpathyIndividualStorePriv *priv;
1813 GtkTreeModel *model;
1815 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1817 priv = GET_PRIV (self);
1819 priv->is_compact = is_compact;
1821 model = GTK_TREE_MODEL (self);
1823 gtk_tree_model_foreach (model,
1824 (GtkTreeModelForeachFunc)
1825 individual_store_update_list_mode_foreach, self);
1827 g_object_notify (G_OBJECT (self), "is-compact");
1830 EmpathyIndividualStoreSort
1831 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1833 EmpathyIndividualStorePriv *priv;
1835 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1837 priv = GET_PRIV (self);
1839 return priv->sort_criterium;
1843 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1844 EmpathyIndividualStoreSort sort_criterium)
1846 EmpathyIndividualStorePriv *priv;
1848 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1850 priv = GET_PRIV (self);
1852 priv->sort_criterium = sort_criterium;
1854 switch (sort_criterium)
1856 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1857 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1858 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1861 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1862 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1863 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1867 g_assert_not_reached ();
1870 g_object_notify (G_OBJECT (self), "sort-criterium");
1874 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1878 gboolean is_separator = FALSE;
1880 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1882 gtk_tree_model_get (model, iter,
1883 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1885 return is_separator;
1889 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1891 gboolean *path_is_group,
1892 gboolean *is_fake_group)
1894 GtkTreeIter parent_iter, iter;
1897 gboolean fake = FALSE;
1899 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1903 *path_is_group = FALSE;
1906 if (!gtk_tree_model_get_iter (model, &iter, path))
1911 gtk_tree_model_get (model, &iter,
1912 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1913 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1920 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1927 gtk_tree_model_get (model, &iter,
1928 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1929 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1930 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1940 *path_is_group = TRUE;
1943 if (is_fake_group != NULL)
1944 *is_fake_group = fake;
1950 individual_store_get_individual_status_icon_with_icon_name (
1951 EmpathyIndividualStore *self,
1952 FolksIndividual *individual,
1953 const gchar *status_icon_name)
1955 GdkPixbuf *pixbuf_status;
1956 EmpathyIndividualStorePriv *priv;
1957 const gchar *protocol_name = NULL;
1958 gchar *icon_name = NULL;
1961 guint contact_count = 0;
1962 EmpathyContact *contact = NULL;
1963 gboolean show_protocols_here;
1965 priv = GET_PRIV (self);
1967 personas = folks_individual_get_personas (individual);
1968 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1969 while (gee_iterator_next (iter))
1971 FolksPersona *persona = gee_iterator_get (iter);
1972 if (empathy_folks_persona_is_interesting (persona))
1975 g_clear_object (&persona);
1977 if (contact_count > 1)
1980 g_clear_object (&iter);
1982 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1983 if (show_protocols_here)
1985 contact = empathy_contact_dup_from_folks_individual (individual);
1986 protocol_name = empathy_protocol_name_for_contact (contact);
1987 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1991 icon_name = g_strdup_printf ("%s", status_icon_name);
1994 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
1996 if (pixbuf_status == NULL)
1999 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
2000 status_icon_name, show_protocols_here);
2002 if (pixbuf_status != NULL)
2004 /* pass the reference to the hash table */
2005 g_hash_table_insert (priv->status_icons,
2006 g_strdup (icon_name), pixbuf_status);
2011 tp_clear_object (&contact);
2013 return pixbuf_status;
2017 empathy_individual_store_get_individual_status_icon (
2018 EmpathyIndividualStore *self,
2019 FolksIndividual *individual)
2021 GdkPixbuf *pixbuf_status = NULL;
2022 const gchar *status_icon_name = NULL;
2024 status_icon_name = empathy_icon_name_for_individual (individual);
2025 if (status_icon_name == NULL)
2029 individual_store_get_individual_status_icon_with_icon_name (self,
2030 individual, status_icon_name);
2032 return pixbuf_status;