1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2010 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
24 * Travis Reitter <travis.reitter@collabora.co.uk>
32 #include <glib/gi18n-lib.h>
35 #include <folks/folks.h>
36 #include <folks/folks-telepathy.h>
37 #include <telepathy-glib/util.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-enum-types.h>
41 #include <libempathy/empathy-individual-manager.h>
43 #include "empathy-individual-store.h"
44 #include "empathy-ui-utils.h"
45 #include "empathy-gtk-enum-types.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
48 #include <libempathy/empathy-debug.h>
50 /* Active users are those which have recently changed state
51 * (e.g. online, offline or from normal to a busy state).
54 /* Time in seconds user is shown as active */
55 #define ACTIVE_USER_SHOW_TIME 7
57 /* Time in seconds after connecting which we wait before active users are enabled */
58 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualStore)
63 EmpathyIndividualManager *manager;
64 gboolean show_avatars;
67 gboolean show_protocols;
69 EmpathyIndividualStoreSort sort_criterium;
72 gboolean dispose_has_run;
73 GHashTable *status_icons;
74 /* List of owned GCancellables for each pending avatar load operation */
75 GList *avatar_cancellables;
76 } EmpathyIndividualStorePriv;
87 FolksIndividual *individual;
94 EmpathyIndividualStore *self;
95 FolksIndividual *individual;
103 PROP_INDIVIDUAL_MANAGER,
111 /* prototypes to break cycles */
112 static void individual_store_contact_update (EmpathyIndividualStore *self,
113 FolksIndividual *individual);
115 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
116 GTK_TYPE_TREE_STORE);
119 add_individual_to_store (GtkTreeStore *self,
122 FolksIndividual *individual,
123 EmpathyIndividualManagerFlags flags)
125 EmpathyContact *contact;
127 contact = empathy_contact_dup_from_folks_individual (individual);
129 gtk_tree_store_insert_with_values (self, iter, parent, 0,
130 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
131 folks_individual_get_alias (individual),
132 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
133 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
134 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
135 EMPATHY_INDIVIDUAL_STORE_COL_FLAGS, flags,
140 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
141 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
142 empathy_contact_get_capabilities (contact) &
143 EMPATHY_CAPABILITIES_AUDIO,
144 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
145 empathy_contact_get_capabilities (contact) &
146 EMPATHY_CAPABILITIES_VIDEO,
150 tp_clear_object (&contact);
154 individual_store_get_group_foreach (GtkTreeModel *model,
162 /* Groups are only at the top level. */
163 if (gtk_tree_path_get_depth (path) != 1)
166 gtk_tree_model_get (model, iter,
167 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
168 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
170 if (is_group && !tp_strdiff (str, fg->name))
182 individual_store_get_group (EmpathyIndividualStore *self,
184 GtkTreeIter *iter_group_to_set,
185 GtkTreeIter *iter_separator_to_set,
187 gboolean is_fake_group)
189 EmpathyIndividualStorePriv *priv;
191 GtkTreeIter iter_group;
192 GtkTreeIter iter_separator;
195 priv = GET_PRIV (self);
197 memset (&fg, 0, sizeof (fg));
201 model = GTK_TREE_MODEL (self);
202 gtk_tree_model_foreach (model,
203 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
210 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
212 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
213 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
214 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
215 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
216 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
217 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
220 if (iter_group_to_set)
221 *iter_group_to_set = iter_group;
223 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
225 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
228 if (iter_separator_to_set)
229 *iter_separator_to_set = iter_separator;
236 if (iter_group_to_set)
237 *iter_group_to_set = fg.iter;
239 iter_separator = fg.iter;
241 if (gtk_tree_model_iter_next (model, &iter_separator))
243 gboolean is_separator;
245 gtk_tree_model_get (model, &iter_separator,
246 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
248 if (is_separator && iter_separator_to_set)
249 *iter_separator_to_set = iter_separator;
255 individual_store_find_contact_foreach (GtkTreeModel *model,
260 FolksIndividual *individual;
262 gtk_tree_model_get (model, iter,
263 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
265 if (individual == fc->individual)
268 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
271 tp_clear_object (&individual);
277 individual_store_find_contact (EmpathyIndividualStore *self,
278 FolksIndividual *individual)
280 EmpathyIndividualStorePriv *priv;
285 priv = GET_PRIV (self);
287 memset (&fc, 0, sizeof (fc));
289 fc.individual = individual;
291 model = GTK_TREE_MODEL (self);
292 gtk_tree_model_foreach (model,
293 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
302 individual_store_remove_individual (EmpathyIndividualStore *self,
303 FolksIndividual *individual)
305 EmpathyIndividualStorePriv *priv;
309 priv = GET_PRIV (self);
311 iters = individual_store_find_contact (self, individual);
316 model = GTK_TREE_MODEL (self);
318 for (l = iters; l; l = l->next)
322 /* NOTE: it is only <= 2 here because we have
323 * separators after the group name, otherwise it
326 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
327 gtk_tree_model_iter_n_children (model, &parent) <= 2)
329 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
333 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
337 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
342 individual_store_add_individual (EmpathyIndividualStore *self,
343 FolksIndividual *individual)
345 EmpathyIndividualStorePriv *priv;
347 GHashTable *group_set = NULL;
348 GList *groups = NULL, *l;
349 EmpathyContact *contact;
350 TpConnection *connection;
351 EmpathyIndividualManagerFlags flags = 0;
352 gchar *protocol_name;
354 priv = GET_PRIV (self);
356 if (EMP_STR_EMPTY (folks_individual_get_alias (individual)))
359 if (priv->show_groups)
361 group_set = folks_individual_get_groups (individual);
362 groups = g_hash_table_get_keys (group_set);
365 contact = empathy_contact_dup_from_folks_individual (individual);
366 connection = empathy_contact_get_connection (contact);
367 flags = empathy_individual_manager_get_flags_for_connection (priv->manager,
370 tp_connection_parse_object_path (connection, &protocol_name, NULL);
374 GtkTreeIter iter_group, *parent;
376 parent = &iter_group;
378 if (!priv->show_groups)
380 else if (!tp_strdiff (protocol_name, "local-xmpp"))
382 /* these are People Nearby */
383 individual_store_get_group (self,
384 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
389 individual_store_get_group (self,
390 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
391 &iter_group, NULL, NULL, TRUE);
394 add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
398 g_free (protocol_name);
400 /* Else add to each group. */
401 for (l = groups; l; l = l->next)
403 GtkTreeIter iter_group;
405 individual_store_get_group (self, l->data, &iter_group, NULL, NULL,
408 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
411 g_list_free (groups);
412 if (group_set != NULL)
413 g_hash_table_unref (group_set);
415 if (priv->show_groups &&
416 folks_favourite_get_is_favourite (FOLKS_FAVOURITE (individual)))
418 /* Add contact to the fake 'Favorites' group */
419 GtkTreeIter iter_group;
421 individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
422 &iter_group, NULL, NULL, TRUE);
424 add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
428 individual_store_contact_update (self, individual);
430 tp_clear_object (&contact);
434 individual_store_contact_set_active (EmpathyIndividualStore *self,
435 FolksIndividual *individual,
437 gboolean set_changed)
439 EmpathyIndividualStorePriv *priv;
443 priv = GET_PRIV (self);
444 model = GTK_TREE_MODEL (self);
446 iters = individual_store_find_contact (self, individual);
447 for (l = iters; l; l = l->next)
451 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
452 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
455 DEBUG ("Set item %s", active ? "active" : "inactive");
459 path = gtk_tree_model_get_path (model, l->data);
460 gtk_tree_model_row_changed (model, path, l->data);
461 gtk_tree_path_free (path);
465 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
470 static void individual_store_contact_active_free (ShowActiveData *data);
473 individual_store_contact_active_invalidated (ShowActiveData *data,
476 /* Remove the timeout and free the struct, since the individual or individual
477 * store has disappeared. */
478 g_source_remove (data->timeout);
480 if (old_object == (GObject *) data->self)
482 else if (old_object == (GObject *) data->individual)
483 data->individual = NULL;
485 g_assert_not_reached ();
487 individual_store_contact_active_free (data);
490 static ShowActiveData *
491 individual_store_contact_active_new (EmpathyIndividualStore *self,
492 FolksIndividual *individual,
495 ShowActiveData *data;
497 DEBUG ("Individual'%s' now active, and %s be removed",
498 folks_individual_get_alias (individual), remove_ ? "WILL" : "WILL NOT");
500 data = g_slice_new0 (ShowActiveData);
502 /* We don't actually want to force either the IndividualStore or the
503 * Individual to stay alive, since the user could quit Empathy or disable
504 * the account before the contact_active timeout is fired. */
505 g_object_weak_ref (G_OBJECT (self),
506 (GWeakNotify) individual_store_contact_active_invalidated, data);
507 g_object_weak_ref (G_OBJECT (individual),
508 (GWeakNotify) individual_store_contact_active_invalidated, data);
511 data->individual = individual;
512 data->remove = remove_;
519 individual_store_contact_active_free (ShowActiveData *data)
521 if (data->self != NULL)
523 g_object_weak_unref (G_OBJECT (data->self),
524 (GWeakNotify) individual_store_contact_active_invalidated, data);
527 if (data->individual != NULL)
529 g_object_weak_unref (G_OBJECT (data->individual),
530 (GWeakNotify) individual_store_contact_active_invalidated, data);
533 g_slice_free (ShowActiveData, data);
537 individual_store_contact_active_cb (ShowActiveData *data)
541 DEBUG ("Individual'%s' active timeout, removing item",
542 folks_individual_get_alias (data->individual));
543 individual_store_remove_individual (data->self, data->individual);
546 DEBUG ("Individual'%s' no longer active",
547 folks_individual_get_alias (data->individual));
549 individual_store_contact_set_active (data->self,
550 data->individual, FALSE, TRUE);
552 individual_store_contact_active_free (data);
558 EmpathyIndividualStore *store; /* weak */
559 GCancellable *cancellable; /* owned */
563 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
564 GAsyncResult *result,
565 LoadAvatarData *data)
567 GError *error = NULL;
570 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
575 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
576 folks_individual_get_alias (individual),
578 g_clear_error (&error);
580 else if (data->store != NULL)
584 iters = individual_store_find_contact (data->store, individual);
585 for (l = iters; l; l = l->next)
587 gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
588 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
594 if (data->store != NULL)
596 EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
598 g_object_remove_weak_pointer (G_OBJECT (data->store),
599 (gpointer *) &data->store);
600 priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
604 g_object_unref (data->cancellable);
605 g_slice_free (LoadAvatarData, data);
609 individual_store_contact_update (EmpathyIndividualStore *self,
610 FolksIndividual *individual)
612 EmpathyIndividualStorePriv *priv;
613 ShowActiveData *data;
615 EmpathyContact *contact;
618 gboolean was_online = TRUE;
619 gboolean now_online = FALSE;
620 gboolean set_model = FALSE;
621 gboolean do_remove = FALSE;
622 gboolean do_set_active = FALSE;
623 gboolean do_set_refresh = FALSE;
624 gboolean show_avatar = FALSE;
625 GdkPixbuf *pixbuf_status;
626 LoadAvatarData *load_avatar_data;
628 priv = GET_PRIV (self);
630 model = GTK_TREE_MODEL (self);
631 contact = empathy_contact_dup_from_folks_individual (individual);
633 iters = individual_store_find_contact (self, individual);
643 /* Get online state now. */
644 now_online = folks_individual_is_online (individual);
648 DEBUG ("Individual'%s' in list:NO, should be:YES",
649 folks_individual_get_alias (individual));
651 individual_store_add_individual (self, individual);
653 if (priv->show_active)
655 do_set_active = TRUE;
657 DEBUG ("Set active (individual added)");
662 DEBUG ("Individual'%s' in list:YES, should be:YES",
663 folks_individual_get_alias (individual));
665 /* Get online state before. */
666 if (iters && g_list_length (iters) > 0)
668 gtk_tree_model_get (model, iters->data,
669 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
672 /* Is this really an update or an online/offline. */
673 if (priv->show_active)
675 if (was_online != now_online)
677 do_set_active = TRUE;
678 do_set_refresh = TRUE;
680 DEBUG ("Set active (individual updated %s)",
681 was_online ? "online -> offline" : "offline -> online");
685 /* Was TRUE for presence updates. */
686 /* do_set_active = FALSE; */
687 do_set_refresh = TRUE;
689 DEBUG ("Set active (individual updated)");
696 if (priv->show_avatars && !priv->is_compact)
701 /* Load the avatar asynchronously */
702 load_avatar_data = g_slice_new (LoadAvatarData);
703 load_avatar_data->store = self;
704 g_object_add_weak_pointer (G_OBJECT (self),
705 (gpointer *) &load_avatar_data->store);
706 load_avatar_data->cancellable = g_cancellable_new ();
708 priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
709 load_avatar_data->cancellable);
710 empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
711 load_avatar_data->cancellable,
712 (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
716 empathy_individual_store_get_individual_status_icon (self, individual);
718 for (l = iters; l && set_model; l = l->next)
720 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
721 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
722 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
723 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
724 folks_individual_get_alias (individual),
725 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
726 folks_individual_get_presence_type (individual),
727 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
728 folks_individual_get_presence_message (individual),
729 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
730 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
731 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
732 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
737 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
738 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
739 empathy_contact_get_capabilities (contact) &
740 EMPATHY_CAPABILITIES_AUDIO,
741 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
742 empathy_contact_get_capabilities (contact) &
743 EMPATHY_CAPABILITIES_VIDEO,
748 if (priv->show_active && do_set_active)
750 individual_store_contact_set_active (self, individual, do_set_active,
756 individual_store_contact_active_new (self, individual,
758 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
759 (GSourceFunc) individual_store_contact_active_cb, data);
763 /* FIXME: when someone goes online then offline quickly, the
764 * first timeout sets the user to be inactive and the second
765 * timeout removes the user from the contact list, really we
766 * should remove the first timeout.
768 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
770 tp_clear_object (&contact);
774 individual_store_individual_updated_cb (FolksIndividual *individual,
776 EmpathyIndividualStore *self)
778 DEBUG ("Individual'%s' updated, checking roster is in sync...",
779 folks_individual_get_alias (individual));
781 individual_store_contact_update (self, individual);
785 individual_store_contact_updated_cb (EmpathyContact *contact,
787 EmpathyIndividualStore *self)
789 FolksIndividual *individual;
791 DEBUG ("Contact '%s' updated, checking roster is in sync...",
792 empathy_contact_get_alias (contact));
794 individual = g_object_get_data (G_OBJECT (contact), "individual");
795 if (individual == NULL)
798 individual_store_contact_update (self, individual);
802 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
803 FolksIndividual *individual)
807 g_signal_connect (individual, "notify::avatar",
808 G_CALLBACK (individual_store_individual_updated_cb), self);
809 g_signal_connect (individual, "notify::presence-type",
810 G_CALLBACK (individual_store_individual_updated_cb), self);
811 g_signal_connect (individual, "notify::presence-message",
812 G_CALLBACK (individual_store_individual_updated_cb), self);
813 g_signal_connect (individual, "notify::alias",
814 G_CALLBACK (individual_store_individual_updated_cb), self);
816 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
817 * through the EmpathyContacts for them. */
818 personas = folks_individual_get_personas (individual);
819 for (l = personas; l != NULL; l = l->next)
821 TpContact *tp_contact;
822 EmpathyContact *contact;
824 if (!TPF_IS_PERSONA (l->data))
827 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
828 contact = empathy_contact_dup_from_tp_contact (tp_contact);
829 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
831 g_object_set_data (G_OBJECT (contact), "individual", individual);
832 g_signal_connect (contact, "notify::capabilities",
833 G_CALLBACK (individual_store_contact_updated_cb), self);
835 g_object_unref (contact);
838 individual_store_add_individual (self, individual);
842 individual_store_disconnect_individual (EmpathyIndividualStore *self,
843 FolksIndividual *individual)
847 g_signal_handlers_disconnect_by_func (individual,
848 G_CALLBACK (individual_store_individual_updated_cb), self);
850 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
851 * through the EmpathyContacts for them. */
852 personas = folks_individual_get_personas (individual);
853 for (l = personas; l != NULL; l = l->next)
855 TpContact *tp_contact;
856 EmpathyContact *contact;
858 if (!TPF_IS_PERSONA (l->data))
861 tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
862 contact = empathy_contact_dup_from_tp_contact (tp_contact);
863 empathy_contact_set_persona (contact, FOLKS_PERSONA (l->data));
865 g_signal_handlers_disconnect_by_func (contact,
866 G_CALLBACK (individual_store_contact_updated_cb), self);
868 g_object_unref (contact);
873 individual_store_remove_individual_and_disconnect (
874 EmpathyIndividualStore *self,
875 FolksIndividual *individual)
877 individual_store_disconnect_individual (self, individual);
878 individual_store_remove_individual (self, individual);
882 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
883 const gchar *message,
887 EmpathyIndividualStore *self)
891 for (l = added; l; l = l->next)
893 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
895 individual_store_add_individual_and_connect (self, l->data);
897 for (l = removed; l; l = l->next)
899 DEBUG ("Individual %s %s",
900 folks_individual_get_id (l->data), "removed");
902 individual_store_remove_individual_and_disconnect (self, l->data);
907 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
908 FolksIndividual *individual,
909 gboolean is_favourite,
910 EmpathyIndividualStore *self)
912 EmpathyIndividualStorePriv *priv;
914 priv = GET_PRIV (self);
916 DEBUG ("Individual %s is %s a favourite",
917 folks_individual_get_id (individual),
918 is_favourite ? "now" : "no longer");
920 individual_store_remove_individual (self, individual);
921 individual_store_add_individual (self, individual);
925 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
926 FolksIndividual *individual,
929 EmpathyIndividualStore *self)
931 EmpathyIndividualStorePriv *priv;
932 gboolean show_active;
934 priv = GET_PRIV (self);
936 DEBUG ("Updating groups for individual %s",
937 folks_individual_get_id (individual));
939 /* We do this to make sure the groups are correct, if not, we
940 * would have to check the groups already set up for each
941 * contact and then see what has been updated.
943 show_active = priv->show_active;
944 priv->show_active = FALSE;
945 individual_store_remove_individual (self, individual);
946 individual_store_add_individual (self, individual);
947 priv->show_active = show_active;
951 individual_store_manager_setup (gpointer user_data)
953 EmpathyIndividualStore *self = user_data;
954 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
957 /* Signal connection. */
959 /* TODO: implement */
960 DEBUG ("handling individual renames unimplemented");
962 g_signal_connect (priv->manager,
964 G_CALLBACK (individual_store_members_changed_cb), self);
966 g_signal_connect (priv->manager,
967 "favourites-changed",
968 G_CALLBACK (individual_store_favourites_changed_cb), self);
970 g_signal_connect (priv->manager,
972 G_CALLBACK (individual_store_groups_changed_cb), self);
974 /* Add contacts already created. */
975 individuals = empathy_individual_manager_get_members (priv->manager);
976 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
978 individual_store_members_changed_cb (priv->manager, "initial add",
979 individuals, NULL, 0, self);
980 g_list_free (individuals);
983 priv->setup_idle_id = 0;
988 individual_store_set_individual_manager (EmpathyIndividualStore *self,
989 EmpathyIndividualManager *manager)
991 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
993 priv->manager = g_object_ref (manager);
995 /* Let a chance to have all properties set before populating */
996 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1000 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1001 FolksIndividual *old_individual,
1002 FolksIndividual *new_individual,
1004 const gchar *message,
1005 EmpathyIndividualStore *self)
1007 EmpathyIndividualStorePriv *priv;
1009 priv = GET_PRIV (self);
1011 DEBUG ("Individual %s renamed to %s",
1012 folks_individual_get_id (old_individual),
1013 folks_individual_get_id (new_individual));
1015 /* add the new contact */
1016 individual_store_add_individual_and_connect (self, new_individual);
1018 /* remove old contact */
1019 individual_store_remove_individual_and_disconnect (self, old_individual);
1023 individual_store_dispose (GObject *object)
1025 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1026 GList *individuals, *l;
1028 if (priv->dispose_has_run)
1030 priv->dispose_has_run = TRUE;
1032 /* Cancel any pending avatar load operations */
1033 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1035 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1036 g_cancellable_cancel (G_CANCELLABLE (l->data));
1038 g_list_free (priv->avatar_cancellables);
1040 individuals = empathy_individual_manager_get_members (priv->manager);
1041 for (l = individuals; l; l = l->next)
1043 individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1044 FOLKS_INDIVIDUAL (l->data));
1046 g_list_free (individuals);
1048 g_signal_handlers_disconnect_by_func (priv->manager,
1049 G_CALLBACK (individual_store_member_renamed_cb), object);
1050 g_signal_handlers_disconnect_by_func (priv->manager,
1051 G_CALLBACK (individual_store_members_changed_cb), object);
1052 g_signal_handlers_disconnect_by_func (priv->manager,
1053 G_CALLBACK (individual_store_favourites_changed_cb), object);
1054 g_signal_handlers_disconnect_by_func (priv->manager,
1055 G_CALLBACK (individual_store_groups_changed_cb), object);
1056 g_object_unref (priv->manager);
1058 if (priv->inhibit_active)
1060 g_source_remove (priv->inhibit_active);
1063 if (priv->setup_idle_id != 0)
1065 g_source_remove (priv->setup_idle_id);
1068 g_hash_table_destroy (priv->status_icons);
1069 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1073 individual_store_get_property (GObject *object,
1078 EmpathyIndividualStorePriv *priv;
1080 priv = GET_PRIV (object);
1084 case PROP_INDIVIDUAL_MANAGER:
1085 g_value_set_object (value, priv->manager);
1087 case PROP_SHOW_AVATARS:
1088 g_value_set_boolean (value, priv->show_avatars);
1090 case PROP_SHOW_PROTOCOLS:
1091 g_value_set_boolean (value, priv->show_protocols);
1093 case PROP_SHOW_GROUPS:
1094 g_value_set_boolean (value, priv->show_groups);
1096 case PROP_IS_COMPACT:
1097 g_value_set_boolean (value, priv->is_compact);
1099 case PROP_SORT_CRITERIUM:
1100 g_value_set_enum (value, priv->sort_criterium);
1103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1109 individual_store_set_property (GObject *object,
1111 const GValue *value,
1114 EmpathyIndividualStorePriv *priv;
1116 priv = GET_PRIV (object);
1120 case PROP_INDIVIDUAL_MANAGER:
1121 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1122 (object), g_value_get_object (value));
1124 case PROP_SHOW_AVATARS:
1125 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1126 (object), g_value_get_boolean (value));
1128 case PROP_SHOW_PROTOCOLS:
1129 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1130 (object), g_value_get_boolean (value));
1132 case PROP_SHOW_GROUPS:
1133 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1134 (object), g_value_get_boolean (value));
1136 case PROP_IS_COMPACT:
1137 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1138 (object), g_value_get_boolean (value));
1140 case PROP_SORT_CRITERIUM:
1141 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1142 (object), g_value_get_enum (value));
1145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1151 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1153 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1155 object_class->dispose = individual_store_dispose;
1156 object_class->get_property = individual_store_get_property;
1157 object_class->set_property = individual_store_set_property;
1159 g_object_class_install_property (object_class,
1160 PROP_INDIVIDUAL_MANAGER,
1161 g_param_spec_object ("individual-manager",
1162 "The individual manager",
1163 "The individual manager",
1164 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1165 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1166 g_object_class_install_property (object_class,
1168 g_param_spec_boolean ("show-avatars",
1170 "Whether contact list should display "
1171 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1172 g_object_class_install_property (object_class,
1173 PROP_SHOW_PROTOCOLS,
1174 g_param_spec_boolean ("show-protocols",
1176 "Whether contact list should display "
1177 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1178 g_object_class_install_property (object_class,
1180 g_param_spec_boolean ("show-groups",
1182 "Whether contact list should display "
1183 "contact groups", TRUE, G_PARAM_READWRITE));
1184 g_object_class_install_property (object_class,
1186 g_param_spec_boolean ("is-compact",
1188 "Whether the contact list is in compact mode or not",
1189 FALSE, G_PARAM_READWRITE));
1191 g_object_class_install_property (object_class,
1192 PROP_SORT_CRITERIUM,
1193 g_param_spec_enum ("sort-criterium",
1195 "The sort criterium to use for sorting the contact list",
1196 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1197 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1199 g_type_class_add_private (object_class,
1200 sizeof (EmpathyIndividualStorePriv));
1204 get_position (const char **strv,
1209 for (i = 0; strv[i] != NULL; i++)
1211 if (!tp_strdiff (strv[i], str))
1219 compare_separator_and_groups (gboolean is_separator_a,
1220 gboolean is_separator_b,
1221 const gchar *name_a,
1222 const gchar *name_b,
1223 FolksIndividual *individual_a,
1224 FolksIndividual *individual_b,
1225 gboolean fake_group_a,
1226 gboolean fake_group_b)
1228 /* these two lists are the sorted list of fake groups to include at the
1229 * top and bottom of the roster */
1230 const char *top_groups[] = {
1231 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1235 const char *bottom_groups[] = {
1236 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1240 if (is_separator_a || is_separator_b)
1242 /* We have at least one separator */
1247 else if (is_separator_b)
1253 /* One group and one contact */
1254 if (!individual_a && individual_b)
1258 else if (individual_a && !individual_b)
1262 else if (!individual_a && !individual_b)
1264 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1266 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1267 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1268 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1269 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1271 if (a_in_top && b_in_top)
1273 /* compare positions */
1274 return CLAMP (get_position (top_groups, name_a) -
1275 get_position (top_groups, name_b), -1, 1);
1277 else if (a_in_bottom && b_in_bottom)
1279 /* compare positions */
1280 return CLAMP (get_position (bottom_groups, name_a) -
1281 get_position (bottom_groups, name_b), -1, 1);
1283 else if (a_in_top || b_in_bottom)
1287 else if (b_in_top || a_in_bottom)
1293 return g_utf8_collate (name_a, name_b);
1297 /* Two contacts, ordering depends of the sorting policy */
1302 individual_store_contact_sort (FolksIndividual *individual_a,
1303 FolksIndividual *individual_b)
1306 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1307 TpAccount *account_a, *account_b;
1309 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1312 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1313 folks_individual_get_alias (individual_b));
1318 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1319 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1320 account_a = empathy_contact_get_account (contact_a);
1321 account_b = empathy_contact_get_account (contact_b);
1324 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1325 tp_account_get_protocol (account_b));
1331 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1332 tp_proxy_get_object_path (account_b));
1338 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1339 folks_individual_get_id (individual_b));
1342 tp_clear_object (&contact_a);
1343 tp_clear_object (&contact_b);
1349 individual_store_state_sort_func (GtkTreeModel *model,
1350 GtkTreeIter *iter_a,
1351 GtkTreeIter *iter_b,
1355 FolksIndividual *individual_a, *individual_b;
1356 gchar *name_a, *name_b;
1357 gboolean is_separator_a, is_separator_b;
1358 gboolean fake_group_a, fake_group_b;
1359 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1360 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1362 gtk_tree_model_get (model, iter_a,
1363 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1364 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1365 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1366 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1367 gtk_tree_model_get (model, iter_b,
1368 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1369 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1370 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1371 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1373 if (individual_a == NULL || individual_b == NULL)
1375 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1376 name_a, name_b, individual_a, individual_b, fake_group_a,
1381 /* If we managed to get this far, we can start looking at
1384 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1385 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1386 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1387 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1389 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1394 /* Fallback: compare by name et al. */
1395 ret_val = individual_store_contact_sort (individual_a, individual_b);
1401 tp_clear_object (&individual_a);
1402 tp_clear_object (&individual_b);
1408 individual_store_name_sort_func (GtkTreeModel *model,
1409 GtkTreeIter *iter_a,
1410 GtkTreeIter *iter_b,
1413 gchar *name_a, *name_b;
1414 FolksIndividual *individual_a, *individual_b;
1415 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1417 gboolean fake_group_a, fake_group_b;
1419 gtk_tree_model_get (model, iter_a,
1420 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1421 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1422 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1423 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1424 gtk_tree_model_get (model, iter_b,
1425 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1426 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1427 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1428 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1430 if (individual_a == NULL || individual_b == NULL)
1431 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1432 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1434 ret_val = individual_store_contact_sort (individual_a, individual_b);
1436 tp_clear_object (&individual_a);
1437 tp_clear_object (&individual_b);
1443 individual_store_setup (EmpathyIndividualStore *self)
1445 EmpathyIndividualStorePriv *priv;
1447 GDK_TYPE_PIXBUF, /* Status pixbuf */
1448 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1449 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1450 G_TYPE_STRING, /* Name */
1451 G_TYPE_UINT, /* Presence type */
1452 G_TYPE_STRING, /* Status string */
1453 G_TYPE_BOOLEAN, /* Compact view */
1454 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1455 G_TYPE_BOOLEAN, /* Is group */
1456 G_TYPE_BOOLEAN, /* Is active */
1457 G_TYPE_BOOLEAN, /* Is online */
1458 G_TYPE_BOOLEAN, /* Is separator */
1459 G_TYPE_BOOLEAN, /* Can make audio calls */
1460 G_TYPE_BOOLEAN, /* Can make video calls */
1461 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1462 G_TYPE_BOOLEAN, /* Is a fake group */
1465 priv = GET_PRIV (self);
1467 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1468 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1470 /* Set up sorting */
1471 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1472 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1473 individual_store_name_sort_func, self, NULL);
1474 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1475 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1476 individual_store_state_sort_func, self, NULL);
1478 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1479 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1483 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1485 EmpathyIndividualStorePriv *priv;
1487 priv = GET_PRIV (self);
1489 priv->show_active = TRUE;
1490 priv->inhibit_active = 0;
1496 empathy_individual_store_init (EmpathyIndividualStore *self)
1498 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1499 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1502 priv->show_avatars = TRUE;
1503 priv->show_groups = TRUE;
1504 priv->show_protocols = FALSE;
1505 priv->inhibit_active =
1506 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1507 (GSourceFunc) individual_store_inhibit_active_cb, self);
1508 priv->status_icons =
1509 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1510 individual_store_setup (self);
1513 EmpathyIndividualStore *
1514 empathy_individual_store_new (EmpathyIndividualManager *manager)
1516 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1518 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1519 "individual-manager", manager, NULL);
1522 EmpathyIndividualManager *
1523 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1525 EmpathyIndividualStorePriv *priv;
1527 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1529 priv = GET_PRIV (self);
1531 return priv->manager;
1535 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1537 EmpathyIndividualStorePriv *priv;
1539 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1541 priv = GET_PRIV (self);
1543 return priv->show_avatars;
1547 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1550 EmpathyIndividualStore *self)
1552 EmpathyIndividualStorePriv *priv;
1553 gboolean show_avatar = FALSE;
1554 FolksIndividual *individual;
1555 GdkPixbuf *pixbuf_status;
1557 priv = GET_PRIV (self);
1559 if (priv->show_avatars && !priv->is_compact)
1564 gtk_tree_model_get (model, iter,
1565 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1567 if (individual == NULL)
1571 /* get icon from hash_table */
1573 empathy_individual_store_get_individual_status_icon (self, individual);
1575 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1576 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1577 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1578 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1580 g_object_unref (individual);
1586 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1587 gboolean show_avatars)
1589 EmpathyIndividualStorePriv *priv;
1590 GtkTreeModel *model;
1592 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1594 priv = GET_PRIV (self);
1596 priv->show_avatars = show_avatars;
1598 model = GTK_TREE_MODEL (self);
1600 gtk_tree_model_foreach (model,
1601 (GtkTreeModelForeachFunc)
1602 individual_store_update_list_mode_foreach, self);
1604 g_object_notify (G_OBJECT (self), "show-avatars");
1608 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1610 EmpathyIndividualStorePriv *priv;
1612 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1614 priv = GET_PRIV (self);
1616 return priv->show_protocols;
1620 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1621 gboolean show_protocols)
1623 EmpathyIndividualStorePriv *priv;
1624 GtkTreeModel *model;
1626 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1628 priv = GET_PRIV (self);
1630 priv->show_protocols = show_protocols;
1632 model = GTK_TREE_MODEL (self);
1634 gtk_tree_model_foreach (model,
1635 (GtkTreeModelForeachFunc)
1636 individual_store_update_list_mode_foreach, self);
1638 g_object_notify (G_OBJECT (self), "show-protocols");
1642 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1644 EmpathyIndividualStorePriv *priv;
1646 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1648 priv = GET_PRIV (self);
1650 return priv->show_groups;
1654 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1655 gboolean show_groups)
1657 EmpathyIndividualStorePriv *priv;
1659 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1661 priv = GET_PRIV (self);
1663 if (priv->show_groups == show_groups)
1668 priv->show_groups = show_groups;
1670 if (priv->setup_idle_id == 0)
1672 /* Remove all contacts and add them back, not optimized but
1673 * that's the easy way :)
1675 * This is only done if there's not a pending setup idle
1676 * callback, otherwise it will race and the contacts will get
1680 gtk_tree_store_clear (GTK_TREE_STORE (self));
1681 contacts = empathy_individual_manager_get_members (priv->manager);
1683 individual_store_members_changed_cb (priv->manager,
1684 "re-adding members: toggled group visibility",
1685 contacts, NULL, 0, self);
1686 g_list_free (contacts);
1689 g_object_notify (G_OBJECT (self), "show-groups");
1693 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1695 EmpathyIndividualStorePriv *priv;
1697 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1699 priv = GET_PRIV (self);
1701 return priv->is_compact;
1705 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1706 gboolean is_compact)
1708 EmpathyIndividualStorePriv *priv;
1709 GtkTreeModel *model;
1711 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1713 priv = GET_PRIV (self);
1715 priv->is_compact = is_compact;
1717 model = GTK_TREE_MODEL (self);
1719 gtk_tree_model_foreach (model,
1720 (GtkTreeModelForeachFunc)
1721 individual_store_update_list_mode_foreach, self);
1723 g_object_notify (G_OBJECT (self), "is-compact");
1726 EmpathyIndividualStoreSort
1727 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1729 EmpathyIndividualStorePriv *priv;
1731 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1733 priv = GET_PRIV (self);
1735 return priv->sort_criterium;
1739 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1740 EmpathyIndividualStoreSort sort_criterium)
1742 EmpathyIndividualStorePriv *priv;
1744 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1746 priv = GET_PRIV (self);
1748 priv->sort_criterium = sort_criterium;
1750 switch (sort_criterium)
1752 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1753 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1754 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1757 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1758 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1759 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1763 g_assert_not_reached ();
1766 g_object_notify (G_OBJECT (self), "sort-criterium");
1770 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1774 gboolean is_separator = FALSE;
1776 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1778 gtk_tree_model_get (model, iter,
1779 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1781 return is_separator;
1785 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1787 gboolean *path_is_group,
1788 gboolean *is_fake_group)
1790 GtkTreeIter parent_iter, iter;
1795 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1799 *path_is_group = FALSE;
1802 if (!gtk_tree_model_get_iter (model, &iter, path))
1807 gtk_tree_model_get (model, &iter,
1808 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1809 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1816 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1823 gtk_tree_model_get (model, &iter,
1824 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1825 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1826 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1836 *path_is_group = TRUE;
1839 if (is_fake_group != NULL)
1840 *is_fake_group = fake;
1846 individual_store_get_individual_status_icon_with_icon_name (
1847 EmpathyIndividualStore *self,
1848 FolksIndividual *individual,
1849 const gchar *status_icon_name)
1851 GdkPixbuf *pixbuf_status = NULL;
1852 EmpathyIndividualStorePriv *priv;
1853 const gchar *protocol_name = NULL;
1854 gchar *icon_name = NULL;
1855 GList *personas, *l;
1856 guint contact_count;
1857 EmpathyContact *contact = NULL;
1858 gboolean show_protocols_here;
1860 priv = GET_PRIV (self);
1862 personas = folks_individual_get_personas (individual);
1863 for (l = personas, contact_count = 0; l; l = l->next)
1865 if (TPF_IS_PERSONA (l->data))
1868 if (contact_count > 1)
1872 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1873 if (show_protocols_here)
1875 contact = empathy_contact_dup_from_folks_individual (individual);
1876 protocol_name = empathy_protocol_name_for_contact (contact);
1877 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1881 icon_name = g_strdup_printf ("%s", status_icon_name);
1883 if (pixbuf_status == NULL)
1886 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1887 status_icon_name, show_protocols_here);
1888 if (pixbuf_status != NULL)
1890 g_hash_table_insert (priv->status_icons,
1891 g_strdup (icon_name), pixbuf_status);
1896 tp_clear_object (&contact);
1898 return pixbuf_status;
1902 empathy_individual_store_get_individual_status_icon (
1903 EmpathyIndividualStore *self,
1904 FolksIndividual *individual)
1906 GdkPixbuf *pixbuf_status = NULL;
1907 const gchar *status_icon_name = NULL;
1909 status_icon_name = empathy_icon_name_for_individual (individual);
1910 if (status_icon_name == NULL)
1914 individual_store_get_individual_status_icon_with_icon_name (self,
1915 individual, status_icon_name);
1917 return pixbuf_status;