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_aliasable_get_alias (FOLKS_ALIASABLE (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)
216 folks_aliasable_get_alias (FOLKS_ALIASABLE (data->persona));
220 DEBUG ("Contact:'%s' active timeout, removing item", alias);
221 remove_persona (data->store, data->persona);
224 DEBUG ("Contact:'%s' no longer active", alias);
225 persona_set_active (data->store, data->persona, FALSE, TRUE);
227 persona_active_free (data);
233 persona_updated_cb (FolksPersona *persona,
235 EmpathyPersonaStore *self)
237 DEBUG ("Contact:'%s' updated, checking roster is in sync...",
238 folks_aliasable_get_alias (FOLKS_ALIASABLE (persona)));
240 update_persona (self, persona);
244 add_persona_and_connect (EmpathyPersonaStore *self,
245 FolksPersona *persona)
247 /* We don't want any non-Telepathy personas */
248 if (!TPF_IS_PERSONA (persona))
251 g_signal_connect (persona, "notify::presence",
252 (GCallback) persona_updated_cb, self);
253 g_signal_connect (persona, "notify::presence-message",
254 (GCallback) persona_updated_cb, self);
255 g_signal_connect (persona, "notify::alias",
256 (GCallback) persona_updated_cb, self);
257 g_signal_connect (persona, "notify::avatar",
258 (GCallback) persona_updated_cb, self);
260 add_persona (self, persona);
264 remove_persona_and_disconnect (EmpathyPersonaStore *self,
265 FolksPersona *persona)
267 if (!TPF_IS_PERSONA (persona))
270 g_signal_handlers_disconnect_by_func (persona,
271 (GCallback) persona_updated_cb, self);
273 remove_persona (self, persona);
277 add_persona (EmpathyPersonaStore *self,
278 FolksPersona *persona)
280 EmpathyPersonaStorePriv *priv;
283 FolksPersonaStore *store;
284 EmpathyContact *contact;
287 if (!TPF_IS_PERSONA (persona))
290 priv = GET_PRIV (self);
292 alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
293 if (EMP_STR_EMPTY (alias))
296 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
297 TPF_PERSONA (persona)));
298 store = folks_persona_get_store (persona);
300 gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0,
301 EMPATHY_PERSONA_STORE_COL_NAME, alias,
302 EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
303 folks_persona_store_get_display_name (store),
304 EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
305 folks_persona_get_display_id (persona),
306 EMPATHY_PERSONA_STORE_COL_PERSONA, persona,
307 EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
308 empathy_contact_get_capabilities (contact) &
309 EMPATHY_CAPABILITIES_AUDIO,
310 EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
311 empathy_contact_get_capabilities (contact) &
312 EMPATHY_CAPABILITIES_VIDEO,
315 g_object_unref (contact);
317 path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter);
318 g_hash_table_replace (priv->personas, g_object_ref (persona),
319 gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path));
320 gtk_tree_path_free (path);
322 update_persona (self, persona);
326 remove_persona (EmpathyPersonaStore *self,
327 FolksPersona *persona)
329 EmpathyPersonaStorePriv *priv;
333 if (!TPF_IS_PERSONA (persona))
336 priv = GET_PRIV (self);
338 path = find_persona (self, persona);
342 g_hash_table_remove (priv->personas, persona);
344 gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
345 gtk_list_store_remove (GTK_LIST_STORE (self), &iter);
346 gtk_tree_path_free (path);
350 get_persona_status_icon (EmpathyPersonaStore *self,
351 FolksPersona *persona)
353 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
354 EmpathyContact *contact;
355 const gchar *protocol_name = NULL;
356 gchar *icon_name = NULL;
357 GdkPixbuf *pixbuf_status = NULL;
358 const gchar *status_icon_name = NULL;
360 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
361 TPF_PERSONA (persona)));
363 status_icon_name = empathy_icon_name_for_contact (contact);
364 if (status_icon_name == NULL)
366 g_object_unref (contact);
370 if (priv->show_protocols)
372 protocol_name = empathy_protocol_name_for_contact (contact);
373 icon_name = g_strdup_printf ("%s-%s", status_icon_name, protocol_name);
377 icon_name = g_strdup_printf ("%s", status_icon_name);
380 pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
382 if (pixbuf_status == NULL)
384 pixbuf_status = empathy_pixbuf_contact_status_icon_with_icon_name (
385 contact, status_icon_name, priv->show_protocols);
387 if (pixbuf_status != NULL)
389 g_hash_table_insert (priv->status_icons, g_strdup (icon_name),
394 g_object_unref (contact);
397 return pixbuf_status;
401 update_persona (EmpathyPersonaStore *self,
402 FolksPersona *persona)
404 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
406 gboolean do_set_active = FALSE;
407 gboolean do_set_refresh = FALSE;
410 path = find_persona (self, persona);
411 alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
415 DEBUG ("Contact:'%s' in list:NO, should be:YES", alias);
417 add_persona (self, persona);
419 if (priv->show_active)
421 do_set_active = TRUE;
422 DEBUG ("Set active (contact added)");
427 FolksPersonaStore *store;
428 EmpathyContact *contact;
430 GdkPixbuf *pixbuf_avatar;
431 GdkPixbuf *pixbuf_status;
432 gboolean now_online = FALSE;
433 gboolean was_online = TRUE;
435 DEBUG ("Contact:'%s' in list:YES, should be:YES", alias);
437 gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
438 gtk_tree_path_free (path);
440 /* Get online state now. */
441 now_online = folks_presence_is_online (FOLKS_PRESENCE (persona));
443 /* Get online state before. */
444 gtk_tree_model_get (GTK_TREE_MODEL (self), &iter,
445 EMPATHY_PERSONA_STORE_COL_IS_ONLINE, &was_online,
448 /* Is this really an update or an online/offline. */
449 if (priv->show_active)
451 if (was_online != now_online)
453 do_set_active = TRUE;
454 do_set_refresh = TRUE;
456 DEBUG ("Set active (contact updated %s)",
457 was_online ? "online -> offline" : "offline -> online");
461 /* Was TRUE for presence updates. */
462 /* do_set_active = FALSE; */
463 do_set_refresh = TRUE;
464 DEBUG ("Set active (contact updated)");
468 /* We still need to use EmpathyContact for the capabilities stuff */
469 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
470 TPF_PERSONA (persona)));
471 store = folks_persona_get_store (persona);
473 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
475 pixbuf_status = get_persona_status_icon (self, persona);
477 gtk_list_store_set (GTK_LIST_STORE (self), &iter,
478 EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
479 EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
480 EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
481 EMPATHY_PERSONA_STORE_COL_NAME, alias,
482 EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
483 folks_persona_store_get_display_name (store),
484 EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
485 folks_persona_get_display_id (persona),
486 EMPATHY_PERSONA_STORE_COL_PRESENCE_TYPE,
487 folks_presence_get_presence_type (FOLKS_PRESENCE (persona)),
488 EMPATHY_PERSONA_STORE_COL_STATUS,
489 folks_presence_get_presence_message (FOLKS_PRESENCE (persona)),
490 EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
491 EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
492 empathy_contact_get_capabilities (contact) &
493 EMPATHY_CAPABILITIES_AUDIO,
494 EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
495 empathy_contact_get_capabilities (contact) &
496 EMPATHY_CAPABILITIES_VIDEO,
499 g_object_unref (contact);
502 g_object_unref (pixbuf_avatar);
505 if (priv->show_active && do_set_active)
507 persona_set_active (self, persona, do_set_active, do_set_refresh);
511 ShowActiveData *data;
513 data = persona_active_new (self, persona, FALSE);
514 data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
515 (GSourceFunc) persona_active_cb,
520 /* FIXME: when someone goes online then offline quickly, the
521 * first timeout sets the user to be inactive and the second
522 * timeout removes the user from the contact list, really we
523 * should remove the first timeout.
528 individual_personas_changed_cb (GObject *object,
531 EmpathyPersonaStore *self)
535 /* Remove the old personas. */
536 for (l = removed; l != NULL; l = l->next)
537 remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
539 /* Add each of the new personas to the tree model */
540 for (l = added; l != NULL; l = l->next)
541 add_persona_and_connect (self, FOLKS_PERSONA (l->data));
545 sort_personas (FolksPersona *persona_a,
546 FolksPersona *persona_b)
548 EmpathyContact *contact;
549 TpAccount *account_a, *account_b;
552 g_return_val_if_fail (persona_a != NULL || persona_b != NULL, 0);
555 ret_val = g_utf8_collate (
556 folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_a)),
557 folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_b)));
563 ret_val = g_utf8_collate (folks_persona_get_display_id (persona_a),
564 folks_persona_get_display_id (persona_b));
569 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
570 TPF_PERSONA (persona_a)));
571 account_a = empathy_contact_get_account (contact);
572 g_object_unref (contact);
574 contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
575 TPF_PERSONA (persona_b)));
576 account_b = empathy_contact_get_account (contact);
577 g_object_unref (contact);
580 ret_val = strcmp (tp_account_get_protocol (account_a),
581 tp_account_get_protocol (account_a));
587 ret_val = strcmp (tp_proxy_get_object_path (account_a),
588 tp_proxy_get_object_path (account_a));
595 state_sort_func (GtkTreeModel *model,
601 gchar *name_a, *name_b;
602 FolksPersona *persona_a, *persona_b;
604 gtk_tree_model_get (model, iter_a,
605 EMPATHY_PERSONA_STORE_COL_NAME, &name_a,
606 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_a,
608 gtk_tree_model_get (model, iter_b,
609 EMPATHY_PERSONA_STORE_COL_NAME, &name_b,
610 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_b,
613 if (persona_a == NULL || persona_b == NULL) {
618 /* If we managed to get this far, we can start looking at
621 ret_val = -tp_connection_presence_type_cmp_availability (
622 folks_presence_get_presence_type (FOLKS_PRESENCE (persona_a)),
623 folks_presence_get_presence_type (FOLKS_PRESENCE (persona_b)));
626 /* Fallback: compare by name et al. */
627 ret_val = sort_personas (persona_a, persona_b);
634 tp_clear_object (&persona_a);
635 tp_clear_object (&persona_b);
641 name_sort_func (GtkTreeModel *model,
646 gchar *name_a, *name_b;
647 FolksPersona *persona_a, *persona_b;
650 gtk_tree_model_get (model, iter_a,
651 EMPATHY_PERSONA_STORE_COL_NAME, &name_a,
652 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_a,
654 gtk_tree_model_get (model, iter_b,
655 EMPATHY_PERSONA_STORE_COL_NAME, &name_b,
656 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona_b,
659 if (persona_a == NULL || persona_b == NULL)
662 ret_val = sort_personas (persona_a, persona_b);
664 tp_clear_object (&persona_a);
665 tp_clear_object (&persona_b);
671 find_persona (EmpathyPersonaStore *self,
672 FolksPersona *persona)
674 EmpathyPersonaStorePriv *priv = GET_PRIV (self);
675 GtkTreeRowReference *row;
677 row = g_hash_table_lookup (priv->personas, persona);
681 return gtk_tree_row_reference_get_path (row);
685 update_list_mode_foreach (GtkTreeModel *model,
688 EmpathyPersonaStore *self)
690 EmpathyPersonaStorePriv *priv;
691 FolksPersona *persona;
692 GdkPixbuf *pixbuf_status;
694 priv = GET_PRIV (self);
696 gtk_tree_model_get (model, iter,
697 EMPATHY_PERSONA_STORE_COL_PERSONA, &persona,
703 /* get icon from hash_table */
704 pixbuf_status = get_persona_status_icon (self, persona);
706 gtk_list_store_set (GTK_LIST_STORE (self), iter,
707 EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
708 EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
711 tp_clear_object (&persona);
717 set_up (EmpathyPersonaStore *self)
719 EmpathyPersonaStorePriv *priv;
721 GDK_TYPE_PIXBUF, /* Status pixbuf */
722 GDK_TYPE_PIXBUF, /* Avatar pixbuf */
723 G_TYPE_BOOLEAN, /* Avatar pixbuf visible */
724 G_TYPE_STRING, /* Name */
725 G_TYPE_STRING, /* Account name */
726 G_TYPE_STRING, /* Display ID */
727 G_TYPE_UINT, /* Presence type */
728 G_TYPE_STRING, /* Status string */
729 FOLKS_TYPE_PERSONA, /* Persona */
730 G_TYPE_BOOLEAN, /* Is active */
731 G_TYPE_BOOLEAN, /* Is online */
732 G_TYPE_BOOLEAN, /* Can make audio calls */
733 G_TYPE_BOOLEAN, /* Can make video calls */
736 priv = GET_PRIV (self);
738 gtk_list_store_set_column_types (GTK_LIST_STORE (self),
739 EMPATHY_PERSONA_STORE_COL_COUNT, types);
742 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
743 EMPATHY_PERSONA_STORE_COL_NAME, name_sort_func, self, NULL);
744 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
745 EMPATHY_PERSONA_STORE_COL_STATUS, state_sort_func, self, NULL);
747 priv->sort_criterion = EMPATHY_PERSONA_STORE_SORT_NAME;
748 empathy_persona_store_set_sort_criterion (self, priv->sort_criterion);
752 empathy_persona_store_init (EmpathyPersonaStore *self)
754 EmpathyPersonaStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
755 EMPATHY_TYPE_PERSONA_STORE, EmpathyPersonaStorePriv);
759 priv->show_avatars = TRUE;
760 priv->show_protocols = FALSE;
761 priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
762 (GSourceFunc) inhibit_active_cb, self);
764 priv->status_icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
766 priv->personas = g_hash_table_new_full (g_direct_hash, g_direct_equal,
767 g_object_unref, (GDestroyNotify) gtk_tree_row_reference_free);
773 get_property (GObject *object,
778 EmpathyPersonaStorePriv *priv = GET_PRIV (object);
782 case PROP_INDIVIDUAL:
783 g_value_set_object (value, priv->individual);
785 case PROP_SHOW_AVATARS:
786 g_value_set_boolean (value, priv->show_avatars);
788 case PROP_SHOW_PROTOCOLS:
789 g_value_set_boolean (value, priv->show_protocols);
791 case PROP_SORT_CRITERION:
792 g_value_set_enum (value, priv->sort_criterion);
795 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
801 set_property (GObject *object,
806 EmpathyPersonaStore *self = EMPATHY_PERSONA_STORE (object);
810 case PROP_INDIVIDUAL:
811 empathy_persona_store_set_individual (self, g_value_get_object (value));
813 case PROP_SHOW_AVATARS:
814 empathy_persona_store_set_show_avatars (self,
815 g_value_get_boolean (value));
817 case PROP_SHOW_PROTOCOLS:
818 empathy_persona_store_set_show_protocols (self,
819 g_value_get_boolean (value));
821 case PROP_SORT_CRITERION:
822 empathy_persona_store_set_sort_criterion (self,
823 g_value_get_enum (value));
826 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
832 dispose (GObject *object)
834 EmpathyPersonaStorePriv *priv = GET_PRIV (object);
836 empathy_persona_store_set_individual (EMPATHY_PERSONA_STORE (object), NULL);
838 if (priv->inhibit_active != 0)
840 g_source_remove (priv->inhibit_active);
841 priv->inhibit_active = 0;
844 if (priv->setup_idle_id != 0)
846 g_source_remove (priv->setup_idle_id);
847 priv->setup_idle_id = 0;
850 G_OBJECT_CLASS (empathy_persona_store_parent_class)->dispose (object);
854 finalize (GObject *object)
856 EmpathyPersonaStorePriv *priv = GET_PRIV (object);
858 g_hash_table_destroy (priv->status_icons);
859 g_hash_table_destroy (priv->personas);
861 G_OBJECT_CLASS (empathy_persona_store_parent_class)->finalize (object);
865 empathy_persona_store_class_init (EmpathyPersonaStoreClass *klass)
867 GObjectClass *object_class = G_OBJECT_CLASS (klass);
869 object_class->get_property = get_property;
870 object_class->set_property = set_property;
871 object_class->dispose = dispose;
872 object_class->finalize = finalize;
875 * EmpathyPersonaStore:individual:
877 * The #FolksIndividual whose personas should be listed by the store. This
878 * may be %NULL, which results in an empty store.
880 g_object_class_install_property (object_class, PROP_INDIVIDUAL,
881 g_param_spec_object ("individual",
883 "The FolksIndividual whose Personas should be listed by the store.",
884 FOLKS_TYPE_INDIVIDUAL,
885 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
888 * EmpathyPersonaStore:show-avatars:
890 * Whether the store should display avatars for personas. This is a property
891 * of the store rather than of #EmpathyPersonaView for efficiency reasons.
893 g_object_class_install_property (object_class, PROP_SHOW_AVATARS,
894 g_param_spec_boolean ("show-avatars",
896 "Whether the store should display avatars for personas.",
898 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
901 * EmpathyPersonaStore:show-protocols:
903 * Whether the store should display protocol icons for personas. This is a
904 * property of the store rather than of #EmpathyPersonaView because it is
905 * closely tied in with #EmpathyPersonaStore:show-avatars.
907 g_object_class_install_property (object_class, PROP_SHOW_PROTOCOLS,
908 g_param_spec_boolean ("show-protocols",
910 "Whether the store should display protocol icons for personas.",
912 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
915 * EmpathyPersonaStore:sort-criterion:
917 * The criterion used to sort the personas in the store.
919 g_object_class_install_property (object_class, PROP_SORT_CRITERION,
920 g_param_spec_enum ("sort-criterion",
922 "The sort criterion to use for sorting the persona list",
923 EMPATHY_TYPE_PERSONA_STORE_SORT,
924 EMPATHY_PERSONA_STORE_SORT_NAME,
925 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
927 g_type_class_add_private (object_class, sizeof (EmpathyPersonaStorePriv));
931 * empathy_persona_store_new:
932 * @individual: the #FolksIndividual whose personas should be used in the store,
935 * Create a new #EmpathyPersonaStore with the personas from the given
938 * Return value: a new #EmpathyPersonaStore
940 EmpathyPersonaStore *
941 empathy_persona_store_new (FolksIndividual *individual)
943 g_return_val_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual),
946 return g_object_new (EMPATHY_TYPE_PERSONA_STORE,
947 "individual", individual, NULL);
951 * empathy_persona_store_get_individual:
952 * @self: an #EmpathyPersonaStore
954 * Get the value of #EmpathyPersonaStore:individual.
956 * Return value: the individual being displayed by the store, or %NULL
959 empathy_persona_store_get_individual (EmpathyPersonaStore *self)
961 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), NULL);
963 return GET_PRIV (self)->individual;
967 * empathy_persona_store_set_individual:
968 * @self: an #EmpathyPersonaStore
969 * @individual: the new individual to display in the store, or %NULL
971 * Set #EmpathyPersonaStore:individual to @individual, replacing the personas
972 * which were in the store with the personas belonging to @individual, or with
973 * nothing if @individual is %NULL.
976 empathy_persona_store_set_individual (EmpathyPersonaStore *self,
977 FolksIndividual *individual)
979 EmpathyPersonaStorePriv *priv;
981 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
982 g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));
984 priv = GET_PRIV (self);
986 /* Remove the old individual */
987 if (priv->individual != NULL)
991 g_signal_handlers_disconnect_by_func (priv->individual,
992 (GCallback) individual_personas_changed_cb, self);
994 /* Disconnect from and remove all personas belonging to this individual */
995 personas = folks_individual_get_personas (priv->individual);
996 for (l = personas; l != NULL; l = l->next)
997 remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
999 g_object_unref (priv->individual);
1002 priv->individual = individual;
1004 /* Add the new individual */
1005 if (individual != NULL)
1007 GList *personas, *l;
1009 g_object_ref (individual);
1011 g_signal_connect (individual, "personas-changed",
1012 (GCallback) individual_personas_changed_cb, self);
1014 /* Add pre-existing Personas */
1015 personas = folks_individual_get_personas (individual);
1016 for (l = personas; l != NULL; l = l->next)
1017 add_persona_and_connect (self, FOLKS_PERSONA (l->data));
1020 g_object_notify (G_OBJECT (self), "individual");
1024 * empathy_persona_store_get_show_avatars:
1025 * @self: an #EmpathyPersonaStore
1027 * Get the value of #EmpathyPersonaStore:show-avatars.
1029 * Return value: %TRUE if avatars are made available by the store, %FALSE
1033 empathy_persona_store_get_show_avatars (EmpathyPersonaStore *self)
1035 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), TRUE);
1037 return GET_PRIV (self)->show_avatars;
1041 * empathy_persona_store_set_show_avatars:
1042 * @self: an #EmpathyPersonaStore
1043 * @show_avatars: %TRUE to make avatars available through the store, %FALSE
1046 * Set #EmpathyPersonaStore:show-avatars to @show_avatars.
1049 empathy_persona_store_set_show_avatars (EmpathyPersonaStore *self,
1050 gboolean show_avatars)
1052 EmpathyPersonaStorePriv *priv;
1054 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1056 priv = GET_PRIV (self);
1057 priv->show_avatars = show_avatars;
1059 gtk_tree_model_foreach (GTK_TREE_MODEL (self),
1060 (GtkTreeModelForeachFunc) update_list_mode_foreach, self);
1062 g_object_notify (G_OBJECT (self), "show-avatars");
1066 * empathy_persona_store_get_show_protocols:
1067 * @self: an #EmpathyPersonaStore
1069 * Get the value of #EmpathyPersonaStore:show-protocols.
1071 * Return value: %TRUE if protocol images are made available by the store,
1075 empathy_persona_store_get_show_protocols (EmpathyPersonaStore *self)
1077 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), TRUE);
1079 return GET_PRIV (self)->show_protocols;
1083 * empathy_persona_store_set_show_protocols:
1084 * @self: an #EmpathyPersonaStore
1085 * @show_protocols: %TRUE to make protocol images available through the store,
1088 * Set #EmpathyPersonaStore:show-protocols to @show_protocols.
1091 empathy_persona_store_set_show_protocols (EmpathyPersonaStore *self,
1092 gboolean show_protocols)
1094 EmpathyPersonaStorePriv *priv;
1096 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1098 priv = GET_PRIV (self);
1099 priv->show_protocols = show_protocols;
1101 gtk_tree_model_foreach (GTK_TREE_MODEL (self),
1102 (GtkTreeModelForeachFunc) update_list_mode_foreach, self);
1104 g_object_notify (G_OBJECT (self), "show-protocols");
1108 * empathy_persona_store_get_sort_criterion:
1109 * @self: an #EmpathyPersonaStore
1111 * Get the value of #EmpathyPersonaStore:sort-criterion.
1113 * Return value: the criterion used to sort the personas in the store
1115 EmpathyPersonaStoreSort
1116 empathy_persona_store_get_sort_criterion (EmpathyPersonaStore *self)
1118 g_return_val_if_fail (EMPATHY_IS_PERSONA_STORE (self), 0);
1120 return GET_PRIV (self)->sort_criterion;
1124 * empathy_persona_store_set_sort_criterion:
1125 * @self: an #EmpathyPersonaStore
1126 * @show_avatars: a criterion to be used to sort personas in the store
1128 * Set #EmpathyPersonaStore:sort-criterion to @sort_criterion.
1131 empathy_persona_store_set_sort_criterion (EmpathyPersonaStore *self,
1132 EmpathyPersonaStoreSort sort_criterion)
1134 EmpathyPersonaStorePriv *priv;
1136 g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
1138 priv = GET_PRIV (self);
1139 priv->sort_criterion = sort_criterion;
1141 switch (sort_criterion)
1143 case EMPATHY_PERSONA_STORE_SORT_STATE:
1144 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1145 EMPATHY_PERSONA_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1147 case EMPATHY_PERSONA_STORE_SORT_NAME:
1148 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1149 EMPATHY_PERSONA_STORE_COL_NAME, GTK_SORT_ASCENDING);
1152 g_assert_not_reached ();
1156 g_object_notify (G_OBJECT (self), "sort-criterion");