]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-roster-view.c
roster-view: clear the view when disposing
[empathy.git] / libempathy-gtk / empathy-roster-view.c
1 #include "config.h"
2
3 #include "empathy-roster-view.h"
4
5 #include <glib/gi18n-lib.h>
6
7 #include <libempathy/empathy-contact-groups.h>
8
9 #include <libempathy-gtk/empathy-roster-contact.h>
10 #include <libempathy-gtk/empathy-roster-group.h>
11 #include <libempathy-gtk/empathy-ui-utils.h>
12
13 #include <libempathy/empathy-utils.h>
14
15 G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX)
16
17 /* Flashing delay for icons (milliseconds). */
18 #define FLASH_TIMEOUT 500
19
20 enum
21 {
22   PROP_MODEL = 1,
23   PROP_SHOW_OFFLINE,
24   PROP_SHOW_GROUPS,
25   PROP_EMPTY,
26   N_PROPS
27 };
28
29 enum
30 {
31   SIG_INDIVIDUAL_ACTIVATED,
32   SIG_POPUP_INDIVIDUAL_MENU,
33   SIG_EVENT_ACTIVATED,
34   SIG_INDIVIDUAL_TOOLTIP,
35   LAST_SIGNAL
36 };
37
38 static guint signals[LAST_SIGNAL];
39
40 #define NO_GROUP "X-no-group"
41
42 struct _EmpathyRosterViewPriv
43 {
44   /* FolksIndividual (borrowed) -> GHashTable (
45    * (gchar * group_name) -> EmpathyRosterContact (borrowed))
46    *
47    * When not using groups, this hash just have one element mapped
48    * from the special NO_GROUP key. We could use it as a set but
49    * I prefer to stay coherent in the way this hash is managed.
50    */
51   GHashTable *roster_contacts;
52   /* (gchar *group_name) -> EmpathyRosterGroup (borrowed) */
53   GHashTable *roster_groups;
54   /* Hash of the EmpathyRosterContact currently displayed */
55   GHashTable *displayed_contacts;
56
57   guint last_event_id;
58   /* queue of (Event *). The most recent events are in the head of the queue
59    * so we always display the icon of the oldest one. */
60   GQueue *events;
61   guint flash_id;
62   gboolean display_flash_event;
63
64   gboolean show_offline;
65   gboolean show_groups;
66   gboolean empty;
67
68   EmpathyLiveSearch *search;
69
70   EmpathyRosterModel *model;
71 };
72
73 typedef struct
74 {
75   guint id;
76   FolksIndividual *individual;
77   gchar *icon;
78   gpointer user_data;
79 } Event;
80
81 static Event *
82 event_new (guint id,
83     FolksIndividual *individual,
84     const gchar *icon,
85     gpointer user_data)
86 {
87   Event *event = g_slice_new (Event);
88
89   event->id = id;
90   event->individual = g_object_ref (individual);
91   event->icon = g_strdup (icon);
92   event->user_data = user_data;
93   return event;
94 }
95
96 static void
97 event_free (gpointer data)
98 {
99   Event *event = data;
100   g_object_unref (event->individual);
101   g_free (event->icon);
102
103   g_slice_free (Event, event);
104 }
105
106 static void
107 empathy_roster_view_get_property (GObject *object,
108     guint property_id,
109     GValue *value,
110     GParamSpec *pspec)
111 {
112   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
113
114   switch (property_id)
115     {
116       case PROP_MODEL:
117         g_value_set_object (value, self->priv->model);
118         break;
119       case PROP_SHOW_OFFLINE:
120         g_value_set_boolean (value, self->priv->show_offline);
121         break;
122       case PROP_SHOW_GROUPS:
123         g_value_set_boolean (value, self->priv->show_groups);
124         break;
125       case PROP_EMPTY:
126         g_value_set_boolean (value, self->priv->empty);
127         break;
128       default:
129         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
130         break;
131     }
132 }
133
134 static void
135 empathy_roster_view_set_property (GObject *object,
136     guint property_id,
137     const GValue *value,
138     GParamSpec *pspec)
139 {
140   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
141
142   switch (property_id)
143     {
144       case PROP_MODEL:
145         g_assert (self->priv->model == NULL);
146         self->priv->model = g_value_dup_object (value);
147         break;
148       case PROP_SHOW_OFFLINE:
149         empathy_roster_view_show_offline (self, g_value_get_boolean (value));
150         break;
151       case PROP_SHOW_GROUPS:
152         empathy_roster_view_show_groups (self, g_value_get_boolean (value));
153         break;
154       default:
155         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
156         break;
157     }
158 }
159
160 static void
161 roster_contact_changed_cb (GtkWidget *child,
162     GParamSpec *spec,
163     EmpathyRosterView *self)
164 {
165   egg_list_box_child_changed (EGG_LIST_BOX (self), child);
166 }
167
168 static GtkWidget *
169 add_roster_contact (EmpathyRosterView *self,
170     FolksIndividual *individual,
171     const gchar *group)
172 {
173   GtkWidget *contact;
174
175   contact = empathy_roster_contact_new (individual, group);
176
177   /* Need to refilter if online is changed */
178   g_signal_connect (contact, "notify::online",
179       G_CALLBACK (roster_contact_changed_cb), self);
180
181   /* Need to resort if alias is changed */
182   g_signal_connect (contact, "notify::alias",
183       G_CALLBACK (roster_contact_changed_cb), self);
184
185   gtk_widget_show (contact);
186   gtk_container_add (GTK_CONTAINER (self), contact);
187
188   return contact;
189 }
190
191 static void
192 group_expanded_cb (EmpathyRosterGroup *group,
193     GParamSpec *spec,
194     EmpathyRosterView *self)
195 {
196   GList *widgets, *l;
197
198   widgets = empathy_roster_group_get_widgets (group);
199   for (l = widgets; l != NULL; l = g_list_next (l))
200     {
201       egg_list_box_child_changed (EGG_LIST_BOX (self), l->data);
202     }
203
204   g_list_free (widgets);
205
206   empathy_contact_group_set_expanded (empathy_roster_group_get_name (group),
207       gtk_expander_get_expanded (GTK_EXPANDER (group)));
208 }
209
210 static EmpathyRosterGroup *
211 lookup_roster_group (EmpathyRosterView *self,
212     const gchar *group)
213 {
214   return g_hash_table_lookup (self->priv->roster_groups, group);
215 }
216
217 static EmpathyRosterGroup *
218 ensure_roster_group (EmpathyRosterView *self,
219     const gchar *group)
220 {
221   GtkWidget *roster_group;
222
223   roster_group = (GtkWidget *) lookup_roster_group (self, group);
224   if (roster_group != NULL)
225     return EMPATHY_ROSTER_GROUP (roster_group);
226
227   if (!tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
228     roster_group = empathy_roster_group_new (group, "emblem-favorite-symbolic");
229   else if (!tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_PEOPLE_NEARBY))
230     roster_group = empathy_roster_group_new (group, "im-local-xmpp");
231   else
232     roster_group = empathy_roster_group_new (group, NULL);
233
234   gtk_expander_set_expanded (GTK_EXPANDER (roster_group),
235       empathy_contact_group_get_expanded (group));
236
237   g_signal_connect (roster_group, "notify::expanded",
238       G_CALLBACK (group_expanded_cb), self);
239
240   gtk_widget_show (roster_group);
241   gtk_container_add (GTK_CONTAINER (self), roster_group);
242
243   g_hash_table_insert (self->priv->roster_groups, g_strdup (group),
244       roster_group);
245
246   return EMPATHY_ROSTER_GROUP (roster_group);
247 }
248
249 static void
250 update_empty (EmpathyRosterView *self,
251     gboolean empty)
252 {
253   if (self->priv->empty == empty)
254     return;
255
256   self->priv->empty = empty;
257   g_object_notify (G_OBJECT (self), "empty");
258 }
259
260 static gboolean filter_group (EmpathyRosterView *self,
261     EmpathyRosterGroup *group);
262
263 static gboolean
264 at_least_one_group_displayed (EmpathyRosterView *self)
265 {
266   GHashTableIter iter;
267   gpointer v;
268
269   g_hash_table_iter_init (&iter, self->priv->roster_groups);
270   while (g_hash_table_iter_next (&iter, NULL, &v))
271     {
272       EmpathyRosterGroup *group = EMPATHY_ROSTER_GROUP (v);
273
274       if (filter_group (self, group))
275         return TRUE;
276     }
277
278   return FALSE;
279 }
280
281 static void
282 check_if_empty (EmpathyRosterView *self)
283 {
284   /* Roster is considered as empty if there is no contact *and* no group
285    * currently displayed. */
286   if (g_hash_table_size (self->priv->displayed_contacts) != 0 ||
287       at_least_one_group_displayed (self))
288     {
289       update_empty (self, FALSE);
290       return;
291     }
292
293   update_empty (self, TRUE);
294 }
295
296 static void
297 update_group_widgets (EmpathyRosterView *self,
298     EmpathyRosterGroup *group,
299     EmpathyRosterContact *contact,
300     gboolean add)
301 {
302   guint old_count, count;
303
304   old_count = empathy_roster_group_get_widgets_count (group);
305
306   if (add)
307     count = empathy_roster_group_add_widget (group, GTK_WIDGET (contact));
308   else
309     count = empathy_roster_group_remove_widget (group, GTK_WIDGET (contact));
310
311   if (count != old_count)
312     {
313       egg_list_box_child_changed (EGG_LIST_BOX (self), GTK_WIDGET (group));
314
315       check_if_empty (self);
316     }
317 }
318
319 static void
320 add_to_group (EmpathyRosterView *self,
321     FolksIndividual *individual,
322     const gchar *group)
323 {
324   GtkWidget *contact;
325   GHashTable *contacts;
326   EmpathyRosterGroup *roster_group = NULL;
327
328   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
329   if (contacts == NULL)
330     return;
331
332   if (g_hash_table_lookup (contacts, group) != NULL)
333     return;
334
335   if (tp_strdiff (group, NO_GROUP))
336     roster_group = ensure_roster_group (self, group);
337
338   contact = add_roster_contact (self, individual, group);
339   g_hash_table_insert (contacts, g_strdup (group), contact);
340
341   if (roster_group != NULL)
342     {
343       update_group_widgets (self, roster_group,
344           EMPATHY_ROSTER_CONTACT (contact), TRUE);
345     }
346 }
347
348 static void
349 individual_favourite_change_cb (FolksIndividual *individual,
350     GParamSpec *spec,
351     EmpathyRosterView *self)
352 {
353   /* We may have to refilter the contact as only favorite contacts are always
354    * displayed regardless of their presence. */
355   GHashTable *contacts;
356   GtkWidget *contact;
357
358   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
359   if (contacts == NULL)
360     return;
361
362   if (self->priv->show_groups)
363     contact = g_hash_table_lookup (contacts,
364         EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP);
365   else
366     contact = g_hash_table_lookup (contacts, NO_GROUP);
367
368   if (contact == NULL)
369     return;
370
371   egg_list_box_child_changed (EGG_LIST_BOX (self), contact);
372 }
373
374 static void
375 individual_added (EmpathyRosterView *self,
376     FolksIndividual *individual)
377 {
378   GHashTable *contacts;
379
380   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
381   if (contacts != NULL)
382     return;
383
384   contacts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
385
386   g_hash_table_insert (self->priv->roster_contacts, individual, contacts);
387
388   if (!self->priv->show_groups)
389     {
390       add_to_group (self, individual, NO_GROUP);
391     }
392   else
393     {
394       GList *groups, *l;
395
396       groups = empathy_roster_model_get_groups_for_individual (self->priv->model,
397           individual);
398
399       if (g_list_length (groups) > 0)
400         {
401           for (l = groups; l != NULL; l = g_list_next (l))
402             {
403               add_to_group (self, individual, l->data);
404             }
405         }
406       else
407         {
408           /* No group, adds to Ungrouped */
409           add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
410         }
411
412       g_list_free (groups);
413     }
414
415   tp_g_signal_connect_object (individual, "notify::is-favourite",
416       G_CALLBACK (individual_favourite_change_cb), self, 0);
417 }
418
419 static void
420 set_event_icon_on_individual (EmpathyRosterView *self,
421     FolksIndividual *individual,
422     const gchar *icon)
423 {
424   GHashTable *contacts;
425   GHashTableIter iter;
426   gpointer v;
427
428   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
429   if (contacts == NULL)
430     return;
431
432   g_hash_table_iter_init (&iter, contacts);
433   while (g_hash_table_iter_next (&iter, NULL, &v))
434     {
435       EmpathyRosterContact *contact =v;
436
437       empathy_roster_contact_set_event_icon (contact, icon);
438     }
439 }
440
441 static void
442 flash_event (Event *event,
443     EmpathyRosterView *self)
444 {
445   set_event_icon_on_individual (self, event->individual, event->icon);
446 }
447
448 static void
449 unflash_event (Event *event,
450     EmpathyRosterView *self)
451 {
452   set_event_icon_on_individual (self, event->individual, NULL);
453 }
454
455 static gboolean
456 flash_cb (gpointer data)
457 {
458   EmpathyRosterView *self = data;
459
460   if (self->priv->display_flash_event)
461     {
462       g_queue_foreach (self->priv->events, (GFunc) flash_event, self);
463       self->priv->display_flash_event = FALSE;
464     }
465   else
466     {
467       g_queue_foreach (self->priv->events, (GFunc) unflash_event, self);
468       self->priv->display_flash_event = TRUE;
469     }
470
471   return TRUE;
472 }
473
474 static void
475 start_flashing (EmpathyRosterView *self)
476 {
477   if (self->priv->flash_id != 0)
478     return;
479
480   self->priv->display_flash_event = TRUE;
481
482   self->priv->flash_id = g_timeout_add (FLASH_TIMEOUT,
483       flash_cb, self);
484 }
485
486 static void
487 stop_flashing (EmpathyRosterView *self)
488 {
489   if (self->priv->flash_id == 0)
490     return;
491
492   g_source_remove (self->priv->flash_id);
493   self->priv->flash_id = 0;
494 }
495
496 static void
497 remove_event (EmpathyRosterView *self,
498     Event *event)
499 {
500   unflash_event (event, self);
501   g_queue_remove (self->priv->events, event);
502
503   if (g_queue_get_length (self->priv->events) == 0)
504     {
505       stop_flashing (self);
506     }
507 }
508
509 static void
510 remove_all_individual_event (EmpathyRosterView *self,
511     FolksIndividual *individual)
512 {
513   GList *l;
514
515   for (l = g_queue_peek_head_link (self->priv->events); l != NULL;
516       l = g_list_next (l))
517     {
518       Event *event = l->data;
519
520       if (event->individual == individual)
521         {
522           remove_event (self, event);
523           return;
524         }
525     }
526 }
527
528 static void
529 individual_removed (EmpathyRosterView *self,
530     FolksIndividual *individual)
531 {
532   GHashTable *contacts;
533   GHashTableIter iter;
534   gpointer key, value;
535
536   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
537   if (contacts == NULL)
538     return;
539
540   remove_all_individual_event (self, individual);
541
542   g_hash_table_iter_init (&iter, contacts);
543   while (g_hash_table_iter_next (&iter, &key, &value))
544     {
545       const gchar *group_name = key;
546       GtkWidget *contact = value;
547       EmpathyRosterGroup *group;
548
549       group = lookup_roster_group (self, group_name);
550       if (group != NULL)
551         {
552           update_group_widgets (self, group,
553               EMPATHY_ROSTER_CONTACT (contact), FALSE);
554         }
555
556       gtk_container_remove (GTK_CONTAINER (self), contact);
557     }
558
559   g_hash_table_remove (self->priv->roster_contacts, individual);
560 }
561
562 static void
563 individual_added_cb (EmpathyRosterModel *model,
564     FolksIndividual *individual,
565     EmpathyRosterView *self)
566 {
567   individual_added (self, individual);
568 }
569
570 static void
571 individual_removed_cb (EmpathyRosterModel *model,
572     FolksIndividual *individual,
573     EmpathyRosterView *self)
574 {
575   individual_removed (self, individual);
576 }
577
578 static gboolean
579 contact_in_top (EmpathyRosterView *self,
580     EmpathyRosterContact *contact)
581 {
582   if (!self->priv->show_groups)
583     {
584       /* Always display top contacts in non-group mode. */
585       GList *groups;
586       FolksIndividual *individual;
587       gboolean result = FALSE;
588
589       individual = empathy_roster_contact_get_individual (contact);
590
591       groups = empathy_roster_model_get_groups_for_individual (
592           self->priv->model, individual);
593
594       if (g_list_find_custom (groups, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP,
595             (GCompareFunc) g_strcmp0) != NULL)
596         result = TRUE;
597
598       g_list_free (groups);
599
600       return result;
601     }
602
603   if (!tp_strdiff (empathy_roster_contact_get_group (contact),
604           EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
605     /* If we are displaying contacts, we only want to *always* display the
606      * RosterContact which is displayed at the top; not the ones displayed in
607      * the 'normal' group sections */
608     return TRUE;
609
610   return FALSE;
611 }
612
613 static gint
614 compare_roster_contacts_by_alias (EmpathyRosterContact *a,
615     EmpathyRosterContact *b)
616 {
617   FolksIndividual *ind_a, *ind_b;
618   const gchar *alias_a, *alias_b;
619
620   ind_a = empathy_roster_contact_get_individual (a);
621   ind_b = empathy_roster_contact_get_individual (b);
622
623   alias_a = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_a));
624   alias_b = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_b));
625
626   return g_ascii_strcasecmp (alias_a, alias_b);
627 }
628
629 static gint
630 compare_roster_contacts_no_group (EmpathyRosterView *self,
631     EmpathyRosterContact *a,
632     EmpathyRosterContact *b)
633 {
634   gboolean top_a, top_b;
635
636   top_a = contact_in_top (self, a);
637   top_b = contact_in_top (self, b);
638
639   if (top_a == top_b)
640     /* Both contacts are in the top of the roster (or not). Sort them
641      * alphabetically */
642     return compare_roster_contacts_by_alias (a, b);
643   else if (top_a)
644     return -1;
645   else
646     return 1;
647 }
648
649 static gint
650 compare_group_names (const gchar *group_a,
651     const gchar *group_b)
652 {
653   if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
654     return -1;
655
656   if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
657     return 1;
658
659   if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
660     return 1;
661   else if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
662     return -1;
663
664   return g_ascii_strcasecmp (group_a, group_b);
665 }
666
667 static gint
668 compare_roster_contacts_with_groups (EmpathyRosterView *self,
669     EmpathyRosterContact *a,
670     EmpathyRosterContact *b)
671 {
672   const gchar *group_a, *group_b;
673
674   group_a = empathy_roster_contact_get_group (a);
675   group_b = empathy_roster_contact_get_group (b);
676
677   if (!tp_strdiff (group_a, group_b))
678     /* Same group, compare the contacts */
679     return compare_roster_contacts_by_alias (a, b);
680
681   /* Sort by group */
682   return compare_group_names (group_a, group_b);
683 }
684
685 static gint
686 compare_roster_contacts (EmpathyRosterView *self,
687     EmpathyRosterContact *a,
688     EmpathyRosterContact *b)
689 {
690   if (!self->priv->show_groups)
691     return compare_roster_contacts_no_group (self, a, b);
692   else
693     return compare_roster_contacts_with_groups (self, a, b);
694 }
695
696 static gint
697 compare_roster_groups (EmpathyRosterGroup *a,
698     EmpathyRosterGroup *b)
699 {
700   const gchar *name_a, *name_b;
701
702   name_a = empathy_roster_group_get_name (a);
703   name_b = empathy_roster_group_get_name (b);
704
705   return compare_group_names (name_a, name_b);
706 }
707
708 static gint
709 compare_contact_group (EmpathyRosterContact *contact,
710     EmpathyRosterGroup *group)
711 {
712   const char *contact_group, *group_name;
713
714   contact_group = empathy_roster_contact_get_group (contact);
715   group_name = empathy_roster_group_get_name (group);
716
717   if (!tp_strdiff (contact_group, group_name))
718     /* @contact is in @group, @group has to be displayed first */
719     return 1;
720
721   /* @contact is in a different group, sort by group name */
722   return compare_group_names (contact_group, group_name);
723 }
724
725 static gint
726 roster_view_sort (gconstpointer a,
727     gconstpointer b,
728     gpointer user_data)
729 {
730   EmpathyRosterView *self = user_data;
731
732   if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_CONTACT (b))
733     return compare_roster_contacts (self, EMPATHY_ROSTER_CONTACT (a),
734         EMPATHY_ROSTER_CONTACT (b));
735   else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_GROUP (b))
736     return compare_roster_groups (EMPATHY_ROSTER_GROUP (a),
737         EMPATHY_ROSTER_GROUP (b));
738   else if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_GROUP (b))
739     return compare_contact_group (EMPATHY_ROSTER_CONTACT (a),
740         EMPATHY_ROSTER_GROUP (b));
741   else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_CONTACT (b))
742     return -1 * compare_contact_group (EMPATHY_ROSTER_CONTACT (b),
743         EMPATHY_ROSTER_GROUP (a));
744
745   g_return_val_if_reached (0);
746 }
747
748 static void
749 update_separator (GtkWidget **separator,
750     GtkWidget *child,
751     GtkWidget *before,
752     gpointer user_data)
753 {
754   if (before == NULL)
755     {
756       /* No separator before the first row */
757       g_clear_object (separator);
758       return;
759     }
760
761   if (*separator != NULL)
762     return;
763
764   *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
765   g_object_ref_sink (*separator);
766 }
767
768 static gboolean
769 is_searching (EmpathyRosterView *self)
770 {
771   if (self->priv->search == NULL)
772     return FALSE;
773
774   return gtk_widget_get_visible (GTK_WIDGET (self->priv->search));
775 }
776
777 static void
778 add_to_displayed (EmpathyRosterView *self,
779     EmpathyRosterContact *contact)
780 {
781   FolksIndividual *individual;
782   GHashTable *contacts;
783   GHashTableIter iter;
784   gpointer k;
785
786   if (g_hash_table_lookup (self->priv->displayed_contacts, contact) != NULL)
787     return;
788
789   g_hash_table_add (self->priv->displayed_contacts, contact);
790   update_empty (self, FALSE);
791
792   /* Groups of this contact may now be displayed if we just displays the first
793    * child in this group. */
794
795   if (!self->priv->show_groups)
796     return;
797
798   individual = empathy_roster_contact_get_individual (contact);
799   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
800   if (contacts == NULL)
801     return;
802
803   g_hash_table_iter_init (&iter, contacts);
804   while (g_hash_table_iter_next (&iter, &k, NULL))
805     {
806       const gchar *group_name = k;
807       GtkWidget *group;
808
809       group = g_hash_table_lookup (self->priv->roster_groups, group_name);
810       if (group == NULL)
811         continue;
812
813       egg_list_box_child_changed (EGG_LIST_BOX (self), group);
814     }
815 }
816
817 static void
818 remove_from_displayed (EmpathyRosterView *self,
819     EmpathyRosterContact *contact)
820 {
821   g_hash_table_remove (self->priv->displayed_contacts, contact);
822
823   check_if_empty (self);
824 }
825
826 static gboolean
827 contact_is_favorite (EmpathyRosterContact *contact)
828 {
829   FolksIndividual *individual;
830
831   individual = empathy_roster_contact_get_individual (contact);
832
833   return folks_favourite_details_get_is_favourite (
834       FOLKS_FAVOURITE_DETAILS (individual));
835 }
836
837 /**
838  * check if @contact should be displayed according to @self's current status
839  * and without consideration for the state of @contact's groups.
840  */
841 static gboolean
842 contact_should_be_displayed (EmpathyRosterView *self,
843     EmpathyRosterContact *contact)
844 {
845   if (is_searching (self))
846     {
847       FolksIndividual *individual;
848
849       individual = empathy_roster_contact_get_individual (contact);
850
851       return empathy_individual_match_string (individual,
852           empathy_live_search_get_text (self->priv->search),
853           empathy_live_search_get_words (self->priv->search));
854     }
855
856   if (self->priv->show_offline)
857       return TRUE;
858
859   if (contact_in_top (self, contact) &&
860       contact_is_favorite (contact))
861     /* Favorite top contacts are always displayed */
862     return TRUE;
863
864   return empathy_roster_contact_is_online (contact);
865 }
866
867
868 static gboolean
869 filter_contact (EmpathyRosterView *self,
870     EmpathyRosterContact *contact)
871 {
872   gboolean displayed;
873
874   displayed = contact_should_be_displayed (self, contact);
875
876   if (self->priv->show_groups)
877     {
878       const gchar *group_name;
879       EmpathyRosterGroup *group;
880
881       group_name = empathy_roster_contact_get_group (contact);
882       group = lookup_roster_group (self, group_name);
883
884       if (group != NULL)
885         {
886           /* When searching, always display even if the group is closed */
887           if (!is_searching (self) &&
888               !gtk_expander_get_expanded (GTK_EXPANDER (group)))
889             displayed = FALSE;
890         }
891     }
892
893   if (displayed)
894     {
895       add_to_displayed (self, contact);
896     }
897   else
898     {
899       remove_from_displayed (self, contact);
900     }
901
902   return displayed;
903 }
904
905 static gboolean
906 filter_group (EmpathyRosterView *self,
907     EmpathyRosterGroup *group)
908 {
909   GList *widgets, *l;
910
911   /* Display the group if it contains at least one displayed contact */
912   widgets = empathy_roster_group_get_widgets (group);
913   for (l = widgets; l != NULL; l = g_list_next (l))
914     {
915       EmpathyRosterContact *contact = l->data;
916
917       if (contact_should_be_displayed (self, contact))
918         return TRUE;
919     }
920
921   return FALSE;
922 }
923
924 static gboolean
925 filter_list (GtkWidget *child,
926     gpointer user_data)
927 {
928   EmpathyRosterView *self = user_data;
929
930   if (EMPATHY_IS_ROSTER_CONTACT (child))
931     return filter_contact (self, EMPATHY_ROSTER_CONTACT (child));
932
933   else if (EMPATHY_IS_ROSTER_GROUP (child))
934     return filter_group (self, EMPATHY_ROSTER_GROUP (child));
935
936   g_return_val_if_reached (FALSE);
937 }
938
939 static void
940 populate_view (EmpathyRosterView *self)
941 {
942   GList *individuals, *l;
943
944   individuals = empathy_roster_model_get_individuals (self->priv->model);
945   for (l = individuals; l != NULL; l = g_list_next (l))
946     {
947       FolksIndividual *individual = l->data;
948
949       individual_added (self, individual);
950     }
951
952   g_list_free (individuals);
953 }
954
955 static void
956 remove_from_group (EmpathyRosterView *self,
957     FolksIndividual *individual,
958     const gchar *group)
959 {
960   GHashTable *contacts;
961   GtkWidget *contact;
962   EmpathyRosterGroup *roster_group;
963
964   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
965   if (contacts == NULL)
966     return;
967
968   contact = g_hash_table_lookup (contacts, group);
969   if (contact == NULL)
970     return;
971
972   g_hash_table_remove (contacts, group);
973
974   if (g_hash_table_size (contacts) == 0)
975     {
976       add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
977     }
978
979   roster_group = lookup_roster_group (self, group);
980
981   if (roster_group != NULL)
982     {
983       update_group_widgets (self, roster_group,
984           EMPATHY_ROSTER_CONTACT (contact), FALSE);
985     }
986
987   gtk_container_remove (GTK_CONTAINER (self), contact);
988 }
989
990 static void
991 groups_changed_cb (EmpathyRosterModel *model,
992     FolksIndividual *individual,
993     const gchar *group,
994     gboolean is_member,
995     EmpathyRosterView *self)
996 {
997   if (!self->priv->show_groups)
998     {
999       egg_list_box_resort (EGG_LIST_BOX (self));
1000       return;
1001     }
1002
1003   if (is_member)
1004     {
1005       add_to_group (self, individual, group);
1006     }
1007   else
1008     {
1009       remove_from_group (self, individual, group);
1010     }
1011 }
1012
1013 static void
1014 empathy_roster_view_constructed (GObject *object)
1015 {
1016   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
1017   void (*chain_up) (GObject *) =
1018       ((GObjectClass *) empathy_roster_view_parent_class)->constructed;
1019
1020   if (chain_up != NULL)
1021     chain_up (object);
1022
1023   g_assert (EMPATHY_IS_ROSTER_MODEL (self->priv->model));
1024
1025   /* Get saved group states. */
1026   empathy_contact_groups_get_all ();
1027
1028   populate_view (self);
1029
1030   tp_g_signal_connect_object (self->priv->model, "individual-added",
1031       G_CALLBACK (individual_added_cb), self, 0);
1032   tp_g_signal_connect_object (self->priv->model, "individual-removed",
1033       G_CALLBACK (individual_removed_cb), self, 0);
1034   tp_g_signal_connect_object (self->priv->model, "groups-changed",
1035       G_CALLBACK (groups_changed_cb), self, 0);
1036
1037   egg_list_box_set_sort_func (EGG_LIST_BOX (self),
1038       roster_view_sort, self, NULL);
1039
1040   egg_list_box_set_separator_funcs (EGG_LIST_BOX (self), update_separator,
1041       self, NULL);
1042
1043   egg_list_box_set_filter_func (EGG_LIST_BOX (self), filter_list, self, NULL);
1044
1045   egg_list_box_set_activate_on_single_click (EGG_LIST_BOX (self), FALSE);
1046 }
1047
1048 static void
1049 clear_view (EmpathyRosterView *self)
1050 {
1051   g_hash_table_remove_all (self->priv->roster_contacts);
1052   g_hash_table_remove_all (self->priv->roster_groups);
1053   g_hash_table_remove_all (self->priv->displayed_contacts);
1054
1055   gtk_container_foreach (GTK_CONTAINER (self),
1056       (GtkCallback) gtk_widget_destroy, NULL);
1057 }
1058
1059 static void
1060 empathy_roster_view_dispose (GObject *object)
1061 {
1062   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
1063   void (*chain_up) (GObject *) =
1064       ((GObjectClass *) empathy_roster_view_parent_class)->dispose;
1065
1066   /* Start by clearing the view so our internal hash tables are cleared from
1067    * objects being destroyed. */
1068   clear_view (self);
1069
1070   stop_flashing (self);
1071
1072   empathy_roster_view_set_live_search (self, NULL);
1073   g_clear_object (&self->priv->model);
1074
1075   if (chain_up != NULL)
1076     chain_up (object);
1077 }
1078
1079 static void
1080 empathy_roster_view_finalize (GObject *object)
1081 {
1082   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
1083   void (*chain_up) (GObject *) =
1084       ((GObjectClass *) empathy_roster_view_parent_class)->finalize;
1085
1086   g_hash_table_unref (self->priv->roster_contacts);
1087   g_hash_table_unref (self->priv->roster_groups);
1088   g_hash_table_unref (self->priv->displayed_contacts);
1089   g_queue_free_full (self->priv->events, event_free);
1090
1091   if (chain_up != NULL)
1092     chain_up (object);
1093 }
1094
1095 static void
1096 empathy_roster_view_child_activated (EggListBox *box,
1097     GtkWidget *child)
1098 {
1099   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (box);
1100   EmpathyRosterContact *contact;
1101   FolksIndividual *individual;
1102   GList *l;
1103
1104   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1105     return;
1106
1107   contact = EMPATHY_ROSTER_CONTACT (child);
1108   individual = empathy_roster_contact_get_individual (contact);
1109
1110   /* Activate the oldest event associated with this contact, if any */
1111   for (l = g_queue_peek_tail_link (self->priv->events); l != NULL;
1112       l = g_list_previous (l))
1113     {
1114       Event *event = l->data;
1115
1116       if (event->individual == individual)
1117         {
1118           g_signal_emit (box, signals[SIG_EVENT_ACTIVATED], 0, individual,
1119               event->user_data);
1120           return;
1121         }
1122     }
1123
1124   g_signal_emit (box, signals[SIG_INDIVIDUAL_ACTIVATED], 0, individual);
1125 }
1126
1127 static void
1128 fire_popup_individual_menu (EmpathyRosterView *self,
1129     GtkWidget *child,
1130     guint button,
1131     guint time)
1132 {
1133   EmpathyRosterContact *contact;
1134   FolksIndividual *individual;
1135
1136   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1137     return;
1138
1139   contact = EMPATHY_ROSTER_CONTACT (child);
1140   individual = empathy_roster_contact_get_individual (contact);
1141
1142   g_signal_emit (self, signals[SIG_POPUP_INDIVIDUAL_MENU], 0,
1143       individual, button, time);
1144 }
1145
1146 static gboolean
1147 empathy_roster_view_button_press_event (GtkWidget *widget,
1148     GdkEventButton *event)
1149 {
1150   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
1151   gboolean (*chain_up) (GtkWidget *, GdkEventButton *) =
1152       ((GtkWidgetClass *) empathy_roster_view_parent_class)->button_press_event;
1153
1154   if (event->button == 3)
1155     {
1156       GtkWidget *child;
1157
1158       child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), event->y);
1159
1160       if (child != NULL)
1161         {
1162           egg_list_box_select_child (EGG_LIST_BOX (self), child);
1163
1164           fire_popup_individual_menu (self, child, event->button, event->time);
1165         }
1166     }
1167
1168   return chain_up (widget, event);
1169 }
1170
1171 static gboolean
1172 empathy_roster_view_key_press_event (GtkWidget *widget,
1173     GdkEventKey *event)
1174 {
1175   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
1176   gboolean (*chain_up) (GtkWidget *, GdkEventKey *) =
1177       ((GtkWidgetClass *) empathy_roster_view_parent_class)->key_press_event;
1178
1179   if (event->keyval == GDK_KEY_Menu)
1180     {
1181       GtkWidget *child;
1182
1183       child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
1184
1185       if (child != NULL)
1186         fire_popup_individual_menu (self, child, 0, event->time);
1187     }
1188
1189   return chain_up (widget, event);
1190 }
1191
1192 /**
1193  * @out_child: (out) (allow-none)
1194  */
1195 FolksIndividual *
1196 empathy_roster_view_get_individual_at_y (EmpathyRosterView *self,
1197     gint y,
1198     GtkWidget **out_child)
1199 {
1200   GtkWidget *child;
1201
1202   child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
1203
1204   if (out_child != NULL)
1205     *out_child = child;
1206
1207   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1208     return NULL;
1209
1210   return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
1211 }
1212
1213 /**
1214  * @out_child: (out) (allow-none)
1215  */
1216 const gchar *
1217 empathy_roster_view_get_group_at_y (EmpathyRosterView *self,
1218     gint y)
1219 {
1220   GtkWidget *child;
1221
1222   child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
1223
1224   if (EMPATHY_IS_ROSTER_CONTACT (child))
1225     return empathy_roster_contact_get_group (EMPATHY_ROSTER_CONTACT (child));
1226   else if (EMPATHY_IS_ROSTER_GROUP (child))
1227     return empathy_roster_group_get_name (EMPATHY_ROSTER_GROUP (child));
1228
1229   return NULL;
1230 }
1231
1232 static gboolean
1233 empathy_roster_view_query_tooltip (GtkWidget *widget,
1234     gint x,
1235     gint y,
1236     gboolean keyboard_mode,
1237     GtkTooltip *tooltip)
1238 {
1239   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
1240   FolksIndividual *individual;
1241   gboolean result;
1242   GtkWidget *child;
1243
1244   individual = empathy_roster_view_get_individual_at_y (self, y, &child);
1245   if (individual == NULL)
1246     return FALSE;
1247
1248   g_signal_emit (self, signals[SIG_INDIVIDUAL_TOOLTIP], 0,
1249       individual, keyboard_mode, tooltip, &result);
1250
1251   if (result)
1252     {
1253       GtkAllocation allocation;
1254
1255       gtk_widget_get_allocation (child, &allocation);
1256       gtk_tooltip_set_tip_area (tooltip, (GdkRectangle *) &allocation);
1257     }
1258
1259   return result;
1260 }
1261
1262 static void
1263 empathy_roster_view_remove (GtkContainer *container,
1264     GtkWidget *widget)
1265 {
1266   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (container);
1267   void (*chain_up) (GtkContainer *, GtkWidget *) =
1268       ((GtkContainerClass *) empathy_roster_view_parent_class)->remove;
1269
1270   chain_up (container, widget);
1271
1272   if (EMPATHY_IS_ROSTER_CONTACT (widget))
1273     remove_from_displayed (self, (EmpathyRosterContact *) widget);
1274 }
1275
1276 static void
1277 empathy_roster_view_class_init (
1278     EmpathyRosterViewClass *klass)
1279 {
1280   GObjectClass *oclass = G_OBJECT_CLASS (klass);
1281   EggListBoxClass *box_class = EGG_LIST_BOX_CLASS (klass);
1282   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1283   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
1284   GParamSpec *spec;
1285
1286   oclass->get_property = empathy_roster_view_get_property;
1287   oclass->set_property = empathy_roster_view_set_property;
1288   oclass->constructed = empathy_roster_view_constructed;
1289   oclass->dispose = empathy_roster_view_dispose;
1290   oclass->finalize = empathy_roster_view_finalize;
1291
1292   widget_class->button_press_event = empathy_roster_view_button_press_event;
1293   widget_class->key_press_event = empathy_roster_view_key_press_event;
1294   widget_class->query_tooltip = empathy_roster_view_query_tooltip;
1295
1296   container_class->remove = empathy_roster_view_remove;
1297
1298   box_class->child_activated = empathy_roster_view_child_activated;
1299
1300   spec = g_param_spec_object ("model", "Model",
1301       "EmpathyRosterModel",
1302       EMPATHY_TYPE_ROSTER_MODEL,
1303       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1304   g_object_class_install_property (oclass, PROP_MODEL, spec);
1305
1306   spec = g_param_spec_boolean ("show-offline", "Show Offline",
1307       "Show offline contacts",
1308       FALSE,
1309       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1310   g_object_class_install_property (oclass, PROP_SHOW_OFFLINE, spec);
1311
1312   spec = g_param_spec_boolean ("show-groups", "Show Groups",
1313       "Show groups",
1314       FALSE,
1315       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1316   g_object_class_install_property (oclass, PROP_SHOW_GROUPS, spec);
1317
1318   spec = g_param_spec_boolean ("empty", "Empty",
1319       "Is the view currently empty?",
1320       FALSE,
1321       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1322   g_object_class_install_property (oclass, PROP_EMPTY, spec);
1323
1324   signals[SIG_INDIVIDUAL_ACTIVATED] = g_signal_new ("individual-activated",
1325       G_OBJECT_CLASS_TYPE (klass),
1326       G_SIGNAL_RUN_LAST,
1327       0, NULL, NULL, NULL,
1328       G_TYPE_NONE,
1329       1, FOLKS_TYPE_INDIVIDUAL);
1330
1331   signals[SIG_POPUP_INDIVIDUAL_MENU] = g_signal_new ("popup-individual-menu",
1332       G_OBJECT_CLASS_TYPE (klass),
1333       G_SIGNAL_RUN_LAST,
1334       0, NULL, NULL, NULL,
1335       G_TYPE_NONE,
1336       3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT, G_TYPE_UINT);
1337
1338   signals[SIG_EVENT_ACTIVATED] = g_signal_new ("event-activated",
1339       G_OBJECT_CLASS_TYPE (klass),
1340       G_SIGNAL_RUN_LAST,
1341       0, NULL, NULL, NULL,
1342       G_TYPE_NONE,
1343       2, FOLKS_TYPE_INDIVIDUAL, G_TYPE_POINTER);
1344
1345   signals[SIG_INDIVIDUAL_TOOLTIP] = g_signal_new ("individual-tooltip",
1346       G_OBJECT_CLASS_TYPE (klass),
1347       G_SIGNAL_RUN_LAST,
1348       0, g_signal_accumulator_true_handled, NULL, NULL,
1349       G_TYPE_BOOLEAN,
1350       3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_BOOLEAN, GTK_TYPE_TOOLTIP);
1351
1352   g_type_class_add_private (klass, sizeof (EmpathyRosterViewPriv));
1353 }
1354
1355 static void
1356 empathy_roster_view_init (EmpathyRosterView *self)
1357 {
1358   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1359       EMPATHY_TYPE_ROSTER_VIEW, EmpathyRosterViewPriv);
1360
1361   self->priv->roster_contacts = g_hash_table_new_full (NULL, NULL,
1362       NULL, (GDestroyNotify) g_hash_table_unref);
1363   self->priv->roster_groups = g_hash_table_new_full (g_str_hash, g_str_equal,
1364       g_free, NULL);
1365   self->priv->displayed_contacts = g_hash_table_new (NULL, NULL);
1366
1367   self->priv->events = g_queue_new ();
1368
1369   self->priv->empty = TRUE;
1370 }
1371
1372 GtkWidget *
1373 empathy_roster_view_new (EmpathyRosterModel *model)
1374 {
1375   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (model), NULL);
1376
1377   return g_object_new (EMPATHY_TYPE_ROSTER_VIEW,
1378       "model", model,
1379       NULL);
1380 }
1381
1382 void
1383 empathy_roster_view_show_offline (EmpathyRosterView *self,
1384     gboolean show)
1385 {
1386   if (self->priv->show_offline == show)
1387     return;
1388
1389   self->priv->show_offline = show;
1390   egg_list_box_refilter (EGG_LIST_BOX (self));
1391
1392   g_object_notify (G_OBJECT (self), "show-offline");
1393 }
1394
1395 void
1396 empathy_roster_view_show_groups (EmpathyRosterView *self,
1397     gboolean show)
1398 {
1399   if (self->priv->show_groups == show)
1400     return;
1401
1402   self->priv->show_groups = show;
1403
1404   /* TODO: block sort/filter? */
1405   clear_view (self);
1406   populate_view (self);
1407
1408   g_object_notify (G_OBJECT (self), "show-groups");
1409 }
1410
1411 static void
1412 select_first_contact (EmpathyRosterView *self)
1413 {
1414   GList *children, *l;
1415
1416   children = gtk_container_get_children (GTK_CONTAINER (self));
1417   for (l = children; l != NULL; l = g_list_next (l))
1418     {
1419       GtkWidget *child = l->data;
1420
1421       if (!gtk_widget_get_child_visible (child))
1422         continue;
1423
1424       if (!EMPATHY_IS_ROSTER_CONTACT (child))
1425         continue;
1426
1427       egg_list_box_select_child (EGG_LIST_BOX (self), child);
1428       break;
1429     }
1430
1431   g_list_free (children);
1432 }
1433
1434 static void
1435 search_text_notify_cb (EmpathyLiveSearch *search,
1436     GParamSpec *pspec,
1437     EmpathyRosterView *self)
1438 {
1439   egg_list_box_refilter (EGG_LIST_BOX (self));
1440
1441   select_first_contact (self);
1442 }
1443
1444 static void
1445 search_activate_cb (GtkWidget *search,
1446   EmpathyRosterView *self)
1447 {
1448   EggListBox *box = EGG_LIST_BOX (self);
1449   GtkWidget *child;
1450
1451   child = egg_list_box_get_selected_child (box);
1452   if (child == NULL)
1453     return;
1454
1455   empathy_roster_view_child_activated (box, child);
1456 }
1457
1458 void
1459 empathy_roster_view_set_live_search (EmpathyRosterView *self,
1460     EmpathyLiveSearch *search)
1461 {
1462   if (self->priv->search != NULL)
1463     {
1464       g_signal_handlers_disconnect_by_func (self->priv->search,
1465           search_text_notify_cb, self);
1466       g_signal_handlers_disconnect_by_func (self->priv->search,
1467           search_activate_cb, self);
1468
1469       g_clear_object (&self->priv->search);
1470     }
1471
1472   if (search == NULL)
1473     return;
1474
1475   self->priv->search = g_object_ref (search);
1476
1477   g_signal_connect (self->priv->search, "notify::text",
1478       G_CALLBACK (search_text_notify_cb), self);
1479   g_signal_connect (self->priv->search, "activate",
1480       G_CALLBACK (search_activate_cb), self);
1481 }
1482
1483 gboolean
1484 empathy_roster_view_is_empty (EmpathyRosterView *self)
1485 {
1486   return self->priv->empty;
1487 }
1488
1489 gboolean
1490 empathy_roster_view_is_searching (EmpathyRosterView *self)
1491 {
1492   return (self->priv->search != NULL &&
1493       gtk_widget_get_visible (GTK_WIDGET (self->priv->search)));
1494 }
1495
1496 /* Don't use EmpathyEvent as I prefer to keep this object not too specific to
1497  * Empathy's internals. */
1498 guint
1499 empathy_roster_view_add_event (EmpathyRosterView *self,
1500     FolksIndividual *individual,
1501     const gchar *icon,
1502     gpointer user_data)
1503 {
1504   GHashTable *contacts;
1505
1506   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
1507   if (contacts == NULL)
1508     return 0;
1509
1510   self->priv->last_event_id++;
1511
1512   g_queue_push_head (self->priv->events,
1513       event_new (self->priv->last_event_id, individual, icon, user_data));
1514
1515   start_flashing (self);
1516
1517   return self->priv->last_event_id;
1518 }
1519
1520 void
1521 empathy_roster_view_remove_event (EmpathyRosterView *self,
1522     guint event_id)
1523 {
1524   GList *l;
1525
1526   for (l = g_queue_peek_head_link (self->priv->events); l != NULL;
1527       l = g_list_next (l))
1528     {
1529       Event *event = l->data;
1530
1531       if (event->id == event_id)
1532         {
1533           remove_event (self, event);
1534           return;
1535         }
1536     }
1537 }
1538
1539 FolksIndividual *
1540 empathy_roster_view_get_selected_individual (EmpathyRosterView *self)
1541 {
1542   GtkWidget *child;
1543
1544   child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
1545
1546   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1547     return NULL;
1548
1549   return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
1550 }