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 EmpathyContact *contact;
126 contact = empathy_contact_dup_from_folks_individual (individual);
128 gtk_tree_store_insert_with_values (self, iter, parent, 0,
129 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
130 folks_individual_get_alias (individual),
131 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
132 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
133 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
134 EMPATHY_INDIVIDUAL_STORE_COL_FLAGS, flags,
139 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
140 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
141 empathy_contact_get_capabilities (contact) &
142 EMPATHY_CAPABILITIES_AUDIO,
143 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
144 empathy_contact_get_capabilities (contact) &
145 EMPATHY_CAPABILITIES_VIDEO,
149 tp_clear_object (&contact);
153 individual_store_get_group_foreach (GtkTreeModel *model,
161 /* Groups are only at the top level. */
162 if (gtk_tree_path_get_depth (path) != 1)
165 gtk_tree_model_get (model, iter,
166 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &str,
167 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
169 if (is_group && !tp_strdiff (str, fg->name))
181 individual_store_get_group (EmpathyIndividualStore *self,
183 GtkTreeIter *iter_group_to_set,
184 GtkTreeIter *iter_separator_to_set,
186 gboolean is_fake_group)
188 EmpathyIndividualStorePriv *priv;
190 GtkTreeIter iter_group;
191 GtkTreeIter iter_separator;
194 priv = GET_PRIV (self);
196 memset (&fg, 0, sizeof (fg));
200 model = GTK_TREE_MODEL (self);
201 gtk_tree_model_foreach (model,
202 (GtkTreeModelForeachFunc) individual_store_get_group_foreach, &fg);
209 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
211 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
212 EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
213 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
214 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
215 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
216 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
219 if (iter_group_to_set)
220 *iter_group_to_set = iter_group;
222 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
224 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
227 if (iter_separator_to_set)
228 *iter_separator_to_set = iter_separator;
235 if (iter_group_to_set)
236 *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)
248 *iter_separator_to_set = iter_separator;
254 individual_store_find_contact_foreach (GtkTreeModel *model,
259 FolksIndividual *individual;
261 gtk_tree_model_get (model, iter,
262 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
264 if (individual == fc->individual)
267 fc->iters = g_list_append (fc->iters, gtk_tree_iter_copy (iter));
270 tp_clear_object (&individual);
276 individual_store_find_contact (EmpathyIndividualStore *self,
277 FolksIndividual *individual)
279 EmpathyIndividualStorePriv *priv;
284 priv = GET_PRIV (self);
286 memset (&fc, 0, sizeof (fc));
288 fc.individual = individual;
290 model = GTK_TREE_MODEL (self);
291 gtk_tree_model_foreach (model,
292 (GtkTreeModelForeachFunc) individual_store_find_contact_foreach, &fc);
301 individual_store_remove_individual (EmpathyIndividualStore *self,
302 FolksIndividual *individual)
304 EmpathyIndividualStorePriv *priv;
308 priv = GET_PRIV (self);
310 iters = individual_store_find_contact (self, individual);
315 model = GTK_TREE_MODEL (self);
317 for (l = iters; l; l = l->next)
321 /* NOTE: it is only <= 2 here because we have
322 * separators after the group name, otherwise it
325 if (gtk_tree_model_iter_parent (model, &parent, l->data) &&
326 gtk_tree_model_iter_n_children (model, &parent) <= 2)
328 gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
332 gtk_tree_store_remove (GTK_TREE_STORE (self), l->data);
336 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
341 individual_store_add_individual (EmpathyIndividualStore *self,
342 FolksIndividual *individual)
344 EmpathyIndividualStorePriv *priv;
346 GHashTable *group_set = NULL;
347 GList *groups = NULL, *l;
348 EmpathyContact *contact;
349 TpConnection *connection;
350 EmpathyIndividualManagerFlags flags = 0;
351 gchar *protocol_name;
353 priv = GET_PRIV (self);
355 if (EMP_STR_EMPTY (folks_individual_get_alias (individual)) ||
356 (!priv->show_offline && !folks_individual_is_online (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 ShowActiveData *
471 individual_store_contact_active_new (EmpathyIndividualStore *self,
472 FolksIndividual *individual,
475 ShowActiveData *data;
477 DEBUG ("Individual'%s' now active, and %s be removed",
478 folks_individual_get_alias (individual), remove_ ? "WILL" : "WILL NOT");
480 data = g_slice_new0 (ShowActiveData);
482 /* We don't actually want to force either the IndividualStore or the
483 * Individual to stay alive, since the user could quit Empathy or disable
484 * the account before the contact_active timeout is fired. */
485 g_object_add_weak_pointer (G_OBJECT (self), (gpointer) &(data->self));
486 g_object_add_weak_pointer (G_OBJECT (individual),
487 (gpointer) &(data->individual));
490 data->individual = individual;
491 data->remove = remove_;
497 individual_store_contact_active_free (ShowActiveData *data)
499 g_slice_free (ShowActiveData, data);
503 individual_store_contact_active_cb (ShowActiveData *data)
505 EmpathyIndividualStorePriv *priv;
507 /* They're weak pointers, so may have been NULLified between ShowActiveData
508 * being created and the timeout being fired. We assume they can only be
509 * destroyed in this thread, so this isn't MT-safe. */
510 if (data->self == NULL || data->individual == NULL)
512 individual_store_contact_active_free (data);
516 priv = GET_PRIV (data->self);
519 !priv->show_offline && !folks_individual_is_online (data->individual))
521 DEBUG ("Individual'%s' active timeout, removing item",
522 folks_individual_get_alias (data->individual));
523 individual_store_remove_individual (data->self, data->individual);
526 DEBUG ("Individual'%s' no longer active",
527 folks_individual_get_alias (data->individual));
529 individual_store_contact_set_active (data->self,
530 data->individual, FALSE, TRUE);
532 individual_store_contact_active_free (data);
538 individual_avatar_pixbuf_received_cb (GObject *object,
539 GAsyncResult *result,
542 FolksIndividual *individual = FOLKS_INDIVIDUAL (object);
543 EmpathyIndividualStore *self = user_data;
544 GError *error = NULL;
547 pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
552 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
553 folks_individual_get_alias (individual),
555 g_clear_error (&error);
561 iters = individual_store_find_contact (self, individual);
562 for (l = iters; l; l = l->next)
564 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
565 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
572 individual_store_contact_update (EmpathyIndividualStore *self,
573 FolksIndividual *individual)
575 EmpathyIndividualStorePriv *priv;
576 ShowActiveData *data;
578 EmpathyContact *contact;
581 gboolean should_be_in_list;
582 gboolean was_online = TRUE;
583 gboolean now_online = FALSE;
584 gboolean set_model = FALSE;
585 gboolean do_remove = FALSE;
586 gboolean do_set_active = FALSE;
587 gboolean do_set_refresh = FALSE;
588 gboolean show_avatar = FALSE;
589 GdkPixbuf *pixbuf_status;
591 priv = GET_PRIV (self);
593 model = GTK_TREE_MODEL (self);
594 contact = empathy_contact_dup_from_folks_individual (individual);
596 iters = individual_store_find_contact (self, individual);
606 /* Get online state now. */
607 now_online = folks_individual_is_online (individual);
609 if (priv->show_offline || now_online)
611 should_be_in_list = TRUE;
615 should_be_in_list = FALSE;
618 if (!in_list && !should_be_in_list)
621 DEBUG ("Individual:'%s' in list:NO, should be:NO",
622 folks_individual_get_alias (individual));
624 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
628 else if (in_list && !should_be_in_list)
630 DEBUG ("Individual:'%s' in list:YES, should be:NO",
631 folks_individual_get_alias (individual));
633 if (priv->show_active)
636 do_set_active = TRUE;
637 do_set_refresh = TRUE;
640 DEBUG ("Remove item (after timeout)");
644 DEBUG ("Remove item (now)!");
645 individual_store_remove_individual (self, individual);
648 else if (!in_list && should_be_in_list)
650 DEBUG ("Individual'%s' in list:NO, should be:YES",
651 folks_individual_get_alias (individual));
653 individual_store_add_individual (self, individual);
655 if (priv->show_active)
657 do_set_active = TRUE;
659 DEBUG ("Set active (individual added)");
664 DEBUG ("Individual'%s' in list:YES, should be:YES",
665 folks_individual_get_alias (individual));
667 /* Get online state before. */
668 if (iters && g_list_length (iters) > 0)
670 gtk_tree_model_get (model, iters->data,
671 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
674 /* Is this really an update or an online/offline. */
675 if (priv->show_active)
677 if (was_online != now_online)
679 do_set_active = TRUE;
680 do_set_refresh = TRUE;
682 DEBUG ("Set active (individual updated %s)",
683 was_online ? "online -> offline" : "offline -> online");
687 /* Was TRUE for presence updates. */
688 /* do_set_active = FALSE; */
689 do_set_refresh = TRUE;
691 DEBUG ("Set active (individual updated)");
698 if (priv->show_avatars && !priv->is_compact)
703 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
704 individual_avatar_pixbuf_received_cb, 32, 32, self);
707 empathy_individual_store_get_individual_status_icon (self, individual);
709 for (l = iters; l && set_model; l = l->next)
711 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
712 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
713 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
714 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
715 folks_individual_get_alias (individual),
716 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
717 folks_individual_get_presence_type (individual),
718 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
719 folks_individual_get_presence_message (individual),
720 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
721 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
722 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
723 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
728 gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
729 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
730 empathy_contact_get_capabilities (contact) &
731 EMPATHY_CAPABILITIES_AUDIO,
732 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
733 empathy_contact_get_capabilities (contact) &
734 EMPATHY_CAPABILITIES_VIDEO,
739 if (priv->show_active && do_set_active)
741 individual_store_contact_set_active (self, individual, do_set_active,
747 individual_store_contact_active_new (self, individual,
749 g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
750 (GSourceFunc) individual_store_contact_active_cb, data);
754 /* FIXME: when someone goes online then offline quickly, the
755 * first timeout sets the user to be inactive and the second
756 * timeout removes the user from the contact list, really we
757 * should remove the first timeout.
759 g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
761 tp_clear_object (&contact);
765 individual_store_contact_updated_cb (FolksIndividual *individual,
767 EmpathyIndividualStore *self)
769 DEBUG ("Individual'%s' updated, checking roster is in sync...",
770 folks_individual_get_alias (individual));
772 individual_store_contact_update (self, individual);
776 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
777 FolksIndividual *individual)
779 g_signal_connect (individual, "notify::avatar",
780 G_CALLBACK (individual_store_contact_updated_cb), self);
781 g_signal_connect (individual, "notify::presence-type",
782 G_CALLBACK (individual_store_contact_updated_cb), self);
783 g_signal_connect (individual, "notify::presence-message",
784 G_CALLBACK (individual_store_contact_updated_cb), self);
785 g_signal_connect (individual, "notify::alias",
786 G_CALLBACK (individual_store_contact_updated_cb), self);
787 g_signal_connect (individual, "notify::capabilities",
788 G_CALLBACK (individual_store_contact_updated_cb), self);
790 individual_store_add_individual (self, individual);
794 individual_store_remove_individual_and_disconnect (
795 EmpathyIndividualStore *self,
796 FolksIndividual *individual)
798 g_signal_handlers_disconnect_by_func (individual,
799 G_CALLBACK (individual_store_contact_updated_cb), self);
801 individual_store_remove_individual (self, individual);
805 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
810 EmpathyIndividualStore *self)
814 for (l = added; l; l = l->next)
816 DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
818 individual_store_add_individual_and_connect (self, l->data);
820 for (l = removed; l; l = l->next)
822 DEBUG ("Individual %s %s",
823 folks_individual_get_id (l->data), "removed");
825 individual_store_remove_individual_and_disconnect (self, l->data);
830 individual_store_favourites_changed_cb (EmpathyIndividualManager *manager,
831 FolksIndividual *individual,
832 gboolean is_favourite,
833 EmpathyIndividualStore *self)
835 EmpathyIndividualStorePriv *priv;
837 priv = GET_PRIV (self);
839 DEBUG ("Individual %s is %s a favourite",
840 folks_individual_get_id (individual),
841 is_favourite ? "now" : "no longer");
843 individual_store_remove_individual (self, individual);
844 individual_store_add_individual (self, individual);
848 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
849 FolksIndividual *individual,
852 EmpathyIndividualStore *self)
854 EmpathyIndividualStorePriv *priv;
855 gboolean show_active;
857 priv = GET_PRIV (self);
859 DEBUG ("Updating groups for individual %s",
860 folks_individual_get_id (individual));
862 /* We do this to make sure the groups are correct, if not, we
863 * would have to check the groups already set up for each
864 * contact and then see what has been updated.
866 show_active = priv->show_active;
867 priv->show_active = FALSE;
868 individual_store_remove_individual (self, individual);
869 individual_store_add_individual (self, individual);
870 priv->show_active = show_active;
874 individual_store_manager_setup (gpointer user_data)
876 EmpathyIndividualStore *self = user_data;
877 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
880 /* Signal connection. */
882 /* TODO: implement */
883 DEBUG ("handling individual renames unimplemented");
885 g_signal_connect (priv->manager,
887 G_CALLBACK (individual_store_members_changed_cb), self);
889 g_signal_connect (priv->manager,
890 "favourites-changed",
891 G_CALLBACK (individual_store_favourites_changed_cb), self);
893 g_signal_connect (priv->manager,
895 G_CALLBACK (individual_store_groups_changed_cb), self);
897 /* Add contacts already created. */
898 individuals = empathy_individual_manager_get_members (priv->manager);
899 if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
901 individual_store_members_changed_cb (priv->manager, "initial add",
902 individuals, NULL, 0, self);
903 g_list_free (individuals);
906 priv->setup_idle_id = 0;
911 individual_store_set_individual_manager (EmpathyIndividualStore *self,
912 EmpathyIndividualManager *manager)
914 EmpathyIndividualStorePriv *priv = GET_PRIV (self);
916 priv->manager = g_object_ref (manager);
918 /* Let a chance to have all properties set before populating */
919 priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
923 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
924 FolksIndividual *old_individual,
925 FolksIndividual *new_individual,
928 EmpathyIndividualStore *self)
930 EmpathyIndividualStorePriv *priv;
932 priv = GET_PRIV (self);
934 DEBUG ("Individual %s renamed to %s",
935 folks_individual_get_id (old_individual),
936 folks_individual_get_id (new_individual));
938 /* add the new contact */
939 individual_store_add_individual_and_connect (self, new_individual);
941 /* remove old contact */
942 individual_store_remove_individual_and_disconnect (self, old_individual);
946 individual_store_dispose (GObject *object)
948 EmpathyIndividualStorePriv *priv = GET_PRIV (object);
951 if (priv->dispose_has_run)
953 priv->dispose_has_run = TRUE;
955 contacts = empathy_individual_manager_get_members (priv->manager);
956 for (l = contacts; l; l = l->next)
958 g_signal_handlers_disconnect_by_func (l->data,
959 G_CALLBACK (individual_store_contact_updated_cb), object);
961 g_list_free (contacts);
963 g_signal_handlers_disconnect_by_func (priv->manager,
964 G_CALLBACK (individual_store_member_renamed_cb), object);
965 g_signal_handlers_disconnect_by_func (priv->manager,
966 G_CALLBACK (individual_store_members_changed_cb), object);
967 g_signal_handlers_disconnect_by_func (priv->manager,
968 G_CALLBACK (individual_store_favourites_changed_cb), object);
969 g_signal_handlers_disconnect_by_func (priv->manager,
970 G_CALLBACK (individual_store_groups_changed_cb), object);
971 g_object_unref (priv->manager);
973 if (priv->inhibit_active)
975 g_source_remove (priv->inhibit_active);
978 if (priv->setup_idle_id != 0)
980 g_source_remove (priv->setup_idle_id);
983 g_hash_table_destroy (priv->status_icons);
984 G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
988 individual_store_get_property (GObject *object,
993 EmpathyIndividualStorePriv *priv;
995 priv = GET_PRIV (object);
999 case PROP_INDIVIDUAL_MANAGER:
1000 g_value_set_object (value, priv->manager);
1002 case PROP_SHOW_OFFLINE:
1003 g_value_set_boolean (value, priv->show_offline);
1005 case PROP_SHOW_AVATARS:
1006 g_value_set_boolean (value, priv->show_avatars);
1008 case PROP_SHOW_PROTOCOLS:
1009 g_value_set_boolean (value, priv->show_protocols);
1011 case PROP_SHOW_GROUPS:
1012 g_value_set_boolean (value, priv->show_groups);
1014 case PROP_IS_COMPACT:
1015 g_value_set_boolean (value, priv->is_compact);
1017 case PROP_SORT_CRITERIUM:
1018 g_value_set_enum (value, priv->sort_criterium);
1021 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1027 individual_store_set_property (GObject *object,
1029 const GValue *value,
1032 EmpathyIndividualStorePriv *priv;
1034 priv = GET_PRIV (object);
1038 case PROP_INDIVIDUAL_MANAGER:
1039 individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1040 (object), g_value_get_object (value));
1042 case PROP_SHOW_OFFLINE:
1043 empathy_individual_store_set_show_offline (EMPATHY_INDIVIDUAL_STORE
1044 (object), g_value_get_boolean (value));
1046 case PROP_SHOW_AVATARS:
1047 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1048 (object), g_value_get_boolean (value));
1050 case PROP_SHOW_PROTOCOLS:
1051 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1052 (object), g_value_get_boolean (value));
1054 case PROP_SHOW_GROUPS:
1055 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1056 (object), g_value_get_boolean (value));
1058 case PROP_IS_COMPACT:
1059 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1060 (object), g_value_get_boolean (value));
1062 case PROP_SORT_CRITERIUM:
1063 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1064 (object), g_value_get_enum (value));
1067 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1073 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1075 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1077 object_class->dispose = individual_store_dispose;
1078 object_class->get_property = individual_store_get_property;
1079 object_class->set_property = individual_store_set_property;
1081 g_object_class_install_property (object_class,
1082 PROP_INDIVIDUAL_MANAGER,
1083 g_param_spec_object ("individual-manager",
1084 "The individual manager",
1085 "The individual manager",
1086 EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1087 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1088 g_object_class_install_property (object_class,
1090 g_param_spec_boolean ("show-offline",
1092 "Whether contact list should display "
1093 "offline contacts", FALSE, G_PARAM_READWRITE));
1094 g_object_class_install_property (object_class,
1096 g_param_spec_boolean ("show-avatars",
1098 "Whether contact list should display "
1099 "avatars for contacts", TRUE, G_PARAM_READWRITE));
1100 g_object_class_install_property (object_class,
1101 PROP_SHOW_PROTOCOLS,
1102 g_param_spec_boolean ("show-protocols",
1104 "Whether contact list should display "
1105 "protocols for contacts", FALSE, G_PARAM_READWRITE));
1106 g_object_class_install_property (object_class,
1108 g_param_spec_boolean ("show-groups",
1110 "Whether contact list should display "
1111 "contact groups", TRUE, G_PARAM_READWRITE));
1112 g_object_class_install_property (object_class,
1114 g_param_spec_boolean ("is-compact",
1116 "Whether the contact list is in compact mode or not",
1117 FALSE, G_PARAM_READWRITE));
1119 g_object_class_install_property (object_class,
1120 PROP_SORT_CRITERIUM,
1121 g_param_spec_enum ("sort-criterium",
1123 "The sort criterium to use for sorting the contact list",
1124 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1125 EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1127 g_type_class_add_private (object_class,
1128 sizeof (EmpathyIndividualStorePriv));
1132 get_position (const char **strv,
1137 for (i = 0; strv[i] != NULL; i++)
1139 if (!tp_strdiff (strv[i], str))
1147 compare_separator_and_groups (gboolean is_separator_a,
1148 gboolean is_separator_b,
1149 const gchar *name_a,
1150 const gchar *name_b,
1151 FolksIndividual *individual_a,
1152 FolksIndividual *individual_b,
1153 gboolean fake_group_a,
1154 gboolean fake_group_b)
1156 /* these two lists are the sorted list of fake groups to include at the
1157 * top and bottom of the roster */
1158 const char *top_groups[] = {
1159 EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1163 const char *bottom_groups[] = {
1164 EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1168 if (is_separator_a || is_separator_b)
1170 /* We have at least one separator */
1175 else if (is_separator_b)
1181 /* One group and one contact */
1182 if (!individual_a && individual_b)
1186 else if (individual_a && !individual_b)
1190 else if (!individual_a && !individual_b)
1192 gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1194 a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1195 b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1196 a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1197 b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1199 if (a_in_top && b_in_top)
1201 /* compare positions */
1202 return CLAMP (get_position (top_groups, name_a) -
1203 get_position (top_groups, name_b), -1, 1);
1205 else if (a_in_bottom && b_in_bottom)
1207 /* compare positions */
1208 return CLAMP (get_position (bottom_groups, name_a) -
1209 get_position (bottom_groups, name_b), -1, 1);
1211 else if (a_in_top || b_in_bottom)
1215 else if (b_in_top || a_in_bottom)
1221 return g_utf8_collate (name_a, name_b);
1225 /* Two contacts, ordering depends of the sorting policy */
1230 individual_store_contact_sort (FolksIndividual *individual_a,
1231 FolksIndividual *individual_b)
1234 EmpathyContact *contact_a = NULL, *contact_b = NULL;
1235 TpAccount *account_a, *account_b;
1237 g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1240 ret_val = g_utf8_collate (folks_individual_get_alias (individual_a),
1241 folks_individual_get_alias (individual_b));
1246 contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1247 contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1248 account_a = empathy_contact_get_account (contact_a);
1249 account_b = empathy_contact_get_account (contact_b);
1252 ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1253 tp_account_get_protocol (account_b));
1259 ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1260 tp_proxy_get_object_path (account_b));
1266 ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1267 folks_individual_get_id (individual_b));
1270 tp_clear_object (&contact_a);
1271 tp_clear_object (&contact_b);
1277 individual_store_state_sort_func (GtkTreeModel *model,
1278 GtkTreeIter *iter_a,
1279 GtkTreeIter *iter_b,
1283 FolksIndividual *individual_a, *individual_b;
1284 gchar *name_a, *name_b;
1285 gboolean is_separator_a, is_separator_b;
1286 gboolean fake_group_a, fake_group_b;
1287 FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1288 TpConnectionPresenceType tp_presence_a, tp_presence_b;
1290 gtk_tree_model_get (model, iter_a,
1291 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1292 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1293 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1294 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1295 gtk_tree_model_get (model, iter_b,
1296 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1297 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1298 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1299 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1301 if (individual_a == NULL || individual_b == NULL)
1303 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1304 name_a, name_b, individual_a, individual_b, fake_group_a,
1309 /* If we managed to get this far, we can start looking at
1312 folks_presence_type_a = folks_individual_get_presence_type (individual_a);
1313 folks_presence_type_b = folks_individual_get_presence_type (individual_b);
1314 tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1315 tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1317 ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1322 /* Fallback: compare by name et al. */
1323 ret_val = individual_store_contact_sort (individual_a, individual_b);
1329 tp_clear_object (&individual_a);
1330 tp_clear_object (&individual_b);
1336 individual_store_name_sort_func (GtkTreeModel *model,
1337 GtkTreeIter *iter_a,
1338 GtkTreeIter *iter_b,
1341 gchar *name_a, *name_b;
1342 FolksIndividual *individual_a, *individual_b;
1343 gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1345 gboolean fake_group_a, fake_group_b;
1347 gtk_tree_model_get (model, iter_a,
1348 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1349 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1350 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1351 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1352 gtk_tree_model_get (model, iter_b,
1353 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1354 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1355 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1356 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1358 if (individual_a == NULL || individual_b == NULL)
1359 ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1360 name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1362 ret_val = individual_store_contact_sort (individual_a, individual_b);
1364 tp_clear_object (&individual_a);
1365 tp_clear_object (&individual_b);
1371 individual_store_setup (EmpathyIndividualStore *self)
1373 EmpathyIndividualStorePriv *priv;
1375 GDK_TYPE_PIXBUF, /* Status pixbuf */
1376 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
1377 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
1378 G_TYPE_STRING, /* Name */
1379 G_TYPE_UINT, /* Presence type */
1380 G_TYPE_STRING, /* Status string */
1381 G_TYPE_BOOLEAN, /* Compact view */
1382 FOLKS_TYPE_INDIVIDUAL, /* Individual type */
1383 G_TYPE_BOOLEAN, /* Is group */
1384 G_TYPE_BOOLEAN, /* Is active */
1385 G_TYPE_BOOLEAN, /* Is online */
1386 G_TYPE_BOOLEAN, /* Is separator */
1387 G_TYPE_BOOLEAN, /* Can make audio calls */
1388 G_TYPE_BOOLEAN, /* Can make video calls */
1389 EMPATHY_TYPE_INDIVIDUAL_MANAGER_FLAGS, /* Flags */
1390 G_TYPE_BOOLEAN, /* Is a fake group */
1393 priv = GET_PRIV (self);
1395 gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1396 EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1398 /* Set up sorting */
1399 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1400 EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1401 individual_store_name_sort_func, self, NULL);
1402 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1403 EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1404 individual_store_state_sort_func, self, NULL);
1406 priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1407 empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1411 individual_store_inibit_active_cb (EmpathyIndividualStore *self)
1413 EmpathyIndividualStorePriv *priv;
1415 priv = GET_PRIV (self);
1417 priv->show_active = TRUE;
1418 priv->inhibit_active = 0;
1424 empathy_individual_store_init (EmpathyIndividualStore *self)
1426 EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1427 EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1430 priv->show_avatars = TRUE;
1431 priv->show_groups = TRUE;
1432 priv->show_protocols = FALSE;
1433 priv->inhibit_active =
1434 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1435 (GSourceFunc) individual_store_inibit_active_cb, self);
1436 priv->status_icons =
1437 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1438 individual_store_setup (self);
1441 EmpathyIndividualStore *
1442 empathy_individual_store_new (EmpathyIndividualManager *manager)
1444 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1446 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1447 "individual-manager", manager, NULL);
1450 EmpathyIndividualManager *
1451 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1453 EmpathyIndividualStorePriv *priv;
1455 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1457 priv = GET_PRIV (self);
1459 return priv->manager;
1463 empathy_individual_store_get_show_offline (EmpathyIndividualStore *self)
1465 EmpathyIndividualStorePriv *priv;
1467 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1469 priv = GET_PRIV (self);
1471 return priv->show_offline;
1475 empathy_individual_store_set_show_offline (EmpathyIndividualStore *self,
1476 gboolean show_offline)
1478 EmpathyIndividualStorePriv *priv;
1479 GList *contacts, *l;
1480 gboolean show_active;
1482 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1484 priv = GET_PRIV (self);
1486 priv->show_offline = show_offline;
1487 show_active = priv->show_active;
1489 /* Disable temporarily. */
1490 priv->show_active = FALSE;
1492 contacts = empathy_individual_manager_get_members (priv->manager);
1493 for (l = contacts; l; l = l->next)
1495 individual_store_contact_update (self, l->data);
1497 g_list_free (contacts);
1499 /* Restore to original setting. */
1500 priv->show_active = show_active;
1502 g_object_notify (G_OBJECT (self), "show-offline");
1506 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1508 EmpathyIndividualStorePriv *priv;
1510 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1512 priv = GET_PRIV (self);
1514 return priv->show_avatars;
1518 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1521 EmpathyIndividualStore *self)
1523 EmpathyIndividualStorePriv *priv;
1524 gboolean show_avatar = FALSE;
1525 FolksIndividual *individual;
1526 GdkPixbuf *pixbuf_status;
1528 priv = GET_PRIV (self);
1530 if (priv->show_avatars && !priv->is_compact)
1535 gtk_tree_model_get (model, iter,
1536 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1538 if (individual == NULL)
1542 /* get icon from hash_table */
1544 empathy_individual_store_get_individual_status_icon (self, individual);
1546 gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1547 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1548 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1549 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1551 g_object_unref (individual);
1557 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1558 gboolean show_avatars)
1560 EmpathyIndividualStorePriv *priv;
1561 GtkTreeModel *model;
1563 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1565 priv = GET_PRIV (self);
1567 priv->show_avatars = show_avatars;
1569 model = GTK_TREE_MODEL (self);
1571 gtk_tree_model_foreach (model,
1572 (GtkTreeModelForeachFunc)
1573 individual_store_update_list_mode_foreach, self);
1575 g_object_notify (G_OBJECT (self), "show-avatars");
1579 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1581 EmpathyIndividualStorePriv *priv;
1583 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1585 priv = GET_PRIV (self);
1587 return priv->show_protocols;
1591 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1592 gboolean show_protocols)
1594 EmpathyIndividualStorePriv *priv;
1595 GtkTreeModel *model;
1597 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1599 priv = GET_PRIV (self);
1601 priv->show_protocols = show_protocols;
1603 model = GTK_TREE_MODEL (self);
1605 gtk_tree_model_foreach (model,
1606 (GtkTreeModelForeachFunc)
1607 individual_store_update_list_mode_foreach, self);
1609 g_object_notify (G_OBJECT (self), "show-protocols");
1613 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1615 EmpathyIndividualStorePriv *priv;
1617 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1619 priv = GET_PRIV (self);
1621 return priv->show_groups;
1625 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1626 gboolean show_groups)
1628 EmpathyIndividualStorePriv *priv;
1630 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1632 priv = GET_PRIV (self);
1634 if (priv->show_groups == show_groups)
1639 priv->show_groups = show_groups;
1641 if (priv->setup_idle_id == 0)
1643 /* Remove all contacts and add them back, not optimized but
1644 * that's the easy way :)
1646 * This is only done if there's not a pending setup idle
1647 * callback, otherwise it will race and the contacts will get
1651 gtk_tree_store_clear (GTK_TREE_STORE (self));
1652 contacts = empathy_individual_manager_get_members (priv->manager);
1654 individual_store_members_changed_cb (priv->manager,
1655 "re-adding members: toggled group visibility",
1656 contacts, NULL, 0, self);
1657 g_list_free (contacts);
1660 g_object_notify (G_OBJECT (self), "show-groups");
1664 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1666 EmpathyIndividualStorePriv *priv;
1668 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1670 priv = GET_PRIV (self);
1672 return priv->is_compact;
1676 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1677 gboolean is_compact)
1679 EmpathyIndividualStorePriv *priv;
1680 GtkTreeModel *model;
1682 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1684 priv = GET_PRIV (self);
1686 priv->is_compact = is_compact;
1688 model = GTK_TREE_MODEL (self);
1690 gtk_tree_model_foreach (model,
1691 (GtkTreeModelForeachFunc)
1692 individual_store_update_list_mode_foreach, self);
1694 g_object_notify (G_OBJECT (self), "is-compact");
1697 EmpathyIndividualStoreSort
1698 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1700 EmpathyIndividualStorePriv *priv;
1702 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1704 priv = GET_PRIV (self);
1706 return priv->sort_criterium;
1710 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1711 EmpathyIndividualStoreSort sort_criterium)
1713 EmpathyIndividualStorePriv *priv;
1715 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1717 priv = GET_PRIV (self);
1719 priv->sort_criterium = sort_criterium;
1721 switch (sort_criterium)
1723 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1724 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1725 EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1728 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1729 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1730 EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1734 g_object_notify (G_OBJECT (self), "sort-criterium");
1738 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1742 gboolean is_separator = FALSE;
1744 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1746 gtk_tree_model_get (model, iter,
1747 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1749 return is_separator;
1753 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1755 gboolean *path_is_group,
1756 gboolean *is_fake_group)
1758 GtkTreeIter parent_iter, iter;
1763 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1767 *path_is_group = FALSE;
1770 if (!gtk_tree_model_get_iter (model, &iter, path))
1775 gtk_tree_model_get (model, &iter,
1776 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1777 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1784 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1791 gtk_tree_model_get (model, &iter,
1792 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1793 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1794 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1804 *path_is_group = TRUE;
1807 if (is_fake_group != NULL)
1808 *is_fake_group = fake;
1814 individual_store_get_individual_status_icon_with_icon_name (
1815 EmpathyIndividualStore *self,
1816 FolksIndividual *individual,
1817 const gchar *status_icon_name)
1819 GdkPixbuf *pixbuf_status = NULL;
1820 EmpathyIndividualStorePriv *priv;
1821 const gchar *protocol_name = NULL;
1822 gchar *icon_name = NULL;
1823 GList *personas, *l;
1824 guint contact_count;
1825 EmpathyContact *contact = NULL;
1826 gboolean show_protocols_here;
1828 priv = GET_PRIV (self);
1830 personas = folks_individual_get_personas (individual);
1831 for (l = personas, contact_count = 0; l; l = l->next)
1833 if (TPF_IS_PERSONA (l->data))
1836 if (contact_count > 1)
1840 show_protocols_here = (priv->show_protocols && (contact_count == 1));
1841 if (show_protocols_here)
1843 contact = empathy_contact_dup_from_folks_individual (individual);
1844 protocol_name = empathy_protocol_name_for_contact (contact);
1845 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
1849 icon_name = g_strdup_printf ("%s", status_icon_name);
1851 if (pixbuf_status == NULL)
1854 empathy_pixbuf_contact_status_icon_with_icon_name (contact,
1855 status_icon_name, priv->show_protocols);
1856 if (pixbuf_status != NULL)
1858 g_hash_table_insert (priv->status_icons,
1859 g_strdup (icon_name), pixbuf_status);
1864 tp_clear_object (&contact);
1866 return pixbuf_status;
1870 empathy_individual_store_get_individual_status_icon (
1871 EmpathyIndividualStore *self,
1872 FolksIndividual *individual)
1874 GdkPixbuf *pixbuf_status = NULL;
1875 const gchar *status_icon_name = NULL;
1877 status_icon_name = empathy_icon_name_for_individual (individual);
1878 if (status_icon_name == NULL)
1882 individual_store_get_individual_status_icon_with_icon_name (self,
1883 individual, status_icon_name);
1885 return pixbuf_status;