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));
274 g_object_unref (individual);
281 individual_store_find_contact (EmpathyIndividualStore *self,
282 FolksIndividual *individual)
284 EmpathyIndividualStorePriv *priv;
289 priv = GET_PRIV (self);
291 memset (&fc, 0, sizeof (fc));
293 fc.individual = individual;
295 model = GTK_TREE_MODEL (self);
296 gtk_tree_model_foreach (model,
297 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
308 individual_store_remove_individual (EmpathyIndividualStore *self,
309 FolksIndividual *individual)
311 EmpathyIndividualStorePriv *priv;
315 priv = GET_PRIV (self);
317 iters = individual_store_find_contact (self, individual);
324 model = GTK_TREE_MODEL (self);
326 for (l = iters; l; l = l->next)
330 /* NOTE: it is only <= 2 here because we have
331 * separators after the group name, otherwise it
334 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
335 gtk_tree_model_iter_n_children (model, &parent) <= 2)
337 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
341 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
345 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
350 individual_store_add_individual (EmpathyIndividualStore *self,
351 FolksIndividual *individual)
353 EmpathyIndividualStorePriv *priv;
355 GHashTable *group_set = NULL;
356 GList *groups = NULL, *l;
357 EmpathyIndividualManager *manager;
358 EmpathyContact *contact;
359 TpConnection *connection;
360 EmpathyIndividualManagerFlags flags = 0;
362 priv = GET_PRIV (self);
364 if (EMP_STR_EMPTY (folks_individual_get_alias (individual)) ||
365 (!priv->show_offline && !folks_individual_is_online (individual)))
370 if (priv->show_groups)
372 group_set = folks_individual_get_groups (individual);
373 groups = g_hash_table_get_keys (group_set);
376 manager = empathy_individual_manager_dup_singleton ();
377 contact = empathy_contact_from_folks_individual (individual);
378 connection = empathy_contact_get_connection (contact);
379 flags = empathy_individual_manager_get_flags_for_connection (manager,
384 GtkTreeIter iter_group, *parent;
386 parent = &iter_group;
388 /* TODO: implement */
389 DEBUG ("forcing the People Nearby group even when 'show "
390 "groups' is off is unimplemented");
392 if (!priv->show_groups)
398 individual_store_get_group (self,
399 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
400 &iter_group, NULL, NULL, TRUE);
403 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
407 /* Else add to each group. */
408 for (l = groups; l; l = l->next)
410 GtkTreeIter iter_group;
412 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
415 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
418 g_list_free (groups);
419 if (group_set != NULL)
420 g_hash_table_unref (group_set);
422 if (priv->show_groups &&
423 folks_favourite_get_is_favourite (FOLKS_FAVOURITE (individual)))
425 /* Add contact to the fake 'Favorites' group */
426 GtkTreeIter iter_group;
428 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
429 &iter_group, NULL, NULL, TRUE);
431 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
435 individual_store_contact_update (self, individual);
439 individual_store_contact_set_active (EmpathyIndividualStore *self,
440 FolksIndividual *individual,
442 gboolean set_changed)
444 EmpathyIndividualStorePriv *priv;
448 priv = GET_PRIV (self);
449 model = GTK_TREE_MODEL (self);
451 iters = individual_store_find_contact (self, individual);
452 for (l = iters; l; l = l->next)
456 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
457 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
460 DEBUG ("Set item %s", active ? "active" : "inactive");
464 path = gtk_tree_model_get_path (model, l->data);
465 gtk_tree_model_row_changed (model, path, l->data);
466 gtk_tree_path_free (path);
470 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
475 static ShowActiveData *
476 individual_store_contact_active_new (EmpathyIndividualStore *self,
477 FolksIndividual *individual,
480 ShowActiveData *data;
482 DEBUG ("Individual'%s' now active, and %s be removed",
483 folks_individual_get_alias (individual), remove_ ? "WILL" : "WILL NOT");
485 data = g_slice_new0 (ShowActiveData);
487 data->self = g_object_ref (self);
488 data->individual = g_object_ref (individual);
489 data->remove = remove_;
495 individual_store_contact_active_free (ShowActiveData *data)
497 g_object_unref (data->individual);
498 g_object_unref (data->self);
500 g_slice_free (ShowActiveData, data);
504 individual_store_contact_active_cb (ShowActiveData *data)
506 EmpathyIndividualStorePriv *priv;
508 priv = GET_PRIV (data->self);
511 !priv->show_offline && !folks_individual_is_online (data->individual))
513 DEBUG ("Individual'%s' active timeout, removing item",
514 folks_individual_get_alias (data->individual));
515 individual_store_remove_individual (data->self, data->individual);
518 DEBUG ("Individual'%s' no longer active",
519 folks_individual_get_alias (data->individual));
521 individual_store_contact_set_active (data->self,
522 data->individual, FALSE, TRUE);
524 individual_store_contact_active_free (data);
530 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
534 EmpathyIndividualStore *self = user_data;
537 iters = individual_store_find_contact (self, individual);
539 for (l = iters; l; l = l->next)
541 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
542 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
548 individual_store_contact_update (EmpathyIndividualStore *self,
549 FolksIndividual *individual)
551 EmpathyIndividualStorePriv *priv;
552 ShowActiveData *data;
556 gboolean should_be_in_list;
557 gboolean was_online = TRUE;
558 gboolean now_online = FALSE;
559 gboolean set_model = FALSE;
560 gboolean do_remove = FALSE;
561 gboolean do_set_active = FALSE;
562 gboolean do_set_refresh = FALSE;
563 gboolean show_avatar = FALSE;
564 GdkPixbuf *pixbuf_status;
566 priv = GET_PRIV (self);
568 model = GTK_TREE_MODEL (self);
570 iters = individual_store_find_contact (self, individual);
580 /* Get online state now. */
581 now_online = folks_individual_is_online (individual);
583 if (priv->show_offline || now_online)
585 should_be_in_list = TRUE;
589 should_be_in_list = FALSE;
592 if (!in_list && !should_be_in_list)
595 DEBUG ("Individual:'%s' in list:NO, should be:NO",
596 folks_individual_get_alias (individual));
598 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
602 else if (in_list && !should_be_in_list)
604 DEBUG ("Individual:'%s' in list:YES, should be:NO",
605 folks_individual_get_alias (individual));
607 if (priv->show_active)
610 do_set_active = TRUE;
611 do_set_refresh = TRUE;
614 DEBUG ("Remove item (after timeout)");
618 DEBUG ("Remove item (now)!");
619 individual_store_remove_individual (self, individual);
622 else if (!in_list && should_be_in_list)
624 DEBUG ("Individual'%s' in list:NO, should be:YES",
625 folks_individual_get_alias (individual));
627 individual_store_add_individual (self, individual);
629 if (priv->show_active)
631 do_set_active = TRUE;
633 DEBUG ("Set active (individual added)");
638 DEBUG ("Individual'%s' in list:YES, should be:YES",
639 folks_individual_get_alias (individual));
641 /* Get online state before. */
642 if (iters && g_list_length (iters) > 0)
644 gtk_tree_model_get (model, iters->data,
645 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
648 /* Is this really an update or an online/offline. */
649 if (priv->show_active)
651 if (was_online != now_online)
653 do_set_active = TRUE;
654 do_set_refresh = TRUE;
656 DEBUG ("Set active (individual updated %s)",
657 was_online ? "online -> offline" : "offline -> online");
661 /* Was TRUE for presence updates. */
662 /* do_set_active = FALSE; */
663 do_set_refresh = TRUE;
665 DEBUG ("Set active (individual updated)");
672 if (priv->show_avatars && !priv->is_compact)
677 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
678 individual_avatar_pixbuf_received_cb, self);
680 empathy_individual_store_get_individual_status_icon (self, individual);
682 for (l = iters; l && set_model; l = l->next)
684 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
685 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
686 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
687 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
688 folks_individual_get_alias (individual),
689 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
690 folks_individual_get_presence_type (individual),
691 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
692 folks_individual_get_presence_message (individual),
693 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
694 folks_individual_get_capabilities (individual) &
695 FOLKS_CAPABILITIES_FLAGS_AUDIO,
696 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
697 folks_individual_get_capabilities (individual) &
698 FOLKS_CAPABILITIES_FLAGS_VIDEO,
699 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
700 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
701 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
702 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
706 if (priv->show_active && do_set_active)
708 individual_store_contact_set_active (self, individual, do_set_active,
714 individual_store_contact_active_new (self, individual,
716 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
717 (GSourceFunc) individual_store_contact_active_cb, data);
721 /* FIXME: when someone goes online then offline quickly, the
722 * first timeout sets the user to be inactive and the second
723 * timeout removes the user from the contact list, really we
724 * should remove the first timeout.
726 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
731 individual_store_contact_updated_cb (FolksIndividual *individual,
733 EmpathyIndividualStore *self)
735 DEBUG ("Individual'%s' updated, checking roster is in sync...",
736 folks_individual_get_alias (individual));
738 individual_store_contact_update (self, individual);
742 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
743 FolksIndividual *individual)
745 g_signal_connect (individual, "notify::avatar",
746 G_CALLBACK (individual_store_contact_updated_cb), self);
747 g_signal_connect (individual, "notify::presence-type",
748 G_CALLBACK (individual_store_contact_updated_cb), self);
749 g_signal_connect (individual, "notify::presence-message",
750 G_CALLBACK (individual_store_contact_updated_cb), self);
751 g_signal_connect (individual, "notify::name",
752 G_CALLBACK (individual_store_contact_updated_cb), self);
753 g_signal_connect (individual, "notify::avatar",
754 G_CALLBACK (individual_store_contact_updated_cb), self);
755 g_signal_connect (individual, "notify::capabilities",
756 G_CALLBACK (individual_store_contact_updated_cb), self);
758 individual_store_add_individual (self, individual);
762 individual_store_remove_individual_and_disconnect (
763 EmpathyIndividualStore *self,
764 FolksIndividual *individual)
766 g_signal_handlers_disconnect_by_func (individual,
767 G_CALLBACK (individual_store_contact_updated_cb), self);
769 individual_store_remove_individual (self, individual);
773 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
778 EmpathyIndividualStore *self)
782 for (l = added; l; l = l->next)
784 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
786 individual_store_add_individual_and_connect (self, l->data);
788 for (l = removed; l; l = l->next)
790 DEBUG ("Individual %s %s",
791 folks_individual_get_id (l->data), "removed");
793 individual_store_remove_individual_and_disconnect (self, l->data);
798 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
799 FolksIndividual *individual,
800 gboolean is_favourite,
801 EmpathyIndividualStore *self)
803 EmpathyIndividualStorePriv *priv;
805 priv = GET_PRIV (self);
807 DEBUG ("Individual %s is %s a favourite",
808 folks_individual_get_id (individual),
809 is_favourite ? "now" : "no longer");
811 individual_store_remove_individual (self, individual);
812 individual_store_add_individual (self, individual);
816 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
817 FolksIndividual *individual,
820 EmpathyIndividualStore *self)
822 EmpathyIndividualStorePriv *priv;
823 gboolean show_active;
825 priv = GET_PRIV (self);
827 DEBUG ("Updating groups for individual %s",
828 folks_individual_get_id (individual));
830 /* We do this to make sure the groups are correct, if not, we
831 * would have to check the groups already set up for each
832 * contact and then see what has been updated.
834 show_active = priv->show_active;
835 priv->show_active = FALSE;
836 individual_store_remove_individual (self, individual);
837 individual_store_add_individual (self, individual);
838 priv->show_active = show_active;
842 individual_store_manager_setup (gpointer user_data)
844 EmpathyIndividualStore *self = user_data;
845 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
848 /* Signal connection. */
850 /* TODO: implement */
851 DEBUG ("handling individual renames unimplemented");
853 g_signal_connect (priv->manager,
855 G_CALLBACK (individual_store_members_changed_cb), self);
857 g_signal_connect (priv->manager,
858 "favourites-changed",
859 G_CALLBACK (individual_store_favourites_changed_cb), self);
861 g_signal_connect (priv->manager,
863 G_CALLBACK (individual_store_groups_changed_cb), self);
865 /* Add contacts already created. */
866 individuals = empathy_individual_manager_get_members (priv->manager);
867 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
869 individual_store_members_changed_cb (priv->manager, "initial add",
870 individuals, NULL, 0, self);
871 g_list_free (individuals);
874 priv->setup_idle_id = 0;
879 individual_store_set_individual_manager (EmpathyIndividualStore *self,
880 EmpathyIndividualManager *manager)
882 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
884 priv->manager = g_object_ref (manager);
886 /* Let a chance to have all properties set before populating */
887 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
891 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
892 FolksIndividual *old_individual,
893 FolksIndividual *new_individual,
896 EmpathyIndividualStore *self)
898 EmpathyIndividualStorePriv *priv;
900 priv = GET_PRIV (self);
902 DEBUG ("Individual %s renamed to %s",
903 folks_individual_get_id (old_individual),
904 folks_individual_get_id (new_individual));
906 /* add the new contact */
907 individual_store_add_individual_and_connect (self, new_individual);
909 /* remove old contact */
910 individual_store_remove_individual_and_disconnect (self, old_individual);
914 individual_store_dispose (GObject *object)
916 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
919 if (priv->dispose_has_run)
921 priv->dispose_has_run = TRUE;
923 contacts = empathy_individual_manager_get_members (priv->manager);
924 for (l = contacts; l; l = l->next)
926 g_signal_handlers_disconnect_by_func (l->data,
927 G_CALLBACK (individual_store_contact_updated_cb), object);
929 g_list_free (contacts);
931 g_signal_handlers_disconnect_by_func (priv->manager,
932 G_CALLBACK (individual_store_member_renamed_cb), object);
933 g_signal_handlers_disconnect_by_func (priv->manager,
934 G_CALLBACK (individual_store_members_changed_cb), object);
935 g_signal_handlers_disconnect_by_func (priv->manager,
936 G_CALLBACK (individual_store_favourites_changed_cb), object);
937 g_signal_handlers_disconnect_by_func (priv->manager,
938 G_CALLBACK (individual_store_groups_changed_cb), object);
939 g_object_unref (priv->manager);
941 if (priv->inhibit_active)
943 g_source_remove (priv->inhibit_active);
946 if (priv->setup_idle_id != 0)
948 g_source_remove (priv->setup_idle_id);
951 g_hash_table_destroy (priv->status_icons);
952 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
956 individual_store_get_property (GObject *object,
961 EmpathyIndividualStorePriv *priv;
963 priv = GET_PRIV (object);
967 case PROP_INDIVIDUAL_MANAGER:
968 g_value_set_object (value, priv->manager);
970 case PROP_SHOW_OFFLINE:
971 g_value_set_boolean (value, priv->show_offline);
973 case PROP_SHOW_AVATARS:
974 g_value_set_boolean (value, priv->show_avatars);
976 case PROP_SHOW_PROTOCOLS:
977 g_value_set_boolean (value, priv->show_protocols);
979 case PROP_SHOW_GROUPS:
980 g_value_set_boolean (value, priv->show_groups);
982 case PROP_IS_COMPACT:
983 g_value_set_boolean (value, priv->is_compact);
985 case PROP_SORT_CRITERIUM:
986 g_value_set_enum (value, priv->sort_criterium);
989 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
995 individual_store_set_property (GObject *object,
1000 EmpathyIndividualStorePriv *priv;
1002 priv = GET_PRIV (object);
1006 case PROP_INDIVIDUAL_MANAGER:
1007 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1008 (object), g_value_get_object (value));
1010 case PROP_SHOW_OFFLINE:
1011 empathy_individual_store_set_show_offline (EMPATHY_INDIVIDUAL_STORE
1012 (object), g_value_get_boolean (value));
1014 case PROP_SHOW_AVATARS:
1015 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1016 (object), g_value_get_boolean (value));
1018 case PROP_SHOW_PROTOCOLS:
1019 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1020 (object), g_value_get_boolean (value));
1022 case PROP_SHOW_GROUPS:
1023 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1024 (object), g_value_get_boolean (value));
1026 case PROP_IS_COMPACT:
1027 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1028 (object), g_value_get_boolean (value));
1030 case PROP_SORT_CRITERIUM:
1031 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1032 (object), g_value_get_enum (value));
1035 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1041 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1043 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1045 object_class->dispose = individual_store_dispose;
1046 object_class->get_property = individual_store_get_property;
1047 object_class->set_property = individual_store_set_property;
1049 g_object_class_install_property (object_class,
1050 PROP_INDIVIDUAL_MANAGER,
1051 g_param_spec_object ("individual-manager",
1052 "The individual manager",
1053 "The individual manager",
1054 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1055 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1056 g_object_class_install_property (object_class,
1058 g_param_spec_boolean ("show-offline",
1060 "Whether contact list should display "
1061 "offline contacts", FALSE, G_PARAM_READWRITE));
1062 g_object_class_install_property (object_class,
1064 g_param_spec_boolean ("show-avatars",
1066 "Whether contact list should display "
1067 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1068 g_object_class_install_property (object_class,
1069 PROP_SHOW_PROTOCOLS,
1070 g_param_spec_boolean ("show-protocols",
1072 "Whether contact list should display "
1073 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1074 g_object_class_install_property (object_class,
1076 g_param_spec_boolean ("show-groups",
1078 "Whether contact list should display "
1079 "contact groups", TRUE, G_PARAM_READWRITE));
1080 g_object_class_install_property (object_class,
1082 g_param_spec_boolean ("is-compact",
1084 "Whether the contact list is in compact mode or not",
1085 FALSE, G_PARAM_READWRITE));
1087 g_object_class_install_property (object_class,
1088 PROP_SORT_CRITERIUM,
1089 g_param_spec_enum ("sort-criterium",
1091 "The sort criterium to use for sorting the contact list",
1092 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1093 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1095 g_type_class_add_private (object_class,
1096 sizeof (EmpathyIndividualStorePriv));
1100 get_position (const char **strv,
1105 for (i = 0; strv[i] != NULL; i++)
1107 if (!tp_strdiff (strv[i], str))
1115 compare_separator_and_groups (gboolean is_separator_a,
1116 gboolean is_separator_b,
1117 const gchar *name_a,
1118 const gchar *name_b,
1119 FolksIndividual *individual_a,
1120 FolksIndividual *individual_b,
1121 gboolean fake_group_a,
1122 gboolean fake_group_b)
1124 /* these two lists are the sorted list of fake groups to include at the
1125 * top and bottom of the roster */
1126 const char *top_groups[] = {
1127 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1131 const char *bottom_groups[] = {
1132 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1136 if (is_separator_a || is_separator_b)
1138 /* We have at least one separator */
1143 else if (is_separator_b)
1149 /* One group and one contact */
1150 if (!individual_a && individual_b)
1154 else if (individual_a && !individual_b)
1158 else if (!individual_a && !individual_b)
1160 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1162 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1163 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1164 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1165 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1167 if (a_in_top && b_in_top)
1169 /* compare positions */
1170 return CLAMP (get_position (top_groups, name_a) -
1171 get_position (top_groups, name_b), -1, 1);
1173 else if (a_in_bottom && b_in_bottom)
1175 /* compare positions */
1176 return CLAMP (get_position (bottom_groups, name_a) -
1177 get_position (bottom_groups, name_b), -1, 1);
1179 else if (a_in_top || b_in_bottom)
1183 else if (b_in_top || a_in_bottom)
1189 return g_utf8_collate (name_a, name_b);
1193 /* Two contacts, ordering depends of the sorting policy */
1198 individual_store_contact_sort (FolksIndividual *individual_a,
1199 FolksIndividual *individual_b)
1204 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1205 folks_individual_get_alias (individual_b));
1211 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1212 folks_individual_get_id (individual_b));
1222 individual_store_state_sort_func (GtkTreeModel *model,
1223 GtkTreeIter *iter_a,
1224 GtkTreeIter *iter_b,
1228 FolksIndividual *individual_a, *individual_b;
1229 gchar *name_a, *name_b;
1230 gboolean is_separator_a, is_separator_b;
1231 gboolean fake_group_a, fake_group_b;
1232 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1233 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1235 gtk_tree_model_get (model, iter_a,
1236 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1237 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1238 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1239 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1240 gtk_tree_model_get (model, iter_b,
1241 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1242 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1243 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1244 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1246 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1247 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1254 /* If we managed to get this far, we can start looking at
1257 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1258 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1259 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1260 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1262 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1267 /* Fallback: compare by name et al. */
1268 ret_val = individual_store_contact_sort (individual_a, individual_b);
1277 g_object_unref (individual_a);
1282 g_object_unref (individual_b);
1289 individual_store_name_sort_func (GtkTreeModel *model,
1290 GtkTreeIter *iter_a,
1291 GtkTreeIter *iter_b,
1294 gchar *name_a, *name_b;
1295 FolksIndividual *individual_a, *individual_b;
1296 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1298 gboolean fake_group_a, fake_group_b;
1300 gtk_tree_model_get (model, iter_a,
1301 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1302 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1303 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1304 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1305 gtk_tree_model_get (model, iter_b,
1306 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1307 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1308 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1309 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1311 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1312 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1315 ret_val = individual_store_contact_sort (individual_a, individual_b);
1319 g_object_unref (individual_a);
1324 g_object_unref (individual_b);
1331 individual_store_setup (EmpathyIndividualStore *self)
1333 EmpathyIndividualStorePriv *priv;
1335 GDK_TYPE_PIXBUF, /* Status pixbuf */
1336 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1337 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1338 G_TYPE_STRING, /* Name */
1339 G_TYPE_UINT, /* Presence type */
1340 G_TYPE_STRING, /* Status string */
1341 G_TYPE_BOOLEAN, /* Compact view */
1342 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1343 G_TYPE_BOOLEAN, /* Is group */
1344 G_TYPE_BOOLEAN, /* Is active */
1345 G_TYPE_BOOLEAN, /* Is online */
1346 G_TYPE_BOOLEAN, /* Is separator */
1347 G_TYPE_BOOLEAN, /* Can make audio calls */
1348 G_TYPE_BOOLEAN, /* Can make video calls */
1349 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1350 G_TYPE_BOOLEAN, /* Is a fake group */
1353 priv = GET_PRIV (self);
1355 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1356 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1358 /* Set up sorting */
1359 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1360 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1361 individual_store_name_sort_func, self, NULL);
1362 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1363 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1364 individual_store_state_sort_func, self, NULL);
1366 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1367 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1371 individual_store_inibit_active_cb (EmpathyIndividualStore *self)
1373 EmpathyIndividualStorePriv *priv;
1375 priv = GET_PRIV (self);
1377 priv->show_active = TRUE;
1378 priv->inhibit_active = 0;
1384 empathy_individual_store_init (EmpathyIndividualStore *self)
1386 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1387 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1390 priv->show_avatars = TRUE;
1391 priv->show_groups = TRUE;
1392 priv->show_protocols = FALSE;
1393 priv->inhibit_active =
1394 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1395 (GSourceFunc) individual_store_inibit_active_cb, self);
1396 priv->status_icons =
1397 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1398 individual_store_setup (self);
1401 EmpathyIndividualStore *
1402 empathy_individual_store_new (EmpathyIndividualManager *manager)
1404 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1406 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1407 "individual-manager", manager, NULL);
1410 EmpathyIndividualManager *
1411 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1413 EmpathyIndividualStorePriv *priv;
1415 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1417 priv = GET_PRIV (self);
1419 return priv->manager;
1423 empathy_individual_store_get_show_offline (EmpathyIndividualStore *self)
1425 EmpathyIndividualStorePriv *priv;
1427 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1429 priv = GET_PRIV (self);
1431 return priv->show_offline;
1435 empathy_individual_store_set_show_offline (EmpathyIndividualStore *self,
1436 gboolean show_offline)
1438 EmpathyIndividualStorePriv *priv;
1439 GList *contacts, *l;
1440 gboolean show_active;
1442 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1444 priv = GET_PRIV (self);
1446 priv->show_offline = show_offline;
1447 show_active = priv->show_active;
1449 /* Disable temporarily. */
1450 priv->show_active = FALSE;
1452 contacts = empathy_individual_manager_get_members (priv->manager);
1453 for (l = contacts; l; l = l->next)
1455 individual_store_contact_update (self, l->data);
1457 g_list_free (contacts);
1459 /* Restore to original setting. */
1460 priv->show_active = show_active;
1462 g_object_notify (G_OBJECT (self), "show-offline");
1466 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1468 EmpathyIndividualStorePriv *priv;
1470 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1472 priv = GET_PRIV (self);
1474 return priv->show_avatars;
1478 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1481 EmpathyIndividualStore *self)
1483 EmpathyIndividualStorePriv *priv;
1484 gboolean show_avatar = FALSE;
1485 FolksIndividual *individual;
1486 GdkPixbuf *pixbuf_status;
1488 priv = GET_PRIV (self);
1490 if (priv->show_avatars && !priv->is_compact)
1495 gtk_tree_model_get (model, iter,
1496 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1498 if (individual == NULL)
1502 /* get icon from hash_table */
1504 empathy_individual_store_get_individual_status_icon (self, individual);
1506 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1507 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1508 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1509 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1511 g_object_unref (individual);
1517 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1518 gboolean show_avatars)
1520 EmpathyIndividualStorePriv *priv;
1521 GtkTreeModel *model;
1523 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1525 priv = GET_PRIV (self);
1527 priv->show_avatars = show_avatars;
1529 model = GTK_TREE_MODEL (self);
1531 gtk_tree_model_foreach (model,
1532 (GtkTreeModelForeachFunc)
1533 individual_store_update_list_mode_foreach, self);
1535 g_object_notify (G_OBJECT (self), "show-avatars");
1539 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1541 EmpathyIndividualStorePriv *priv;
1543 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1545 priv = GET_PRIV (self);
1547 return priv->show_protocols;
1551 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1552 gboolean show_protocols)
1554 EmpathyIndividualStorePriv *priv;
1555 GtkTreeModel *model;
1557 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1559 priv = GET_PRIV (self);
1561 priv->show_protocols = show_protocols;
1563 model = GTK_TREE_MODEL (self);
1565 gtk_tree_model_foreach (model,
1566 (GtkTreeModelForeachFunc)
1567 individual_store_update_list_mode_foreach, self);
1569 g_object_notify (G_OBJECT (self), "show-protocols");
1573 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1575 EmpathyIndividualStorePriv *priv;
1577 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1579 priv = GET_PRIV (self);
1581 return priv->show_groups;
1585 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1586 gboolean show_groups)
1588 EmpathyIndividualStorePriv *priv;
1590 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1592 priv = GET_PRIV (self);
1594 if (priv->show_groups == show_groups)
1599 priv->show_groups = show_groups;
1601 if (priv->setup_idle_id == 0)
1603 /* Remove all contacts and add them back, not optimized but
1604 * that's the easy way :)
1606 * This is only done if there's not a pending setup idle
1607 * callback, otherwise it will race and the contacts will get
1611 gtk_tree_store_clear (GTK_TREE_STORE (self));
1612 contacts = empathy_individual_manager_get_members (priv->manager);
1614 individual_store_members_changed_cb (priv->manager,
1615 "re-adding members: toggled group visibility",
1616 contacts, NULL, 0, self);
1617 g_list_free (contacts);
1620 g_object_notify (G_OBJECT (self), "show-groups");
1624 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1626 EmpathyIndividualStorePriv *priv;
1628 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1630 priv = GET_PRIV (self);
1632 return priv->is_compact;
1636 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1637 gboolean is_compact)
1639 EmpathyIndividualStorePriv *priv;
1640 GtkTreeModel *model;
1642 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1644 priv = GET_PRIV (self);
1646 priv->is_compact = is_compact;
1648 model = GTK_TREE_MODEL (self);
1650 gtk_tree_model_foreach (model,
1651 (GtkTreeModelForeachFunc)
1652 individual_store_update_list_mode_foreach, self);
1654 g_object_notify (G_OBJECT (self), "is-compact");
1657 EmpathyIndividualStoreSort
1658 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1660 EmpathyIndividualStorePriv *priv;
1662 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1664 priv = GET_PRIV (self);
1666 return priv->sort_criterium;
1670 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1671 EmpathyIndividualStoreSort sort_criterium)
1673 EmpathyIndividualStorePriv *priv;
1675 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1677 priv = GET_PRIV (self);
1679 priv->sort_criterium = sort_criterium;
1681 switch (sort_criterium)
1683 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1684 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1685 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1688 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1689 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1690 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1694 g_object_notify (G_OBJECT (self), "sort-criterium");
1698 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1702 gboolean is_separator = FALSE;
1704 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1706 gtk_tree_model_get (model, iter,
1707 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1709 return is_separator;
1713 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1715 gboolean *path_is_group,
1716 gboolean *is_fake_group)
1718 GtkTreeIter parent_iter, iter;
1723 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1727 *path_is_group = FALSE;
1730 if (!gtk_tree_model_get_iter (model, &iter, path))
1735 gtk_tree_model_get (model, &iter,
1736 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1737 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1744 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1751 gtk_tree_model_get (model, &iter,
1752 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1753 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1754 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1764 *path_is_group = TRUE;
1767 if (is_fake_group != NULL)
1768 *is_fake_group = fake;
1774 individual_store_get_individual_status_icon_with_icon_name (
1775 EmpathyIndividualStore *self,
1776 FolksIndividual *individual,
1777 const gchar *status_icon_name)
1779 GdkPixbuf *pixbuf_status = NULL;
1780 EmpathyIndividualStorePriv *priv;
1781 const gchar *protocol_name = NULL;
1782 gchar *icon_name = NULL;
1783 GList *personas, *l;
1784 guint contact_count;
1785 EmpathyContact *contact = NULL;
1786 gboolean show_protocols_here;
1788 priv = GET_PRIV (self);
1790 personas = folks_individual_get_personas (individual);
1791 for (l = personas, contact_count = 0; l; l = l->next)
1793 if (TPF_IS_PERSONA (l->data))
1796 if (contact_count > 1)
1800 show_protocols_here = priv->show_protocols && (contact_count == 1);
1801 if (show_protocols_here)
1803 contact = empathy_contact_from_folks_individual (individual);
1804 protocol_name = empathy_protocol_name_for_contact (contact);
1805 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1809 icon_name = g_strdup_printf ("%s", status_icon_name);
1811 if (pixbuf_status == NULL)
1814 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1815 status_icon_name, priv->show_protocols);
1816 if (pixbuf_status != NULL)
1818 g_hash_table_insert (priv->status_icons,
1819 g_strdup (icon_name), pixbuf_status);
1824 return pixbuf_status;
1828 empathy_individual_store_get_individual_status_icon (
1829 EmpathyIndividualStore *self,
1830 FolksIndividual *individual)
1832 GdkPixbuf *pixbuf_status = NULL;
1833 const gchar *status_icon_name = NULL;
1835 status_icon_name = empathy_icon_name_for_individual (individual);
1836 if (status_icon_name == NULL)
1840 individual_store_get_individual_status_icon_with_icon_name (self,
1841 individual, status_icon_name);
1843 return pixbuf_status;