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)
805 EmpathyContact *contact;
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 EmpathyContact for them. */
818 contact = empathy_contact_dup_from_folks_individual (individual);
819 g_object_set_data (G_OBJECT (contact), "individual", individual);
820 g_signal_connect (contact, "notify::capabilities",
821 G_CALLBACK (individual_store_contact_updated_cb), self);
822 g_object_unref (contact);
824 individual_store_add_individual (self, individual);
828 individual_store_remove_individual_and_disconnect (
829 EmpathyIndividualStore *self,
830 FolksIndividual *individual)
832 g_signal_handlers_disconnect_by_func (individual,
833 G_CALLBACK (individual_store_individual_updated_cb), self);
834 g_signal_handlers_disconnect_by_func (individual,
835 G_CALLBACK (individual_store_contact_updated_cb), self);
837 individual_store_remove_individual (self, individual);
841 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
842 const gchar *message,
846 EmpathyIndividualStore *self)
850 for (l = added; l; l = l->next)
852 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
854 individual_store_add_individual_and_connect (self, l->data);
856 for (l = removed; l; l = l->next)
858 DEBUG ("Individual %s %s",
859 folks_individual_get_id (l->data), "removed");
861 individual_store_remove_individual_and_disconnect (self, l->data);
866 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
867 FolksIndividual *individual,
868 gboolean is_favourite,
869 EmpathyIndividualStore *self)
871 EmpathyIndividualStorePriv *priv;
873 priv = GET_PRIV (self);
875 DEBUG ("Individual %s is %s a favourite",
876 folks_individual_get_id (individual),
877 is_favourite ? "now" : "no longer");
879 individual_store_remove_individual (self, individual);
880 individual_store_add_individual (self, individual);
884 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
885 FolksIndividual *individual,
888 EmpathyIndividualStore *self)
890 EmpathyIndividualStorePriv *priv;
891 gboolean show_active;
893 priv = GET_PRIV (self);
895 DEBUG ("Updating groups for individual %s",
896 folks_individual_get_id (individual));
898 /* We do this to make sure the groups are correct, if not, we
899 * would have to check the groups already set up for each
900 * contact and then see what has been updated.
902 show_active = priv->show_active;
903 priv->show_active = FALSE;
904 individual_store_remove_individual (self, individual);
905 individual_store_add_individual (self, individual);
906 priv->show_active = show_active;
910 individual_store_manager_setup (gpointer user_data)
912 EmpathyIndividualStore *self = user_data;
913 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
916 /* Signal connection. */
918 /* TODO: implement */
919 DEBUG ("handling individual renames unimplemented");
921 g_signal_connect (priv->manager,
923 G_CALLBACK (individual_store_members_changed_cb), self);
925 g_signal_connect (priv->manager,
926 "favourites-changed",
927 G_CALLBACK (individual_store_favourites_changed_cb), self);
929 g_signal_connect (priv->manager,
931 G_CALLBACK (individual_store_groups_changed_cb), self);
933 /* Add contacts already created. */
934 individuals = empathy_individual_manager_get_members (priv->manager);
935 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
937 individual_store_members_changed_cb (priv->manager, "initial add",
938 individuals, NULL, 0, self);
939 g_list_free (individuals);
942 priv->setup_idle_id = 0;
947 individual_store_set_individual_manager (EmpathyIndividualStore *self,
948 EmpathyIndividualManager *manager)
950 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
952 priv->manager = g_object_ref (manager);
954 /* Let a chance to have all properties set before populating */
955 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
959 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
960 FolksIndividual *old_individual,
961 FolksIndividual *new_individual,
963 const gchar *message,
964 EmpathyIndividualStore *self)
966 EmpathyIndividualStorePriv *priv;
968 priv = GET_PRIV (self);
970 DEBUG ("Individual %s renamed to %s",
971 folks_individual_get_id (old_individual),
972 folks_individual_get_id (new_individual));
974 /* add the new contact */
975 individual_store_add_individual_and_connect (self, new_individual);
977 /* remove old contact */
978 individual_store_remove_individual_and_disconnect (self, old_individual);
982 individual_store_dispose (GObject *object)
984 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
987 if (priv->dispose_has_run)
989 priv->dispose_has_run = TRUE;
991 /* Cancel any pending avatar load operations */
992 for (l = priv->avatar_cancellables; l != NULL; l = l->next)
994 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
995 g_cancellable_cancel (G_CANCELLABLE (l->data));
997 g_list_free (priv->avatar_cancellables);
999 contacts = empathy_individual_manager_get_members (priv->manager);
1000 for (l = contacts; l; l = l->next)
1002 g_signal_handlers_disconnect_by_func (l->data,
1003 G_CALLBACK (individual_store_individual_updated_cb), object);
1004 g_signal_handlers_disconnect_by_func (l->data,
1005 G_CALLBACK (individual_store_contact_updated_cb), object);
1007 g_list_free (contacts);
1009 g_signal_handlers_disconnect_by_func (priv->manager,
1010 G_CALLBACK (individual_store_member_renamed_cb), object);
1011 g_signal_handlers_disconnect_by_func (priv->manager,
1012 G_CALLBACK (individual_store_members_changed_cb), object);
1013 g_signal_handlers_disconnect_by_func (priv->manager,
1014 G_CALLBACK (individual_store_favourites_changed_cb), object);
1015 g_signal_handlers_disconnect_by_func (priv->manager,
1016 G_CALLBACK (individual_store_groups_changed_cb), object);
1017 g_object_unref (priv->manager);
1019 if (priv->inhibit_active)
1021 g_source_remove (priv->inhibit_active);
1024 if (priv->setup_idle_id != 0)
1026 g_source_remove (priv->setup_idle_id);
1029 g_hash_table_destroy (priv->status_icons);
1030 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1034 individual_store_get_property (GObject *object,
1039 EmpathyIndividualStorePriv *priv;
1041 priv = GET_PRIV (object);
1045 case PROP_INDIVIDUAL_MANAGER:
1046 g_value_set_object (value, priv->manager);
1048 case PROP_SHOW_AVATARS:
1049 g_value_set_boolean (value, priv->show_avatars);
1051 case PROP_SHOW_PROTOCOLS:
1052 g_value_set_boolean (value, priv->show_protocols);
1054 case PROP_SHOW_GROUPS:
1055 g_value_set_boolean (value, priv->show_groups);
1057 case PROP_IS_COMPACT:
1058 g_value_set_boolean (value, priv->is_compact);
1060 case PROP_SORT_CRITERIUM:
1061 g_value_set_enum (value, priv->sort_criterium);
1064 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1070 individual_store_set_property (GObject *object,
1072 const GValue *value,
1075 EmpathyIndividualStorePriv *priv;
1077 priv = GET_PRIV (object);
1081 case PROP_INDIVIDUAL_MANAGER:
1082 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1083 (object), g_value_get_object (value));
1085 case PROP_SHOW_AVATARS:
1086 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1087 (object), g_value_get_boolean (value));
1089 case PROP_SHOW_PROTOCOLS:
1090 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1091 (object), g_value_get_boolean (value));
1093 case PROP_SHOW_GROUPS:
1094 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1095 (object), g_value_get_boolean (value));
1097 case PROP_IS_COMPACT:
1098 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1099 (object), g_value_get_boolean (value));
1101 case PROP_SORT_CRITERIUM:
1102 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1103 (object), g_value_get_enum (value));
1106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1112 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1114 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1116 object_class->dispose = individual_store_dispose;
1117 object_class->get_property = individual_store_get_property;
1118 object_class->set_property = individual_store_set_property;
1120 g_object_class_install_property (object_class,
1121 PROP_INDIVIDUAL_MANAGER,
1122 g_param_spec_object ("individual-manager",
1123 "The individual manager",
1124 "The individual manager",
1125 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1126 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1127 g_object_class_install_property (object_class,
1129 g_param_spec_boolean ("show-avatars",
1131 "Whether contact list should display "
1132 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1133 g_object_class_install_property (object_class,
1134 PROP_SHOW_PROTOCOLS,
1135 g_param_spec_boolean ("show-protocols",
1137 "Whether contact list should display "
1138 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1139 g_object_class_install_property (object_class,
1141 g_param_spec_boolean ("show-groups",
1143 "Whether contact list should display "
1144 "contact groups", TRUE, G_PARAM_READWRITE));
1145 g_object_class_install_property (object_class,
1147 g_param_spec_boolean ("is-compact",
1149 "Whether the contact list is in compact mode or not",
1150 FALSE, G_PARAM_READWRITE));
1152 g_object_class_install_property (object_class,
1153 PROP_SORT_CRITERIUM,
1154 g_param_spec_enum ("sort-criterium",
1156 "The sort criterium to use for sorting the contact list",
1157 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1158 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1160 g_type_class_add_private (object_class,
1161 sizeof (EmpathyIndividualStorePriv));
1165 get_position (const char **strv,
1170 for (i = 0; strv[i] != NULL; i++)
1172 if (!tp_strdiff (strv[i], str))
1180 compare_separator_and_groups (gboolean is_separator_a,
1181 gboolean is_separator_b,
1182 const gchar *name_a,
1183 const gchar *name_b,
1184 FolksIndividual *individual_a,
1185 FolksIndividual *individual_b,
1186 gboolean fake_group_a,
1187 gboolean fake_group_b)
1189 /* these two lists are the sorted list of fake groups to include at the
1190 * top and bottom of the roster */
1191 const char *top_groups[] = {
1192 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1196 const char *bottom_groups[] = {
1197 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1201 if (is_separator_a || is_separator_b)
1203 /* We have at least one separator */
1208 else if (is_separator_b)
1214 /* One group and one contact */
1215 if (!individual_a && individual_b)
1219 else if (individual_a && !individual_b)
1223 else if (!individual_a && !individual_b)
1225 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1227 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1228 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1229 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1230 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1232 if (a_in_top && b_in_top)
1234 /* compare positions */
1235 return CLAMP (get_position (top_groups, name_a) -
1236 get_position (top_groups, name_b), -1, 1);
1238 else if (a_in_bottom && b_in_bottom)
1240 /* compare positions */
1241 return CLAMP (get_position (bottom_groups, name_a) -
1242 get_position (bottom_groups, name_b), -1, 1);
1244 else if (a_in_top || b_in_bottom)
1248 else if (b_in_top || a_in_bottom)
1254 return g_utf8_collate (name_a, name_b);
1258 /* Two contacts, ordering depends of the sorting policy */
1263 individual_store_contact_sort (FolksIndividual *individual_a,
1264 FolksIndividual *individual_b)
1267 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1268 TpAccount *account_a, *account_b;
1270 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1273 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1274 folks_individual_get_alias (individual_b));
1279 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1280 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1281 account_a = empathy_contact_get_account (contact_a);
1282 account_b = empathy_contact_get_account (contact_b);
1285 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1286 tp_account_get_protocol (account_b));
1292 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1293 tp_proxy_get_object_path (account_b));
1299 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1300 folks_individual_get_id (individual_b));
1303 tp_clear_object (&contact_a);
1304 tp_clear_object (&contact_b);
1310 individual_store_state_sort_func (GtkTreeModel *model,
1311 GtkTreeIter *iter_a,
1312 GtkTreeIter *iter_b,
1316 FolksIndividual *individual_a, *individual_b;
1317 gchar *name_a, *name_b;
1318 gboolean is_separator_a, is_separator_b;
1319 gboolean fake_group_a, fake_group_b;
1320 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1321 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1323 gtk_tree_model_get (model, iter_a,
1324 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1325 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1326 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1327 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1328 gtk_tree_model_get (model, iter_b,
1329 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1330 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1331 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1332 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1334 if (individual_a == NULL || individual_b == NULL)
1336 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1337 name_a, name_b, individual_a, individual_b, fake_group_a,
1342 /* If we managed to get this far, we can start looking at
1345 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1346 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1347 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1348 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1350 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1355 /* Fallback: compare by name et al. */
1356 ret_val = individual_store_contact_sort (individual_a, individual_b);
1362 tp_clear_object (&individual_a);
1363 tp_clear_object (&individual_b);
1369 individual_store_name_sort_func (GtkTreeModel *model,
1370 GtkTreeIter *iter_a,
1371 GtkTreeIter *iter_b,
1374 gchar *name_a, *name_b;
1375 FolksIndividual *individual_a, *individual_b;
1376 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1378 gboolean fake_group_a, fake_group_b;
1380 gtk_tree_model_get (model, iter_a,
1381 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1382 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1383 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1384 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1385 gtk_tree_model_get (model, iter_b,
1386 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1387 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1388 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1389 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1391 if (individual_a == NULL || individual_b == NULL)
1392 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1393 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1395 ret_val = individual_store_contact_sort (individual_a, individual_b);
1397 tp_clear_object (&individual_a);
1398 tp_clear_object (&individual_b);
1404 individual_store_setup (EmpathyIndividualStore *self)
1406 EmpathyIndividualStorePriv *priv;
1408 GDK_TYPE_PIXBUF, /* Status pixbuf */
1409 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1410 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1411 G_TYPE_STRING, /* Name */
1412 G_TYPE_UINT, /* Presence type */
1413 G_TYPE_STRING, /* Status string */
1414 G_TYPE_BOOLEAN, /* Compact view */
1415 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1416 G_TYPE_BOOLEAN, /* Is group */
1417 G_TYPE_BOOLEAN, /* Is active */
1418 G_TYPE_BOOLEAN, /* Is online */
1419 G_TYPE_BOOLEAN, /* Is separator */
1420 G_TYPE_BOOLEAN, /* Can make audio calls */
1421 G_TYPE_BOOLEAN, /* Can make video calls */
1422 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1423 G_TYPE_BOOLEAN, /* Is a fake group */
1426 priv = GET_PRIV (self);
1428 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1429 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1431 /* Set up sorting */
1432 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1433 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1434 individual_store_name_sort_func, self, NULL);
1435 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1436 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1437 individual_store_state_sort_func, self, NULL);
1439 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1440 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1444 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1446 EmpathyIndividualStorePriv *priv;
1448 priv = GET_PRIV (self);
1450 priv->show_active = TRUE;
1451 priv->inhibit_active = 0;
1457 empathy_individual_store_init (EmpathyIndividualStore *self)
1459 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1460 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1463 priv->show_avatars = TRUE;
1464 priv->show_groups = TRUE;
1465 priv->show_protocols = FALSE;
1466 priv->inhibit_active =
1467 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1468 (GSourceFunc) individual_store_inhibit_active_cb, self);
1469 priv->status_icons =
1470 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1471 individual_store_setup (self);
1474 EmpathyIndividualStore *
1475 empathy_individual_store_new (EmpathyIndividualManager *manager)
1477 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1479 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1480 "individual-manager", manager, NULL);
1483 EmpathyIndividualManager *
1484 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1486 EmpathyIndividualStorePriv *priv;
1488 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1490 priv = GET_PRIV (self);
1492 return priv->manager;
1496 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1498 EmpathyIndividualStorePriv *priv;
1500 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1502 priv = GET_PRIV (self);
1504 return priv->show_avatars;
1508 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1511 EmpathyIndividualStore *self)
1513 EmpathyIndividualStorePriv *priv;
1514 gboolean show_avatar = FALSE;
1515 FolksIndividual *individual;
1516 GdkPixbuf *pixbuf_status;
1518 priv = GET_PRIV (self);
1520 if (priv->show_avatars && !priv->is_compact)
1525 gtk_tree_model_get (model, iter,
1526 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1528 if (individual == NULL)
1532 /* get icon from hash_table */
1534 empathy_individual_store_get_individual_status_icon (self, individual);
1536 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1537 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1538 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1539 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1541 g_object_unref (individual);
1547 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1548 gboolean show_avatars)
1550 EmpathyIndividualStorePriv *priv;
1551 GtkTreeModel *model;
1553 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1555 priv = GET_PRIV (self);
1557 priv->show_avatars = show_avatars;
1559 model = GTK_TREE_MODEL (self);
1561 gtk_tree_model_foreach (model,
1562 (GtkTreeModelForeachFunc)
1563 individual_store_update_list_mode_foreach, self);
1565 g_object_notify (G_OBJECT (self), "show-avatars");
1569 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1571 EmpathyIndividualStorePriv *priv;
1573 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1575 priv = GET_PRIV (self);
1577 return priv->show_protocols;
1581 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1582 gboolean show_protocols)
1584 EmpathyIndividualStorePriv *priv;
1585 GtkTreeModel *model;
1587 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1589 priv = GET_PRIV (self);
1591 priv->show_protocols = show_protocols;
1593 model = GTK_TREE_MODEL (self);
1595 gtk_tree_model_foreach (model,
1596 (GtkTreeModelForeachFunc)
1597 individual_store_update_list_mode_foreach, self);
1599 g_object_notify (G_OBJECT (self), "show-protocols");
1603 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1605 EmpathyIndividualStorePriv *priv;
1607 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1609 priv = GET_PRIV (self);
1611 return priv->show_groups;
1615 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1616 gboolean show_groups)
1618 EmpathyIndividualStorePriv *priv;
1620 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1622 priv = GET_PRIV (self);
1624 if (priv->show_groups == show_groups)
1629 priv->show_groups = show_groups;
1631 if (priv->setup_idle_id == 0)
1633 /* Remove all contacts and add them back, not optimized but
1634 * that's the easy way :)
1636 * This is only done if there's not a pending setup idle
1637 * callback, otherwise it will race and the contacts will get
1641 gtk_tree_store_clear (GTK_TREE_STORE (self));
1642 contacts = empathy_individual_manager_get_members (priv->manager);
1644 individual_store_members_changed_cb (priv->manager,
1645 "re-adding members: toggled group visibility",
1646 contacts, NULL, 0, self);
1647 g_list_free (contacts);
1650 g_object_notify (G_OBJECT (self), "show-groups");
1654 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1656 EmpathyIndividualStorePriv *priv;
1658 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1660 priv = GET_PRIV (self);
1662 return priv->is_compact;
1666 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1667 gboolean is_compact)
1669 EmpathyIndividualStorePriv *priv;
1670 GtkTreeModel *model;
1672 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1674 priv = GET_PRIV (self);
1676 priv->is_compact = is_compact;
1678 model = GTK_TREE_MODEL (self);
1680 gtk_tree_model_foreach (model,
1681 (GtkTreeModelForeachFunc)
1682 individual_store_update_list_mode_foreach, self);
1684 g_object_notify (G_OBJECT (self), "is-compact");
1687 EmpathyIndividualStoreSort
1688 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1690 EmpathyIndividualStorePriv *priv;
1692 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1694 priv = GET_PRIV (self);
1696 return priv->sort_criterium;
1700 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1701 EmpathyIndividualStoreSort sort_criterium)
1703 EmpathyIndividualStorePriv *priv;
1705 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1707 priv = GET_PRIV (self);
1709 priv->sort_criterium = sort_criterium;
1711 switch (sort_criterium)
1713 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1714 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1715 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1718 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1719 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1720 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1724 g_assert_not_reached ();
1727 g_object_notify (G_OBJECT (self), "sort-criterium");
1731 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1735 gboolean is_separator = FALSE;
1737 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1739 gtk_tree_model_get (model, iter,
1740 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1742 return is_separator;
1746 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1748 gboolean *path_is_group,
1749 gboolean *is_fake_group)
1751 GtkTreeIter parent_iter, iter;
1756 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1760 *path_is_group = FALSE;
1763 if (!gtk_tree_model_get_iter (model, &iter, path))
1768 gtk_tree_model_get (model, &iter,
1769 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1770 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1777 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1784 gtk_tree_model_get (model, &iter,
1785 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1786 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1787 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1797 *path_is_group = TRUE;
1800 if (is_fake_group != NULL)
1801 *is_fake_group = fake;
1807 individual_store_get_individual_status_icon_with_icon_name (
1808 EmpathyIndividualStore *self,
1809 FolksIndividual *individual,
1810 const gchar *status_icon_name)
1812 GdkPixbuf *pixbuf_status = NULL;
1813 EmpathyIndividualStorePriv *priv;
1814 const gchar *protocol_name = NULL;
1815 gchar *icon_name = NULL;
1816 GList *personas, *l;
1817 guint contact_count;
1818 EmpathyContact *contact = NULL;
1819 gboolean show_protocols_here;
1821 priv = GET_PRIV (self);
1823 personas = folks_individual_get_personas (individual);
1824 for (l = personas, contact_count = 0; l; l = l->next)
1826 if (TPF_IS_PERSONA (l->data))
1829 if (contact_count > 1)
1833 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1834 if (show_protocols_here)
1836 contact = empathy_contact_dup_from_folks_individual (individual);
1837 protocol_name = empathy_protocol_name_for_contact (contact);
1838 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1842 icon_name = g_strdup_printf ("%s", status_icon_name);
1844 if (pixbuf_status == NULL)
1847 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1848 status_icon_name, priv->show_protocols);
1849 if (pixbuf_status != NULL)
1851 g_hash_table_insert (priv->status_icons,
1852 g_strdup (icon_name), pixbuf_status);
1857 tp_clear_object (&contact);
1859 return pixbuf_status;
1863 empathy_individual_store_get_individual_status_icon (
1864 EmpathyIndividualStore *self,
1865 FolksIndividual *individual)
1867 GdkPixbuf *pixbuf_status = NULL;
1868 const gchar *status_icon_name = NULL;
1870 status_icon_name = empathy_icon_name_for_individual (individual);
1871 if (status_icon_name == NULL)
1875 individual_store_get_individual_status_icon_with_icon_name (self,
1876 individual, status_icon_name);
1878 return pixbuf_status;