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>
28 #include "empathy-individual-store.h"
30 #include <glib/gi18n-lib.h>
31 #include <tp-account-widgets/tpaw-utils.h>
33 #include "empathy-gtk-enum-types.h"
34 #include "empathy-ui-utils.h"
35 #include "empathy-utils.h"
37 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
38 #include "empathy-debug.h"
40 /* Active users are those which have recently changed state
41 * (e.g. online, offline or from normal to a busy state).
44 /* Time in seconds user is shown as active */
45 #define ACTIVE_USER_SHOW_TIME 7
47 /* Time in seconds after connecting which we wait before active users are enabled */
48 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
50 struct _EmpathyIndividualStorePriv
52 gboolean show_avatars
;
55 gboolean show_protocols
;
56 EmpathyIndividualStoreSort sort_criterium
;
58 gboolean dispose_has_run
;
59 GHashTable
*status_icons
;
60 /* List of owned GCancellables for each pending avatar load operation */
61 GList
*avatar_cancellables
;
62 /* Hash: FolksIndividual* -> GQueue (GtkTreeIter *) */
63 GHashTable
*folks_individual_cache
;
64 /* Hash: char *groupname -> GtkTreeIter * */
65 GHashTable
*empathy_group_cache
;
71 EmpathyIndividualStore
*self
;
72 FolksIndividual
*individual
;
87 /* prototypes to break cycles */
88 static void individual_store_contact_update (EmpathyIndividualStore
*self
,
89 FolksIndividual
*individual
);
91 G_DEFINE_TYPE (EmpathyIndividualStore
, empathy_individual_store
,
95 add_individual_to_store (GtkTreeStore
*store
,
98 FolksIndividual
*individual
)
100 EmpathyIndividualStore
*self
= EMPATHY_INDIVIDUAL_STORE (store
);
101 gboolean can_audio_call
, can_video_call
;
102 const gchar
* const *types
;
105 empathy_individual_can_audio_video_call (individual
, &can_audio_call
,
106 &can_video_call
, NULL
);
108 types
= empathy_individual_get_client_types (individual
);
110 gtk_tree_store_insert_with_values (store
, iter
, parent
, 0,
111 EMPATHY_INDIVIDUAL_STORE_COL_NAME
,
112 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual
)),
113 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL
, individual
,
114 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP
, FALSE
,
115 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, FALSE
,
116 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL
, can_audio_call
,
117 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL
, can_video_call
,
118 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES
, types
,
121 queue
= g_hash_table_lookup (self
->priv
->folks_individual_cache
, individual
);
124 g_queue_push_tail (queue
, gtk_tree_iter_copy (iter
));
128 queue
= g_queue_new ();
129 g_queue_push_tail (queue
, gtk_tree_iter_copy (iter
));
130 g_hash_table_insert (self
->priv
->folks_individual_cache
, individual
,
136 individual_store_get_group (EmpathyIndividualStore
*self
,
138 GtkTreeIter
*iter_group_to_set
,
139 GtkTreeIter
*iter_separator_to_set
,
141 gboolean is_fake_group
)
144 GtkTreeIter iter_group
;
145 GtkTreeIter iter_separator
;
148 model
= GTK_TREE_MODEL (self
);
149 iter
= g_hash_table_lookup (self
->priv
->empathy_group_cache
, name
);
156 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self
), &iter_group
,
158 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS
, NULL
,
159 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, name
,
160 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP
, TRUE
,
161 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE
, FALSE
,
162 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, FALSE
,
163 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP
, is_fake_group
,
166 g_hash_table_insert (self
->priv
->empathy_group_cache
, g_strdup (name
),
167 gtk_tree_iter_copy (&iter_group
));
169 if (iter_group_to_set
)
170 *iter_group_to_set
= iter_group
;
172 gtk_tree_store_insert_with_values (GTK_TREE_STORE (self
), &iter_separator
,
174 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, TRUE
,
177 if (iter_separator_to_set
)
178 *iter_separator_to_set
= iter_separator
;
185 if (iter_group_to_set
)
186 *iter_group_to_set
= *iter
;
188 iter_separator
= *iter
;
190 if (gtk_tree_model_iter_next (model
, &iter_separator
))
192 gboolean is_separator
;
194 gtk_tree_model_get (model
, &iter_separator
,
195 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, &is_separator
, -1);
197 if (is_separator
&& iter_separator_to_set
)
198 *iter_separator_to_set
= iter_separator
;
204 /* (transfer full) free with empathy_individual_store_free_iters() */
205 empathy_individual_store_find_contact (EmpathyIndividualStore
*self
,
206 FolksIndividual
*individual
)
208 GQueue
*row_refs_queue
;
210 GList
*iters_list
= NULL
;
212 row_refs_queue
= g_hash_table_lookup (self
->priv
->folks_individual_cache
,
217 for (i
= g_queue_peek_head_link (row_refs_queue
) ; i
!= NULL
; i
= i
->next
)
219 GtkTreeIter
*iter
= i
->data
;
221 iters_list
= g_list_prepend (iters_list
, gtk_tree_iter_copy (iter
));
228 empathy_individual_store_free_iters (GList
*iters
)
230 g_list_foreach (iters
, (GFunc
) gtk_tree_iter_free
, NULL
);
235 empathy_individual_store_remove_individual (EmpathyIndividualStore
*self
,
236 FolksIndividual
*individual
)
242 row_refs
= g_hash_table_lookup (self
->priv
->folks_individual_cache
,
248 model
= GTK_TREE_MODEL (self
);
250 for (l
= g_queue_peek_head_link (row_refs
); l
; l
= l
->next
)
252 GtkTreeIter
*iter
= l
->data
;
255 /* NOTE: it is only <= 2 here because we have
256 * separators after the group name, otherwise it
259 if (gtk_tree_model_iter_parent (model
, &parent
, iter
) &&
260 gtk_tree_model_iter_n_children (model
, &parent
) <= 2)
263 gtk_tree_model_get (model
, &parent
,
264 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &group_name
,
266 g_hash_table_remove (self
->priv
->empathy_group_cache
,
268 gtk_tree_store_remove (GTK_TREE_STORE (self
), &parent
);
272 gtk_tree_store_remove (GTK_TREE_STORE (self
), iter
);
276 g_hash_table_remove (self
->priv
->folks_individual_cache
, individual
);
280 empathy_individual_store_add_individual (EmpathyIndividualStore
*self
,
281 FolksIndividual
*individual
)
283 GtkTreeIter iter
, iter_group
;
284 GeeSet
*group_set
= NULL
;
285 gboolean grouped
= FALSE
;
287 if (TPAW_STR_EMPTY (folks_alias_details_get_alias (
288 FOLKS_ALIAS_DETAILS (individual
))))
291 if (!self
->priv
->show_groups
)
293 /* add our individual to the toplevel of the store */
294 add_individual_to_store (GTK_TREE_STORE (self
), &iter
, NULL
,
300 group_set
= folks_group_details_get_groups (
301 FOLKS_GROUP_DETAILS (individual
));
303 if (gee_collection_get_size (GEE_COLLECTION (group_set
)) > 0)
305 /* add the contact to its groups */
306 GeeIterator
*group_iter
=
307 gee_iterable_iterator (GEE_ITERABLE (group_set
));
309 while (group_iter
!= NULL
&& gee_iterator_next (group_iter
))
311 gchar
*group_name
= gee_iterator_get (group_iter
);
313 individual_store_get_group (self
, group_name
, &iter_group
,
316 add_individual_to_store (GTK_TREE_STORE (self
), &iter
, &iter_group
,
323 g_clear_object (&group_iter
);
327 /* fall-back groups, in case there are no named groups */
328 EmpathyContact
*contact
;
329 TpConnection
*connection
;
330 const gchar
*protocol_name
= NULL
;
332 contact
= empathy_contact_dup_from_folks_individual (individual
);
335 connection
= empathy_contact_get_connection (contact
);
336 protocol_name
= tp_connection_get_protocol_name (connection
);
339 if (!tp_strdiff (protocol_name
, "local-xmpp"))
341 /* these are People Nearby */
342 individual_store_get_group (self
,
343 EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY
, &iter_group
, NULL
, NULL
,
345 add_individual_to_store (GTK_TREE_STORE (self
), &iter
, &iter_group
,
350 g_clear_object (&contact
);
353 if (folks_favourite_details_get_is_favourite (
354 FOLKS_FAVOURITE_DETAILS (individual
)))
356 /* Add contact to the fake 'Favorites' group */
357 individual_store_get_group (self
, EMPATHY_INDIVIDUAL_STORE_FAVORITE
,
358 &iter_group
, NULL
, NULL
, TRUE
);
360 add_individual_to_store (GTK_TREE_STORE (self
), &iter
, &iter_group
,
367 /* Else add the contact to 'Ungrouped' */
368 individual_store_get_group (self
,
369 EMPATHY_INDIVIDUAL_STORE_UNGROUPED
,
370 &iter_group
, NULL
, NULL
, TRUE
);
371 add_individual_to_store (GTK_TREE_STORE (self
), &iter
, &iter_group
,
377 individual_store_contact_update (self
, individual
);
381 individual_store_contact_set_active (EmpathyIndividualStore
*self
,
382 FolksIndividual
*individual
,
384 gboolean set_changed
)
389 model
= GTK_TREE_MODEL (self
);
391 iters
= empathy_individual_store_find_contact (self
, individual
);
392 for (l
= iters
; l
; l
= l
->next
)
396 gtk_tree_store_set (GTK_TREE_STORE (self
), l
->data
,
397 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE
, active
,
402 path
= gtk_tree_model_get_path (model
, l
->data
);
403 gtk_tree_model_row_changed (model
, path
, l
->data
);
404 gtk_tree_path_free (path
);
408 empathy_individual_store_free_iters (iters
);
411 static void individual_store_contact_active_free (ShowActiveData
*data
);
414 individual_store_contact_active_invalidated (ShowActiveData
*data
,
417 /* Remove the timeout and free the struct, since the individual or individual
418 * store has disappeared. */
419 g_source_remove (data
->timeout
);
421 if (old_object
== (GObject
*) data
->self
)
423 else if (old_object
== (GObject
*) data
->individual
)
424 data
->individual
= NULL
;
426 g_assert_not_reached ();
428 individual_store_contact_active_free (data
);
431 static ShowActiveData
*
432 individual_store_contact_active_new (EmpathyIndividualStore
*self
,
433 FolksIndividual
*individual
,
436 ShowActiveData
*data
;
438 data
= g_slice_new0 (ShowActiveData
);
440 /* We don't actually want to force either the IndividualStore or the
441 * Individual to stay alive, since the user could quit Empathy or disable
442 * the account before the contact_active timeout is fired. */
443 g_object_weak_ref (G_OBJECT (self
),
444 (GWeakNotify
) individual_store_contact_active_invalidated
, data
);
445 g_object_weak_ref (G_OBJECT (individual
),
446 (GWeakNotify
) individual_store_contact_active_invalidated
, data
);
449 data
->individual
= individual
;
450 data
->remove
= remove_
;
457 individual_store_contact_active_free (ShowActiveData
*data
)
459 if (data
->self
!= NULL
)
461 g_object_weak_unref (G_OBJECT (data
->self
),
462 (GWeakNotify
) individual_store_contact_active_invalidated
, data
);
465 if (data
->individual
!= NULL
)
467 g_object_weak_unref (G_OBJECT (data
->individual
),
468 (GWeakNotify
) individual_store_contact_active_invalidated
, data
);
471 g_slice_free (ShowActiveData
, data
);
475 individual_store_contact_active_cb (ShowActiveData
*data
)
479 DEBUG ("Individual'%s' active timeout, removing item",
480 folks_alias_details_get_alias (
481 FOLKS_ALIAS_DETAILS (data
->individual
)));
482 empathy_individual_store_remove_individual (data
->self
, data
->individual
);
485 individual_store_contact_set_active (data
->self
,
486 data
->individual
, FALSE
, TRUE
);
488 individual_store_contact_active_free (data
);
494 EmpathyIndividualStore
*store
; /* weak */
495 GCancellable
*cancellable
; /* owned */
499 individual_avatar_pixbuf_received_cb (FolksIndividual
*individual
,
500 GAsyncResult
*result
,
501 LoadAvatarData
*data
)
503 GError
*error
= NULL
;
506 pixbuf
= empathy_pixbuf_avatar_from_individual_scaled_finish (individual
,
511 /* No need to display an error if the individal just doesn't have an
513 if (!g_error_matches (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
))
515 DEBUG ("failed to retrieve pixbuf for individual %s: %s",
516 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual
)),
520 g_clear_error (&error
);
522 else if (data
->store
!= NULL
)
526 iters
= empathy_individual_store_find_contact (data
->store
, individual
);
527 for (l
= iters
; l
; l
= l
->next
)
529 gtk_tree_store_set (GTK_TREE_STORE (data
->store
), l
->data
,
530 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR
, pixbuf
,
534 empathy_individual_store_free_iters (iters
);
538 if (data
->store
!= NULL
)
540 g_object_remove_weak_pointer (G_OBJECT (data
->store
),
541 (gpointer
*) &data
->store
);
542 data
->store
->priv
->avatar_cancellables
= g_list_remove (
543 data
->store
->priv
->avatar_cancellables
, data
->cancellable
);
546 tp_clear_object (&pixbuf
);
547 g_object_unref (data
->cancellable
);
548 g_slice_free (LoadAvatarData
, data
);
552 individual_store_contact_update (EmpathyIndividualStore
*self
,
553 FolksIndividual
*individual
)
555 ShowActiveData
*data
;
559 gboolean was_online
= TRUE
;
560 gboolean now_online
= FALSE
;
561 gboolean set_model
= FALSE
;
562 gboolean do_remove
= FALSE
;
563 gboolean do_set_active
= FALSE
;
564 gboolean do_set_refresh
= FALSE
;
565 gboolean show_avatar
= FALSE
;
566 GdkPixbuf
*pixbuf_status
;
567 LoadAvatarData
*load_avatar_data
;
569 model
= GTK_TREE_MODEL (self
);
571 iters
= empathy_individual_store_find_contact (self
, individual
);
581 /* Get online state now. */
582 now_online
= folks_presence_details_is_online (
583 FOLKS_PRESENCE_DETAILS (individual
));
587 DEBUG ("Individual'%s' in list:NO, should be:YES",
588 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual
)));
590 empathy_individual_store_add_individual (self
, individual
);
592 if (self
->priv
->show_active
)
594 do_set_active
= TRUE
;
599 /* Get online state before. */
600 if (iters
&& g_list_length (iters
) > 0)
602 gtk_tree_model_get (model
, iters
->data
,
603 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE
, &was_online
, -1);
606 /* Is this really an update or an online/offline. */
607 if (self
->priv
->show_active
)
609 if (was_online
!= now_online
)
611 do_set_active
= TRUE
;
612 do_set_refresh
= TRUE
;
616 /* Was TRUE for presence updates. */
617 /* do_set_active = FALSE; */
618 do_set_refresh
= TRUE
;
625 if (self
->priv
->show_avatars
&& !self
->priv
->is_compact
)
630 /* Load the avatar asynchronously */
631 load_avatar_data
= g_slice_new (LoadAvatarData
);
632 load_avatar_data
->store
= self
;
633 g_object_add_weak_pointer (G_OBJECT (self
),
634 (gpointer
*) &load_avatar_data
->store
);
635 load_avatar_data
->cancellable
= g_cancellable_new ();
637 self
->priv
->avatar_cancellables
= g_list_prepend (
638 self
->priv
->avatar_cancellables
, load_avatar_data
->cancellable
);
640 empathy_pixbuf_avatar_from_individual_scaled_async (individual
, 32, 32,
641 load_avatar_data
->cancellable
,
642 (GAsyncReadyCallback
) individual_avatar_pixbuf_received_cb
,
646 empathy_individual_store_get_individual_status_icon (self
, individual
);
648 for (l
= iters
; l
&& set_model
; l
= l
->next
)
650 gboolean can_audio_call
, can_video_call
;
651 const gchar
* const *types
;
653 empathy_individual_can_audio_video_call (individual
, &can_audio_call
,
654 &can_video_call
, NULL
);
656 types
= empathy_individual_get_client_types (individual
);
658 gtk_tree_store_set (GTK_TREE_STORE (self
), l
->data
,
659 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS
, pixbuf_status
,
660 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE
, show_avatar
,
661 EMPATHY_INDIVIDUAL_STORE_COL_NAME
,
662 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual
)),
663 EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE
,
664 folks_presence_details_get_presence_type (
665 FOLKS_PRESENCE_DETAILS (individual
)),
666 EMPATHY_INDIVIDUAL_STORE_COL_STATUS
,
667 folks_presence_details_get_presence_message (
668 FOLKS_PRESENCE_DETAILS (individual
)),
669 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT
, self
->priv
->is_compact
,
670 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP
, FALSE
,
671 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE
, now_online
,
672 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, FALSE
,
673 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL
, can_audio_call
,
674 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL
, can_video_call
,
675 EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES
, types
,
679 if (self
->priv
->show_active
&& do_set_active
)
681 individual_store_contact_set_active (self
, individual
, do_set_active
,
687 individual_store_contact_active_new (self
, individual
,
689 data
->timeout
= g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME
,
690 (GSourceFunc
) individual_store_contact_active_cb
, data
);
694 /* FIXME: when someone goes online then offline quickly, the
695 * first timeout sets the user to be inactive and the second
696 * timeout removes the user from the contact list, really we
697 * should remove the first timeout.
699 empathy_individual_store_free_iters (iters
);
703 individual_store_individual_updated_cb (FolksIndividual
*individual
,
705 EmpathyIndividualStore
*self
)
707 individual_store_contact_update (self
, individual
);
711 individual_store_contact_updated_cb (EmpathyContact
*contact
,
713 EmpathyIndividualStore
*self
)
715 FolksIndividual
*individual
;
717 individual
= g_object_get_data (G_OBJECT (contact
), "individual");
718 if (individual
== NULL
)
721 individual_store_contact_update (self
, individual
);
725 individual_personas_changed_cb (FolksIndividual
*individual
,
728 EmpathyIndividualStore
*self
)
732 iter
= gee_iterable_iterator (GEE_ITERABLE (removed
));
733 /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
734 * through the EmpathyContacts for them. */
735 while (gee_iterator_next (iter
))
737 TpfPersona
*persona
= gee_iterator_get (iter
);
738 TpContact
*tp_contact
;
739 EmpathyContact
*contact
;
741 if (TPF_IS_PERSONA (persona
))
743 tp_contact
= tpf_persona_get_contact (persona
);
744 if (tp_contact
!= NULL
)
746 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
747 empathy_contact_set_persona (contact
, FOLKS_PERSONA (persona
));
749 g_object_set_data (G_OBJECT (contact
), "individual", NULL
);
750 g_signal_handlers_disconnect_by_func (contact
,
751 (GCallback
) individual_store_contact_updated_cb
, self
);
753 g_object_unref (contact
);
757 g_clear_object (&persona
);
759 g_clear_object (&iter
);
761 iter
= gee_iterable_iterator (GEE_ITERABLE (added
));
762 while (gee_iterator_next (iter
))
764 TpfPersona
*persona
= gee_iterator_get (iter
);
765 TpContact
*tp_contact
;
766 EmpathyContact
*contact
;
768 if (TPF_IS_PERSONA (persona
))
770 tp_contact
= tpf_persona_get_contact (persona
);
771 if (tp_contact
!= NULL
)
773 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
774 empathy_contact_set_persona (contact
, FOLKS_PERSONA (persona
));
776 g_object_set_data (G_OBJECT (contact
), "individual", individual
);
777 g_signal_connect (contact
, "notify::capabilities",
778 (GCallback
) individual_store_contact_updated_cb
, self
);
779 g_signal_connect (contact
, "notify::client-types",
780 (GCallback
) individual_store_contact_updated_cb
, self
);
782 g_object_unref (contact
);
786 g_clear_object (&persona
);
788 g_clear_object (&iter
);
792 individual_store_favourites_changed_cb (FolksIndividual
*individual
,
794 EmpathyIndividualStore
*self
)
796 DEBUG ("Individual %s is %s a favourite",
797 folks_individual_get_id (individual
),
798 folks_favourite_details_get_is_favourite (
799 FOLKS_FAVOURITE_DETAILS (individual
)) ? "now" : "no longer");
801 empathy_individual_store_remove_individual (self
, individual
);
802 empathy_individual_store_add_individual (self
, individual
);
806 individual_store_add_individual_and_connect (EmpathyIndividualStore
*self
,
807 FolksIndividual
*individual
)
809 GeeSet
*empty_set
= gee_set_empty (G_TYPE_NONE
, NULL
, NULL
);
811 empathy_individual_store_add_individual (self
, individual
);
813 g_signal_connect (individual
, "notify::avatar",
814 (GCallback
) individual_store_individual_updated_cb
, self
);
815 g_signal_connect (individual
, "notify::presence-type",
816 (GCallback
) individual_store_individual_updated_cb
, self
);
817 g_signal_connect (individual
, "notify::presence-message",
818 (GCallback
) individual_store_individual_updated_cb
, self
);
819 g_signal_connect (individual
, "notify::alias",
820 (GCallback
) individual_store_individual_updated_cb
, self
);
821 g_signal_connect (individual
, "personas-changed",
822 (GCallback
) individual_personas_changed_cb
, self
);
823 g_signal_connect (individual
, "notify::is-favourite",
824 (GCallback
) individual_store_favourites_changed_cb
, self
);
826 /* provide an empty set so the callback can assume non-NULL sets */
827 individual_personas_changed_cb (individual
,
828 folks_individual_get_personas (individual
), empty_set
, self
);
829 g_clear_object (&empty_set
);
833 empathy_individual_store_disconnect_individual (EmpathyIndividualStore
*self
,
834 FolksIndividual
*individual
)
836 GeeSet
*empty_set
= gee_set_empty (G_TYPE_NONE
, NULL
, NULL
);
838 /* provide an empty set so the callback can assume non-NULL sets */
839 individual_personas_changed_cb (individual
, empty_set
,
840 folks_individual_get_personas (individual
), self
);
841 g_clear_object (&empty_set
);
843 g_signal_handlers_disconnect_by_func (individual
,
844 (GCallback
) individual_store_individual_updated_cb
, self
);
845 g_signal_handlers_disconnect_by_func (individual
,
846 (GCallback
) individual_personas_changed_cb
, self
);
847 g_signal_handlers_disconnect_by_func (individual
,
848 (GCallback
) individual_store_favourites_changed_cb
, self
);
852 individual_store_remove_individual_and_disconnect (
853 EmpathyIndividualStore
*self
,
854 FolksIndividual
*individual
)
856 empathy_individual_store_disconnect_individual (self
, individual
);
857 empathy_individual_store_remove_individual (self
, individual
);
861 individual_store_dispose (GObject
*object
)
863 EmpathyIndividualStore
*self
= EMPATHY_INDIVIDUAL_STORE (object
);
866 if (self
->priv
->dispose_has_run
)
868 self
->priv
->dispose_has_run
= TRUE
;
870 /* Cancel any pending avatar load operations */
871 for (l
= self
->priv
->avatar_cancellables
; l
!= NULL
; l
= l
->next
)
873 /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
874 g_cancellable_cancel (G_CANCELLABLE (l
->data
));
876 g_list_free (self
->priv
->avatar_cancellables
);
878 if (self
->priv
->inhibit_active
)
880 g_source_remove (self
->priv
->inhibit_active
);
883 g_hash_table_unref (self
->priv
->status_icons
);
884 g_hash_table_unref (self
->priv
->folks_individual_cache
);
885 g_hash_table_unref (self
->priv
->empathy_group_cache
);
886 G_OBJECT_CLASS (empathy_individual_store_parent_class
)->dispose (object
);
890 individual_store_get_property (GObject
*object
,
895 EmpathyIndividualStore
*self
= EMPATHY_INDIVIDUAL_STORE (object
);
899 case PROP_SHOW_AVATARS
:
900 g_value_set_boolean (value
, self
->priv
->show_avatars
);
902 case PROP_SHOW_PROTOCOLS
:
903 g_value_set_boolean (value
, self
->priv
->show_protocols
);
905 case PROP_SHOW_GROUPS
:
906 g_value_set_boolean (value
, self
->priv
->show_groups
);
908 case PROP_IS_COMPACT
:
909 g_value_set_boolean (value
, self
->priv
->is_compact
);
911 case PROP_SORT_CRITERIUM
:
912 g_value_set_enum (value
, self
->priv
->sort_criterium
);
915 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
921 individual_store_set_property (GObject
*object
,
928 case PROP_SHOW_AVATARS
:
929 empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
930 (object
), g_value_get_boolean (value
));
932 case PROP_SHOW_PROTOCOLS
:
933 empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
934 (object
), g_value_get_boolean (value
));
936 case PROP_SHOW_GROUPS
:
937 empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
938 (object
), g_value_get_boolean (value
));
940 case PROP_IS_COMPACT
:
941 empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
942 (object
), g_value_get_boolean (value
));
944 case PROP_SORT_CRITERIUM
:
945 empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
946 (object
), g_value_get_enum (value
));
949 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
955 empathy_individual_store_class_init (EmpathyIndividualStoreClass
*klass
)
957 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
959 object_class
->dispose
= individual_store_dispose
;
960 object_class
->get_property
= individual_store_get_property
;
961 object_class
->set_property
= individual_store_set_property
;
963 g_object_class_install_property (object_class
,
965 g_param_spec_boolean ("show-avatars",
967 "Whether contact list should display "
968 "avatars for contacts", TRUE
, G_PARAM_READWRITE
));
969 g_object_class_install_property (object_class
,
971 g_param_spec_boolean ("show-protocols",
973 "Whether contact list should display "
974 "protocols for contacts", FALSE
, G_PARAM_READWRITE
));
975 g_object_class_install_property (object_class
,
977 g_param_spec_boolean ("show-groups",
979 "Whether contact list should display "
980 "contact groups", TRUE
, G_PARAM_READWRITE
));
981 g_object_class_install_property (object_class
,
983 g_param_spec_boolean ("is-compact",
985 "Whether the contact list is in compact mode or not",
986 FALSE
, G_PARAM_READWRITE
));
988 g_object_class_install_property (object_class
,
990 g_param_spec_enum ("sort-criterium",
992 "The sort criterium to use for sorting the contact list",
993 EMPATHY_TYPE_INDIVIDUAL_STORE_SORT
,
994 EMPATHY_INDIVIDUAL_STORE_SORT_NAME
, G_PARAM_READWRITE
));
996 g_type_class_add_private (object_class
,
997 sizeof (EmpathyIndividualStorePriv
));
1001 get_position (const char **strv
,
1006 for (i
= 0; strv
[i
] != NULL
; i
++)
1008 if (!tp_strdiff (strv
[i
], str
))
1016 compare_separator_and_groups (gboolean is_separator_a
,
1017 gboolean is_separator_b
,
1018 const gchar
*name_a
,
1019 const gchar
*name_b
,
1020 FolksIndividual
*individual_a
,
1021 FolksIndividual
*individual_b
,
1022 gboolean fake_group_a
,
1023 gboolean fake_group_b
)
1025 /* these two lists are the sorted list of fake groups to include at the
1026 * top and bottom of the roster */
1027 const char *top_groups
[] = {
1028 EMPATHY_INDIVIDUAL_STORE_FAVORITE
,
1032 const char *bottom_groups
[] = {
1033 EMPATHY_INDIVIDUAL_STORE_UNGROUPED
,
1037 if (is_separator_a
|| is_separator_b
)
1039 /* We have at least one separator */
1044 else if (is_separator_b
)
1050 /* One group and one contact */
1051 if (!individual_a
&& individual_b
)
1055 else if (individual_a
&& !individual_b
)
1059 else if (!individual_a
&& !individual_b
)
1061 gboolean a_in_top
, b_in_top
, a_in_bottom
, b_in_bottom
;
1063 a_in_top
= fake_group_a
&& tp_strv_contains (top_groups
, name_a
);
1064 b_in_top
= fake_group_b
&& tp_strv_contains (top_groups
, name_b
);
1065 a_in_bottom
= fake_group_a
&& tp_strv_contains (bottom_groups
, name_a
);
1066 b_in_bottom
= fake_group_b
&& tp_strv_contains (bottom_groups
, name_b
);
1068 if (a_in_top
&& b_in_top
)
1070 /* compare positions */
1071 return CLAMP (get_position (top_groups
, name_a
) -
1072 get_position (top_groups
, name_b
), -1, 1);
1074 else if (a_in_bottom
&& b_in_bottom
)
1076 /* compare positions */
1077 return CLAMP (get_position (bottom_groups
, name_a
) -
1078 get_position (bottom_groups
, name_b
), -1, 1);
1080 else if (a_in_top
|| b_in_bottom
)
1084 else if (b_in_top
|| a_in_bottom
)
1090 return g_utf8_collate (name_a
, name_b
);
1094 /* Two contacts, ordering depends of the sorting policy */
1099 individual_store_contact_sort (FolksIndividual
*individual_a
,
1100 FolksIndividual
*individual_b
)
1103 EmpathyContact
*contact_a
= NULL
, *contact_b
= NULL
;
1104 TpAccount
*account_a
, *account_b
;
1106 g_return_val_if_fail (individual_a
!= NULL
|| individual_b
!= NULL
, 0);
1109 ret_val
= g_utf8_collate (
1110 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a
)),
1111 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b
)));
1116 contact_a
= empathy_contact_dup_from_folks_individual (individual_a
);
1117 contact_b
= empathy_contact_dup_from_folks_individual (individual_b
);
1118 if (contact_a
!= NULL
&& contact_b
!= NULL
)
1120 account_a
= empathy_contact_get_account (contact_a
);
1121 account_b
= empathy_contact_get_account (contact_b
);
1123 g_assert (account_a
!= NULL
);
1124 g_assert (account_b
!= NULL
);
1127 ret_val
= g_strcmp0 (tp_account_get_protocol_name (account_a
),
1128 tp_account_get_protocol_name (account_b
));
1134 ret_val
= g_strcmp0 (tp_proxy_get_object_path (account_a
),
1135 tp_proxy_get_object_path (account_b
));
1142 ret_val
= g_utf8_collate (folks_individual_get_id (individual_a
),
1143 folks_individual_get_id (individual_b
));
1146 tp_clear_object (&contact_a
);
1147 tp_clear_object (&contact_b
);
1153 individual_store_state_sort_func (GtkTreeModel
*model
,
1154 GtkTreeIter
*iter_a
,
1155 GtkTreeIter
*iter_b
,
1159 FolksIndividual
*individual_a
, *individual_b
;
1160 gchar
*name_a
, *name_b
;
1161 gboolean is_separator_a
, is_separator_b
;
1162 gboolean fake_group_a
, fake_group_b
;
1163 FolksPresenceType folks_presence_type_a
, folks_presence_type_b
;
1164 TpConnectionPresenceType tp_presence_a
, tp_presence_b
;
1166 gtk_tree_model_get (model
, iter_a
,
1167 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &name_a
,
1168 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL
, &individual_a
,
1169 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, &is_separator_a
,
1170 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP
, &fake_group_a
, -1);
1171 gtk_tree_model_get (model
, iter_b
,
1172 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &name_b
,
1173 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL
, &individual_b
,
1174 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, &is_separator_b
,
1175 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP
, &fake_group_b
, -1);
1177 if (individual_a
== NULL
|| individual_b
== NULL
)
1179 ret_val
= compare_separator_and_groups (is_separator_a
, is_separator_b
,
1180 name_a
, name_b
, individual_a
, individual_b
, fake_group_a
,
1185 /* If we managed to get this far, we can start looking at
1188 folks_presence_type_a
=
1189 folks_presence_details_get_presence_type (
1190 FOLKS_PRESENCE_DETAILS (individual_a
));
1191 folks_presence_type_b
=
1192 folks_presence_details_get_presence_type (
1193 FOLKS_PRESENCE_DETAILS (individual_b
));
1194 tp_presence_a
= empathy_folks_presence_type_to_tp (folks_presence_type_a
);
1195 tp_presence_b
= empathy_folks_presence_type_to_tp (folks_presence_type_b
);
1197 ret_val
= -tp_connection_presence_type_cmp_availability (tp_presence_a
,
1202 /* Fallback: compare by name et al. */
1203 ret_val
= individual_store_contact_sort (individual_a
, individual_b
);
1209 tp_clear_object (&individual_a
);
1210 tp_clear_object (&individual_b
);
1216 individual_store_name_sort_func (GtkTreeModel
*model
,
1217 GtkTreeIter
*iter_a
,
1218 GtkTreeIter
*iter_b
,
1221 gchar
*name_a
, *name_b
;
1222 FolksIndividual
*individual_a
, *individual_b
;
1223 gboolean is_separator_a
= FALSE
, is_separator_b
= FALSE
;
1225 gboolean fake_group_a
, fake_group_b
;
1227 gtk_tree_model_get (model
, iter_a
,
1228 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &name_a
,
1229 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL
, &individual_a
,
1230 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, &is_separator_a
,
1231 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP
, &fake_group_a
, -1);
1232 gtk_tree_model_get (model
, iter_b
,
1233 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &name_b
,
1234 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL
, &individual_b
,
1235 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, &is_separator_b
,
1236 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP
, &fake_group_b
, -1);
1238 if (individual_a
== NULL
|| individual_b
== NULL
)
1239 ret_val
= compare_separator_and_groups (is_separator_a
, is_separator_b
,
1240 name_a
, name_b
, individual_a
, individual_b
, fake_group_a
, fake_group_b
);
1242 ret_val
= individual_store_contact_sort (individual_a
, individual_b
);
1244 tp_clear_object (&individual_a
);
1245 tp_clear_object (&individual_b
);
1253 individual_store_setup (EmpathyIndividualStore
*self
)
1256 GDK_TYPE_PIXBUF
, /* Status pixbuf */
1257 GDK_TYPE_PIXBUF
, /* Avatar pixbuf */
1258 G_TYPE_BOOLEAN
, /* Avatar pixbuf visible */
1259 G_TYPE_STRING
, /* Name */
1260 G_TYPE_UINT
, /* Presence type */
1261 G_TYPE_STRING
, /* Status string */
1262 G_TYPE_BOOLEAN
, /* Compact view */
1263 FOLKS_TYPE_INDIVIDUAL
, /* Individual type */
1264 G_TYPE_BOOLEAN
, /* Is group */
1265 G_TYPE_BOOLEAN
, /* Is active */
1266 G_TYPE_BOOLEAN
, /* Is online */
1267 G_TYPE_BOOLEAN
, /* Is separator */
1268 G_TYPE_BOOLEAN
, /* Can make audio calls */
1269 G_TYPE_BOOLEAN
, /* Can make video calls */
1270 G_TYPE_BOOLEAN
, /* Is a fake group */
1271 G_TYPE_STRV
, /* Client types */
1272 G_TYPE_UINT
, /* Event count */
1275 gtk_tree_store_set_column_types (GTK_TREE_STORE (self
),
1276 EMPATHY_INDIVIDUAL_STORE_COL_COUNT
, types
);
1278 /* Set up sorting */
1279 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self
),
1280 EMPATHY_INDIVIDUAL_STORE_COL_NAME
,
1281 individual_store_name_sort_func
, self
, NULL
);
1282 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self
),
1283 EMPATHY_INDIVIDUAL_STORE_COL_STATUS
,
1284 individual_store_state_sort_func
, self
, NULL
);
1286 self
->priv
->sort_criterium
= EMPATHY_INDIVIDUAL_STORE_SORT_NAME
;
1288 empathy_individual_store_set_sort_criterium (self
,
1289 self
->priv
->sort_criterium
);
1293 individual_store_inhibit_active_cb (EmpathyIndividualStore
*self
)
1295 self
->priv
->show_active
= TRUE
;
1296 self
->priv
->inhibit_active
= 0;
1302 g_queue_free_full_iter (gpointer data
)
1304 GQueue
*queue
= (GQueue
*) data
;
1305 g_queue_foreach (queue
, (GFunc
) gtk_tree_iter_free
, NULL
);
1306 g_queue_free (queue
);
1310 empathy_individual_store_init (EmpathyIndividualStore
*self
)
1312 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
1313 EMPATHY_TYPE_INDIVIDUAL_STORE
, EmpathyIndividualStorePriv
);
1315 self
->priv
->show_avatars
= TRUE
;
1316 self
->priv
->show_groups
= TRUE
;
1317 self
->priv
->show_protocols
= FALSE
;
1318 self
->priv
->inhibit_active
=
1319 g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME
,
1320 (GSourceFunc
) individual_store_inhibit_active_cb
, self
);
1321 self
->priv
->status_icons
=
1322 g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
, g_object_unref
);
1323 self
->priv
->folks_individual_cache
= g_hash_table_new_full (NULL
, NULL
, NULL
,
1324 g_queue_free_full_iter
);
1325 self
->priv
->empathy_group_cache
= g_hash_table_new_full (g_str_hash
,
1326 g_str_equal
, g_free
, (GDestroyNotify
) gtk_tree_iter_free
);
1327 individual_store_setup (self
);
1331 empathy_individual_store_get_show_avatars (EmpathyIndividualStore
*self
)
1333 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
), TRUE
);
1335 return self
->priv
->show_avatars
;
1339 individual_store_update_list_mode_foreach (GtkTreeModel
*model
,
1342 EmpathyIndividualStore
*self
)
1344 gboolean show_avatar
= FALSE
;
1345 FolksIndividual
*individual
;
1346 GdkPixbuf
*pixbuf_status
;
1348 if (self
->priv
->show_avatars
&& !self
->priv
->is_compact
)
1353 gtk_tree_model_get (model
, iter
,
1354 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL
, &individual
, -1);
1356 if (individual
== NULL
)
1360 /* get icon from hash_table */
1362 empathy_individual_store_get_individual_status_icon (self
, individual
);
1364 gtk_tree_store_set (GTK_TREE_STORE (self
), iter
,
1365 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS
, pixbuf_status
,
1366 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE
, show_avatar
,
1367 EMPATHY_INDIVIDUAL_STORE_COL_COMPACT
, self
->priv
->is_compact
, -1);
1369 g_object_unref (individual
);
1375 empathy_individual_store_set_show_avatars (EmpathyIndividualStore
*self
,
1376 gboolean show_avatars
)
1378 GtkTreeModel
*model
;
1380 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
));
1382 self
->priv
->show_avatars
= show_avatars
;
1384 model
= GTK_TREE_MODEL (self
);
1386 gtk_tree_model_foreach (model
,
1387 (GtkTreeModelForeachFunc
)
1388 individual_store_update_list_mode_foreach
, self
);
1390 g_object_notify (G_OBJECT (self
), "show-avatars");
1394 empathy_individual_store_get_show_protocols (EmpathyIndividualStore
*self
)
1396 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
), TRUE
);
1398 return self
->priv
->show_protocols
;
1402 empathy_individual_store_set_show_protocols (EmpathyIndividualStore
*self
,
1403 gboolean show_protocols
)
1405 GtkTreeModel
*model
;
1407 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
));
1409 self
->priv
->show_protocols
= show_protocols
;
1411 model
= GTK_TREE_MODEL (self
);
1413 gtk_tree_model_foreach (model
,
1414 (GtkTreeModelForeachFunc
)
1415 individual_store_update_list_mode_foreach
, self
);
1417 g_object_notify (G_OBJECT (self
), "show-protocols");
1421 empathy_individual_store_get_show_groups (EmpathyIndividualStore
*self
)
1423 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
), TRUE
);
1425 return self
->priv
->show_groups
;
1429 empathy_individual_store_set_show_groups (EmpathyIndividualStore
*self
,
1430 gboolean show_groups
)
1432 EmpathyIndividualStoreClass
*klass
;
1434 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
));
1436 klass
= EMPATHY_INDIVIDUAL_STORE_GET_CLASS ( self
);
1438 if (self
->priv
->show_groups
== show_groups
)
1443 self
->priv
->show_groups
= show_groups
;
1445 if (!klass
->initial_loading (self
))
1447 /* Remove all contacts and add them back, not optimized but
1448 * that's the easy way :)
1450 * This is only done if there's not a pending setup idle
1451 * callback, otherwise it will race and the contacts will get
1454 gtk_tree_store_clear (GTK_TREE_STORE (self
));
1455 /* Also clear the cache */
1456 g_hash_table_remove_all (self
->priv
->folks_individual_cache
);
1457 g_hash_table_remove_all (self
->priv
->empathy_group_cache
);
1459 klass
->reload_individuals (self
);
1462 g_object_notify (G_OBJECT (self
), "show-groups");
1466 empathy_individual_store_get_is_compact (EmpathyIndividualStore
*self
)
1468 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
), TRUE
);
1470 return self
->priv
->is_compact
;
1474 empathy_individual_store_set_is_compact (EmpathyIndividualStore
*self
,
1475 gboolean is_compact
)
1477 GtkTreeModel
*model
;
1479 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
));
1481 self
->priv
->is_compact
= is_compact
;
1483 model
= GTK_TREE_MODEL (self
);
1485 gtk_tree_model_foreach (model
,
1486 (GtkTreeModelForeachFunc
)
1487 individual_store_update_list_mode_foreach
, self
);
1489 g_object_notify (G_OBJECT (self
), "is-compact");
1492 EmpathyIndividualStoreSort
1493 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore
*self
)
1495 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
), 0);
1497 return self
->priv
->sort_criterium
;
1501 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore
*self
,
1502 EmpathyIndividualStoreSort sort_criterium
)
1504 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self
));
1506 self
->priv
->sort_criterium
= sort_criterium
;
1508 switch (sort_criterium
)
1510 case EMPATHY_INDIVIDUAL_STORE_SORT_STATE
:
1511 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self
),
1512 EMPATHY_INDIVIDUAL_STORE_COL_STATUS
, GTK_SORT_ASCENDING
);
1515 case EMPATHY_INDIVIDUAL_STORE_SORT_NAME
:
1516 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self
),
1517 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, GTK_SORT_ASCENDING
);
1521 g_assert_not_reached ();
1524 g_object_notify (G_OBJECT (self
), "sort-criterium");
1528 empathy_individual_store_row_separator_func (GtkTreeModel
*model
,
1532 gboolean is_separator
= FALSE
;
1534 g_return_val_if_fail (GTK_IS_TREE_MODEL (model
), FALSE
);
1536 gtk_tree_model_get (model
, iter
,
1537 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR
, &is_separator
, -1);
1539 return is_separator
;
1543 empathy_individual_store_get_parent_group (GtkTreeModel
*model
,
1545 gboolean
*path_is_group
,
1546 gboolean
*is_fake_group
)
1548 GtkTreeIter parent_iter
, iter
;
1551 gboolean fake
= FALSE
;
1553 g_return_val_if_fail (GTK_IS_TREE_MODEL (model
), NULL
);
1557 *path_is_group
= FALSE
;
1560 if (!gtk_tree_model_get_iter (model
, &iter
, path
))
1565 gtk_tree_model_get (model
, &iter
,
1566 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP
, &is_group
,
1567 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &name
, -1);
1574 if (!gtk_tree_model_iter_parent (model
, &parent_iter
, &iter
))
1581 gtk_tree_model_get (model
, &iter
,
1582 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP
, &is_group
,
1583 EMPATHY_INDIVIDUAL_STORE_COL_NAME
, &name
,
1584 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP
, &fake
, -1);
1594 *path_is_group
= TRUE
;
1597 if (is_fake_group
!= NULL
)
1598 *is_fake_group
= fake
;
1604 individual_store_get_individual_status_icon_with_icon_name (
1605 EmpathyIndividualStore
*self
,
1606 FolksIndividual
*individual
,
1607 const gchar
*status_icon_name
)
1609 GdkPixbuf
*pixbuf_status
;
1610 const gchar
*protocol_name
= NULL
;
1611 gchar
*icon_name
= NULL
;
1614 guint contact_count
= 0;
1615 EmpathyContact
*contact
= NULL
;
1616 gboolean show_protocols_here
;
1618 personas
= folks_individual_get_personas (individual
);
1619 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
1620 while (gee_iterator_next (iter
))
1622 FolksPersona
*persona
= gee_iterator_get (iter
);
1623 if (empathy_folks_persona_is_interesting (persona
))
1626 g_clear_object (&persona
);
1628 if (contact_count
> 1)
1631 g_clear_object (&iter
);
1633 show_protocols_here
= (self
->priv
->show_protocols
&& (contact_count
== 1));
1634 if (show_protocols_here
)
1636 contact
= empathy_contact_dup_from_folks_individual (individual
);
1637 if (contact
!= NULL
)
1639 protocol_name
= empathy_protocol_name_for_contact (contact
);
1640 icon_name
= g_strdup_printf ("%s-%s", status_icon_name
,
1645 g_warning ("Cannot retrieve contact from individual '%s'",
1646 folks_alias_details_get_alias (
1647 FOLKS_ALIAS_DETAILS (individual
)));
1654 icon_name
= g_strdup_printf ("%s", status_icon_name
);
1657 pixbuf_status
= g_hash_table_lookup (self
->priv
->status_icons
, icon_name
);
1659 if (pixbuf_status
== NULL
)
1662 empathy_pixbuf_contact_status_icon_with_icon_name (contact
,
1663 status_icon_name
, show_protocols_here
);
1665 if (pixbuf_status
!= NULL
)
1667 /* pass the reference to the hash table */
1668 g_hash_table_insert (self
->priv
->status_icons
,
1669 g_strdup (icon_name
), pixbuf_status
);
1674 tp_clear_object (&contact
);
1676 return pixbuf_status
;
1680 empathy_individual_store_get_individual_status_icon (
1681 EmpathyIndividualStore
*self
,
1682 FolksIndividual
*individual
)
1684 GdkPixbuf
*pixbuf_status
= NULL
;
1685 const gchar
*status_icon_name
= NULL
;
1687 status_icon_name
= empathy_icon_name_for_individual (individual
);
1688 if (status_icon_name
== NULL
)
1692 individual_store_get_individual_status_icon_with_icon_name (self
,
1693 individual
, status_icon_name
);
1695 return pixbuf_status
;
1699 empathy_individual_store_refresh_individual (EmpathyIndividualStore
*self
,
1700 FolksIndividual
*individual
)
1702 gboolean show_active
;
1704 show_active
= self
->priv
->show_active
;
1705 self
->priv
->show_active
= FALSE
;
1706 empathy_individual_store_remove_individual (self
, individual
);
1707 empathy_individual_store_add_individual (self
, individual
);
1708 self
->priv
->show_active
= show_active
;