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_offline;
65 gboolean show_avatars;
68 gboolean show_protocols;
70 EmpathyIndividualStoreSort sort_criterium;
73 gboolean dispose_has_run;
74 GHashTable *status_icons;
75 } EmpathyIndividualStorePriv;
86 FolksIndividual *individual;
93 EmpathyIndividualStore *self;
94 FolksIndividual *individual;
101 PROP_INDIVIDUAL_MANAGER,
110 /* prototypes to break cycles */
111 static void individual_store_contact_update (EmpathyIndividualStore *self,
112 FolksIndividual *individual);
114 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
115 GTK_TYPE_TREE_STORE);
118 add_individual_to_store (GtkTreeStore *self,
121 FolksIndividual *individual,
122 EmpathyIndividualManagerFlags flags)
124 gtk_tree_store_insert_with_values (self, iter, parent, 0,
125 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
126 folks_individual_get_alias (individual),
127 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
128 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
129 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
130 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
131 folks_individual_get_capabilities (individual) &
132 FOLKS_CAPABILITIES_FLAGS_AUDIO,
133 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
134 folks_individual_get_capabilities (individual) &
135 FOLKS_CAPABILITIES_FLAGS_VIDEO,
136 EMPATHY_INDIVIDUAL_STORE_COL_FLAGS, flags,
141 individual_store_get_group_foreach (GtkTreeModel *model,
149 /* Groups are only at the top level. */
150 if (gtk_tree_path_get_depth (path) != 1)
155 gtk_tree_model_get (model, iter,
156 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
157 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
159 if (is_group && !tp_strdiff (str, fg->name))
171 individual_store_get_group (EmpathyIndividualStore *self,
173 GtkTreeIter *iter_group_to_set,
174 GtkTreeIter *iter_separator_to_set,
176 gboolean is_fake_group)
178 EmpathyIndividualStorePriv *priv;
180 GtkTreeIter iter_group;
181 GtkTreeIter iter_separator;
184 priv = GET_PRIV (self);
186 memset (&fg, 0, sizeof (fg));
190 model = GTK_TREE_MODEL (self);
191 gtk_tree_model_foreach (model,
192 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
201 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
203 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
204 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
205 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
206 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
207 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
208 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
211 if (iter_group_to_set)
213 *iter_group_to_set = iter_group;
216 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
218 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
221 if (iter_separator_to_set)
223 *iter_separator_to_set = iter_separator;
233 if (iter_group_to_set)
235 *iter_group_to_set = fg.iter;
238 iter_separator = fg.iter;
240 if (gtk_tree_model_iter_next (model, &iter_separator))
242 gboolean is_separator;
244 gtk_tree_model_get (model, &iter_separator,
245 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
247 if (is_separator && iter_separator_to_set)
249 *iter_separator_to_set = iter_separator;
256 individual_store_find_contact_foreach (GtkTreeModel *model,
261 FolksIndividual *individual;
263 gtk_tree_model_get (model, iter,
264 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
266 if (individual == fc->individual)
269 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
272 tp_clear_object (&individual);
278 individual_store_find_contact (EmpathyIndividualStore *self,
279 FolksIndividual *individual)
281 EmpathyIndividualStorePriv *priv;
286 priv = GET_PRIV (self);
288 memset (&fc, 0, sizeof (fc));
290 fc.individual = individual;
292 model = GTK_TREE_MODEL (self);
293 gtk_tree_model_foreach (model,
294 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
305 individual_store_remove_individual (EmpathyIndividualStore *self,
306 FolksIndividual *individual)
308 EmpathyIndividualStorePriv *priv;
312 priv = GET_PRIV (self);
314 iters = individual_store_find_contact (self, individual);
321 model = GTK_TREE_MODEL (self);
323 for (l = iters; l; l = l->next)
327 /* NOTE: it is only <= 2 here because we have
328 * separators after the group name, otherwise it
331 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
332 gtk_tree_model_iter_n_children (model, &parent) <= 2)
334 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
338 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
342 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
347 individual_store_add_individual (EmpathyIndividualStore *self,
348 FolksIndividual *individual)
350 EmpathyIndividualStorePriv *priv;
352 GHashTable *group_set = NULL;
353 GList *groups = NULL, *l;
354 EmpathyIndividualManager *manager;
355 EmpathyContact *contact;
356 TpConnection *connection;
357 EmpathyIndividualManagerFlags flags = 0;
359 priv = GET_PRIV (self);
361 if (EMP_STR_EMPTY (folks_individual_get_alias (individual)) ||
362 (!priv->show_offline && !folks_individual_is_online (individual)))
367 if (priv->show_groups)
369 group_set = folks_individual_get_groups (individual);
370 groups = g_hash_table_get_keys (group_set);
373 manager = empathy_individual_manager_dup_singleton ();
374 contact = empathy_contact_dup_from_folks_individual (individual);
375 connection = empathy_contact_get_connection (contact);
376 flags = empathy_individual_manager_get_flags_for_connection (manager,
381 GtkTreeIter iter_group, *parent;
383 parent = &iter_group;
385 /* TODO: implement */
386 DEBUG ("forcing the People Nearby group even when 'show "
387 "groups' is off is unimplemented");
389 if (!priv->show_groups)
395 individual_store_get_group (self,
396 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
397 &iter_group, NULL, NULL, TRUE);
400 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
404 /* Else add to each group. */
405 for (l = groups; l; l = l->next)
407 GtkTreeIter iter_group;
409 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
412 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
415 g_list_free (groups);
416 if (group_set != NULL)
417 g_hash_table_unref (group_set);
419 if (priv->show_groups &&
420 folks_favourite_get_is_favourite (FOLKS_FAVOURITE (individual)))
422 /* Add contact to the fake 'Favorites' group */
423 GtkTreeIter iter_group;
425 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
426 &iter_group, NULL, NULL, TRUE);
428 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
432 individual_store_contact_update (self, individual);
434 tp_clear_object (&contact);
438 individual_store_contact_set_active (EmpathyIndividualStore *self,
439 FolksIndividual *individual,
441 gboolean set_changed)
443 EmpathyIndividualStorePriv *priv;
447 priv = GET_PRIV (self);
448 model = GTK_TREE_MODEL (self);
450 iters = individual_store_find_contact (self, individual);
451 for (l = iters; l; l = l->next)
455 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
456 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
459 DEBUG ("Set item %s", active ? "active" : "inactive");
463 path = gtk_tree_model_get_path (model, l->data);
464 gtk_tree_model_row_changed (model, path, l->data);
465 gtk_tree_path_free (path);
469 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
474 static ShowActiveData *
475 individual_store_contact_active_new (EmpathyIndividualStore *self,
476 FolksIndividual *individual,
479 ShowActiveData *data;
481 DEBUG ("Individual'%s' now active, and %s be removed",
482 folks_individual_get_alias (individual), remove_ ? "WILL" : "WILL NOT");
484 data = g_slice_new0 (ShowActiveData);
486 data->self = g_object_ref (self);
487 data->individual = g_object_ref (individual);
488 data->remove = remove_;
494 individual_store_contact_active_free (ShowActiveData *data)
496 g_object_unref (data->individual);
497 g_object_unref (data->self);
499 g_slice_free (ShowActiveData, data);
503 individual_store_contact_active_cb (ShowActiveData *data)
505 EmpathyIndividualStorePriv *priv;
507 priv = GET_PRIV (data->self);
510 !priv->show_offline && !folks_individual_is_online (data->individual))
512 DEBUG ("Individual'%s' active timeout, removing item",
513 folks_individual_get_alias (data->individual));
514 individual_store_remove_individual (data->self, data->individual);
517 DEBUG ("Individual'%s' no longer active",
518 folks_individual_get_alias (data->individual));
520 individual_store_contact_set_active (data->self,
521 data->individual, FALSE, TRUE);
523 individual_store_contact_active_free (data);
529 individual_avatar_pixbuf_received_cb (GObject *object,
530 GAsyncResult *result,
533 FolksIndividual *individual = FOLKS_INDIVIDUAL (object);
534 EmpathyIndividualStore *self = user_data;
535 GError *error = NULL;
538 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
543 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
544 folks_individual_get_alias (individual),
546 g_clear_error (&error);
552 iters = individual_store_find_contact (self, individual);
553 for (l = iters; l; l = l->next)
555 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
556 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
563 individual_store_contact_update (EmpathyIndividualStore *self,
564 FolksIndividual *individual)
566 EmpathyIndividualStorePriv *priv;
567 ShowActiveData *data;
571 gboolean should_be_in_list;
572 gboolean was_online = TRUE;
573 gboolean now_online = FALSE;
574 gboolean set_model = FALSE;
575 gboolean do_remove = FALSE;
576 gboolean do_set_active = FALSE;
577 gboolean do_set_refresh = FALSE;
578 gboolean show_avatar = FALSE;
579 GdkPixbuf *pixbuf_status;
581 priv = GET_PRIV (self);
583 model = GTK_TREE_MODEL (self);
585 iters = individual_store_find_contact (self, individual);
595 /* Get online state now. */
596 now_online = folks_individual_is_online (individual);
598 if (priv->show_offline || now_online)
600 should_be_in_list = TRUE;
604 should_be_in_list = FALSE;
607 if (!in_list && !should_be_in_list)
610 DEBUG ("Individual:'%s' in list:NO, should be:NO",
611 folks_individual_get_alias (individual));
613 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
617 else if (in_list && !should_be_in_list)
619 DEBUG ("Individual:'%s' in list:YES, should be:NO",
620 folks_individual_get_alias (individual));
622 if (priv->show_active)
625 do_set_active = TRUE;
626 do_set_refresh = TRUE;
629 DEBUG ("Remove item (after timeout)");
633 DEBUG ("Remove item (now)!");
634 individual_store_remove_individual (self, individual);
637 else if (!in_list && should_be_in_list)
639 DEBUG ("Individual'%s' in list:NO, should be:YES",
640 folks_individual_get_alias (individual));
642 individual_store_add_individual (self, individual);
644 if (priv->show_active)
646 do_set_active = TRUE;
648 DEBUG ("Set active (individual added)");
653 DEBUG ("Individual'%s' in list:YES, should be:YES",
654 folks_individual_get_alias (individual));
656 /* Get online state before. */
657 if (iters && g_list_length (iters) > 0)
659 gtk_tree_model_get (model, iters->data,
660 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
663 /* Is this really an update or an online/offline. */
664 if (priv->show_active)
666 if (was_online != now_online)
668 do_set_active = TRUE;
669 do_set_refresh = TRUE;
671 DEBUG ("Set active (individual updated %s)",
672 was_online ? "online -> offline" : "offline -> online");
676 /* Was TRUE for presence updates. */
677 /* do_set_active = FALSE; */
678 do_set_refresh = TRUE;
680 DEBUG ("Set active (individual updated)");
687 if (priv->show_avatars && !priv->is_compact)
692 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
693 individual_avatar_pixbuf_received_cb, 32, 32, self);
696 empathy_individual_store_get_individual_status_icon (self, individual);
698 for (l = iters; l && set_model; l = l->next)
700 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
701 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
702 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
703 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
704 folks_individual_get_alias (individual),
705 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
706 folks_individual_get_presence_type (individual),
707 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
708 folks_individual_get_presence_message (individual),
709 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
710 folks_individual_get_capabilities (individual) &
711 FOLKS_CAPABILITIES_FLAGS_AUDIO,
712 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
713 folks_individual_get_capabilities (individual) &
714 FOLKS_CAPABILITIES_FLAGS_VIDEO,
715 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
716 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
717 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
718 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
722 if (priv->show_active && do_set_active)
724 individual_store_contact_set_active (self, individual, do_set_active,
730 individual_store_contact_active_new (self, individual,
732 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
733 (GSourceFunc) individual_store_contact_active_cb, data);
737 /* FIXME: when someone goes online then offline quickly, the
738 * first timeout sets the user to be inactive and the second
739 * timeout removes the user from the contact list, really we
740 * should remove the first timeout.
742 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
747 individual_store_contact_updated_cb (FolksIndividual *individual,
749 EmpathyIndividualStore *self)
751 DEBUG ("Individual'%s' updated, checking roster is in sync...",
752 folks_individual_get_alias (individual));
754 individual_store_contact_update (self, individual);
758 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
759 FolksIndividual *individual)
761 g_signal_connect (individual, "notify::avatar",
762 G_CALLBACK (individual_store_contact_updated_cb), self);
763 g_signal_connect (individual, "notify::presence-type",
764 G_CALLBACK (individual_store_contact_updated_cb), self);
765 g_signal_connect (individual, "notify::presence-message",
766 G_CALLBACK (individual_store_contact_updated_cb), self);
767 g_signal_connect (individual, "notify::alias",
768 G_CALLBACK (individual_store_contact_updated_cb), self);
769 g_signal_connect (individual, "notify::capabilities",
770 G_CALLBACK (individual_store_contact_updated_cb), self);
772 individual_store_add_individual (self, individual);
776 individual_store_remove_individual_and_disconnect (
777 EmpathyIndividualStore *self,
778 FolksIndividual *individual)
780 g_signal_handlers_disconnect_by_func (individual,
781 G_CALLBACK (individual_store_contact_updated_cb), self);
783 individual_store_remove_individual (self, individual);
787 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
792 EmpathyIndividualStore *self)
796 for (l = added; l; l = l->next)
798 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
800 individual_store_add_individual_and_connect (self, l->data);
802 for (l = removed; l; l = l->next)
804 DEBUG ("Individual %s %s",
805 folks_individual_get_id (l->data), "removed");
807 individual_store_remove_individual_and_disconnect (self, l->data);
812 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
813 FolksIndividual *individual,
814 gboolean is_favourite,
815 EmpathyIndividualStore *self)
817 EmpathyIndividualStorePriv *priv;
819 priv = GET_PRIV (self);
821 DEBUG ("Individual %s is %s a favourite",
822 folks_individual_get_id (individual),
823 is_favourite ? "now" : "no longer");
825 individual_store_remove_individual (self, individual);
826 individual_store_add_individual (self, individual);
830 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
831 FolksIndividual *individual,
834 EmpathyIndividualStore *self)
836 EmpathyIndividualStorePriv *priv;
837 gboolean show_active;
839 priv = GET_PRIV (self);
841 DEBUG ("Updating groups for individual %s",
842 folks_individual_get_id (individual));
844 /* We do this to make sure the groups are correct, if not, we
845 * would have to check the groups already set up for each
846 * contact and then see what has been updated.
848 show_active = priv->show_active;
849 priv->show_active = FALSE;
850 individual_store_remove_individual (self, individual);
851 individual_store_add_individual (self, individual);
852 priv->show_active = show_active;
856 individual_store_manager_setup (gpointer user_data)
858 EmpathyIndividualStore *self = user_data;
859 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
862 /* Signal connection. */
864 /* TODO: implement */
865 DEBUG ("handling individual renames unimplemented");
867 g_signal_connect (priv->manager,
869 G_CALLBACK (individual_store_members_changed_cb), self);
871 g_signal_connect (priv->manager,
872 "favourites-changed",
873 G_CALLBACK (individual_store_favourites_changed_cb), self);
875 g_signal_connect (priv->manager,
877 G_CALLBACK (individual_store_groups_changed_cb), self);
879 /* Add contacts already created. */
880 individuals = empathy_individual_manager_get_members (priv->manager);
881 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
883 individual_store_members_changed_cb (priv->manager, "initial add",
884 individuals, NULL, 0, self);
885 g_list_free (individuals);
888 priv->setup_idle_id = 0;
893 individual_store_set_individual_manager (EmpathyIndividualStore *self,
894 EmpathyIndividualManager *manager)
896 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
898 priv->manager = g_object_ref (manager);
900 /* Let a chance to have all properties set before populating */
901 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
905 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
906 FolksIndividual *old_individual,
907 FolksIndividual *new_individual,
910 EmpathyIndividualStore *self)
912 EmpathyIndividualStorePriv *priv;
914 priv = GET_PRIV (self);
916 DEBUG ("Individual %s renamed to %s",
917 folks_individual_get_id (old_individual),
918 folks_individual_get_id (new_individual));
920 /* add the new contact */
921 individual_store_add_individual_and_connect (self, new_individual);
923 /* remove old contact */
924 individual_store_remove_individual_and_disconnect (self, old_individual);
928 individual_store_dispose (GObject *object)
930 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
933 if (priv->dispose_has_run)
935 priv->dispose_has_run = TRUE;
937 contacts = empathy_individual_manager_get_members (priv->manager);
938 for (l = contacts; l; l = l->next)
940 g_signal_handlers_disconnect_by_func (l->data,
941 G_CALLBACK (individual_store_contact_updated_cb), object);
943 g_list_free (contacts);
945 g_signal_handlers_disconnect_by_func (priv->manager,
946 G_CALLBACK (individual_store_member_renamed_cb), object);
947 g_signal_handlers_disconnect_by_func (priv->manager,
948 G_CALLBACK (individual_store_members_changed_cb), object);
949 g_signal_handlers_disconnect_by_func (priv->manager,
950 G_CALLBACK (individual_store_favourites_changed_cb), object);
951 g_signal_handlers_disconnect_by_func (priv->manager,
952 G_CALLBACK (individual_store_groups_changed_cb), object);
953 g_object_unref (priv->manager);
955 if (priv->inhibit_active)
957 g_source_remove (priv->inhibit_active);
960 if (priv->setup_idle_id != 0)
962 g_source_remove (priv->setup_idle_id);
965 g_hash_table_destroy (priv->status_icons);
966 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
970 individual_store_get_property (GObject *object,
975 EmpathyIndividualStorePriv *priv;
977 priv = GET_PRIV (object);
981 case PROP_INDIVIDUAL_MANAGER:
982 g_value_set_object (value, priv->manager);
984 case PROP_SHOW_OFFLINE:
985 g_value_set_boolean (value, priv->show_offline);
987 case PROP_SHOW_AVATARS:
988 g_value_set_boolean (value, priv->show_avatars);
990 case PROP_SHOW_PROTOCOLS:
991 g_value_set_boolean (value, priv->show_protocols);
993 case PROP_SHOW_GROUPS:
994 g_value_set_boolean (value, priv->show_groups);
996 case PROP_IS_COMPACT:
997 g_value_set_boolean (value, priv->is_compact);
999 case PROP_SORT_CRITERIUM:
1000 g_value_set_enum (value, priv->sort_criterium);
1003 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1009 individual_store_set_property (GObject *object,
1011 const GValue *value,
1014 EmpathyIndividualStorePriv *priv;
1016 priv = GET_PRIV (object);
1020 case PROP_INDIVIDUAL_MANAGER:
1021 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1022 (object), g_value_get_object (value));
1024 case PROP_SHOW_OFFLINE:
1025 empathy_individual_store_set_show_offline (EMPATHY_INDIVIDUAL_STORE
1026 (object), g_value_get_boolean (value));
1028 case PROP_SHOW_AVATARS:
1029 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1030 (object), g_value_get_boolean (value));
1032 case PROP_SHOW_PROTOCOLS:
1033 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1034 (object), g_value_get_boolean (value));
1036 case PROP_SHOW_GROUPS:
1037 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1038 (object), g_value_get_boolean (value));
1040 case PROP_IS_COMPACT:
1041 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1042 (object), g_value_get_boolean (value));
1044 case PROP_SORT_CRITERIUM:
1045 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1046 (object), g_value_get_enum (value));
1049 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1055 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1057 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1059 object_class->dispose = individual_store_dispose;
1060 object_class->get_property = individual_store_get_property;
1061 object_class->set_property = individual_store_set_property;
1063 g_object_class_install_property (object_class,
1064 PROP_INDIVIDUAL_MANAGER,
1065 g_param_spec_object ("individual-manager",
1066 "The individual manager",
1067 "The individual manager",
1068 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1069 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1070 g_object_class_install_property (object_class,
1072 g_param_spec_boolean ("show-offline",
1074 "Whether contact list should display "
1075 "offline contacts", FALSE, G_PARAM_READWRITE));
1076 g_object_class_install_property (object_class,
1078 g_param_spec_boolean ("show-avatars",
1080 "Whether contact list should display "
1081 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1082 g_object_class_install_property (object_class,
1083 PROP_SHOW_PROTOCOLS,
1084 g_param_spec_boolean ("show-protocols",
1086 "Whether contact list should display "
1087 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1088 g_object_class_install_property (object_class,
1090 g_param_spec_boolean ("show-groups",
1092 "Whether contact list should display "
1093 "contact groups", TRUE, G_PARAM_READWRITE));
1094 g_object_class_install_property (object_class,
1096 g_param_spec_boolean ("is-compact",
1098 "Whether the contact list is in compact mode or not",
1099 FALSE, G_PARAM_READWRITE));
1101 g_object_class_install_property (object_class,
1102 PROP_SORT_CRITERIUM,
1103 g_param_spec_enum ("sort-criterium",
1105 "The sort criterium to use for sorting the contact list",
1106 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1107 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1109 g_type_class_add_private (object_class,
1110 sizeof (EmpathyIndividualStorePriv));
1114 get_position (const char **strv,
1119 for (i = 0; strv[i] != NULL; i++)
1121 if (!tp_strdiff (strv[i], str))
1129 compare_separator_and_groups (gboolean is_separator_a,
1130 gboolean is_separator_b,
1131 const gchar *name_a,
1132 const gchar *name_b,
1133 FolksIndividual *individual_a,
1134 FolksIndividual *individual_b,
1135 gboolean fake_group_a,
1136 gboolean fake_group_b)
1138 /* these two lists are the sorted list of fake groups to include at the
1139 * top and bottom of the roster */
1140 const char *top_groups[] = {
1141 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1145 const char *bottom_groups[] = {
1146 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1150 if (is_separator_a || is_separator_b)
1152 /* We have at least one separator */
1157 else if (is_separator_b)
1163 /* One group and one contact */
1164 if (!individual_a && individual_b)
1168 else if (individual_a && !individual_b)
1172 else if (!individual_a && !individual_b)
1174 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1176 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1177 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1178 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1179 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1181 if (a_in_top && b_in_top)
1183 /* compare positions */
1184 return CLAMP (get_position (top_groups, name_a) -
1185 get_position (top_groups, name_b), -1, 1);
1187 else if (a_in_bottom && b_in_bottom)
1189 /* compare positions */
1190 return CLAMP (get_position (bottom_groups, name_a) -
1191 get_position (bottom_groups, name_b), -1, 1);
1193 else if (a_in_top || b_in_bottom)
1197 else if (b_in_top || a_in_bottom)
1203 return g_utf8_collate (name_a, name_b);
1207 /* Two contacts, ordering depends of the sorting policy */
1212 individual_store_contact_sort (FolksIndividual *individual_a,
1213 FolksIndividual *individual_b)
1217 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1220 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1221 folks_individual_get_alias (individual_b));
1227 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1228 folks_individual_get_id (individual_b));
1238 individual_store_state_sort_func (GtkTreeModel *model,
1239 GtkTreeIter *iter_a,
1240 GtkTreeIter *iter_b,
1244 FolksIndividual *individual_a, *individual_b;
1245 gchar *name_a, *name_b;
1246 gboolean is_separator_a, is_separator_b;
1247 gboolean fake_group_a, fake_group_b;
1248 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1249 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1251 gtk_tree_model_get (model, iter_a,
1252 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1253 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1254 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1255 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1256 gtk_tree_model_get (model, iter_b,
1257 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1258 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1259 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1260 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1262 if (individual_a == NULL || individual_b == NULL)
1264 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1265 name_a, name_b, individual_a, individual_b, fake_group_a,
1270 /* If we managed to get this far, we can start looking at
1273 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1274 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1275 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1276 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1278 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1283 /* Fallback: compare by name et al. */
1284 ret_val = individual_store_contact_sort (individual_a, individual_b);
1290 tp_clear_object (&individual_a);
1291 tp_clear_object (&individual_b);
1297 individual_store_name_sort_func (GtkTreeModel *model,
1298 GtkTreeIter *iter_a,
1299 GtkTreeIter *iter_b,
1302 gchar *name_a, *name_b;
1303 FolksIndividual *individual_a, *individual_b;
1304 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1306 gboolean fake_group_a, fake_group_b;
1308 gtk_tree_model_get (model, iter_a,
1309 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1310 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1311 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1312 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1313 gtk_tree_model_get (model, iter_b,
1314 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1315 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1316 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1317 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1319 if (individual_a == NULL || individual_b == NULL)
1320 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1321 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1323 ret_val = individual_store_contact_sort (individual_a, individual_b);
1325 tp_clear_object (&individual_a);
1326 tp_clear_object (&individual_b);
1332 individual_store_setup (EmpathyIndividualStore *self)
1334 EmpathyIndividualStorePriv *priv;
1336 GDK_TYPE_PIXBUF, /* Status pixbuf */
1337 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1338 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1339 G_TYPE_STRING, /* Name */
1340 G_TYPE_UINT, /* Presence type */
1341 G_TYPE_STRING, /* Status string */
1342 G_TYPE_BOOLEAN, /* Compact view */
1343 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1344 G_TYPE_BOOLEAN, /* Is group */
1345 G_TYPE_BOOLEAN, /* Is active */
1346 G_TYPE_BOOLEAN, /* Is online */
1347 G_TYPE_BOOLEAN, /* Is separator */
1348 G_TYPE_BOOLEAN, /* Can make audio calls */
1349 G_TYPE_BOOLEAN, /* Can make video calls */
1350 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1351 G_TYPE_BOOLEAN, /* Is a fake group */
1354 priv = GET_PRIV (self);
1356 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1357 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1359 /* Set up sorting */
1360 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1361 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1362 individual_store_name_sort_func, self, NULL);
1363 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1364 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1365 individual_store_state_sort_func, self, NULL);
1367 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1368 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1372 individual_store_inibit_active_cb (EmpathyIndividualStore *self)
1374 EmpathyIndividualStorePriv *priv;
1376 priv = GET_PRIV (self);
1378 priv->show_active = TRUE;
1379 priv->inhibit_active = 0;
1385 empathy_individual_store_init (EmpathyIndividualStore *self)
1387 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1388 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1391 priv->show_avatars = TRUE;
1392 priv->show_groups = TRUE;
1393 priv->show_protocols = FALSE;
1394 priv->inhibit_active =
1395 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1396 (GSourceFunc) individual_store_inibit_active_cb, self);
1397 priv->status_icons =
1398 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1399 individual_store_setup (self);
1402 EmpathyIndividualStore *
1403 empathy_individual_store_new (EmpathyIndividualManager *manager)
1405 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1407 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1408 "individual-manager", manager, NULL);
1411 EmpathyIndividualManager *
1412 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1414 EmpathyIndividualStorePriv *priv;
1416 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1418 priv = GET_PRIV (self);
1420 return priv->manager;
1424 empathy_individual_store_get_show_offline (EmpathyIndividualStore *self)
1426 EmpathyIndividualStorePriv *priv;
1428 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1430 priv = GET_PRIV (self);
1432 return priv->show_offline;
1436 empathy_individual_store_set_show_offline (EmpathyIndividualStore *self,
1437 gboolean show_offline)
1439 EmpathyIndividualStorePriv *priv;
1440 GList *contacts, *l;
1441 gboolean show_active;
1443 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1445 priv = GET_PRIV (self);
1447 priv->show_offline = show_offline;
1448 show_active = priv->show_active;
1450 /* Disable temporarily. */
1451 priv->show_active = FALSE;
1453 contacts = empathy_individual_manager_get_members (priv->manager);
1454 for (l = contacts; l; l = l->next)
1456 individual_store_contact_update (self, l->data);
1458 g_list_free (contacts);
1460 /* Restore to original setting. */
1461 priv->show_active = show_active;
1463 g_object_notify (G_OBJECT (self), "show-offline");
1467 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1469 EmpathyIndividualStorePriv *priv;
1471 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1473 priv = GET_PRIV (self);
1475 return priv->show_avatars;
1479 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1482 EmpathyIndividualStore *self)
1484 EmpathyIndividualStorePriv *priv;
1485 gboolean show_avatar = FALSE;
1486 FolksIndividual *individual;
1487 GdkPixbuf *pixbuf_status;
1489 priv = GET_PRIV (self);
1491 if (priv->show_avatars && !priv->is_compact)
1496 gtk_tree_model_get (model, iter,
1497 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1499 if (individual == NULL)
1503 /* get icon from hash_table */
1505 empathy_individual_store_get_individual_status_icon (self, individual);
1507 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1508 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1509 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1510 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1512 g_object_unref (individual);
1518 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1519 gboolean show_avatars)
1521 EmpathyIndividualStorePriv *priv;
1522 GtkTreeModel *model;
1524 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1526 priv = GET_PRIV (self);
1528 priv->show_avatars = show_avatars;
1530 model = GTK_TREE_MODEL (self);
1532 gtk_tree_model_foreach (model,
1533 (GtkTreeModelForeachFunc)
1534 individual_store_update_list_mode_foreach, self);
1536 g_object_notify (G_OBJECT (self), "show-avatars");
1540 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1542 EmpathyIndividualStorePriv *priv;
1544 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1546 priv = GET_PRIV (self);
1548 return priv->show_protocols;
1552 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1553 gboolean show_protocols)
1555 EmpathyIndividualStorePriv *priv;
1556 GtkTreeModel *model;
1558 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1560 priv = GET_PRIV (self);
1562 priv->show_protocols = show_protocols;
1564 model = GTK_TREE_MODEL (self);
1566 gtk_tree_model_foreach (model,
1567 (GtkTreeModelForeachFunc)
1568 individual_store_update_list_mode_foreach, self);
1570 g_object_notify (G_OBJECT (self), "show-protocols");
1574 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1576 EmpathyIndividualStorePriv *priv;
1578 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1580 priv = GET_PRIV (self);
1582 return priv->show_groups;
1586 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1587 gboolean show_groups)
1589 EmpathyIndividualStorePriv *priv;
1591 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1593 priv = GET_PRIV (self);
1595 if (priv->show_groups == show_groups)
1600 priv->show_groups = show_groups;
1602 if (priv->setup_idle_id == 0)
1604 /* Remove all contacts and add them back, not optimized but
1605 * that's the easy way :)
1607 * This is only done if there's not a pending setup idle
1608 * callback, otherwise it will race and the contacts will get
1612 gtk_tree_store_clear (GTK_TREE_STORE (self));
1613 contacts = empathy_individual_manager_get_members (priv->manager);
1615 individual_store_members_changed_cb (priv->manager,
1616 "re-adding members: toggled group visibility",
1617 contacts, NULL, 0, self);
1618 g_list_free (contacts);
1621 g_object_notify (G_OBJECT (self), "show-groups");
1625 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1627 EmpathyIndividualStorePriv *priv;
1629 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1631 priv = GET_PRIV (self);
1633 return priv->is_compact;
1637 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1638 gboolean is_compact)
1640 EmpathyIndividualStorePriv *priv;
1641 GtkTreeModel *model;
1643 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1645 priv = GET_PRIV (self);
1647 priv->is_compact = is_compact;
1649 model = GTK_TREE_MODEL (self);
1651 gtk_tree_model_foreach (model,
1652 (GtkTreeModelForeachFunc)
1653 individual_store_update_list_mode_foreach, self);
1655 g_object_notify (G_OBJECT (self), "is-compact");
1658 EmpathyIndividualStoreSort
1659 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1661 EmpathyIndividualStorePriv *priv;
1663 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1665 priv = GET_PRIV (self);
1667 return priv->sort_criterium;
1671 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1672 EmpathyIndividualStoreSort sort_criterium)
1674 EmpathyIndividualStorePriv *priv;
1676 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1678 priv = GET_PRIV (self);
1680 priv->sort_criterium = sort_criterium;
1682 switch (sort_criterium)
1684 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1685 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1686 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1689 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1690 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1691 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1695 g_object_notify (G_OBJECT (self), "sort-criterium");
1699 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1703 gboolean is_separator = FALSE;
1705 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1707 gtk_tree_model_get (model, iter,
1708 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1710 return is_separator;
1714 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1716 gboolean *path_is_group,
1717 gboolean *is_fake_group)
1719 GtkTreeIter parent_iter, iter;
1724 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1728 *path_is_group = FALSE;
1731 if (!gtk_tree_model_get_iter (model, &iter, path))
1736 gtk_tree_model_get (model, &iter,
1737 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1738 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1745 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1752 gtk_tree_model_get (model, &iter,
1753 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1754 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1755 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1765 *path_is_group = TRUE;
1768 if (is_fake_group != NULL)
1769 *is_fake_group = fake;
1775 individual_store_get_individual_status_icon_with_icon_name (
1776 EmpathyIndividualStore *self,
1777 FolksIndividual *individual,
1778 const gchar *status_icon_name)
1780 GdkPixbuf *pixbuf_status = NULL;
1781 EmpathyIndividualStorePriv *priv;
1782 const gchar *protocol_name = NULL;
1783 gchar *icon_name = NULL;
1784 GList *personas, *l;
1785 guint contact_count;
1786 EmpathyContact *contact = NULL;
1787 gboolean show_protocols_here;
1789 priv = GET_PRIV (self);
1791 personas = folks_individual_get_personas (individual);
1792 for (l = personas, contact_count = 0; l; l = l->next)
1794 if (TPF_IS_PERSONA (l->data))
1797 if (contact_count > 1)
1801 show_protocols_here = priv->show_protocols && (contact_count == 1);
1802 if (show_protocols_here)
1804 contact = empathy_contact_dup_from_folks_individual (individual);
1805 protocol_name = empathy_protocol_name_for_contact (contact);
1806 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1810 icon_name = g_strdup_printf ("%s", status_icon_name);
1812 if (pixbuf_status == NULL)
1815 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1816 status_icon_name, priv->show_protocols);
1817 if (pixbuf_status != NULL)
1819 g_hash_table_insert (priv->status_icons,
1820 g_strdup (icon_name), pixbuf_status);
1825 tp_clear_object (&contact);
1827 return pixbuf_status;
1831 empathy_individual_store_get_individual_status_icon (
1832 EmpathyIndividualStore *self,
1833 FolksIndividual *individual)
1835 GdkPixbuf *pixbuf_status = NULL;
1836 const gchar *status_icon_name = NULL;
1838 status_icon_name = empathy_icon_name_for_individual (individual);
1839 if (status_icon_name == NULL)
1843 individual_store_get_individual_status_icon_with_icon_name (self,
1844 individual, status_icon_name);
1846 return pixbuf_status;