]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-individual-store.c
Remove unused variables [-Werror=unused-but-set-variable]
[empathy.git] / libempathy-gtk / empathy-individual-store.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2005-2007 Imendio AB
4  * Copyright (C) 2007-2010 Collabora Ltd.
5  *
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.
10  *
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.
15  *
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
20  *
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>
25  */
26
27 #include "config.h"
28
29 #include <string.h>
30
31 #include <glib.h>
32 #include <glib/gi18n-lib.h>
33 #include <gtk/gtk.h>
34
35 #include <folks/folks.h>
36 #include <folks/folks-telepathy.h>
37 #include <telepathy-glib/util.h>
38
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-enum-types.h>
41 #include <libempathy/empathy-individual-manager.h>
42
43 #include "empathy-individual-store.h"
44 #include "empathy-ui-utils.h"
45 #include "empathy-gtk-enum-types.h"
46
47 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
48 #include <libempathy/empathy-debug.h>
49
50 /* Active users are those which have recently changed state
51  * (e.g. online, offline or from normal to a busy state).
52  */
53
54 /* Time in seconds user is shown as active */
55 #define ACTIVE_USER_SHOW_TIME 7
56
57 /* Time in seconds after connecting which we wait before active users are enabled */
58 #define ACTIVE_USER_WAIT_TO_ENABLE_TIME 5
59
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualStore)
61 typedef struct
62 {
63   EmpathyIndividualManager *manager;
64   gboolean show_avatars;
65   gboolean show_groups;
66   gboolean is_compact;
67   gboolean show_protocols;
68   gboolean show_active;
69   EmpathyIndividualStoreSort sort_criterium;
70   guint inhibit_active;
71   guint setup_idle_id;
72   gboolean dispose_has_run;
73   GHashTable *status_icons;
74   /* List of owned GCancellables for each pending avatar load operation */
75   GList *avatar_cancellables;
76   /* Hash: FolksIndividual* -> GQueue (GtkTreeIter *) */
77   GHashTable                  *folks_individual_cache;
78   /* Hash: char *groupname -> GtkTreeIter * */
79   GHashTable                  *empathy_group_cache;
80 } EmpathyIndividualStorePriv;
81
82 typedef struct
83 {
84   EmpathyIndividualStore *self;
85   FolksIndividual *individual;
86   gboolean remove;
87   guint timeout;
88 } ShowActiveData;
89
90 enum
91 {
92   PROP_0,
93   PROP_INDIVIDUAL_MANAGER,
94   PROP_SHOW_AVATARS,
95   PROP_SHOW_PROTOCOLS,
96   PROP_SHOW_GROUPS,
97   PROP_IS_COMPACT,
98   PROP_SORT_CRITERIUM
99 };
100
101 /* prototypes to break cycles */
102 static void individual_store_contact_update (EmpathyIndividualStore *self,
103     FolksIndividual *individual);
104
105 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
106     GTK_TYPE_TREE_STORE);
107
108 /* Calculate whether the Individual can do audio or video calls.
109  * FIXME: We can remove this once libfolks has grown capabilities support
110  * again: bgo#626179. */
111 static void
112 individual_can_audio_video_call (FolksIndividual *individual,
113     gboolean *can_audio_call,
114     gboolean *can_video_call)
115 {
116   GeeSet *personas;
117   GeeIterator *iter;
118   gboolean can_audio = FALSE, can_video = FALSE;
119
120   personas = folks_individual_get_personas (individual);
121   iter = gee_iterable_iterator (GEE_ITERABLE (personas));
122   while (gee_iterator_next (iter))
123     {
124       FolksPersona *persona = gee_iterator_get (iter);
125       TpContact *tp_contact;
126
127       if (!empathy_folks_persona_is_interesting (persona))
128         goto while_finish;
129
130       tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
131       if (tp_contact != NULL)
132         {
133           EmpathyContact *contact;
134
135           contact = empathy_contact_dup_from_tp_contact (tp_contact);
136           empathy_contact_set_persona (contact, persona);
137
138           can_audio = can_audio || empathy_contact_get_capabilities (contact) &
139               EMPATHY_CAPABILITIES_AUDIO;
140           can_video = can_video || empathy_contact_get_capabilities (contact) &
141               EMPATHY_CAPABILITIES_VIDEO;
142
143           g_object_unref (contact);
144         }
145 while_finish:
146       g_clear_object (&persona);
147
148       if (can_audio && can_video)
149         break;
150     }
151   g_clear_object (&iter);
152
153   *can_audio_call = can_audio;
154   *can_video_call = can_video;
155 }
156
157 static const gchar * const *
158 individual_get_client_types (FolksIndividual *individual)
159 {
160   GeeSet *personas;
161   GeeIterator *iter;
162   const gchar * const *types = NULL;
163   FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
164
165   personas = folks_individual_get_personas (individual);
166   iter = gee_iterable_iterator (GEE_ITERABLE (personas));
167   while (gee_iterator_next (iter))
168     {
169       FolksPresenceDetails *presence;
170       FolksPersona *persona = gee_iterator_get (iter);
171
172       /* We only want personas which have presence and a TpContact */
173       if (!empathy_folks_persona_is_interesting (persona))
174         goto while_finish;
175
176       presence = FOLKS_PRESENCE_DETAILS (persona);
177
178       if (folks_presence_details_typecmp (
179               folks_presence_details_get_presence_type (presence),
180               presence_type) > 0)
181         {
182           TpContact *tp_contact;
183
184           presence_type = folks_presence_details_get_presence_type (presence);
185
186           tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
187           if (tp_contact != NULL)
188             types = tp_contact_get_client_types (tp_contact);
189         }
190
191 while_finish:
192       g_clear_object (&persona);
193     }
194   g_clear_object (&iter);
195
196   return types;
197 }
198
199 static void
200 add_individual_to_store (GtkTreeStore *self,
201     GtkTreeIter *iter,
202     GtkTreeIter *parent,
203     FolksIndividual *individual)
204 {
205   EmpathyIndividualStorePriv *priv = GET_PRIV (self);
206   gboolean can_audio_call, can_video_call;
207   const gchar * const *types;
208   GQueue *queue;
209
210   individual_can_audio_video_call (individual, &can_audio_call,
211       &can_video_call);
212
213   types = individual_get_client_types (individual);
214
215   gtk_tree_store_insert_with_values (self, iter, parent, 0,
216       EMPATHY_INDIVIDUAL_STORE_COL_NAME,
217       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
218       EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, individual,
219       EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
220       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
221       EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
222       EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
223       EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
224       -1);
225
226   queue = g_hash_table_lookup (priv->folks_individual_cache, individual);
227   if (queue)
228     {
229       g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
230     }
231   else
232     {
233       queue = g_queue_new ();
234       g_queue_push_tail (queue, gtk_tree_iter_copy (iter));
235       g_hash_table_insert (priv->folks_individual_cache, individual,
236           queue);
237     }
238 }
239
240 static void
241 individual_store_get_group (EmpathyIndividualStore *self,
242     const gchar *name,
243     GtkTreeIter *iter_group_to_set,
244     GtkTreeIter *iter_separator_to_set,
245     gboolean *created,
246     gboolean is_fake_group)
247 {
248   EmpathyIndividualStorePriv *priv = GET_PRIV (self);
249   GtkTreeModel *model;
250   GtkTreeIter iter_group;
251   GtkTreeIter iter_separator;
252   GtkTreeIter *iter;
253
254   model = GTK_TREE_MODEL (self);
255   iter = g_hash_table_lookup (priv->empathy_group_cache, name);
256
257   if (iter == NULL)
258     {
259       if (created)
260         *created = TRUE;
261
262       gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_group,
263           NULL, 0,
264           EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, NULL,
265           EMPATHY_INDIVIDUAL_STORE_COL_NAME, name,
266           EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, TRUE,
267           EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, FALSE,
268           EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
269           EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, is_fake_group,
270           -1);
271
272       g_hash_table_insert (priv->empathy_group_cache, g_strdup (name),
273           gtk_tree_iter_copy (&iter_group));
274
275       if (iter_group_to_set)
276         *iter_group_to_set = iter_group;
277
278       gtk_tree_store_insert_with_values (GTK_TREE_STORE (self), &iter_separator,
279           &iter_group, 0,
280           EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, TRUE,
281           -1);
282
283       if (iter_separator_to_set)
284         *iter_separator_to_set = iter_separator;
285     }
286   else
287     {
288       if (created)
289         *created = FALSE;
290
291       if (iter_group_to_set)
292         *iter_group_to_set = *iter;
293
294       iter_separator = *iter;
295
296       if (gtk_tree_model_iter_next (model, &iter_separator))
297         {
298           gboolean is_separator;
299
300           gtk_tree_model_get (model, &iter_separator,
301               EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
302
303           if (is_separator && iter_separator_to_set)
304             *iter_separator_to_set = iter_separator;
305         }
306     }
307 }
308
309 static GList *
310 individual_store_find_contact (EmpathyIndividualStore *self,
311     FolksIndividual *individual)
312 {
313   EmpathyIndividualStorePriv *priv = GET_PRIV (self);
314   GQueue *row_refs_queue;
315   GList *i;
316   GList *iters_list = NULL;
317
318   row_refs_queue = g_hash_table_lookup (priv->folks_individual_cache,
319       individual);
320   if (!row_refs_queue)
321     return NULL;
322
323   for (i = g_queue_peek_head_link (row_refs_queue) ; i != NULL ; i = i->next)
324     {
325       GtkTreeIter *iter = i->data;
326
327       iters_list = g_list_prepend (iters_list, gtk_tree_iter_copy (iter));
328     }
329
330   return iters_list;
331 }
332
333 static void
334 free_iters (GList *iters)
335 {
336   g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
337   g_list_free (iters);
338 }
339
340 static void
341 individual_store_remove_individual (EmpathyIndividualStore *self,
342     FolksIndividual *individual)
343 {
344   EmpathyIndividualStorePriv *priv = GET_PRIV (self);
345   GtkTreeModel *model;
346   GQueue *row_refs;
347   GList *l;
348
349   row_refs = g_hash_table_lookup (priv->folks_individual_cache, individual);
350   if (!row_refs)
351     return;
352
353   /* Clean up model */
354   model = GTK_TREE_MODEL (self);
355
356   for (l = g_queue_peek_head_link (row_refs); l; l = l->next)
357     {
358       GtkTreeIter *iter = l->data;
359       GtkTreeIter parent;
360
361       /* NOTE: it is only <= 2 here because we have
362        * separators after the group name, otherwise it
363        * should be 1.
364        */
365       if (gtk_tree_model_iter_parent (model, &parent, iter) &&
366           gtk_tree_model_iter_n_children (model, &parent) <= 2)
367         {
368           gchar *group_name;
369           gtk_tree_model_get (model, &parent,
370               EMPATHY_CONTACT_LIST_STORE_COL_NAME, &group_name,
371               -1);
372           g_hash_table_remove (priv->empathy_group_cache,
373               group_name);
374           gtk_tree_store_remove (GTK_TREE_STORE (self), &parent);
375         }
376       else
377         {
378           gtk_tree_store_remove (GTK_TREE_STORE (self), iter);
379         }
380     }
381
382   g_hash_table_remove (priv->folks_individual_cache, individual);
383 }
384
385 static void
386 individual_store_add_individual (EmpathyIndividualStore *self,
387     FolksIndividual *individual)
388 {
389   EmpathyIndividualStorePriv *priv;
390   GtkTreeIter iter;
391   GeeIterator *group_iter = NULL;
392
393   priv = GET_PRIV (self);
394
395   if (EMP_STR_EMPTY (folks_alias_details_get_alias (
396           FOLKS_ALIAS_DETAILS (individual))))
397     return;
398
399   if (priv->show_groups)
400     {
401       GeeSet *group_set = NULL;
402
403       group_set = folks_group_details_get_groups (
404           FOLKS_GROUP_DETAILS (individual));
405
406       if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
407         group_iter = gee_iterable_iterator (GEE_ITERABLE (group_set));
408     }
409
410   /* fall-back groups, in case there are no named groups */
411   if (group_iter == NULL)
412     {
413       GtkTreeIter iter_group, *parent;
414       EmpathyContact *contact;
415       TpConnection *connection;
416       gchar *protocol_name = NULL;
417
418       parent = &iter_group;
419
420       contact = empathy_contact_dup_from_folks_individual (individual);
421       if (contact != NULL)
422         {
423           connection = empathy_contact_get_connection (contact);
424           tp_connection_parse_object_path (connection, &protocol_name, NULL);
425         }
426
427       if (!priv->show_groups)
428         parent = NULL;
429       else if (!tp_strdiff (protocol_name, "local-xmpp"))
430         {
431           /* these are People Nearby */
432           individual_store_get_group (self,
433               EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
434               TRUE);
435         }
436       else
437         {
438           individual_store_get_group (self,
439               EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
440               &iter_group, NULL, NULL, TRUE);
441         }
442
443       add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
444           individual);
445
446       g_free (protocol_name);
447       g_clear_object (&contact);
448     }
449
450   /* Else add to each group. */
451   while (group_iter != NULL && gee_iterator_next (group_iter))
452     {
453       gchar *group_name = gee_iterator_get (group_iter);
454       GtkTreeIter iter_group;
455
456       individual_store_get_group (self, group_name, &iter_group, NULL, NULL,
457           FALSE);
458
459       add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
460           individual);
461
462       g_free (group_name);
463     }
464   g_clear_object (&group_iter);
465
466   if (priv->show_groups &&
467       folks_favourite_details_get_is_favourite (
468           FOLKS_FAVOURITE_DETAILS (individual)))
469     {
470       /* Add contact to the fake 'Favorites' group */
471       GtkTreeIter iter_group;
472
473       individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
474           &iter_group, NULL, NULL, TRUE);
475
476       add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
477           individual);
478     }
479
480   individual_store_contact_update (self, individual);
481 }
482
483 static void
484 individual_store_contact_set_active (EmpathyIndividualStore *self,
485     FolksIndividual *individual,
486     gboolean active,
487     gboolean set_changed)
488 {
489   GtkTreeModel *model;
490   GList *iters, *l;
491
492   model = GTK_TREE_MODEL (self);
493
494   iters = individual_store_find_contact (self, individual);
495   for (l = iters; l; l = l->next)
496     {
497       GtkTreePath *path;
498
499       gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
500           EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
501           -1);
502
503       DEBUG ("Set item %s", active ? "active" : "inactive");
504
505       if (set_changed)
506         {
507           path = gtk_tree_model_get_path (model, l->data);
508           gtk_tree_model_row_changed (model, path, l->data);
509           gtk_tree_path_free (path);
510         }
511     }
512
513   free_iters (iters);
514 }
515
516 static void individual_store_contact_active_free (ShowActiveData *data);
517
518 static void
519 individual_store_contact_active_invalidated (ShowActiveData *data,
520     GObject *old_object)
521 {
522   /* Remove the timeout and free the struct, since the individual or individual
523    * store has disappeared. */
524   g_source_remove (data->timeout);
525
526   if (old_object == (GObject *) data->self)
527     data->self = NULL;
528   else if (old_object == (GObject *) data->individual)
529     data->individual = NULL;
530   else
531     g_assert_not_reached ();
532
533   individual_store_contact_active_free (data);
534 }
535
536 static ShowActiveData *
537 individual_store_contact_active_new (EmpathyIndividualStore *self,
538     FolksIndividual *individual,
539     gboolean remove_)
540 {
541   ShowActiveData *data;
542
543   DEBUG ("Individual'%s' now active, and %s be removed",
544       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
545       remove_ ? "WILL" : "WILL NOT");
546
547   data = g_slice_new0 (ShowActiveData);
548
549   /* We don't actually want to force either the IndividualStore or the
550    * Individual to stay alive, since the user could quit Empathy or disable
551    * the account before the contact_active timeout is fired. */
552   g_object_weak_ref (G_OBJECT (self),
553       (GWeakNotify) individual_store_contact_active_invalidated, data);
554   g_object_weak_ref (G_OBJECT (individual),
555       (GWeakNotify) individual_store_contact_active_invalidated, data);
556
557   data->self = self;
558   data->individual = individual;
559   data->remove = remove_;
560   data->timeout = 0;
561
562   return data;
563 }
564
565 static void
566 individual_store_contact_active_free (ShowActiveData *data)
567 {
568   if (data->self != NULL)
569     {
570       g_object_weak_unref (G_OBJECT (data->self),
571           (GWeakNotify) individual_store_contact_active_invalidated, data);
572     }
573
574   if (data->individual != NULL)
575     {
576       g_object_weak_unref (G_OBJECT (data->individual),
577           (GWeakNotify) individual_store_contact_active_invalidated, data);
578     }
579
580   g_slice_free (ShowActiveData, data);
581 }
582
583 static gboolean
584 individual_store_contact_active_cb (ShowActiveData *data)
585 {
586   if (data->remove)
587     {
588       DEBUG ("Individual'%s' active timeout, removing item",
589           folks_alias_details_get_alias (
590             FOLKS_ALIAS_DETAILS (data->individual)));
591       individual_store_remove_individual (data->self, data->individual);
592     }
593
594   DEBUG ("Individual'%s' no longer active",
595       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
596
597   individual_store_contact_set_active (data->self,
598       data->individual, FALSE, TRUE);
599
600   individual_store_contact_active_free (data);
601
602   return FALSE;
603 }
604
605 typedef struct {
606   EmpathyIndividualStore *store; /* weak */
607   GCancellable *cancellable; /* owned */
608 } LoadAvatarData;
609
610 static void
611 individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
612     GAsyncResult *result,
613     LoadAvatarData *data)
614 {
615   GError *error = NULL;
616   GdkPixbuf *pixbuf;
617
618   pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
619       result, &error);
620
621   if (error != NULL)
622     {
623       DEBUG ("failed to retrieve pixbuf for individual %s: %s",
624           folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
625           error->message);
626       g_clear_error (&error);
627     }
628   else if (data->store != NULL)
629     {
630       GList *iters, *l;
631
632       iters = individual_store_find_contact (data->store, individual);
633       for (l = iters; l; l = l->next)
634         {
635           gtk_tree_store_set (GTK_TREE_STORE (data->store), l->data,
636               EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf,
637               -1);
638         }
639
640       free_iters (iters);
641     }
642
643   /* Free things */
644   if (data->store != NULL)
645     {
646       EmpathyIndividualStorePriv *priv = GET_PRIV (data->store);
647
648       g_object_remove_weak_pointer (G_OBJECT (data->store),
649           (gpointer *) &data->store);
650       priv->avatar_cancellables = g_list_remove (priv->avatar_cancellables,
651           data->cancellable);
652     }
653
654   tp_clear_object (&pixbuf);
655   g_object_unref (data->cancellable);
656   g_slice_free (LoadAvatarData, data);
657 }
658
659 static void
660 individual_store_contact_update (EmpathyIndividualStore *self,
661     FolksIndividual *individual)
662 {
663   EmpathyIndividualStorePriv *priv;
664   ShowActiveData *data;
665   GtkTreeModel *model;
666   GList *iters, *l;
667   gboolean in_list;
668   gboolean was_online = TRUE;
669   gboolean now_online = FALSE;
670   gboolean set_model = FALSE;
671   gboolean do_remove = FALSE;
672   gboolean do_set_active = FALSE;
673   gboolean do_set_refresh = FALSE;
674   gboolean show_avatar = FALSE;
675   GdkPixbuf *pixbuf_status;
676   LoadAvatarData *load_avatar_data;
677
678   priv = GET_PRIV (self);
679
680   model = GTK_TREE_MODEL (self);
681
682   iters = individual_store_find_contact (self, individual);
683   if (!iters)
684     {
685       in_list = FALSE;
686     }
687   else
688     {
689       in_list = TRUE;
690     }
691
692   /* Get online state now. */
693   now_online = folks_presence_details_is_online (
694       FOLKS_PRESENCE_DETAILS (individual));
695
696   if (!in_list)
697     {
698       DEBUG ("Individual'%s' in list:NO, should be:YES",
699           folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
700
701       individual_store_add_individual (self, individual);
702
703       if (priv->show_active)
704         {
705           do_set_active = TRUE;
706
707           DEBUG ("Set active (individual added)");
708         }
709     }
710   else
711     {
712       DEBUG ("Individual'%s' in list:YES, should be:YES",
713           folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
714
715       /* Get online state before. */
716       if (iters && g_list_length (iters) > 0)
717         {
718           gtk_tree_model_get (model, iters->data,
719               EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &was_online, -1);
720         }
721
722       /* Is this really an update or an online/offline. */
723       if (priv->show_active)
724         {
725           if (was_online != now_online)
726             {
727               do_set_active = TRUE;
728               do_set_refresh = TRUE;
729
730               DEBUG ("Set active (individual updated %s)",
731                   was_online ? "online  -> offline" : "offline -> online");
732             }
733           else
734             {
735               /* Was TRUE for presence updates. */
736               /* do_set_active = FALSE;  */
737               do_set_refresh = TRUE;
738
739               DEBUG ("Set active (individual updated)");
740             }
741         }
742
743       set_model = TRUE;
744     }
745
746   if (priv->show_avatars && !priv->is_compact)
747     {
748       show_avatar = TRUE;
749     }
750
751   /* Load the avatar asynchronously */
752   load_avatar_data = g_slice_new (LoadAvatarData);
753   load_avatar_data->store = self;
754   g_object_add_weak_pointer (G_OBJECT (self),
755       (gpointer *) &load_avatar_data->store);
756   load_avatar_data->cancellable = g_cancellable_new ();
757
758   priv->avatar_cancellables = g_list_prepend (priv->avatar_cancellables,
759       load_avatar_data->cancellable);
760   empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32,
761       load_avatar_data->cancellable,
762       (GAsyncReadyCallback) individual_avatar_pixbuf_received_cb,
763       load_avatar_data);
764
765   pixbuf_status =
766       empathy_individual_store_get_individual_status_icon (self, individual);
767
768   for (l = iters; l && set_model; l = l->next)
769     {
770       gboolean can_audio_call, can_video_call;
771       const gchar * const *types;
772
773       individual_can_audio_video_call (individual, &can_audio_call,
774           &can_video_call);
775
776       types = individual_get_client_types (individual);
777
778       gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
779           EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
780           EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
781           EMPATHY_INDIVIDUAL_STORE_COL_NAME,
782             folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
783           EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE,
784             folks_presence_details_get_presence_type (
785                 FOLKS_PRESENCE_DETAILS (individual)),
786           EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
787             folks_presence_details_get_presence_message (
788                 FOLKS_PRESENCE_DETAILS (individual)),
789           EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact,
790           EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, FALSE,
791           EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, now_online,
792           EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
793           EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
794           EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
795           EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
796           -1);
797     }
798
799   if (priv->show_active && do_set_active)
800     {
801       individual_store_contact_set_active (self, individual, do_set_active,
802           do_set_refresh);
803
804       if (do_set_active)
805         {
806           data =
807               individual_store_contact_active_new (self, individual,
808               do_remove);
809           data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
810               (GSourceFunc) individual_store_contact_active_cb, data);
811         }
812     }
813
814   /* FIXME: when someone goes online then offline quickly, the
815    * first timeout sets the user to be inactive and the second
816    * timeout removes the user from the contact list, really we
817    * should remove the first timeout.
818    */
819   free_iters (iters);
820 }
821
822 static void
823 individual_store_individual_updated_cb (FolksIndividual *individual,
824     GParamSpec *param,
825     EmpathyIndividualStore *self)
826 {
827   DEBUG ("Individual'%s' updated, checking roster is in sync...",
828       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
829
830   individual_store_contact_update (self, individual);
831 }
832
833 static void
834 individual_store_contact_updated_cb (EmpathyContact *contact,
835     GParamSpec *pspec,
836     EmpathyIndividualStore *self)
837 {
838   FolksIndividual *individual;
839
840   DEBUG ("Contact '%s' updated, checking roster is in sync...",
841       empathy_contact_get_alias (contact));
842
843   individual = g_object_get_data (G_OBJECT (contact), "individual");
844   if (individual == NULL)
845     return;
846
847   individual_store_contact_update (self, individual);
848 }
849
850 static void
851 individual_personas_changed_cb (FolksIndividual *individual,
852     GeeSet *added,
853     GeeSet *removed,
854     EmpathyIndividualStore *self)
855 {
856   GeeIterator *iter;
857
858   DEBUG ("Individual '%s' personas-changed.",
859       folks_individual_get_id (individual));
860
861   iter = gee_iterable_iterator (GEE_ITERABLE (removed));
862   /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
863    * through the EmpathyContacts for them. */
864   while (gee_iterator_next (iter))
865     {
866       TpfPersona *persona = gee_iterator_get (iter);
867       TpContact *tp_contact;
868       EmpathyContact *contact;
869
870       if (TPF_IS_PERSONA (persona))
871         {
872           tp_contact = tpf_persona_get_contact (persona);
873           if (tp_contact != NULL)
874             {
875               contact = empathy_contact_dup_from_tp_contact (tp_contact);
876               empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
877
878               g_object_set_data (G_OBJECT (contact), "individual", NULL);
879               g_signal_handlers_disconnect_by_func (contact,
880                   (GCallback) individual_store_contact_updated_cb, self);
881
882               g_object_unref (contact);
883             }
884         }
885
886       g_clear_object (&persona);
887     }
888   g_clear_object (&iter);
889
890   iter = gee_iterable_iterator (GEE_ITERABLE (added));
891   while (gee_iterator_next (iter))
892     {
893       TpfPersona *persona = gee_iterator_get (iter);
894       TpContact *tp_contact;
895       EmpathyContact *contact;
896
897       if (TPF_IS_PERSONA (persona))
898         {
899           tp_contact = tpf_persona_get_contact (persona);
900           if (tp_contact != NULL)
901             {
902               contact = empathy_contact_dup_from_tp_contact (tp_contact);
903               empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
904
905               g_object_set_data (G_OBJECT (contact), "individual", individual);
906               g_signal_connect (contact, "notify::capabilities",
907                   (GCallback) individual_store_contact_updated_cb, self);
908               g_signal_connect (contact, "notify::client-types",
909                   (GCallback) individual_store_contact_updated_cb, self);
910
911               g_object_unref (contact);
912             }
913         }
914
915       g_clear_object (&persona);
916     }
917   g_clear_object (&iter);
918 }
919
920 static void
921 individual_store_favourites_changed_cb (FolksIndividual *individual,
922     GParamSpec *param,
923     EmpathyIndividualStore *self)
924 {
925   DEBUG ("Individual %s is %s a favourite",
926       folks_individual_get_id (individual),
927       folks_favourite_details_get_is_favourite (
928         FOLKS_FAVOURITE_DETAILS (individual)) ? "now" : "no longer");
929
930   individual_store_remove_individual (self, individual);
931   individual_store_add_individual (self, individual);
932 }
933
934 void
935 individual_store_add_individual_and_connect (EmpathyIndividualStore *self,
936     FolksIndividual *individual)
937 {
938   GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
939
940   individual_store_add_individual (self, individual);
941
942   g_signal_connect (individual, "notify::avatar",
943       (GCallback) individual_store_individual_updated_cb, self);
944   g_signal_connect (individual, "notify::presence-type",
945       (GCallback) individual_store_individual_updated_cb, self);
946   g_signal_connect (individual, "notify::presence-message",
947       (GCallback) individual_store_individual_updated_cb, self);
948   g_signal_connect (individual, "notify::alias",
949       (GCallback) individual_store_individual_updated_cb, self);
950   g_signal_connect (individual, "personas-changed",
951       (GCallback) individual_personas_changed_cb, self);
952   g_signal_connect (individual, "notify::is-favourite",
953       (GCallback) individual_store_favourites_changed_cb, self);
954
955   /* provide an empty set so the callback can assume non-NULL sets */
956   individual_personas_changed_cb (individual,
957       folks_individual_get_personas (individual), empty_set, self);
958   g_clear_object (&empty_set);
959 }
960
961 static void
962 individual_store_disconnect_individual (EmpathyIndividualStore *self,
963     FolksIndividual *individual)
964 {
965   GeeSet *empty_set = gee_set_empty (G_TYPE_NONE, NULL, NULL);
966
967   /* provide an empty set so the callback can assume non-NULL sets */
968   individual_personas_changed_cb (individual, empty_set,
969       folks_individual_get_personas (individual), self);
970   g_clear_object (&empty_set);
971
972   g_signal_handlers_disconnect_by_func (individual,
973       (GCallback) individual_store_individual_updated_cb, self);
974   g_signal_handlers_disconnect_by_func (individual,
975       (GCallback) individual_personas_changed_cb, self);
976   g_signal_handlers_disconnect_by_func (individual,
977       (GCallback) individual_store_favourites_changed_cb, self);
978 }
979
980 void
981 individual_store_remove_individual_and_disconnect (
982     EmpathyIndividualStore *self,
983     FolksIndividual *individual)
984 {
985   individual_store_disconnect_individual (self, individual);
986   individual_store_remove_individual (self, individual);
987 }
988
989 static void
990 individual_store_members_changed_cb (EmpathyIndividualManager *manager,
991     const gchar *message,
992     GList *added,
993     GList *removed,
994     guint reason,
995     EmpathyIndividualStore *self)
996 {
997   GList *l;
998
999   for (l = added; l; l = l->next)
1000     {
1001       DEBUG ("Individual %s %s", folks_individual_get_id (l->data), "added");
1002
1003       individual_store_add_individual_and_connect (self, l->data);
1004     }
1005   for (l = removed; l; l = l->next)
1006     {
1007       DEBUG ("Individual %s %s",
1008           folks_individual_get_id (l->data), "removed");
1009
1010       individual_store_remove_individual_and_disconnect (self, l->data);
1011     }
1012 }
1013
1014 static void
1015 individual_store_groups_changed_cb (EmpathyIndividualManager *manager,
1016     FolksIndividual *individual,
1017     gchar *group,
1018     gboolean is_member,
1019     EmpathyIndividualStore *self)
1020 {
1021   EmpathyIndividualStorePriv *priv;
1022   gboolean show_active;
1023
1024   priv = GET_PRIV (self);
1025
1026   DEBUG ("Updating groups for individual %s",
1027       folks_individual_get_id (individual));
1028
1029   /* We do this to make sure the groups are correct, if not, we
1030    * would have to check the groups already set up for each
1031    * contact and then see what has been updated.
1032    */
1033   show_active = priv->show_active;
1034   priv->show_active = FALSE;
1035   individual_store_remove_individual (self, individual);
1036   individual_store_add_individual (self, individual);
1037   priv->show_active = show_active;
1038 }
1039
1040 static gboolean
1041 individual_store_manager_setup (gpointer user_data)
1042 {
1043   EmpathyIndividualStore *self = user_data;
1044   EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1045   GList *individuals;
1046
1047   /* Signal connection. */
1048
1049   /* TODO: implement */
1050   DEBUG ("handling individual renames unimplemented");
1051
1052   g_signal_connect (priv->manager,
1053       "members-changed",
1054       G_CALLBACK (individual_store_members_changed_cb), self);
1055
1056   g_signal_connect (priv->manager,
1057       "groups-changed",
1058       G_CALLBACK (individual_store_groups_changed_cb), self);
1059
1060   /* Add contacts already created. */
1061   individuals = empathy_individual_manager_get_members (priv->manager);
1062   if (individuals != NULL && FOLKS_IS_INDIVIDUAL (individuals->data))
1063     {
1064       individual_store_members_changed_cb (priv->manager, "initial add",
1065           individuals, NULL, 0, self);
1066       g_list_free (individuals);
1067     }
1068
1069   priv->setup_idle_id = 0;
1070   return FALSE;
1071 }
1072
1073 static void
1074 individual_store_set_individual_manager (EmpathyIndividualStore *self,
1075     EmpathyIndividualManager *manager)
1076 {
1077   EmpathyIndividualStorePriv *priv = GET_PRIV (self);
1078
1079   priv->manager = g_object_ref (manager);
1080
1081   /* Let a chance to have all properties set before populating */
1082   priv->setup_idle_id = g_idle_add (individual_store_manager_setup, self);
1083 }
1084
1085 static void
1086 individual_store_member_renamed_cb (EmpathyIndividualManager *manager,
1087     FolksIndividual *old_individual,
1088     FolksIndividual *new_individual,
1089     guint reason,
1090     const gchar *message,
1091     EmpathyIndividualStore *self)
1092 {
1093   DEBUG ("Individual %s renamed to %s",
1094       folks_individual_get_id (old_individual),
1095       folks_individual_get_id (new_individual));
1096
1097   /* add the new contact */
1098   individual_store_add_individual_and_connect (self, new_individual);
1099
1100   /* remove old contact */
1101   individual_store_remove_individual_and_disconnect (self, old_individual);
1102 }
1103
1104 static void
1105 individual_store_dispose (GObject *object)
1106 {
1107   EmpathyIndividualStorePriv *priv = GET_PRIV (object);
1108   GList *individuals, *l;
1109
1110   if (priv->dispose_has_run)
1111     return;
1112   priv->dispose_has_run = TRUE;
1113
1114   /* Cancel any pending avatar load operations */
1115   for (l = priv->avatar_cancellables; l != NULL; l = l->next)
1116     {
1117       /* The cancellables are freed in individual_avatar_pixbuf_received_cb() */
1118       g_cancellable_cancel (G_CANCELLABLE (l->data));
1119     }
1120   g_list_free (priv->avatar_cancellables);
1121
1122   individuals = empathy_individual_manager_get_members (priv->manager);
1123   for (l = individuals; l; l = l->next)
1124     {
1125       individual_store_disconnect_individual (EMPATHY_INDIVIDUAL_STORE (object),
1126           FOLKS_INDIVIDUAL (l->data));
1127     }
1128   g_list_free (individuals);
1129
1130   g_signal_handlers_disconnect_by_func (priv->manager,
1131       G_CALLBACK (individual_store_member_renamed_cb), object);
1132   g_signal_handlers_disconnect_by_func (priv->manager,
1133       G_CALLBACK (individual_store_members_changed_cb), object);
1134   g_signal_handlers_disconnect_by_func (priv->manager,
1135       G_CALLBACK (individual_store_groups_changed_cb), object);
1136   g_object_unref (priv->manager);
1137
1138   if (priv->inhibit_active)
1139     {
1140       g_source_remove (priv->inhibit_active);
1141     }
1142
1143   if (priv->setup_idle_id != 0)
1144     {
1145       g_source_remove (priv->setup_idle_id);
1146     }
1147
1148   g_hash_table_destroy (priv->status_icons);
1149   g_hash_table_destroy (priv->folks_individual_cache);
1150   g_hash_table_destroy (priv->empathy_group_cache);
1151   G_OBJECT_CLASS (empathy_individual_store_parent_class)->dispose (object);
1152 }
1153
1154 static void
1155 individual_store_get_property (GObject *object,
1156     guint param_id,
1157     GValue *value,
1158     GParamSpec *pspec)
1159 {
1160   EmpathyIndividualStorePriv *priv;
1161
1162   priv = GET_PRIV (object);
1163
1164   switch (param_id)
1165     {
1166     case PROP_INDIVIDUAL_MANAGER:
1167       g_value_set_object (value, priv->manager);
1168       break;
1169     case PROP_SHOW_AVATARS:
1170       g_value_set_boolean (value, priv->show_avatars);
1171       break;
1172     case PROP_SHOW_PROTOCOLS:
1173       g_value_set_boolean (value, priv->show_protocols);
1174       break;
1175     case PROP_SHOW_GROUPS:
1176       g_value_set_boolean (value, priv->show_groups);
1177       break;
1178     case PROP_IS_COMPACT:
1179       g_value_set_boolean (value, priv->is_compact);
1180       break;
1181     case PROP_SORT_CRITERIUM:
1182       g_value_set_enum (value, priv->sort_criterium);
1183       break;
1184     default:
1185       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1186       break;
1187     };
1188 }
1189
1190 static void
1191 individual_store_set_property (GObject *object,
1192     guint param_id,
1193     const GValue *value,
1194     GParamSpec *pspec)
1195 {
1196   switch (param_id)
1197     {
1198     case PROP_INDIVIDUAL_MANAGER:
1199       individual_store_set_individual_manager (EMPATHY_INDIVIDUAL_STORE
1200           (object), g_value_get_object (value));
1201       break;
1202     case PROP_SHOW_AVATARS:
1203       empathy_individual_store_set_show_avatars (EMPATHY_INDIVIDUAL_STORE
1204           (object), g_value_get_boolean (value));
1205       break;
1206     case PROP_SHOW_PROTOCOLS:
1207       empathy_individual_store_set_show_protocols (EMPATHY_INDIVIDUAL_STORE
1208           (object), g_value_get_boolean (value));
1209       break;
1210     case PROP_SHOW_GROUPS:
1211       empathy_individual_store_set_show_groups (EMPATHY_INDIVIDUAL_STORE
1212           (object), g_value_get_boolean (value));
1213       break;
1214     case PROP_IS_COMPACT:
1215       empathy_individual_store_set_is_compact (EMPATHY_INDIVIDUAL_STORE
1216           (object), g_value_get_boolean (value));
1217       break;
1218     case PROP_SORT_CRITERIUM:
1219       empathy_individual_store_set_sort_criterium (EMPATHY_INDIVIDUAL_STORE
1220           (object), g_value_get_enum (value));
1221       break;
1222     default:
1223       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1224       break;
1225     };
1226 }
1227
1228 static void
1229 empathy_individual_store_class_init (EmpathyIndividualStoreClass *klass)
1230 {
1231   GObjectClass *object_class = G_OBJECT_CLASS (klass);
1232
1233   object_class->dispose = individual_store_dispose;
1234   object_class->get_property = individual_store_get_property;
1235   object_class->set_property = individual_store_set_property;
1236
1237   g_object_class_install_property (object_class,
1238       PROP_INDIVIDUAL_MANAGER,
1239       g_param_spec_object ("individual-manager",
1240           "The individual manager",
1241           "The individual manager",
1242           EMPATHY_TYPE_INDIVIDUAL_MANAGER,
1243           G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
1244   g_object_class_install_property (object_class,
1245       PROP_SHOW_AVATARS,
1246       g_param_spec_boolean ("show-avatars",
1247           "Show Avatars",
1248           "Whether contact list should display "
1249           "avatars for contacts", TRUE, G_PARAM_READWRITE));
1250   g_object_class_install_property (object_class,
1251       PROP_SHOW_PROTOCOLS,
1252       g_param_spec_boolean ("show-protocols",
1253           "Show Protocols",
1254           "Whether contact list should display "
1255           "protocols for contacts", FALSE, G_PARAM_READWRITE));
1256   g_object_class_install_property (object_class,
1257       PROP_SHOW_GROUPS,
1258       g_param_spec_boolean ("show-groups",
1259           "Show Groups",
1260           "Whether contact list should display "
1261           "contact groups", TRUE, G_PARAM_READWRITE));
1262   g_object_class_install_property (object_class,
1263       PROP_IS_COMPACT,
1264       g_param_spec_boolean ("is-compact",
1265           "Is Compact",
1266           "Whether the contact list is in compact mode or not",
1267           FALSE, G_PARAM_READWRITE));
1268
1269   g_object_class_install_property (object_class,
1270       PROP_SORT_CRITERIUM,
1271       g_param_spec_enum ("sort-criterium",
1272           "Sort citerium",
1273           "The sort criterium to use for sorting the contact list",
1274           EMPATHY_TYPE_INDIVIDUAL_STORE_SORT,
1275           EMPATHY_INDIVIDUAL_STORE_SORT_NAME, G_PARAM_READWRITE));
1276
1277   g_type_class_add_private (object_class,
1278       sizeof (EmpathyIndividualStorePriv));
1279 }
1280
1281 static gint
1282 get_position (const char **strv,
1283     const char *str)
1284 {
1285   int i;
1286
1287   for (i = 0; strv[i] != NULL; i++)
1288     {
1289       if (!tp_strdiff (strv[i], str))
1290         return i;
1291     }
1292
1293   return -1;
1294 }
1295
1296 static gint
1297 compare_separator_and_groups (gboolean is_separator_a,
1298     gboolean is_separator_b,
1299     const gchar *name_a,
1300     const gchar *name_b,
1301     FolksIndividual *individual_a,
1302     FolksIndividual *individual_b,
1303     gboolean fake_group_a,
1304     gboolean fake_group_b)
1305 {
1306   /* these two lists are the sorted list of fake groups to include at the
1307    * top and bottom of the roster */
1308   const char *top_groups[] = {
1309     EMPATHY_INDIVIDUAL_STORE_FAVORITE,
1310     NULL
1311   };
1312
1313   const char *bottom_groups[] = {
1314     EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
1315     NULL
1316   };
1317
1318   if (is_separator_a || is_separator_b)
1319     {
1320       /* We have at least one separator */
1321       if (is_separator_a)
1322         {
1323           return -1;
1324         }
1325       else if (is_separator_b)
1326         {
1327           return 1;
1328         }
1329     }
1330
1331   /* One group and one contact */
1332   if (!individual_a && individual_b)
1333     {
1334       return 1;
1335     }
1336   else if (individual_a && !individual_b)
1337     {
1338       return -1;
1339     }
1340   else if (!individual_a && !individual_b)
1341     {
1342       gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
1343
1344       a_in_top = fake_group_a && tp_strv_contains (top_groups, name_a);
1345       b_in_top = fake_group_b && tp_strv_contains (top_groups, name_b);
1346       a_in_bottom = fake_group_a && tp_strv_contains (bottom_groups, name_a);
1347       b_in_bottom = fake_group_b && tp_strv_contains (bottom_groups, name_b);
1348
1349       if (a_in_top && b_in_top)
1350         {
1351           /* compare positions */
1352           return CLAMP (get_position (top_groups, name_a) -
1353               get_position (top_groups, name_b), -1, 1);
1354         }
1355       else if (a_in_bottom && b_in_bottom)
1356         {
1357           /* compare positions */
1358           return CLAMP (get_position (bottom_groups, name_a) -
1359               get_position (bottom_groups, name_b), -1, 1);
1360         }
1361       else if (a_in_top || b_in_bottom)
1362         {
1363           return -1;
1364         }
1365       else if (b_in_top || a_in_bottom)
1366         {
1367           return 1;
1368         }
1369       else
1370         {
1371           return g_utf8_collate (name_a, name_b);
1372         }
1373     }
1374
1375   /* Two contacts, ordering depends of the sorting policy */
1376   return 0;
1377 }
1378
1379 static gint
1380 individual_store_contact_sort (FolksIndividual *individual_a,
1381     FolksIndividual *individual_b)
1382 {
1383   gint ret_val;
1384   EmpathyContact *contact_a = NULL, *contact_b = NULL;
1385   TpAccount *account_a, *account_b;
1386
1387   g_return_val_if_fail (individual_a != NULL || individual_b != NULL, 0);
1388
1389   /* alias */
1390   ret_val = g_utf8_collate (
1391       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_a)),
1392       folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual_b)));
1393
1394   if (ret_val != 0)
1395     goto out;
1396
1397   contact_a = empathy_contact_dup_from_folks_individual (individual_a);
1398   contact_b = empathy_contact_dup_from_folks_individual (individual_b);
1399   if (contact_a != NULL && contact_b != NULL)
1400     {
1401       account_a = empathy_contact_get_account (contact_a);
1402       account_b = empathy_contact_get_account (contact_b);
1403
1404       g_assert (account_a != NULL);
1405       g_assert (account_b != NULL);
1406
1407       /* protocol */
1408       ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
1409           tp_account_get_protocol (account_b));
1410
1411       if (ret_val != 0)
1412         goto out;
1413
1414       /* account ID */
1415       ret_val = g_strcmp0 (tp_proxy_get_object_path (account_a),
1416           tp_proxy_get_object_path (account_b));
1417
1418       if (ret_val != 0)
1419         goto out;
1420     }
1421
1422   /* identifier */
1423   ret_val = g_utf8_collate (folks_individual_get_id (individual_a),
1424       folks_individual_get_id (individual_b));
1425
1426 out:
1427   tp_clear_object (&contact_a);
1428   tp_clear_object (&contact_b);
1429
1430   return ret_val;
1431 }
1432
1433 static gint
1434 individual_store_state_sort_func (GtkTreeModel *model,
1435     GtkTreeIter *iter_a,
1436     GtkTreeIter *iter_b,
1437     gpointer user_data)
1438 {
1439   gint ret_val;
1440   FolksIndividual *individual_a, *individual_b;
1441   gchar *name_a, *name_b;
1442   gboolean is_separator_a, is_separator_b;
1443   gboolean fake_group_a, fake_group_b;
1444   FolksPresenceType folks_presence_type_a, folks_presence_type_b;
1445   TpConnectionPresenceType tp_presence_a, tp_presence_b;
1446
1447   gtk_tree_model_get (model, iter_a,
1448       EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1449       EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1450       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1451       EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1452   gtk_tree_model_get (model, iter_b,
1453       EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1454       EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1455       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1456       EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1457
1458   if (individual_a == NULL || individual_b == NULL)
1459     {
1460       ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1461           name_a, name_b, individual_a, individual_b, fake_group_a,
1462           fake_group_b);
1463       goto free_and_out;
1464     }
1465
1466   /* If we managed to get this far, we can start looking at
1467    * the presences.
1468    */
1469   folks_presence_type_a =
1470       folks_presence_details_get_presence_type (
1471           FOLKS_PRESENCE_DETAILS (individual_a));
1472   folks_presence_type_b =
1473       folks_presence_details_get_presence_type (
1474           FOLKS_PRESENCE_DETAILS (individual_b));
1475   tp_presence_a = empathy_folks_presence_type_to_tp (folks_presence_type_a);
1476   tp_presence_b = empathy_folks_presence_type_to_tp (folks_presence_type_b);
1477
1478   ret_val = -tp_connection_presence_type_cmp_availability (tp_presence_a,
1479       tp_presence_b);
1480
1481   if (ret_val == 0)
1482     {
1483       /* Fallback: compare by name et al. */
1484       ret_val = individual_store_contact_sort (individual_a, individual_b);
1485     }
1486
1487 free_and_out:
1488   g_free (name_a);
1489   g_free (name_b);
1490   tp_clear_object (&individual_a);
1491   tp_clear_object (&individual_b);
1492
1493   return ret_val;
1494 }
1495
1496 static gint
1497 individual_store_name_sort_func (GtkTreeModel *model,
1498     GtkTreeIter *iter_a,
1499     GtkTreeIter *iter_b,
1500     gpointer user_data)
1501 {
1502   gchar *name_a, *name_b;
1503   FolksIndividual *individual_a, *individual_b;
1504   gboolean is_separator_a = FALSE, is_separator_b = FALSE;
1505   gint ret_val;
1506   gboolean fake_group_a, fake_group_b;
1507
1508   gtk_tree_model_get (model, iter_a,
1509       EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_a,
1510       EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_a,
1511       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_a,
1512       EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_a, -1);
1513   gtk_tree_model_get (model, iter_b,
1514       EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name_b,
1515       EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual_b,
1516       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator_b,
1517       EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake_group_b, -1);
1518
1519   if (individual_a == NULL || individual_b == NULL)
1520     ret_val = compare_separator_and_groups (is_separator_a, is_separator_b,
1521         name_a, name_b, individual_a, individual_b, fake_group_a, fake_group_b);
1522   else
1523     ret_val = individual_store_contact_sort (individual_a, individual_b);
1524
1525   tp_clear_object (&individual_a);
1526   tp_clear_object (&individual_b);
1527   g_free (name_a);
1528   g_free (name_b);
1529
1530   return ret_val;
1531 }
1532
1533 static void
1534 individual_store_setup (EmpathyIndividualStore *self)
1535 {
1536   EmpathyIndividualStorePriv *priv;
1537   GType types[] = {
1538     GDK_TYPE_PIXBUF,            /* Status pixbuf */
1539     GDK_TYPE_PIXBUF,            /* Avatar pixbuf */
1540     G_TYPE_BOOLEAN,             /* Avatar pixbuf visible */
1541     G_TYPE_STRING,              /* Name */
1542     G_TYPE_UINT,                /* Presence type */
1543     G_TYPE_STRING,              /* Status string */
1544     G_TYPE_BOOLEAN,             /* Compact view */
1545     FOLKS_TYPE_INDIVIDUAL,      /* Individual type */
1546     G_TYPE_BOOLEAN,             /* Is group */
1547     G_TYPE_BOOLEAN,             /* Is active */
1548     G_TYPE_BOOLEAN,             /* Is online */
1549     G_TYPE_BOOLEAN,             /* Is separator */
1550     G_TYPE_BOOLEAN,             /* Can make audio calls */
1551     G_TYPE_BOOLEAN,             /* Can make video calls */
1552     G_TYPE_BOOLEAN,             /* Is a fake group */
1553     G_TYPE_STRV,                /* Client types */
1554     G_TYPE_UINT,                /* Event count */
1555   };
1556
1557   priv = GET_PRIV (self);
1558
1559   gtk_tree_store_set_column_types (GTK_TREE_STORE (self),
1560       EMPATHY_INDIVIDUAL_STORE_COL_COUNT, types);
1561
1562   /* Set up sorting */
1563   gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1564       EMPATHY_INDIVIDUAL_STORE_COL_NAME,
1565       individual_store_name_sort_func, self, NULL);
1566   gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (self),
1567       EMPATHY_INDIVIDUAL_STORE_COL_STATUS,
1568       individual_store_state_sort_func, self, NULL);
1569
1570   priv->sort_criterium = EMPATHY_INDIVIDUAL_STORE_SORT_NAME;
1571   empathy_individual_store_set_sort_criterium (self, priv->sort_criterium);
1572 }
1573
1574 static gboolean
1575 individual_store_inhibit_active_cb (EmpathyIndividualStore *self)
1576 {
1577   EmpathyIndividualStorePriv *priv;
1578
1579   priv = GET_PRIV (self);
1580
1581   priv->show_active = TRUE;
1582   priv->inhibit_active = 0;
1583
1584   return FALSE;
1585 }
1586
1587 static void
1588 g_queue_free_full_iter (gpointer data)
1589 {
1590   GQueue *queue = (GQueue *) data;
1591   g_queue_foreach (queue, (GFunc) gtk_tree_iter_free, NULL);
1592   g_queue_free (queue);
1593 }
1594
1595 static void
1596 empathy_individual_store_init (EmpathyIndividualStore *self)
1597 {
1598   EmpathyIndividualStorePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1599       EMPATHY_TYPE_INDIVIDUAL_STORE, EmpathyIndividualStorePriv);
1600
1601   self->priv = priv;
1602   priv->show_avatars = TRUE;
1603   priv->show_groups = TRUE;
1604   priv->show_protocols = FALSE;
1605   priv->inhibit_active =
1606       g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
1607       (GSourceFunc) individual_store_inhibit_active_cb, self);
1608   priv->status_icons =
1609       g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
1610   priv->folks_individual_cache = g_hash_table_new_full (NULL, NULL, NULL,
1611       g_queue_free_full_iter);
1612   priv->empathy_group_cache = g_hash_table_new_full (g_str_hash,
1613       g_str_equal, g_free, (GDestroyNotify) gtk_tree_iter_free);
1614   individual_store_setup (self);
1615 }
1616
1617 EmpathyIndividualStore *
1618 empathy_individual_store_new (EmpathyIndividualManager *manager)
1619 {
1620   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
1621
1622   return g_object_new (EMPATHY_TYPE_INDIVIDUAL_STORE,
1623       "individual-manager", manager, NULL);
1624 }
1625
1626 EmpathyIndividualManager *
1627 empathy_individual_store_get_manager (EmpathyIndividualStore *self)
1628 {
1629   EmpathyIndividualStorePriv *priv;
1630
1631   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), FALSE);
1632
1633   priv = GET_PRIV (self);
1634
1635   return priv->manager;
1636 }
1637
1638 gboolean
1639 empathy_individual_store_get_show_avatars (EmpathyIndividualStore *self)
1640 {
1641   EmpathyIndividualStorePriv *priv;
1642
1643   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1644
1645   priv = GET_PRIV (self);
1646
1647   return priv->show_avatars;
1648 }
1649
1650 static gboolean
1651 individual_store_update_list_mode_foreach (GtkTreeModel *model,
1652     GtkTreePath *path,
1653     GtkTreeIter *iter,
1654     EmpathyIndividualStore *self)
1655 {
1656   EmpathyIndividualStorePriv *priv;
1657   gboolean show_avatar = FALSE;
1658   FolksIndividual *individual;
1659   GdkPixbuf *pixbuf_status;
1660
1661   priv = GET_PRIV (self);
1662
1663   if (priv->show_avatars && !priv->is_compact)
1664     {
1665       show_avatar = TRUE;
1666     }
1667
1668   gtk_tree_model_get (model, iter,
1669       EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1670
1671   if (individual == NULL)
1672     {
1673       return FALSE;
1674     }
1675   /* get icon from hash_table */
1676   pixbuf_status =
1677       empathy_individual_store_get_individual_status_icon (self, individual);
1678
1679   gtk_tree_store_set (GTK_TREE_STORE (self), iter,
1680       EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
1681       EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
1682       EMPATHY_INDIVIDUAL_STORE_COL_COMPACT, priv->is_compact, -1);
1683
1684   g_object_unref (individual);
1685
1686   return FALSE;
1687 }
1688
1689 void
1690 empathy_individual_store_set_show_avatars (EmpathyIndividualStore *self,
1691     gboolean show_avatars)
1692 {
1693   EmpathyIndividualStorePriv *priv;
1694   GtkTreeModel *model;
1695
1696   g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1697
1698   priv = GET_PRIV (self);
1699
1700   priv->show_avatars = show_avatars;
1701
1702   model = GTK_TREE_MODEL (self);
1703
1704   gtk_tree_model_foreach (model,
1705       (GtkTreeModelForeachFunc)
1706       individual_store_update_list_mode_foreach, self);
1707
1708   g_object_notify (G_OBJECT (self), "show-avatars");
1709 }
1710
1711 gboolean
1712 empathy_individual_store_get_show_protocols (EmpathyIndividualStore *self)
1713 {
1714   EmpathyIndividualStorePriv *priv;
1715
1716   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1717
1718   priv = GET_PRIV (self);
1719
1720   return priv->show_protocols;
1721 }
1722
1723 void
1724 empathy_individual_store_set_show_protocols (EmpathyIndividualStore *self,
1725     gboolean show_protocols)
1726 {
1727   EmpathyIndividualStorePriv *priv;
1728   GtkTreeModel *model;
1729
1730   g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1731
1732   priv = GET_PRIV (self);
1733
1734   priv->show_protocols = show_protocols;
1735
1736   model = GTK_TREE_MODEL (self);
1737
1738   gtk_tree_model_foreach (model,
1739       (GtkTreeModelForeachFunc)
1740       individual_store_update_list_mode_foreach, self);
1741
1742   g_object_notify (G_OBJECT (self), "show-protocols");
1743 }
1744
1745 gboolean
1746 empathy_individual_store_get_show_groups (EmpathyIndividualStore *self)
1747 {
1748   EmpathyIndividualStorePriv *priv;
1749
1750   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1751
1752   priv = GET_PRIV (self);
1753
1754   return priv->show_groups;
1755 }
1756
1757 void
1758 empathy_individual_store_set_show_groups (EmpathyIndividualStore *self,
1759     gboolean show_groups)
1760 {
1761   EmpathyIndividualStorePriv *priv;
1762
1763   g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1764
1765   priv = GET_PRIV (self);
1766
1767   if (priv->show_groups == show_groups)
1768     {
1769       return;
1770     }
1771
1772   priv->show_groups = show_groups;
1773
1774   if (priv->setup_idle_id == 0)
1775     {
1776       /* Remove all contacts and add them back, not optimized but
1777        * that's the easy way :)
1778        *
1779        * This is only done if there's not a pending setup idle
1780        * callback, otherwise it will race and the contacts will get
1781        * added twice */
1782       GList *contacts;
1783
1784       gtk_tree_store_clear (GTK_TREE_STORE (self));
1785       /* Also clear the cache */
1786       g_hash_table_remove_all (priv->folks_individual_cache);
1787       g_hash_table_remove_all (priv->empathy_group_cache);
1788
1789       contacts = empathy_individual_manager_get_members (priv->manager);
1790
1791       individual_store_members_changed_cb (priv->manager,
1792           "re-adding members: toggled group visibility",
1793           contacts, NULL, 0, self);
1794       g_list_free (contacts);
1795     }
1796
1797   g_object_notify (G_OBJECT (self), "show-groups");
1798 }
1799
1800 gboolean
1801 empathy_individual_store_get_is_compact (EmpathyIndividualStore *self)
1802 {
1803   EmpathyIndividualStorePriv *priv;
1804
1805   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), TRUE);
1806
1807   priv = GET_PRIV (self);
1808
1809   return priv->is_compact;
1810 }
1811
1812 void
1813 empathy_individual_store_set_is_compact (EmpathyIndividualStore *self,
1814     gboolean is_compact)
1815 {
1816   EmpathyIndividualStorePriv *priv;
1817   GtkTreeModel *model;
1818
1819   g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1820
1821   priv = GET_PRIV (self);
1822
1823   priv->is_compact = is_compact;
1824
1825   model = GTK_TREE_MODEL (self);
1826
1827   gtk_tree_model_foreach (model,
1828       (GtkTreeModelForeachFunc)
1829       individual_store_update_list_mode_foreach, self);
1830
1831   g_object_notify (G_OBJECT (self), "is-compact");
1832 }
1833
1834 EmpathyIndividualStoreSort
1835 empathy_individual_store_get_sort_criterium (EmpathyIndividualStore *self)
1836 {
1837   EmpathyIndividualStorePriv *priv;
1838
1839   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self), 0);
1840
1841   priv = GET_PRIV (self);
1842
1843   return priv->sort_criterium;
1844 }
1845
1846 void
1847 empathy_individual_store_set_sort_criterium (EmpathyIndividualStore *self,
1848     EmpathyIndividualStoreSort sort_criterium)
1849 {
1850   EmpathyIndividualStorePriv *priv;
1851
1852   g_return_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (self));
1853
1854   priv = GET_PRIV (self);
1855
1856   priv->sort_criterium = sort_criterium;
1857
1858   switch (sort_criterium)
1859     {
1860     case EMPATHY_INDIVIDUAL_STORE_SORT_STATE:
1861       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1862           EMPATHY_INDIVIDUAL_STORE_COL_STATUS, GTK_SORT_ASCENDING);
1863       break;
1864
1865     case EMPATHY_INDIVIDUAL_STORE_SORT_NAME:
1866       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
1867           EMPATHY_INDIVIDUAL_STORE_COL_NAME, GTK_SORT_ASCENDING);
1868       break;
1869
1870     default:
1871       g_assert_not_reached ();
1872     }
1873
1874   g_object_notify (G_OBJECT (self), "sort-criterium");
1875 }
1876
1877 gboolean
1878 empathy_individual_store_row_separator_func (GtkTreeModel *model,
1879     GtkTreeIter *iter,
1880     gpointer data)
1881 {
1882   gboolean is_separator = FALSE;
1883
1884   g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
1885
1886   gtk_tree_model_get (model, iter,
1887       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator, -1);
1888
1889   return is_separator;
1890 }
1891
1892 gchar *
1893 empathy_individual_store_get_parent_group (GtkTreeModel *model,
1894     GtkTreePath *path,
1895     gboolean *path_is_group,
1896     gboolean *is_fake_group)
1897 {
1898   GtkTreeIter parent_iter, iter;
1899   gchar *name = NULL;
1900   gboolean is_group;
1901   gboolean fake = FALSE;
1902
1903   g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1904
1905   if (path_is_group)
1906     {
1907       *path_is_group = FALSE;
1908     }
1909
1910   if (!gtk_tree_model_get_iter (model, &iter, path))
1911     {
1912       return NULL;
1913     }
1914
1915   gtk_tree_model_get (model, &iter,
1916       EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1917       EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1918
1919   if (!is_group)
1920     {
1921       g_free (name);
1922       name = NULL;
1923
1924       if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1925         {
1926           return NULL;
1927         }
1928
1929       iter = parent_iter;
1930
1931       gtk_tree_model_get (model, &iter,
1932           EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1933           EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1934           EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
1935       if (!is_group)
1936         {
1937           g_free (name);
1938           return NULL;
1939         }
1940     }
1941
1942   if (path_is_group)
1943     {
1944       *path_is_group = TRUE;
1945     }
1946
1947   if (is_fake_group != NULL)
1948     *is_fake_group = fake;
1949
1950   return name;
1951 }
1952
1953 static GdkPixbuf *
1954 individual_store_get_individual_status_icon_with_icon_name (
1955     EmpathyIndividualStore *self,
1956     FolksIndividual *individual,
1957     const gchar *status_icon_name)
1958 {
1959   GdkPixbuf *pixbuf_status;
1960   EmpathyIndividualStorePriv *priv;
1961   const gchar *protocol_name = NULL;
1962   gchar *icon_name = NULL;
1963   GeeSet *personas;
1964   GeeIterator *iter;
1965   guint contact_count = 0;
1966   EmpathyContact *contact = NULL;
1967   gboolean show_protocols_here;
1968
1969   priv = GET_PRIV (self);
1970
1971   personas = folks_individual_get_personas (individual);
1972   iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1973   while (gee_iterator_next (iter))
1974     {
1975       FolksPersona *persona = gee_iterator_get (iter);
1976       if (empathy_folks_persona_is_interesting (persona))
1977         contact_count++;
1978
1979       g_clear_object (&persona);
1980
1981       if (contact_count > 1)
1982         break;
1983     }
1984   g_clear_object (&iter);
1985
1986   show_protocols_here = (priv->show_protocols && (contact_count == 1));
1987   if (show_protocols_here)
1988     {
1989       contact = empathy_contact_dup_from_folks_individual (individual);
1990       if (contact != NULL)
1991         {
1992           protocol_name = empathy_protocol_name_for_contact (contact);
1993           icon_name = g_strdup_printf ("%s-%s", status_icon_name,
1994               protocol_name);
1995         }
1996       else
1997         {
1998           g_warning ("Cannot retrieve contact from individual '%s'",
1999               folks_alias_details_get_alias (
2000                 FOLKS_ALIAS_DETAILS (individual)));
2001
2002           return NULL;
2003         }
2004     }
2005   else
2006     {
2007       icon_name = g_strdup_printf ("%s", status_icon_name);
2008     }
2009
2010   pixbuf_status = g_hash_table_lookup (priv->status_icons, icon_name);
2011
2012   if (pixbuf_status == NULL)
2013     {
2014       pixbuf_status =
2015           empathy_pixbuf_contact_status_icon_with_icon_name (contact,
2016           status_icon_name, show_protocols_here);
2017
2018       if (pixbuf_status != NULL)
2019         {
2020           /* pass the reference to the hash table */
2021           g_hash_table_insert (priv->status_icons,
2022               g_strdup (icon_name), pixbuf_status);
2023         }
2024     }
2025
2026   g_free (icon_name);
2027   tp_clear_object (&contact);
2028
2029   return pixbuf_status;
2030 }
2031
2032 GdkPixbuf *
2033 empathy_individual_store_get_individual_status_icon (
2034     EmpathyIndividualStore *self,
2035     FolksIndividual *individual)
2036 {
2037   GdkPixbuf *pixbuf_status = NULL;
2038   const gchar *status_icon_name = NULL;
2039
2040   status_icon_name = empathy_icon_name_for_individual (individual);
2041   if (status_icon_name == NULL)
2042     return NULL;
2043
2044   pixbuf_status =
2045       individual_store_get_individual_status_icon_with_icon_name (self,
2046       individual, status_icon_name);
2047
2048   return pixbuf_status;
2049 }