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 } EmpathyIndividualStorePriv;
85 FolksIndividual *individual;
92 EmpathyIndividualStore *self;
93 FolksIndividual *individual;
101 PROP_INDIVIDUAL_MANAGER,
109 /* prototypes to break cycles */
110 static void individual_store_contact_update (EmpathyIndividualStore *self,
111 FolksIndividual *individual);
113 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
114 GTK_TYPE_TREE_STORE);
117 add_individual_to_store (GtkTreeStore *self,
120 FolksIndividual *individual,
121 EmpathyIndividualManagerFlags flags)
123 EmpathyContact *contact;
125 contact = empathy_contact_dup_from_folks_individual (individual);
127 gtk_tree_store_insert_with_values (self, iter, parent, 0,
128 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
129 folks_individual_get_alias (individual),
130 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
131 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
132 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
133 EMPATHY_INDIVIDUAL_STORE_COL_FLAGS, flags,
138 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
139 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
140 empathy_contact_get_capabilities (contact) &
141 EMPATHY_CAPABILITIES_AUDIO,
142 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
143 empathy_contact_get_capabilities (contact) &
144 EMPATHY_CAPABILITIES_VIDEO,
148 tp_clear_object (&contact);
152 individual_store_get_group_foreach (GtkTreeModel *model,
160 /* Groups are only at the top level. */
161 if (gtk_tree_path_get_depth (path) != 1)
164 gtk_tree_model_get (model, iter,
165 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
166 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
168 if (is_group && !tp_strdiff (str, fg->name))
180 individual_store_get_group (EmpathyIndividualStore *self,
182 GtkTreeIter *iter_group_to_set,
183 GtkTreeIter *iter_separator_to_set,
185 gboolean is_fake_group)
187 EmpathyIndividualStorePriv *priv;
189 GtkTreeIter iter_group;
190 GtkTreeIter iter_separator;
193 priv = GET_PRIV (self);
195 memset (&fg, 0, sizeof (fg));
199 model = GTK_TREE_MODEL (self);
200 gtk_tree_model_foreach (model,
201 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
208 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
210 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
211 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
212 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
213 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
214 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
215 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
218 if (iter_group_to_set)
219 *iter_group_to_set = iter_group;
221 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
223 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
226 if (iter_separator_to_set)
227 *iter_separator_to_set = iter_separator;
234 if (iter_group_to_set)
235 *iter_group_to_set = fg.iter;
237 iter_separator = fg.iter;
239 if (gtk_tree_model_iter_next (model, &iter_separator))
241 gboolean is_separator;
243 gtk_tree_model_get (model, &iter_separator,
244 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
246 if (is_separator && iter_separator_to_set)
247 *iter_separator_to_set = iter_separator;
253 individual_store_find_contact_foreach (GtkTreeModel *model,
258 FolksIndividual *individual;
260 gtk_tree_model_get (model, iter,
261 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
263 if (individual == fc->individual)
266 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
269 tp_clear_object (&individual);
275 individual_store_find_contact (EmpathyIndividualStore *self,
276 FolksIndividual *individual)
278 EmpathyIndividualStorePriv *priv;
283 priv = GET_PRIV (self);
285 memset (&fc, 0, sizeof (fc));
287 fc.individual = individual;
289 model = GTK_TREE_MODEL (self);
290 gtk_tree_model_foreach (model,
291 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
300 individual_store_remove_individual (EmpathyIndividualStore *self,
301 FolksIndividual *individual)
303 EmpathyIndividualStorePriv *priv;
307 priv = GET_PRIV (self);
309 iters = individual_store_find_contact (self, individual);
314 model = GTK_TREE_MODEL (self);
316 for (l = iters; l; l = l->next)
320 /* NOTE: it is only <= 2 here because we have
321 * separators after the group name, otherwise it
324 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
325 gtk_tree_model_iter_n_children (model, &parent) <= 2)
327 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
331 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
335 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
340 individual_store_add_individual (EmpathyIndividualStore *self,
341 FolksIndividual *individual)
343 EmpathyIndividualStorePriv *priv;
345 GHashTable *group_set = NULL;
346 GList *groups = NULL, *l;
347 EmpathyContact *contact;
348 TpConnection *connection;
349 EmpathyIndividualManagerFlags flags = 0;
350 gchar *protocol_name;
352 priv = GET_PRIV (self);
354 if (EMP_STR_EMPTY (folks_individual_get_alias (individual)))
357 if (priv->show_groups)
359 group_set = folks_individual_get_groups (individual);
360 groups = g_hash_table_get_keys (group_set);
363 contact = empathy_contact_dup_from_folks_individual (individual);
364 connection = empathy_contact_get_connection (contact);
365 flags = empathy_individual_manager_get_flags_for_connection (priv->manager,
368 tp_connection_parse_object_path (connection, &protocol_name, NULL);
372 GtkTreeIter iter_group, *parent;
374 parent = &iter_group;
376 if (!priv->show_groups)
378 else if (!tp_strdiff (protocol_name, "local-xmpp"))
380 /* these are People Nearby */
381 individual_store_get_group (self,
382 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
387 individual_store_get_group (self,
388 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
389 &iter_group, NULL, NULL, TRUE);
392 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
396 g_free (protocol_name);
398 /* Else add to each group. */
399 for (l = groups; l; l = l->next)
401 GtkTreeIter iter_group;
403 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
406 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
409 g_list_free (groups);
410 if (group_set != NULL)
411 g_hash_table_unref (group_set);
413 if (priv->show_groups &&
414 folks_favourite_get_is_favourite (FOLKS_FAVOURITE (individual)))
416 /* Add contact to the fake 'Favorites' group */
417 GtkTreeIter iter_group;
419 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
420 &iter_group, NULL, NULL, TRUE);
422 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
426 individual_store_contact_update (self, individual);
428 tp_clear_object (&contact);
432 individual_store_contact_set_active (EmpathyIndividualStore *self,
433 FolksIndividual *individual,
435 gboolean set_changed)
437 EmpathyIndividualStorePriv *priv;
441 priv = GET_PRIV (self);
442 model = GTK_TREE_MODEL (self);
444 iters = individual_store_find_contact (self, individual);
445 for (l = iters; l; l = l->next)
449 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
450 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
453 DEBUG ("Set item %s", active ? "active" : "inactive");
457 path = gtk_tree_model_get_path (model, l->data);
458 gtk_tree_model_row_changed (model, path, l->data);
459 gtk_tree_path_free (path);
463 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
468 static void individual_store_contact_active_free (ShowActiveData *data);
471 individual_store_contact_active_invalidated (ShowActiveData *data,
474 /* Remove the timeout and free the struct, since the individual or individual
475 * store has disappeared. */
476 g_source_remove (data->timeout);
478 if (old_object == (GObject *)data->self)
480 else if (old_object == (GObject *)data->individual)
481 data->individual = NULL;
483 g_assert_not_reached ();
485 individual_store_contact_active_free (data);
488 static ShowActiveData *
489 individual_store_contact_active_new (EmpathyIndividualStore *self,
490 FolksIndividual *individual,
493 ShowActiveData *data;
495 DEBUG ("Individual'%s' now active, and %s be removed",
496 folks_individual_get_alias (individual), remove_ ? "WILL" : "WILL NOT");
498 data = g_slice_new0 (ShowActiveData);
500 /* We don't actually want to force either the IndividualStore or the
501 * Individual to stay alive, since the user could quit Empathy or disable
502 * the account before the contact_active timeout is fired. */
503 g_object_weak_ref (G_OBJECT (self),
504 (GWeakNotify) individual_store_contact_active_invalidated, data);
505 g_object_weak_ref (G_OBJECT (individual),
506 (GWeakNotify) individual_store_contact_active_invalidated, data);
509 data->individual = individual;
510 data->remove = remove_;
517 individual_store_contact_active_free (ShowActiveData *data)
519 if (data->self != NULL)
521 g_object_weak_unref (G_OBJECT (data->self),
522 (GWeakNotify) individual_store_contact_active_invalidated, data);
525 if (data->individual != NULL)
527 g_object_weak_unref (G_OBJECT (data->individual),
528 (GWeakNotify) individual_store_contact_active_invalidated, data);
531 g_slice_free (ShowActiveData, data);
535 individual_store_contact_active_cb (ShowActiveData *data)
539 DEBUG ("Individual'%s' active timeout, removing item",
540 folks_individual_get_alias (data->individual));
541 individual_store_remove_individual (data->self, data->individual);
544 DEBUG ("Individual'%s' no longer active",
545 folks_individual_get_alias (data->individual));
547 individual_store_contact_set_active (data->self,
548 data->individual, FALSE, TRUE);
550 individual_store_contact_active_free (data);
556 individual_avatar_pixbuf_received_cb (GObject *object,
557 GAsyncResult *result,
560 FolksIndividual *individual = FOLKS_INDIVIDUAL (object);
561 EmpathyIndividualStore *self = user_data;
562 GError *error = NULL;
565 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
570 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
571 folks_individual_get_alias (individual),
573 g_clear_error (&error);
579 iters = individual_store_find_contact (self, individual);
580 for (l = iters; l; l = l->next)
582 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
583 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
590 individual_store_contact_update (EmpathyIndividualStore *self,
591 FolksIndividual *individual)
593 EmpathyIndividualStorePriv *priv;
594 ShowActiveData *data;
596 EmpathyContact *contact;
599 gboolean was_online = TRUE;
600 gboolean now_online = FALSE;
601 gboolean set_model = FALSE;
602 gboolean do_remove = FALSE;
603 gboolean do_set_active = FALSE;
604 gboolean do_set_refresh = FALSE;
605 gboolean show_avatar = FALSE;
606 GdkPixbuf *pixbuf_status;
608 priv = GET_PRIV (self);
610 model = GTK_TREE_MODEL (self);
611 contact = empathy_contact_dup_from_folks_individual (individual);
613 iters = individual_store_find_contact (self, individual);
623 /* Get online state now. */
624 now_online = folks_individual_is_online (individual);
628 DEBUG ("Individual'%s' in list:NO, should be:YES",
629 folks_individual_get_alias (individual));
631 individual_store_add_individual (self, individual);
633 if (priv->show_active)
635 do_set_active = TRUE;
637 DEBUG ("Set active (individual added)");
642 DEBUG ("Individual'%s' in list:YES, should be:YES",
643 folks_individual_get_alias (individual));
645 /* Get online state before. */
646 if (iters && g_list_length (iters) > 0)
648 gtk_tree_model_get (model, iters->data,
649 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
652 /* Is this really an update or an online/offline. */
653 if (priv->show_active)
655 if (was_online != now_online)
657 do_set_active = TRUE;
658 do_set_refresh = TRUE;
660 DEBUG ("Set active (individual updated %s)",
661 was_online ? "online -> offline" : "offline -> online");
665 /* Was TRUE for presence updates. */
666 /* do_set_active = FALSE; */
667 do_set_refresh = TRUE;
669 DEBUG ("Set active (individual updated)");
676 if (priv->show_avatars && !priv->is_compact)
681 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
682 individual_avatar_pixbuf_received_cb, 32, 32, self);
685 empathy_individual_store_get_individual_status_icon (self, individual);
687 for (l = iters; l && set_model; l = l->next)
689 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
690 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
691 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
692 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
693 folks_individual_get_alias (individual),
694 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
695 folks_individual_get_presence_type (individual),
696 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
697 folks_individual_get_presence_message (individual),
698 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
699 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
700 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
701 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
706 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
707 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
708 empathy_contact_get_capabilities (contact) &
709 EMPATHY_CAPABILITIES_AUDIO,
710 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
711 empathy_contact_get_capabilities (contact) &
712 EMPATHY_CAPABILITIES_VIDEO,
717 if (priv->show_active && do_set_active)
719 individual_store_contact_set_active (self, individual, do_set_active,
725 individual_store_contact_active_new (self, individual,
727 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
728 (GSourceFunc) individual_store_contact_active_cb, data);
732 /* FIXME: when someone goes online then offline quickly, the
733 * first timeout sets the user to be inactive and the second
734 * timeout removes the user from the contact list, really we
735 * should remove the first timeout.
737 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
739 tp_clear_object (&contact);
743 individual_store_individual_updated_cb (FolksIndividual *individual,
745 EmpathyIndividualStore *self)
747 DEBUG ("Individual'%s' updated, checking roster is in sync...",
748 folks_individual_get_alias (individual));
750 individual_store_contact_update (self, individual);
754 individual_store_contact_updated_cb (EmpathyContact *contact,
756 EmpathyIndividualStore *self)
758 FolksIndividual *individual;
760 DEBUG ("Contact '%s' updated, checking roster is in sync...",
761 empathy_contact_get_alias (contact));
763 individual = g_object_get_data (G_OBJECT (contact), "individual");
764 if (individual == NULL)
767 individual_store_contact_update (self, individual);
771 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
772 FolksIndividual *individual)
774 EmpathyContact *contact;
776 g_signal_connect (individual, "notify::avatar",
777 G_CALLBACK (individual_store_individual_updated_cb), self);
778 g_signal_connect (individual, "notify::presence-type",
779 G_CALLBACK (individual_store_individual_updated_cb), self);
780 g_signal_connect (individual, "notify::presence-message",
781 G_CALLBACK (individual_store_individual_updated_cb), self);
782 g_signal_connect (individual, "notify::alias",
783 G_CALLBACK (individual_store_individual_updated_cb), self);
785 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
786 * through the EmpathyContact for them. */
787 contact = empathy_contact_dup_from_folks_individual (individual);
788 g_object_set_data (G_OBJECT (contact), "individual", individual);
789 g_signal_connect (contact, "notify::capabilities",
790 G_CALLBACK (individual_store_contact_updated_cb), self);
791 g_object_unref (contact);
793 individual_store_add_individual (self, individual);
797 individual_store_remove_individual_and_disconnect (
798 EmpathyIndividualStore *self,
799 FolksIndividual *individual)
801 g_signal_handlers_disconnect_by_func (individual,
802 G_CALLBACK (individual_store_individual_updated_cb), self);
803 g_signal_handlers_disconnect_by_func (individual,
804 G_CALLBACK (individual_store_contact_updated_cb), self);
806 individual_store_remove_individual (self, individual);
810 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
811 const gchar *message,
815 EmpathyIndividualStore *self)
819 for (l = added; l; l = l->next)
821 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
823 individual_store_add_individual_and_connect (self, l->data);
825 for (l = removed; l; l = l->next)
827 DEBUG ("Individual %s %s",
828 folks_individual_get_id (l->data), "removed");
830 individual_store_remove_individual_and_disconnect (self, l->data);
835 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
836 FolksIndividual *individual,
837 gboolean is_favourite,
838 EmpathyIndividualStore *self)
840 EmpathyIndividualStorePriv *priv;
842 priv = GET_PRIV (self);
844 DEBUG ("Individual %s is %s a favourite",
845 folks_individual_get_id (individual),
846 is_favourite ? "now" : "no longer");
848 individual_store_remove_individual (self, individual);
849 individual_store_add_individual (self, individual);
853 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
854 FolksIndividual *individual,
857 EmpathyIndividualStore *self)
859 EmpathyIndividualStorePriv *priv;
860 gboolean show_active;
862 priv = GET_PRIV (self);
864 DEBUG ("Updating groups for individual %s",
865 folks_individual_get_id (individual));
867 /* We do this to make sure the groups are correct, if not, we
868 * would have to check the groups already set up for each
869 * contact and then see what has been updated.
871 show_active = priv->show_active;
872 priv->show_active = FALSE;
873 individual_store_remove_individual (self, individual);
874 individual_store_add_individual (self, individual);
875 priv->show_active = show_active;
879 individual_store_manager_setup (gpointer user_data)
881 EmpathyIndividualStore *self = user_data;
882 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
885 /* Signal connection. */
887 /* TODO: implement */
888 DEBUG ("handling individual renames unimplemented");
890 g_signal_connect (priv->manager,
892 G_CALLBACK (individual_store_members_changed_cb), self);
894 g_signal_connect (priv->manager,
895 "favourites-changed",
896 G_CALLBACK (individual_store_favourites_changed_cb), self);
898 g_signal_connect (priv->manager,
900 G_CALLBACK (individual_store_groups_changed_cb), self);
902 /* Add contacts already created. */
903 individuals = empathy_individual_manager_get_members (priv->manager);
904 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
906 individual_store_members_changed_cb (priv->manager, "initial add",
907 individuals, NULL, 0, self);
908 g_list_free (individuals);
911 priv->setup_idle_id = 0;
916 individual_store_set_individual_manager (EmpathyIndividualStore *self,
917 EmpathyIndividualManager *manager)
919 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
921 priv->manager = g_object_ref (manager);
923 /* Let a chance to have all properties set before populating */
924 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
928 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
929 FolksIndividual *old_individual,
930 FolksIndividual *new_individual,
932 const gchar *message,
933 EmpathyIndividualStore *self)
935 EmpathyIndividualStorePriv *priv;
937 priv = GET_PRIV (self);
939 DEBUG ("Individual %s renamed to %s",
940 folks_individual_get_id (old_individual),
941 folks_individual_get_id (new_individual));
943 /* add the new contact */
944 individual_store_add_individual_and_connect (self, new_individual);
946 /* remove old contact */
947 individual_store_remove_individual_and_disconnect (self, old_individual);
951 individual_store_dispose (GObject *object)
953 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
956 if (priv->dispose_has_run)
958 priv->dispose_has_run = TRUE;
960 contacts = empathy_individual_manager_get_members (priv->manager);
961 for (l = contacts; l; l = l->next)
963 g_signal_handlers_disconnect_by_func (l->data,
964 G_CALLBACK (individual_store_individual_updated_cb), object);
965 g_signal_handlers_disconnect_by_func (l->data,
966 G_CALLBACK (individual_store_contact_updated_cb), object);
968 g_list_free (contacts);
970 g_signal_handlers_disconnect_by_func (priv->manager,
971 G_CALLBACK (individual_store_member_renamed_cb), object);
972 g_signal_handlers_disconnect_by_func (priv->manager,
973 G_CALLBACK (individual_store_members_changed_cb), object);
974 g_signal_handlers_disconnect_by_func (priv->manager,
975 G_CALLBACK (individual_store_favourites_changed_cb), object);
976 g_signal_handlers_disconnect_by_func (priv->manager,
977 G_CALLBACK (individual_store_groups_changed_cb), object);
978 g_object_unref (priv->manager);
980 if (priv->inhibit_active)
982 g_source_remove (priv->inhibit_active);
985 if (priv->setup_idle_id != 0)
987 g_source_remove (priv->setup_idle_id);
990 g_hash_table_destroy (priv->status_icons);
991 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
995 individual_store_get_property (GObject *object,
1000 EmpathyIndividualStorePriv *priv;
1002 priv = GET_PRIV (object);
1006 case PROP_INDIVIDUAL_MANAGER:
1007 g_value_set_object (value, priv->manager);
1009 case PROP_SHOW_AVATARS:
1010 g_value_set_boolean (value, priv->show_avatars);
1012 case PROP_SHOW_PROTOCOLS:
1013 g_value_set_boolean (value, priv->show_protocols);
1015 case PROP_SHOW_GROUPS:
1016 g_value_set_boolean (value, priv->show_groups);
1018 case PROP_IS_COMPACT:
1019 g_value_set_boolean (value, priv->is_compact);
1021 case PROP_SORT_CRITERIUM:
1022 g_value_set_enum (value, priv->sort_criterium);
1025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1031 individual_store_set_property (GObject *object,
1033 const GValue *value,
1036 EmpathyIndividualStorePriv *priv;
1038 priv = GET_PRIV (object);
1042 case PROP_INDIVIDUAL_MANAGER:
1043 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1044 (object), g_value_get_object (value));
1046 case PROP_SHOW_AVATARS:
1047 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1048 (object), g_value_get_boolean (value));
1050 case PROP_SHOW_PROTOCOLS:
1051 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1052 (object), g_value_get_boolean (value));
1054 case PROP_SHOW_GROUPS:
1055 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1056 (object), g_value_get_boolean (value));
1058 case PROP_IS_COMPACT:
1059 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1060 (object), g_value_get_boolean (value));
1062 case PROP_SORT_CRITERIUM:
1063 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1064 (object), g_value_get_enum (value));
1067 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1073 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1075 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1077 object_class->dispose = individual_store_dispose;
1078 object_class->get_property = individual_store_get_property;
1079 object_class->set_property = individual_store_set_property;
1081 g_object_class_install_property (object_class,
1082 PROP_INDIVIDUAL_MANAGER,
1083 g_param_spec_object ("individual-manager",
1084 "The individual manager",
1085 "The individual manager",
1086 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1087 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1088 g_object_class_install_property (object_class,
1090 g_param_spec_boolean ("show-avatars",
1092 "Whether contact list should display "
1093 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1094 g_object_class_install_property (object_class,
1095 PROP_SHOW_PROTOCOLS,
1096 g_param_spec_boolean ("show-protocols",
1098 "Whether contact list should display "
1099 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1100 g_object_class_install_property (object_class,
1102 g_param_spec_boolean ("show-groups",
1104 "Whether contact list should display "
1105 "contact groups", TRUE, G_PARAM_READWRITE));
1106 g_object_class_install_property (object_class,
1108 g_param_spec_boolean ("is-compact",
1110 "Whether the contact list is in compact mode or not",
1111 FALSE, G_PARAM_READWRITE));
1113 g_object_class_install_property (object_class,
1114 PROP_SORT_CRITERIUM,
1115 g_param_spec_enum ("sort-criterium",
1117 "The sort criterium to use for sorting the contact list",
1118 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1119 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1121 g_type_class_add_private (object_class,
1122 sizeof (EmpathyIndividualStorePriv));
1126 get_position (const char **strv,
1131 for (i = 0; strv[i] != NULL; i++)
1133 if (!tp_strdiff (strv[i], str))
1141 compare_separator_and_groups (gboolean is_separator_a,
1142 gboolean is_separator_b,
1143 const gchar *name_a,
1144 const gchar *name_b,
1145 FolksIndividual *individual_a,
1146 FolksIndividual *individual_b,
1147 gboolean fake_group_a,
1148 gboolean fake_group_b)
1150 /* these two lists are the sorted list of fake groups to include at the
1151 * top and bottom of the roster */
1152 const char *top_groups[] = {
1153 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1157 const char *bottom_groups[] = {
1158 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1162 if (is_separator_a || is_separator_b)
1164 /* We have at least one separator */
1169 else if (is_separator_b)
1175 /* One group and one contact */
1176 if (!individual_a && individual_b)
1180 else if (individual_a && !individual_b)
1184 else if (!individual_a && !individual_b)
1186 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1188 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1189 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1190 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1191 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1193 if (a_in_top && b_in_top)
1195 /* compare positions */
1196 return CLAMP (get_position (top_groups, name_a) -
1197 get_position (top_groups, name_b), -1, 1);
1199 else if (a_in_bottom && b_in_bottom)
1201 /* compare positions */
1202 return CLAMP (get_position (bottom_groups, name_a) -
1203 get_position (bottom_groups, name_b), -1, 1);
1205 else if (a_in_top || b_in_bottom)
1209 else if (b_in_top || a_in_bottom)
1215 return g_utf8_collate (name_a, name_b);
1219 /* Two contacts, ordering depends of the sorting policy */
1224 individual_store_contact_sort (FolksIndividual *individual_a,
1225 FolksIndividual *individual_b)
1228 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1229 TpAccount *account_a, *account_b;
1231 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1234 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1235 folks_individual_get_alias (individual_b));
1240 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1241 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1242 account_a = empathy_contact_get_account (contact_a);
1243 account_b = empathy_contact_get_account (contact_b);
1246 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1247 tp_account_get_protocol (account_b));
1253 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1254 tp_proxy_get_object_path (account_b));
1260 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1261 folks_individual_get_id (individual_b));
1264 tp_clear_object (&contact_a);
1265 tp_clear_object (&contact_b);
1271 individual_store_state_sort_func (GtkTreeModel *model,
1272 GtkTreeIter *iter_a,
1273 GtkTreeIter *iter_b,
1277 FolksIndividual *individual_a, *individual_b;
1278 gchar *name_a, *name_b;
1279 gboolean is_separator_a, is_separator_b;
1280 gboolean fake_group_a, fake_group_b;
1281 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1282 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1284 gtk_tree_model_get (model, iter_a,
1285 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1286 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1287 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1288 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1289 gtk_tree_model_get (model, iter_b,
1290 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1291 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1292 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1293 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1295 if (individual_a == NULL || individual_b == NULL)
1297 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1298 name_a, name_b, individual_a, individual_b, fake_group_a,
1303 /* If we managed to get this far, we can start looking at
1306 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1307 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1308 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1309 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1311 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1316 /* Fallback: compare by name et al. */
1317 ret_val = individual_store_contact_sort (individual_a, individual_b);
1323 tp_clear_object (&individual_a);
1324 tp_clear_object (&individual_b);
1330 individual_store_name_sort_func (GtkTreeModel *model,
1331 GtkTreeIter *iter_a,
1332 GtkTreeIter *iter_b,
1335 gchar *name_a, *name_b;
1336 FolksIndividual *individual_a, *individual_b;
1337 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1339 gboolean fake_group_a, fake_group_b;
1341 gtk_tree_model_get (model, iter_a,
1342 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1343 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1344 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1345 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1346 gtk_tree_model_get (model, iter_b,
1347 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1348 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1349 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1350 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1352 if (individual_a == NULL || individual_b == NULL)
1353 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1354 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1356 ret_val = individual_store_contact_sort (individual_a, individual_b);
1358 tp_clear_object (&individual_a);
1359 tp_clear_object (&individual_b);
1365 individual_store_setup (EmpathyIndividualStore *self)
1367 EmpathyIndividualStorePriv *priv;
1369 GDK_TYPE_PIXBUF, /* Status pixbuf */
1370 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1371 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1372 G_TYPE_STRING, /* Name */
1373 G_TYPE_UINT, /* Presence type */
1374 G_TYPE_STRING, /* Status string */
1375 G_TYPE_BOOLEAN, /* Compact view */
1376 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1377 G_TYPE_BOOLEAN, /* Is group */
1378 G_TYPE_BOOLEAN, /* Is active */
1379 G_TYPE_BOOLEAN, /* Is online */
1380 G_TYPE_BOOLEAN, /* Is separator */
1381 G_TYPE_BOOLEAN, /* Can make audio calls */
1382 G_TYPE_BOOLEAN, /* Can make video calls */
1383 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1384 G_TYPE_BOOLEAN, /* Is a fake group */
1387 priv = GET_PRIV (self);
1389 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1390 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1392 /* Set up sorting */
1393 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1394 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1395 individual_store_name_sort_func, self, NULL);
1396 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1397 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1398 individual_store_state_sort_func, self, NULL);
1400 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1401 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1405 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1407 EmpathyIndividualStorePriv *priv;
1409 priv = GET_PRIV (self);
1411 priv->show_active = TRUE;
1412 priv->inhibit_active = 0;
1418 empathy_individual_store_init (EmpathyIndividualStore *self)
1420 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1421 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1424 priv->show_avatars = TRUE;
1425 priv->show_groups = TRUE;
1426 priv->show_protocols = FALSE;
1427 priv->inhibit_active =
1428 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1429 (GSourceFunc) individual_store_inhibit_active_cb, self);
1430 priv->status_icons =
1431 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1432 individual_store_setup (self);
1435 EmpathyIndividualStore *
1436 empathy_individual_store_new (EmpathyIndividualManager *manager)
1438 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1440 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1441 "individual-manager", manager, NULL);
1444 EmpathyIndividualManager *
1445 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1447 EmpathyIndividualStorePriv *priv;
1449 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1451 priv = GET_PRIV (self);
1453 return priv->manager;
1457 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1459 EmpathyIndividualStorePriv *priv;
1461 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1463 priv = GET_PRIV (self);
1465 return priv->show_avatars;
1469 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1472 EmpathyIndividualStore *self)
1474 EmpathyIndividualStorePriv *priv;
1475 gboolean show_avatar = FALSE;
1476 FolksIndividual *individual;
1477 GdkPixbuf *pixbuf_status;
1479 priv = GET_PRIV (self);
1481 if (priv->show_avatars && !priv->is_compact)
1486 gtk_tree_model_get (model, iter,
1487 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1489 if (individual == NULL)
1493 /* get icon from hash_table */
1495 empathy_individual_store_get_individual_status_icon (self, individual);
1497 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1498 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1499 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1500 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1502 g_object_unref (individual);
1508 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1509 gboolean show_avatars)
1511 EmpathyIndividualStorePriv *priv;
1512 GtkTreeModel *model;
1514 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1516 priv = GET_PRIV (self);
1518 priv->show_avatars = show_avatars;
1520 model = GTK_TREE_MODEL (self);
1522 gtk_tree_model_foreach (model,
1523 (GtkTreeModelForeachFunc)
1524 individual_store_update_list_mode_foreach, self);
1526 g_object_notify (G_OBJECT (self), "show-avatars");
1530 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1532 EmpathyIndividualStorePriv *priv;
1534 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1536 priv = GET_PRIV (self);
1538 return priv->show_protocols;
1542 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1543 gboolean show_protocols)
1545 EmpathyIndividualStorePriv *priv;
1546 GtkTreeModel *model;
1548 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1550 priv = GET_PRIV (self);
1552 priv->show_protocols = show_protocols;
1554 model = GTK_TREE_MODEL (self);
1556 gtk_tree_model_foreach (model,
1557 (GtkTreeModelForeachFunc)
1558 individual_store_update_list_mode_foreach, self);
1560 g_object_notify (G_OBJECT (self), "show-protocols");
1564 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1566 EmpathyIndividualStorePriv *priv;
1568 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1570 priv = GET_PRIV (self);
1572 return priv->show_groups;
1576 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1577 gboolean show_groups)
1579 EmpathyIndividualStorePriv *priv;
1581 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1583 priv = GET_PRIV (self);
1585 if (priv->show_groups == show_groups)
1590 priv->show_groups = show_groups;
1592 if (priv->setup_idle_id == 0)
1594 /* Remove all contacts and add them back, not optimized but
1595 * that's the easy way :)
1597 * This is only done if there's not a pending setup idle
1598 * callback, otherwise it will race and the contacts will get
1602 gtk_tree_store_clear (GTK_TREE_STORE (self));
1603 contacts = empathy_individual_manager_get_members (priv->manager);
1605 individual_store_members_changed_cb (priv->manager,
1606 "re-adding members: toggled group visibility",
1607 contacts, NULL, 0, self);
1608 g_list_free (contacts);
1611 g_object_notify (G_OBJECT (self), "show-groups");
1615 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1617 EmpathyIndividualStorePriv *priv;
1619 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1621 priv = GET_PRIV (self);
1623 return priv->is_compact;
1627 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1628 gboolean is_compact)
1630 EmpathyIndividualStorePriv *priv;
1631 GtkTreeModel *model;
1633 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1635 priv = GET_PRIV (self);
1637 priv->is_compact = is_compact;
1639 model = GTK_TREE_MODEL (self);
1641 gtk_tree_model_foreach (model,
1642 (GtkTreeModelForeachFunc)
1643 individual_store_update_list_mode_foreach, self);
1645 g_object_notify (G_OBJECT (self), "is-compact");
1648 EmpathyIndividualStoreSort
1649 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1651 EmpathyIndividualStorePriv *priv;
1653 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1655 priv = GET_PRIV (self);
1657 return priv->sort_criterium;
1661 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1662 EmpathyIndividualStoreSort sort_criterium)
1664 EmpathyIndividualStorePriv *priv;
1666 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1668 priv = GET_PRIV (self);
1670 priv->sort_criterium = sort_criterium;
1672 switch (sort_criterium)
1674 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1675 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1676 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1679 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1680 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1681 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1685 g_assert_not_reached ();
1688 g_object_notify (G_OBJECT (self), "sort-criterium");
1692 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1696 gboolean is_separator = FALSE;
1698 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1700 gtk_tree_model_get (model, iter,
1701 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1703 return is_separator;
1707 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1709 gboolean *path_is_group,
1710 gboolean *is_fake_group)
1712 GtkTreeIter parent_iter, iter;
1717 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1721 *path_is_group = FALSE;
1724 if (!gtk_tree_model_get_iter (model, &iter, path))
1729 gtk_tree_model_get (model, &iter,
1730 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1731 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1738 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1745 gtk_tree_model_get (model, &iter,
1746 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1747 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1748 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1758 *path_is_group = TRUE;
1761 if (is_fake_group != NULL)
1762 *is_fake_group = fake;
1768 individual_store_get_individual_status_icon_with_icon_name (
1769 EmpathyIndividualStore *self,
1770 FolksIndividual *individual,
1771 const gchar *status_icon_name)
1773 GdkPixbuf *pixbuf_status = NULL;
1774 EmpathyIndividualStorePriv *priv;
1775 const gchar *protocol_name = NULL;
1776 gchar *icon_name = NULL;
1777 GList *personas, *l;
1778 guint contact_count;
1779 EmpathyContact *contact = NULL;
1780 gboolean show_protocols_here;
1782 priv = GET_PRIV (self);
1784 personas = folks_individual_get_personas (individual);
1785 for (l = personas, contact_count = 0; l; l = l->next)
1787 if (TPF_IS_PERSONA (l->data))
1790 if (contact_count > 1)
1794 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1795 if (show_protocols_here)
1797 contact = empathy_contact_dup_from_folks_individual (individual);
1798 protocol_name = empathy_protocol_name_for_contact (contact);
1799 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1803 icon_name = g_strdup_printf ("%s", status_icon_name);
1805 if (pixbuf_status == NULL)
1808 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1809 status_icon_name, priv->show_protocols);
1810 if (pixbuf_status != NULL)
1812 g_hash_table_insert (priv->status_icons,
1813 g_strdup (icon_name), pixbuf_status);
1818 tp_clear_object (&contact);
1820 return pixbuf_status;
1824 empathy_individual_store_get_individual_status_icon (
1825 EmpathyIndividualStore *self,
1826 FolksIndividual *individual)
1828 GdkPixbuf *pixbuf_status = NULL;
1829 const gchar *status_icon_name = NULL;
1831 status_icon_name = empathy_icon_name_for_individual (individual);
1832 if (status_icon_name == NULL)
1836 individual_store_get_individual_status_icon_with_icon_name (self,
1837 individual, status_icon_name);
1839 return pixbuf_status;