2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2008, 2010 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Mikael Hallendal <micke@imendio.com>
21 * Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
23 * Philip Withnall <philip.withnall@collabora.co.uk>
25 * Based off EmpathyContactListStore.
33 #include <glib/gi18n-lib.h>
36 #include <telepathy-glib/util.h>
38 #include <folks/folks.h>
39 #include <folks/folks-telepathy.h>
41 #include <libempathy/empathy-utils.h>
43 #include "empathy-persona-store.h"
44 #include "empathy-gtk-enum-types.h"
45 #include "empathy-ui-utils.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). */
53 /* Time in seconds user is shown as active */
54 #define ACTIVE_USER_SHOW_TIME 7
56 /* Time in seconds after connecting which we wait before active users are
58 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
60 static void add_persona (EmpathyPersonaStore *self,
61 FolksPersona *persona);
62 static GtkTreePath * find_persona (EmpathyPersonaStore *self,
63 FolksPersona *persona);
64 static void update_persona (EmpathyPersonaStore *self,
65 FolksPersona *persona);
66 static void remove_persona (EmpathyPersonaStore *self,
67 FolksPersona *persona);
69 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPersonaStore)
73 FolksIndividual *individual; /* owned */
74 GHashTable *personas; /* owned Persona -> owned GtkTreeRowReference */
76 gboolean show_avatars;
77 gboolean show_protocols;
79 EmpathyPersonaStoreSort sort_criterion;
84 GHashTable *status_icons; /* owned icon name -> owned GdkPixbuf */
85 } EmpathyPersonaStorePriv;
95 G_DEFINE_TYPE (EmpathyPersonaStore, empathy_persona_store, GTK_TYPE_LIST_STORE);
98 inhibit_active_cb (EmpathyPersonaStore *store)
100 EmpathyPersonaStorePriv *priv;
102 priv = GET_PRIV (store);
104 priv->show_active = TRUE;
105 priv->inhibit_active = 0;
111 EmpathyPersonaStore *store;
112 FolksPersona *persona;
117 static void persona_active_free (ShowActiveData *data);
120 persona_active_invalidated (ShowActiveData *data,
123 /* Remove the timeout and free the struct, since the persona or persona
124 * store has disappeared. */
125 g_source_remove (data->timeout);
127 if (old_object == (GObject *) data->store)
129 else if (old_object == (GObject *) data->persona)
130 data->persona = NULL;
132 g_assert_not_reached ();
134 persona_active_free (data);
137 static ShowActiveData *
138 persona_active_new (EmpathyPersonaStore *self,
139 FolksPersona *persona,
142 ShowActiveData *data;
144 DEBUG ("Contact:'%s' now active, and %s be removed",
145 folks_alias_get_alias (FOLKS_ALIAS (persona)),
146 remove_ ? "WILL" : "WILL NOT");
148 data = g_slice_new0 (ShowActiveData);
150 /* We don't actually want to force either the PersonaStore or the
151 * Persona to stay alive, since the user could quit Empathy or disable
152 * the account before the persona_active timeout is fired. */
153 g_object_weak_ref (G_OBJECT (self),
154 (GWeakNotify) persona_active_invalidated, data);
155 g_object_weak_ref (G_OBJECT (persona),
156 (GWeakNotify) persona_active_invalidated, data);
159 data->persona = persona;
160 data->remove = remove_;
166 persona_active_free (ShowActiveData *data)
168 if (data->store != NULL)
170 g_object_weak_unref (G_OBJECT (data->store),
171 (GWeakNotify) persona_active_invalidated, data);
174 if (data->persona != NULL)
176 g_object_weak_unref (G_OBJECT (data->persona),
177 (GWeakNotify) persona_active_invalidated, data);
180 g_slice_free (ShowActiveData, data);
184 persona_set_active (EmpathyPersonaStore *self,
185 FolksPersona *persona,
187 gboolean set_changed)
189 EmpathyPersonaStorePriv *priv;
193 priv = GET_PRIV (self);
195 path = find_persona (self, persona);
199 gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
200 gtk_list_store_set (GTK_LIST_STORE (self), &iter,
201 EMPATHY_PERSONA_STORE_COL_IS_ACTIVE, active,
204 DEBUG ("Set item %s", active ? "active" : "inactive");
207 gtk_tree_model_row_changed (GTK_TREE_MODEL (self), path, &iter);
209 gtk_tree_path_free (path);
213 persona_active_cb (ShowActiveData *data)
215 const gchar *alias = folks_alias_get_alias (FOLKS_ALIAS (data->persona));
219 DEBUG ("Contact:'%s' active timeout, removing item", alias);
220 remove_persona (data->store, data->persona);
223 DEBUG ("Contact:'%s' no longer active", alias);
224 persona_set_active (data->store, data->persona, FALSE, TRUE);
226 persona_active_free (data);
232 persona_updated_cb (FolksPersona *persona,
234 EmpathyPersonaStore *self)
236 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
237 folks_alias_get_alias (FOLKS_ALIAS (persona)));
239 update_persona (self, persona);
243 add_persona_and_connect (EmpathyPersonaStore *self,
244 FolksPersona *persona)
246 /* We don't want any non-Telepathy personas */
247 if (!TPF_IS_PERSONA (persona))
250 g_signal_connect (persona, "notify::presence",
251 (GCallback) persona_updated_cb, self);
252 g_signal_connect (persona, "notify::presence-message",
253 (GCallback) persona_updated_cb, self);
254 g_signal_connect (persona, "notify::alias",
255 (GCallback) persona_updated_cb, self);
256 g_signal_connect (persona, "notify::avatar",
257 (GCallback) persona_updated_cb, self);
259 add_persona (self, persona);
263 remove_persona_and_disconnect (EmpathyPersonaStore *self,
264 FolksPersona *persona)
266 if (!TPF_IS_PERSONA (persona))
269 g_signal_handlers_disconnect_by_func (persona,
270 (GCallback) persona_updated_cb, self);
272 remove_persona (self, persona);
276 add_persona (EmpathyPersonaStore *self,
277 FolksPersona *persona)
279 EmpathyPersonaStorePriv *priv;
282 FolksPersonaStore *store;
283 EmpathyContact *contact;
286 if (!TPF_IS_PERSONA (persona))
289 priv = GET_PRIV (self);
291 alias = folks_alias_get_alias (FOLKS_ALIAS (persona));
292 if (EMP_STR_EMPTY (alias))
295 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
296 TPF_PERSONA (persona)));
297 store = folks_persona_get_store (persona);
299 gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0,
300 EMPATHY_PERSONA_STORE_COL_NAME, alias,
301 EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
302 folks_persona_store_get_display_name (store),
303 EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
304 folks_persona_get_display_id (persona),
305 EMPATHY_PERSONA_STORE_COL_PERSONA, persona,
306 EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
307 empathy_contact_get_capabilities (contact) &
308 EMPATHY_CAPABILITIES_AUDIO,
309 EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
310 empathy_contact_get_capabilities (contact) &
311 EMPATHY_CAPABILITIES_VIDEO,
314 g_object_unref (contact);
316 path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter);
317 g_hash_table_replace (priv->personas, g_object_ref (persona),
318 gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path));
319 gtk_tree_path_free (path);
321 update_persona (self, persona);
325 remove_persona (EmpathyPersonaStore *self,
326 FolksPersona *persona)
328 EmpathyPersonaStorePriv *priv;
332 if (!TPF_IS_PERSONA (persona))
335 priv = GET_PRIV (self);
337 path = find_persona (self, persona);
341 g_hash_table_remove (priv->personas, persona);
343 gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
344 gtk_list_store_remove (GTK_LIST_STORE (self), &iter);
345 gtk_tree_path_free (path);
349 get_persona_status_icon (EmpathyPersonaStore *self,
350 FolksPersona *persona)
352 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
353 EmpathyContact *contact;
354 const gchar *protocol_name = NULL;
355 gchar *icon_name = NULL;
356 GdkPixbuf *pixbuf_status = NULL;
357 const gchar *status_icon_name = NULL;
359 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
360 TPF_PERSONA (persona)));
362 status_icon_name = empathy_icon_name_for_contact (contact);
363 if (status_icon_name == NULL)
365 g_object_unref (contact);
369 if (priv->show_protocols)
371 protocol_name = empathy_protocol_name_for_contact (contact);
372 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
376 icon_name = g_strdup_printf ("%s", status_icon_name);
379 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
381 if (pixbuf_status == NULL)
383 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (
384 contact, status_icon_name, priv->show_protocols);
386 if (pixbuf_status != NULL)
388 g_hash_table_insert (priv->status_icons, g_strdup (icon_name),
393 g_object_unref (contact);
396 return pixbuf_status;
400 update_persona (EmpathyPersonaStore *self,
401 FolksPersona *persona)
403 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
405 gboolean do_set_active = FALSE;
406 gboolean do_set_refresh = FALSE;
409 path = find_persona (self, persona);
410 alias = folks_alias_get_alias (FOLKS_ALIAS (persona));
414 DEBUG ("Contact:'%s' in list:NO, should be:YES", alias);
416 add_persona (self, persona);
418 if (priv->show_active)
420 do_set_active = TRUE;
421 DEBUG ("Set active (contact added)");
426 FolksPersonaStore *store;
427 EmpathyContact *contact;
429 GdkPixbuf *pixbuf_avatar;
430 GdkPixbuf *pixbuf_status;
431 gboolean now_online = FALSE;
432 gboolean was_online = TRUE;
434 DEBUG ("Contact:'%s' in list:YES, should be:YES", alias);
436 gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
437 gtk_tree_path_free (path);
439 /* Get online state now. */
440 now_online = folks_presence_is_online (FOLKS_PRESENCE (persona));
442 /* Get online state before. */
443 gtk_tree_model_get (GTK_TREE_MODEL (self), &iter,
444 EMPATHY_PERSONA_STORE_COL_IS_ONLINE, &was_online,
447 /* Is this really an update or an online/offline. */
448 if (priv->show_active)
450 if (was_online != now_online)
452 do_set_active = TRUE;
453 do_set_refresh = TRUE;
455 DEBUG ("Set active (contact updated %s)",
456 was_online ? "online -> offline" : "offline -> online");
460 /* Was TRUE for presence updates. */
461 /* do_set_active = FALSE; */
462 do_set_refresh = TRUE;
463 DEBUG ("Set active (contact updated)");
467 /* We still need to use EmpathyContact for the capabilities stuff */
468 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
469 TPF_PERSONA (persona)));
470 store = folks_persona_get_store (persona);
472 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
474 pixbuf_status = get_persona_status_icon (self, persona);
476 gtk_list_store_set (GTK_LIST_STORE (self), &iter,
477 EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
478 EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
479 EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
480 EMPATHY_PERSONA_STORE_COL_NAME, alias,
481 EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
482 folks_persona_store_get_display_name (store),
483 EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
484 folks_persona_get_display_id (persona),
485 EMPATHY_PERSONA_STORE_COL_PRESENCE_TYPE,
486 folks_presence_get_presence_type (FOLKS_PRESENCE (persona)),
487 EMPATHY_PERSONA_STORE_COL_STATUS,
488 folks_presence_get_presence_message (FOLKS_PRESENCE (persona)),
489 EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
490 EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
491 empathy_contact_get_capabilities (contact) &
492 EMPATHY_CAPABILITIES_AUDIO,
493 EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
494 empathy_contact_get_capabilities (contact) &
495 EMPATHY_CAPABILITIES_VIDEO,
498 g_object_unref (contact);
501 g_object_unref (pixbuf_avatar);
504 if (priv->show_active && do_set_active)
506 persona_set_active (self, persona, do_set_active, do_set_refresh);
510 ShowActiveData *data;
512 data = persona_active_new (self, persona, FALSE);
513 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
514 (GSourceFunc) persona_active_cb,
519 /* FIXME: when someone goes online then offline quickly, the
520 * first timeout sets the user to be inactive and the second
521 * timeout removes the user from the contact list, really we
522 * should remove the first timeout.
527 individual_notify_personas_cb (GObject *object,
529 EmpathyPersonaStore *self)
531 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
532 GList *old_personas, *new_personas, *removed_personas, *l;
534 /* Remove old personas which are no longer in the individual.
535 * Build a list of such personas to remove from our hash table.
537 old_personas = g_hash_table_get_keys (priv->personas);
538 new_personas = folks_individual_get_personas (FOLKS_INDIVIDUAL (object));
539 removed_personas = NULL;
541 for (l = old_personas; l != NULL; l = l->next)
543 GList *i = g_list_find (new_personas, l->data);
545 removed_personas = g_list_prepend (removed_personas, l->data);
547 g_list_free (old_personas);
549 /* Remove the removed personas. We can't do this from inside the above loop,
550 * as old_personas is only valid until the hash table is modified. */
551 for (l = removed_personas; l != NULL; l = l->next)
552 remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
553 g_list_free (removed_personas);
555 /* Add each of the new personas to the tree model */
556 for (l = new_personas; l != NULL; l = l->next)
558 FolksPersona *persona = FOLKS_PERSONA (l->data);
560 if (g_hash_table_lookup (priv->personas, persona) == NULL)
561 add_persona_and_connect (self, persona);
566 sort_personas (FolksPersona *persona_a,
567 FolksPersona *persona_b)
569 EmpathyContact *contact;
570 TpAccount *account_a, *account_b;
573 g_return_val_if_fail (persona_a != NULL || persona_b != NULL, 0);
576 ret_val = g_utf8_collate (folks_alias_get_alias (FOLKS_ALIAS (persona_a)),
577 folks_alias_get_alias (FOLKS_ALIAS (persona_b)));
583 ret_val = g_utf8_collate (folks_persona_get_display_id (persona_a),
584 folks_persona_get_display_id (persona_b));
589 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
590 TPF_PERSONA (persona_a)));
591 account_a = empathy_contact_get_account (contact);
592 g_object_unref (contact);
594 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
595 TPF_PERSONA (persona_b)));
596 account_b = empathy_contact_get_account (contact);
597 g_object_unref (contact);
600 ret_val = strcmp (tp_account_get_protocol (account_a),
601 tp_account_get_protocol (account_a));
607 ret_val = strcmp (tp_proxy_get_object_path (account_a),
608 tp_proxy_get_object_path (account_a));
615 state_sort_func (GtkTreeModel *model,
621 gchar *name_a, *name_b;
622 FolksPersona *persona_a, *persona_b;
624 gtk_tree_model_get (model, iter_a,
625 EMPATHY_PERSONA_STORE_COL_NAME, &name_a,
626 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_a,
628 gtk_tree_model_get (model, iter_b,
629 EMPATHY_PERSONA_STORE_COL_NAME, &name_b,
630 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_b,
633 if (persona_a == NULL || persona_b == NULL) {
638 /* If we managed to get this far, we can start looking at
641 ret_val = -tp_connection_presence_type_cmp_availability (
642 folks_presence_get_presence_type (FOLKS_PRESENCE (persona_a)),
643 folks_presence_get_presence_type (FOLKS_PRESENCE (persona_b)));
646 /* Fallback: compare by name et al. */
647 ret_val = sort_personas (persona_a, persona_b);
654 tp_clear_object (&persona_a);
655 tp_clear_object (&persona_b);
661 name_sort_func (GtkTreeModel *model,
666 gchar *name_a, *name_b;
667 FolksPersona *persona_a, *persona_b;
670 gtk_tree_model_get (model, iter_a,
671 EMPATHY_PERSONA_STORE_COL_NAME, &name_a,
672 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_a,
674 gtk_tree_model_get (model, iter_b,
675 EMPATHY_PERSONA_STORE_COL_NAME, &name_b,
676 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_b,
679 if (persona_a == NULL || persona_b == NULL)
682 ret_val = sort_personas (persona_a, persona_b);
684 tp_clear_object (&persona_a);
685 tp_clear_object (&persona_b);
691 find_persona (EmpathyPersonaStore *self,
692 FolksPersona *persona)
694 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
695 GtkTreeRowReference *row;
697 row = g_hash_table_lookup (priv->personas, persona);
701 return gtk_tree_row_reference_get_path (row);
705 update_list_mode_foreach (GtkTreeModel *model,
708 EmpathyPersonaStore *self)
710 EmpathyPersonaStorePriv *priv;
711 FolksPersona *persona;
712 GdkPixbuf *pixbuf_status;
714 priv = GET_PRIV (self);
716 gtk_tree_model_get (model, iter,
717 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona,
723 /* get icon from hash_table */
724 pixbuf_status = get_persona_status_icon (self, persona);
726 gtk_list_store_set (GTK_LIST_STORE (self), iter,
727 EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
728 EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
731 tp_clear_object (&persona);
737 set_up (EmpathyPersonaStore *self)
739 EmpathyPersonaStorePriv *priv;
741 GDK_TYPE_PIXBUF, /* Status pixbuf */
742 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
743 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
744 G_TYPE_STRING, /* Name */
745 G_TYPE_STRING, /* Account name */
746 G_TYPE_STRING, /* Display ID */
747 G_TYPE_UINT, /* Presence type */
748 G_TYPE_STRING, /* Status string */
749 FOLKS_TYPE_PERSONA, /* Persona */
750 G_TYPE_BOOLEAN, /* Is active */
751 G_TYPE_BOOLEAN, /* Is online */
752 G_TYPE_BOOLEAN, /* Can make audio calls */
753 G_TYPE_BOOLEAN, /* Can make video calls */
756 priv = GET_PRIV (self);
758 gtk_list_store_set_column_types (GTK_LIST_STORE (self),
759 EMPATHY_PERSONA_STORE_COL_COUNT, types);
762 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
763 EMPATHY_PERSONA_STORE_COL_NAME, name_sort_func, self, NULL);
764 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
765 EMPATHY_PERSONA_STORE_COL_STATUS, state_sort_func, self, NULL);
767 priv->sort_criterion = EMPATHY_PERSONA_STORE_SORT_NAME;
768 empathy_persona_store_set_sort_criterion (self, priv->sort_criterion);
772 empathy_persona_store_init (EmpathyPersonaStore *self)
774 EmpathyPersonaStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
775 EMPATHY_TYPE_PERSONA_STORE, EmpathyPersonaStorePriv);
779 priv->show_avatars = TRUE;
780 priv->show_protocols = FALSE;
781 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
782 (GSourceFunc) inhibit_active_cb, self);
784 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
786 priv->personas = g_hash_table_new_full (g_direct_hash, g_direct_equal,
787 g_object_unref, (GDestroyNotify) gtk_tree_row_reference_free);
793 get_property (GObject *object,
798 EmpathyPersonaStorePriv *priv = GET_PRIV (object);
802 case PROP_INDIVIDUAL:
803 g_value_set_object (value, priv->individual);
805 case PROP_SHOW_AVATARS:
806 g_value_set_boolean (value, priv->show_avatars);
808 case PROP_SHOW_PROTOCOLS:
809 g_value_set_boolean (value, priv->show_protocols);
811 case PROP_SORT_CRITERION:
812 g_value_set_enum (value, priv->sort_criterion);
815 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
821 set_property (GObject *object,
826 EmpathyPersonaStore *self = EMPATHY_PERSONA_STORE (object);
830 case PROP_INDIVIDUAL:
831 empathy_persona_store_set_individual (self, g_value_get_object (value));
833 case PROP_SHOW_AVATARS:
834 empathy_persona_store_set_show_avatars (self,
835 g_value_get_boolean (value));
837 case PROP_SHOW_PROTOCOLS:
838 empathy_persona_store_set_show_protocols (self,
839 g_value_get_boolean (value));
841 case PROP_SORT_CRITERION:
842 empathy_persona_store_set_sort_criterion (self,
843 g_value_get_enum (value));
846 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
852 dispose (GObject *object)
854 EmpathyPersonaStorePriv *priv = GET_PRIV (object);
856 empathy_persona_store_set_individual (EMPATHY_PERSONA_STORE (object), NULL);
858 if (priv->inhibit_active != 0)
860 g_source_remove (priv->inhibit_active);
861 priv->inhibit_active = 0;
864 if (priv->setup_idle_id != 0)
866 g_source_remove (priv->setup_idle_id);
867 priv->setup_idle_id = 0;
870 G_OBJECT_CLASS (empathy_persona_store_parent_class)->dispose (object);
874 finalize (GObject *object)
876 EmpathyPersonaStorePriv *priv = GET_PRIV (object);
878 g_hash_table_destroy (priv->status_icons);
879 g_hash_table_destroy (priv->personas);
881 G_OBJECT_CLASS (empathy_persona_store_parent_class)->finalize (object);
885 empathy_persona_store_class_init (EmpathyPersonaStoreClass *klass)
887 GObjectClass *object_class = G_OBJECT_CLASS (klass);
889 object_class->get_property = get_property;
890 object_class->set_property = set_property;
891 object_class->dispose = dispose;
892 object_class->finalize = finalize;
895 * EmpathyPersonaStore:individual:
897 * The #FolksIndividual whose personas should be listed by the store. This
898 * may be %NULL, which results in an empty store.
900 g_object_class_install_property (object_class, PROP_INDIVIDUAL,
901 g_param_spec_object ("individual",
903 "The FolksIndividual whose Personas should be listed by the store.",
904 FOLKS_TYPE_INDIVIDUAL,
905 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
908 * EmpathyPersonaStore:show-avatars:
910 * Whether the store should display avatars for personas. This is a property
911 * of the store rather than of #EmpathyPersonaView for efficiency reasons.
913 g_object_class_install_property (object_class, PROP_SHOW_AVATARS,
914 g_param_spec_boolean ("show-avatars",
916 "Whether the store should display avatars for personas.",
918 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
921 * EmpathyPersonaStore:show-protocols:
923 * Whether the store should display protocol icons for personas. This is a
924 * property of the store rather than of #EmpathyPersonaView because it is
925 * closely tied in with #EmpathyPersonaStore:show-avatars.
927 g_object_class_install_property (object_class, PROP_SHOW_PROTOCOLS,
928 g_param_spec_boolean ("show-protocols",
930 "Whether the store should display protocol icons for personas.",
932 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
935 * EmpathyPersonaStore:sort-criterion:
937 * The criterion used to sort the personas in the store.
939 g_object_class_install_property (object_class, PROP_SORT_CRITERION,
940 g_param_spec_enum ("sort-criterion",
942 "The sort criterion to use for sorting the persona list",
943 EMPATHY_TYPE_PERSONA_STORE_SORT,
944 EMPATHY_PERSONA_STORE_SORT_NAME,
945 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
947 g_type_class_add_private (object_class, sizeof (EmpathyPersonaStorePriv));
951 * empathy_persona_store_new:
952 * @individual: the #FolksIndividual whose personas should be used in the store,
955 * Create a new #EmpathyPersonaStore with the personas from the given
958 * Return value: a new #EmpathyPersonaStore
960 EmpathyPersonaStore *
961 empathy_persona_store_new (FolksIndividual *individual)
963 g_return_val_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual),
966 return g_object_new (EMPATHY_TYPE_PERSONA_STORE,
967 "individual", individual, NULL);
971 * empathy_persona_store_get_individual:
972 * @self: an #EmpathyPersonaStore
974 * Get the value of #EmpathyPersonaStore:individual.
976 * Return value: the individual being displayed by the store, or %NULL
979 empathy_persona_store_get_individual (EmpathyPersonaStore *self)
981 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), NULL);
983 return GET_PRIV (self)->individual;
987 * empathy_persona_store_set_individual:
988 * @self: an #EmpathyPersonaStore
989 * @individual: the new individual to display in the store, or %NULL
991 * Set #EmpathyPersonaStore:individual to @individual, replacing the personas
992 * which were in the store with the personas belonging to @individual, or with
993 * nothing if @individual is %NULL.
996 empathy_persona_store_set_individual (EmpathyPersonaStore *self,
997 FolksIndividual *individual)
999 EmpathyPersonaStorePriv *priv;
1001 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1002 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
1004 priv = GET_PRIV (self);
1006 /* Remove the old individual */
1007 if (priv->individual != NULL)
1009 GList *personas, *l;
1011 g_signal_handlers_disconnect_by_func (priv->individual,
1012 (GCallback) individual_notify_personas_cb, self);
1014 /* Disconnect from and remove all personas belonging to this individual */
1015 personas = folks_individual_get_personas (priv->individual);
1016 for (l = personas; l != NULL; l = l->next)
1017 remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
1019 g_object_unref (priv->individual);
1022 priv->individual = individual;
1024 /* Add the new individual */
1025 if (individual != NULL)
1027 GList *personas, *l;
1029 g_object_ref (individual);
1031 g_signal_connect (individual, "notify::personas",
1032 (GCallback) individual_notify_personas_cb, self);
1034 /* Add pre-existing Personas */
1035 personas = folks_individual_get_personas (individual);
1036 for (l = personas; l != NULL; l = l->next)
1037 add_persona_and_connect (self, FOLKS_PERSONA (l->data));
1040 g_object_notify (G_OBJECT (self), "individual");
1044 * empathy_persona_store_get_show_avatars:
1045 * @self: an #EmpathyPersonaStore
1047 * Get the value of #EmpathyPersonaStore:show-avatars.
1049 * Return value: %TRUE if avatars are made available by the store, %FALSE
1053 empathy_persona_store_get_show_avatars (EmpathyPersonaStore *self)
1055 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), TRUE);
1057 return GET_PRIV (self)->show_avatars;
1061 * empathy_persona_store_set_show_avatars:
1062 * @self: an #EmpathyPersonaStore
1063 * @show_avatars: %TRUE to make avatars available through the store, %FALSE
1066 * Set #EmpathyPersonaStore:show-avatars to @show_avatars.
1069 empathy_persona_store_set_show_avatars (EmpathyPersonaStore *self,
1070 gboolean show_avatars)
1072 EmpathyPersonaStorePriv *priv;
1074 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1076 priv = GET_PRIV (self);
1077 priv->show_avatars = show_avatars;
1079 gtk_tree_model_foreach (GTK_TREE_MODEL (self),
1080 (GtkTreeModelForeachFunc) update_list_mode_foreach, self);
1082 g_object_notify (G_OBJECT (self), "show-avatars");
1086 * empathy_persona_store_get_show_protocols:
1087 * @self: an #EmpathyPersonaStore
1089 * Get the value of #EmpathyPersonaStore:show-protocols.
1091 * Return value: %TRUE if protocol images are made available by the store,
1095 empathy_persona_store_get_show_protocols (EmpathyPersonaStore *self)
1097 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), TRUE);
1099 return GET_PRIV (self)->show_protocols;
1103 * empathy_persona_store_set_show_protocols:
1104 * @self: an #EmpathyPersonaStore
1105 * @show_protocols: %TRUE to make protocol images available through the store,
1108 * Set #EmpathyPersonaStore:show-protocols to @show_protocols.
1111 empathy_persona_store_set_show_protocols (EmpathyPersonaStore *self,
1112 gboolean show_protocols)
1114 EmpathyPersonaStorePriv *priv;
1116 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1118 priv = GET_PRIV (self);
1119 priv->show_protocols = show_protocols;
1121 gtk_tree_model_foreach (GTK_TREE_MODEL (self),
1122 (GtkTreeModelForeachFunc) update_list_mode_foreach, self);
1124 g_object_notify (G_OBJECT (self), "show-protocols");
1128 * empathy_persona_store_get_sort_criterion:
1129 * @self: an #EmpathyPersonaStore
1131 * Get the value of #EmpathyPersonaStore:sort-criterion.
1133 * Return value: the criterion used to sort the personas in the store
1135 EmpathyPersonaStoreSort
1136 empathy_persona_store_get_sort_criterion (EmpathyPersonaStore *self)
1138 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), 0);
1140 return GET_PRIV (self)->sort_criterion;
1144 * empathy_persona_store_set_sort_criterion:
1145 * @self: an #EmpathyPersonaStore
1146 * @show_avatars: a criterion to be used to sort personas in the store
1148 * Set #EmpathyPersonaStore:sort-criterion to @sort_criterion.
1151 empathy_persona_store_set_sort_criterion (EmpathyPersonaStore *self,
1152 EmpathyPersonaStoreSort sort_criterion)
1154 EmpathyPersonaStorePriv *priv;
1156 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1158 priv = GET_PRIV (self);
1159 priv->sort_criterion = sort_criterion;
1161 switch (sort_criterion)
1163 case EMPATHY_PERSONA_STORE_SORT_STATE:
1164 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1165 EMPATHY_PERSONA_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1167 case EMPATHY_PERSONA_STORE_SORT_NAME:
1168 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1169 EMPATHY_PERSONA_STORE_COL_NAME, GTK_SORT_ASCENDING);
1172 g_assert_not_reached ();
1176 g_object_notify (G_OBJECT (self), "sort-criterion");