]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-roster-view.c
roster-view: don't display offline not favorite top contacts
[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 (groups, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP) != NULL)
595         result = TRUE;
596
597       g_list_free (groups);
598
599       return result;
600     }
601
602   if (!tp_strdiff (empathy_roster_contact_get_group (contact),
603           EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
604     /* If we are displaying contacts, we only want to *always* display the
605      * RosterContact which is displayed at the top; not the ones displayed in
606      * the 'normal' group sections */
607     return TRUE;
608
609   return FALSE;
610 }
611
612 static gint
613 compare_roster_contacts_by_alias (EmpathyRosterContact *a,
614     EmpathyRosterContact *b)
615 {
616   FolksIndividual *ind_a, *ind_b;
617   const gchar *alias_a, *alias_b;
618
619   ind_a = empathy_roster_contact_get_individual (a);
620   ind_b = empathy_roster_contact_get_individual (b);
621
622   alias_a = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_a));
623   alias_b = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_b));
624
625   return g_ascii_strcasecmp (alias_a, alias_b);
626 }
627
628 static gint
629 compare_roster_contacts_no_group (EmpathyRosterView *self,
630     EmpathyRosterContact *a,
631     EmpathyRosterContact *b)
632 {
633   gboolean top_a, top_b;
634
635   top_a = contact_in_top (self, a);
636   top_b = contact_in_top (self, b);
637
638   if (top_a == top_b)
639     /* Both contacts are in the top of the roster (or not). Sort them
640      * alphabetically */
641     return compare_roster_contacts_by_alias (a, b);
642   else if (top_a)
643     return -1;
644   else
645     return 1;
646 }
647
648 static gint
649 compare_group_names (const gchar *group_a,
650     const gchar *group_b)
651 {
652   if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
653     return -1;
654
655   if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
656     return 1;
657
658   if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
659     return 1;
660   else if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
661     return -1;
662
663   return g_ascii_strcasecmp (group_a, group_b);
664 }
665
666 static gint
667 compare_roster_contacts_with_groups (EmpathyRosterView *self,
668     EmpathyRosterContact *a,
669     EmpathyRosterContact *b)
670 {
671   const gchar *group_a, *group_b;
672
673   group_a = empathy_roster_contact_get_group (a);
674   group_b = empathy_roster_contact_get_group (b);
675
676   if (!tp_strdiff (group_a, group_b))
677     /* Same group, compare the contacts */
678     return compare_roster_contacts_by_alias (a, b);
679
680   /* Sort by group */
681   return compare_group_names (group_a, group_b);
682 }
683
684 static gint
685 compare_roster_contacts (EmpathyRosterView *self,
686     EmpathyRosterContact *a,
687     EmpathyRosterContact *b)
688 {
689   if (!self->priv->show_groups)
690     return compare_roster_contacts_no_group (self, a, b);
691   else
692     return compare_roster_contacts_with_groups (self, a, b);
693 }
694
695 static gint
696 compare_roster_groups (EmpathyRosterGroup *a,
697     EmpathyRosterGroup *b)
698 {
699   const gchar *name_a, *name_b;
700
701   name_a = empathy_roster_group_get_name (a);
702   name_b = empathy_roster_group_get_name (b);
703
704   return compare_group_names (name_a, name_b);
705 }
706
707 static gint
708 compare_contact_group (EmpathyRosterContact *contact,
709     EmpathyRosterGroup *group)
710 {
711   const char *contact_group, *group_name;
712
713   contact_group = empathy_roster_contact_get_group (contact);
714   group_name = empathy_roster_group_get_name (group);
715
716   if (!tp_strdiff (contact_group, group_name))
717     /* @contact is in @group, @group has to be displayed first */
718     return 1;
719
720   /* @contact is in a different group, sort by group name */
721   return compare_group_names (contact_group, group_name);
722 }
723
724 static gint
725 roster_view_sort (gconstpointer a,
726     gconstpointer b,
727     gpointer user_data)
728 {
729   EmpathyRosterView *self = user_data;
730
731   if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_CONTACT (b))
732     return compare_roster_contacts (self, EMPATHY_ROSTER_CONTACT (a),
733         EMPATHY_ROSTER_CONTACT (b));
734   else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_GROUP (b))
735     return compare_roster_groups (EMPATHY_ROSTER_GROUP (a),
736         EMPATHY_ROSTER_GROUP (b));
737   else if (EMPATHY_IS_ROSTER_CONTACT (a) && EMPATHY_IS_ROSTER_GROUP (b))
738     return compare_contact_group (EMPATHY_ROSTER_CONTACT (a),
739         EMPATHY_ROSTER_GROUP (b));
740   else if (EMPATHY_IS_ROSTER_GROUP (a) && EMPATHY_IS_ROSTER_CONTACT (b))
741     return -1 * compare_contact_group (EMPATHY_ROSTER_CONTACT (b),
742         EMPATHY_ROSTER_GROUP (a));
743
744   g_return_val_if_reached (0);
745 }
746
747 static void
748 update_separator (GtkWidget **separator,
749     GtkWidget *child,
750     GtkWidget *before,
751     gpointer user_data)
752 {
753   if (before == NULL)
754     {
755       /* No separator before the first row */
756       g_clear_object (separator);
757       return;
758     }
759
760   if (*separator != NULL)
761     return;
762
763   *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
764   g_object_ref_sink (*separator);
765 }
766
767 static gboolean
768 is_searching (EmpathyRosterView *self)
769 {
770   if (self->priv->search == NULL)
771     return FALSE;
772
773   return gtk_widget_get_visible (GTK_WIDGET (self->priv->search));
774 }
775
776 static void
777 add_to_displayed (EmpathyRosterView *self,
778     EmpathyRosterContact *contact)
779 {
780   FolksIndividual *individual;
781   GHashTable *contacts;
782   GHashTableIter iter;
783   gpointer k;
784
785   if (g_hash_table_lookup (self->priv->displayed_contacts, contact) != NULL)
786     return;
787
788   g_hash_table_add (self->priv->displayed_contacts, contact);
789   update_empty (self, FALSE);
790
791   /* Groups of this contact may now be displayed if we just displays the first
792    * child in this group. */
793
794   if (!self->priv->show_groups)
795     return;
796
797   individual = empathy_roster_contact_get_individual (contact);
798   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
799   if (contacts == NULL)
800     return;
801
802   g_hash_table_iter_init (&iter, contacts);
803   while (g_hash_table_iter_next (&iter, &k, NULL))
804     {
805       const gchar *group_name = k;
806       GtkWidget *group;
807
808       group = g_hash_table_lookup (self->priv->roster_groups, group_name);
809       if (group == NULL)
810         continue;
811
812       egg_list_box_child_changed (EGG_LIST_BOX (self), group);
813     }
814 }
815
816 static void
817 remove_from_displayed (EmpathyRosterView *self,
818     EmpathyRosterContact *contact)
819 {
820   g_hash_table_remove (self->priv->displayed_contacts, contact);
821
822   check_if_empty (self);
823 }
824
825 static gboolean
826 contact_is_favorite (EmpathyRosterContact *contact)
827 {
828   FolksIndividual *individual;
829
830   individual = empathy_roster_contact_get_individual (contact);
831
832   return folks_favourite_details_get_is_favourite (
833       FOLKS_FAVOURITE_DETAILS (individual));
834 }
835
836 /**
837  * check if @contact should be displayed according to @self's current status
838  * and without consideration for the state of @contact's groups.
839  */
840 static gboolean
841 contact_should_be_displayed (EmpathyRosterView *self,
842     EmpathyRosterContact *contact)
843 {
844   if (is_searching (self))
845     {
846       FolksIndividual *individual;
847
848       individual = empathy_roster_contact_get_individual (contact);
849
850       return empathy_individual_match_string (individual,
851           empathy_live_search_get_text (self->priv->search),
852           empathy_live_search_get_words (self->priv->search));
853     }
854
855   if (self->priv->show_offline)
856       return TRUE;
857
858   if (contact_in_top (self, contact) &&
859       contact_is_favorite (contact))
860     /* Favorite top contacts are always displayed */
861     return TRUE;
862
863   return empathy_roster_contact_is_online (contact);
864 }
865
866
867 static gboolean
868 filter_contact (EmpathyRosterView *self,
869     EmpathyRosterContact *contact)
870 {
871   gboolean displayed;
872
873   displayed = contact_should_be_displayed (self, contact);
874
875   if (self->priv->show_groups)
876     {
877       const gchar *group_name;
878       EmpathyRosterGroup *group;
879
880       group_name = empathy_roster_contact_get_group (contact);
881       group = lookup_roster_group (self, group_name);
882
883       if (group != NULL)
884         {
885           /* When searching, always display even if the group is closed */
886           if (!is_searching (self) &&
887               !gtk_expander_get_expanded (GTK_EXPANDER (group)))
888             displayed = FALSE;
889         }
890     }
891
892   if (displayed)
893     {
894       add_to_displayed (self, contact);
895     }
896   else
897     {
898       remove_from_displayed (self, contact);
899     }
900
901   return displayed;
902 }
903
904 static gboolean
905 filter_group (EmpathyRosterView *self,
906     EmpathyRosterGroup *group)
907 {
908   GList *widgets, *l;
909
910   /* Display the group if it contains at least one displayed contact */
911   widgets = empathy_roster_group_get_widgets (group);
912   for (l = widgets; l != NULL; l = g_list_next (l))
913     {
914       EmpathyRosterContact *contact = l->data;
915
916       if (contact_should_be_displayed (self, contact))
917         return TRUE;
918     }
919
920   return FALSE;
921 }
922
923 static gboolean
924 filter_list (GtkWidget *child,
925     gpointer user_data)
926 {
927   EmpathyRosterView *self = user_data;
928
929   if (EMPATHY_IS_ROSTER_CONTACT (child))
930     return filter_contact (self, EMPATHY_ROSTER_CONTACT (child));
931
932   else if (EMPATHY_IS_ROSTER_GROUP (child))
933     return filter_group (self, EMPATHY_ROSTER_GROUP (child));
934
935   g_return_val_if_reached (FALSE);
936 }
937
938 static void
939 populate_view (EmpathyRosterView *self)
940 {
941   GList *individuals, *l;
942
943   individuals = empathy_roster_model_get_individuals (self->priv->model);
944   for (l = individuals; l != NULL; l = g_list_next (l))
945     {
946       FolksIndividual *individual = l->data;
947
948       individual_added (self, individual);
949     }
950
951   g_list_free (individuals);
952 }
953
954 static void
955 remove_from_group (EmpathyRosterView *self,
956     FolksIndividual *individual,
957     const gchar *group)
958 {
959   GHashTable *contacts;
960   GtkWidget *contact;
961   EmpathyRosterGroup *roster_group;
962
963   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
964   if (contacts == NULL)
965     return;
966
967   contact = g_hash_table_lookup (contacts, group);
968   if (contact == NULL)
969     return;
970
971   g_hash_table_remove (contacts, group);
972
973   if (g_hash_table_size (contacts) == 0)
974     {
975       add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
976     }
977
978   roster_group = lookup_roster_group (self, group);
979
980   if (roster_group != NULL)
981     {
982       update_group_widgets (self, roster_group,
983           EMPATHY_ROSTER_CONTACT (contact), FALSE);
984     }
985
986   gtk_container_remove (GTK_CONTAINER (self), contact);
987 }
988
989 static void
990 groups_changed_cb (EmpathyRosterModel *model,
991     FolksIndividual *individual,
992     const gchar *group,
993     gboolean is_member,
994     EmpathyRosterView *self)
995 {
996   if (!self->priv->show_groups)
997     {
998       egg_list_box_resort (EGG_LIST_BOX (self));
999       return;
1000     }
1001
1002   if (is_member)
1003     {
1004       add_to_group (self, individual, group);
1005     }
1006   else
1007     {
1008       remove_from_group (self, individual, group);
1009     }
1010 }
1011
1012 static void
1013 empathy_roster_view_constructed (GObject *object)
1014 {
1015   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
1016   void (*chain_up) (GObject *) =
1017       ((GObjectClass *) empathy_roster_view_parent_class)->constructed;
1018
1019   if (chain_up != NULL)
1020     chain_up (object);
1021
1022   g_assert (EMPATHY_IS_ROSTER_MODEL (self->priv->model));
1023
1024   /* Get saved group states. */
1025   empathy_contact_groups_get_all ();
1026
1027   populate_view (self);
1028
1029   tp_g_signal_connect_object (self->priv->model, "individual-added",
1030       G_CALLBACK (individual_added_cb), self, 0);
1031   tp_g_signal_connect_object (self->priv->model, "individual-removed",
1032       G_CALLBACK (individual_removed_cb), self, 0);
1033   tp_g_signal_connect_object (self->priv->model, "groups-changed",
1034       G_CALLBACK (groups_changed_cb), self, 0);
1035
1036   egg_list_box_set_sort_func (EGG_LIST_BOX (self),
1037       roster_view_sort, self, NULL);
1038
1039   egg_list_box_set_separator_funcs (EGG_LIST_BOX (self), update_separator,
1040       self, NULL);
1041
1042   egg_list_box_set_filter_func (EGG_LIST_BOX (self), filter_list, self, NULL);
1043
1044   egg_list_box_set_activate_on_single_click (EGG_LIST_BOX (self), FALSE);
1045 }
1046
1047 static void
1048 empathy_roster_view_dispose (GObject *object)
1049 {
1050   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
1051   void (*chain_up) (GObject *) =
1052       ((GObjectClass *) empathy_roster_view_parent_class)->dispose;
1053
1054   stop_flashing (self);
1055
1056   empathy_roster_view_set_live_search (self, NULL);
1057   g_clear_object (&self->priv->model);
1058
1059   if (chain_up != NULL)
1060     chain_up (object);
1061 }
1062
1063 static void
1064 empathy_roster_view_finalize (GObject *object)
1065 {
1066   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object);
1067   void (*chain_up) (GObject *) =
1068       ((GObjectClass *) empathy_roster_view_parent_class)->finalize;
1069
1070   g_hash_table_unref (self->priv->roster_contacts);
1071   g_hash_table_unref (self->priv->roster_groups);
1072   g_hash_table_unref (self->priv->displayed_contacts);
1073   g_queue_free_full (self->priv->events, event_free);
1074
1075   if (chain_up != NULL)
1076     chain_up (object);
1077 }
1078
1079 static void
1080 empathy_roster_view_child_activated (EggListBox *box,
1081     GtkWidget *child)
1082 {
1083   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (box);
1084   EmpathyRosterContact *contact;
1085   FolksIndividual *individual;
1086   GList *l;
1087
1088   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1089     return;
1090
1091   contact = EMPATHY_ROSTER_CONTACT (child);
1092   individual = empathy_roster_contact_get_individual (contact);
1093
1094   /* Activate the oldest event associated with this contact, if any */
1095   for (l = g_queue_peek_tail_link (self->priv->events); l != NULL;
1096       l = g_list_previous (l))
1097     {
1098       Event *event = l->data;
1099
1100       if (event->individual == individual)
1101         {
1102           g_signal_emit (box, signals[SIG_EVENT_ACTIVATED], 0, individual,
1103               event->user_data);
1104           return;
1105         }
1106     }
1107
1108   g_signal_emit (box, signals[SIG_INDIVIDUAL_ACTIVATED], 0, individual);
1109 }
1110
1111 static void
1112 fire_popup_individual_menu (EmpathyRosterView *self,
1113     GtkWidget *child,
1114     guint button,
1115     guint time)
1116 {
1117   EmpathyRosterContact *contact;
1118   FolksIndividual *individual;
1119
1120   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1121     return;
1122
1123   contact = EMPATHY_ROSTER_CONTACT (child);
1124   individual = empathy_roster_contact_get_individual (contact);
1125
1126   g_signal_emit (self, signals[SIG_POPUP_INDIVIDUAL_MENU], 0,
1127       individual, button, time);
1128 }
1129
1130 static gboolean
1131 empathy_roster_view_button_press_event (GtkWidget *widget,
1132     GdkEventButton *event)
1133 {
1134   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
1135   gboolean (*chain_up) (GtkWidget *, GdkEventButton *) =
1136       ((GtkWidgetClass *) empathy_roster_view_parent_class)->button_press_event;
1137
1138   if (event->button == 3)
1139     {
1140       GtkWidget *child;
1141
1142       child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), event->y);
1143
1144       if (child != NULL)
1145         {
1146           egg_list_box_select_child (EGG_LIST_BOX (self), child);
1147
1148           fire_popup_individual_menu (self, child, event->button, event->time);
1149         }
1150     }
1151
1152   return chain_up (widget, event);
1153 }
1154
1155 static gboolean
1156 empathy_roster_view_key_press_event (GtkWidget *widget,
1157     GdkEventKey *event)
1158 {
1159   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
1160   gboolean (*chain_up) (GtkWidget *, GdkEventKey *) =
1161       ((GtkWidgetClass *) empathy_roster_view_parent_class)->key_press_event;
1162
1163   if (event->keyval == GDK_KEY_Menu)
1164     {
1165       GtkWidget *child;
1166
1167       child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
1168
1169       if (child != NULL)
1170         fire_popup_individual_menu (self, child, 0, event->time);
1171     }
1172
1173   return chain_up (widget, event);
1174 }
1175
1176 /**
1177  * @out_child: (out) (allow-none)
1178  */
1179 FolksIndividual *
1180 empathy_roster_view_get_individual_at_y (EmpathyRosterView *self,
1181     gint y,
1182     GtkWidget **out_child)
1183 {
1184   GtkWidget *child;
1185
1186   child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
1187
1188   if (out_child != NULL)
1189     *out_child = child;
1190
1191   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1192     return NULL;
1193
1194   return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
1195 }
1196
1197 /**
1198  * @out_child: (out) (allow-none)
1199  */
1200 const gchar *
1201 empathy_roster_view_get_group_at_y (EmpathyRosterView *self,
1202     gint y)
1203 {
1204   GtkWidget *child;
1205
1206   child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
1207
1208   if (EMPATHY_IS_ROSTER_CONTACT (child))
1209     return empathy_roster_contact_get_group (EMPATHY_ROSTER_CONTACT (child));
1210   else if (EMPATHY_IS_ROSTER_GROUP (child))
1211     return empathy_roster_group_get_name (EMPATHY_ROSTER_GROUP (child));
1212
1213   return NULL;
1214 }
1215
1216 static gboolean
1217 empathy_roster_view_query_tooltip (GtkWidget *widget,
1218     gint x,
1219     gint y,
1220     gboolean keyboard_mode,
1221     GtkTooltip *tooltip)
1222 {
1223   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
1224   FolksIndividual *individual;
1225   gboolean result;
1226   GtkWidget *child;
1227
1228   individual = empathy_roster_view_get_individual_at_y (self, y, &child);
1229   if (individual == NULL)
1230     return FALSE;
1231
1232   g_signal_emit (self, signals[SIG_INDIVIDUAL_TOOLTIP], 0,
1233       individual, keyboard_mode, tooltip, &result);
1234
1235   if (result)
1236     {
1237       GtkAllocation allocation;
1238
1239       gtk_widget_get_allocation (child, &allocation);
1240       gtk_tooltip_set_tip_area (tooltip, (GdkRectangle *) &allocation);
1241     }
1242
1243   return result;
1244 }
1245
1246 static void
1247 empathy_roster_view_remove (GtkContainer *container,
1248     GtkWidget *widget)
1249 {
1250   EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (container);
1251   void (*chain_up) (GtkContainer *, GtkWidget *) =
1252       ((GtkContainerClass *) empathy_roster_view_parent_class)->remove;
1253
1254   chain_up (container, widget);
1255
1256   if (EMPATHY_IS_ROSTER_CONTACT (widget))
1257     remove_from_displayed (self, (EmpathyRosterContact *) widget);
1258 }
1259
1260 static void
1261 empathy_roster_view_class_init (
1262     EmpathyRosterViewClass *klass)
1263 {
1264   GObjectClass *oclass = G_OBJECT_CLASS (klass);
1265   EggListBoxClass *box_class = EGG_LIST_BOX_CLASS (klass);
1266   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1267   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
1268   GParamSpec *spec;
1269
1270   oclass->get_property = empathy_roster_view_get_property;
1271   oclass->set_property = empathy_roster_view_set_property;
1272   oclass->constructed = empathy_roster_view_constructed;
1273   oclass->dispose = empathy_roster_view_dispose;
1274   oclass->finalize = empathy_roster_view_finalize;
1275
1276   widget_class->button_press_event = empathy_roster_view_button_press_event;
1277   widget_class->key_press_event = empathy_roster_view_key_press_event;
1278   widget_class->query_tooltip = empathy_roster_view_query_tooltip;
1279
1280   container_class->remove = empathy_roster_view_remove;
1281
1282   box_class->child_activated = empathy_roster_view_child_activated;
1283
1284   spec = g_param_spec_object ("model", "Model",
1285       "EmpathyRosterModel",
1286       EMPATHY_TYPE_ROSTER_MODEL,
1287       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1288   g_object_class_install_property (oclass, PROP_MODEL, spec);
1289
1290   spec = g_param_spec_boolean ("show-offline", "Show Offline",
1291       "Show offline contacts",
1292       FALSE,
1293       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1294   g_object_class_install_property (oclass, PROP_SHOW_OFFLINE, spec);
1295
1296   spec = g_param_spec_boolean ("show-groups", "Show Groups",
1297       "Show groups",
1298       FALSE,
1299       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1300   g_object_class_install_property (oclass, PROP_SHOW_GROUPS, spec);
1301
1302   spec = g_param_spec_boolean ("empty", "Empty",
1303       "Is the view currently empty?",
1304       FALSE,
1305       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
1306   g_object_class_install_property (oclass, PROP_EMPTY, spec);
1307
1308   signals[SIG_INDIVIDUAL_ACTIVATED] = g_signal_new ("individual-activated",
1309       G_OBJECT_CLASS_TYPE (klass),
1310       G_SIGNAL_RUN_LAST,
1311       0, NULL, NULL, NULL,
1312       G_TYPE_NONE,
1313       1, FOLKS_TYPE_INDIVIDUAL);
1314
1315   signals[SIG_POPUP_INDIVIDUAL_MENU] = g_signal_new ("popup-individual-menu",
1316       G_OBJECT_CLASS_TYPE (klass),
1317       G_SIGNAL_RUN_LAST,
1318       0, NULL, NULL, NULL,
1319       G_TYPE_NONE,
1320       3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT, G_TYPE_UINT);
1321
1322   signals[SIG_EVENT_ACTIVATED] = g_signal_new ("event-activated",
1323       G_OBJECT_CLASS_TYPE (klass),
1324       G_SIGNAL_RUN_LAST,
1325       0, NULL, NULL, NULL,
1326       G_TYPE_NONE,
1327       2, FOLKS_TYPE_INDIVIDUAL, G_TYPE_POINTER);
1328
1329   signals[SIG_INDIVIDUAL_TOOLTIP] = g_signal_new ("individual-tooltip",
1330       G_OBJECT_CLASS_TYPE (klass),
1331       G_SIGNAL_RUN_LAST,
1332       0, g_signal_accumulator_true_handled, NULL, NULL,
1333       G_TYPE_BOOLEAN,
1334       3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_BOOLEAN, GTK_TYPE_TOOLTIP);
1335
1336   g_type_class_add_private (klass, sizeof (EmpathyRosterViewPriv));
1337 }
1338
1339 static void
1340 empathy_roster_view_init (EmpathyRosterView *self)
1341 {
1342   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1343       EMPATHY_TYPE_ROSTER_VIEW, EmpathyRosterViewPriv);
1344
1345   self->priv->roster_contacts = g_hash_table_new_full (NULL, NULL,
1346       NULL, (GDestroyNotify) g_hash_table_unref);
1347   self->priv->roster_groups = g_hash_table_new_full (g_str_hash, g_str_equal,
1348       g_free, NULL);
1349   self->priv->displayed_contacts = g_hash_table_new (NULL, NULL);
1350
1351   self->priv->events = g_queue_new ();
1352
1353   self->priv->empty = TRUE;
1354 }
1355
1356 GtkWidget *
1357 empathy_roster_view_new (EmpathyRosterModel *model)
1358 {
1359   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (model), NULL);
1360
1361   return g_object_new (EMPATHY_TYPE_ROSTER_VIEW,
1362       "model", model,
1363       NULL);
1364 }
1365
1366 void
1367 empathy_roster_view_show_offline (EmpathyRosterView *self,
1368     gboolean show)
1369 {
1370   if (self->priv->show_offline == show)
1371     return;
1372
1373   self->priv->show_offline = show;
1374   egg_list_box_refilter (EGG_LIST_BOX (self));
1375
1376   g_object_notify (G_OBJECT (self), "show-offline");
1377 }
1378
1379 static void
1380 clear_view (EmpathyRosterView *self)
1381 {
1382   g_hash_table_remove_all (self->priv->roster_contacts);
1383   g_hash_table_remove_all (self->priv->roster_groups);
1384   g_hash_table_remove_all (self->priv->displayed_contacts);
1385
1386   gtk_container_foreach (GTK_CONTAINER (self),
1387       (GtkCallback) gtk_widget_destroy, NULL);
1388 }
1389
1390 void
1391 empathy_roster_view_show_groups (EmpathyRosterView *self,
1392     gboolean show)
1393 {
1394   if (self->priv->show_groups == show)
1395     return;
1396
1397   self->priv->show_groups = show;
1398
1399   /* TODO: block sort/filter? */
1400   clear_view (self);
1401   populate_view (self);
1402
1403   g_object_notify (G_OBJECT (self), "show-groups");
1404 }
1405
1406 static void
1407 select_first_contact (EmpathyRosterView *self)
1408 {
1409   GList *children, *l;
1410
1411   children = gtk_container_get_children (GTK_CONTAINER (self));
1412   for (l = children; l != NULL; l = g_list_next (l))
1413     {
1414       GtkWidget *child = l->data;
1415
1416       if (!gtk_widget_get_child_visible (child))
1417         continue;
1418
1419       if (!EMPATHY_IS_ROSTER_CONTACT (child))
1420         continue;
1421
1422       egg_list_box_select_child (EGG_LIST_BOX (self), child);
1423       break;
1424     }
1425
1426   g_list_free (children);
1427 }
1428
1429 static void
1430 search_text_notify_cb (EmpathyLiveSearch *search,
1431     GParamSpec *pspec,
1432     EmpathyRosterView *self)
1433 {
1434   egg_list_box_refilter (EGG_LIST_BOX (self));
1435
1436   select_first_contact (self);
1437 }
1438
1439 static void
1440 search_activate_cb (GtkWidget *search,
1441   EmpathyRosterView *self)
1442 {
1443   EggListBox *box = EGG_LIST_BOX (self);
1444   GtkWidget *child;
1445
1446   child = egg_list_box_get_selected_child (box);
1447   if (child == NULL)
1448     return;
1449
1450   empathy_roster_view_child_activated (box, child);
1451 }
1452
1453 void
1454 empathy_roster_view_set_live_search (EmpathyRosterView *self,
1455     EmpathyLiveSearch *search)
1456 {
1457   if (self->priv->search != NULL)
1458     {
1459       g_signal_handlers_disconnect_by_func (self->priv->search,
1460           search_text_notify_cb, self);
1461       g_signal_handlers_disconnect_by_func (self->priv->search,
1462           search_activate_cb, self);
1463
1464       g_clear_object (&self->priv->search);
1465     }
1466
1467   if (search == NULL)
1468     return;
1469
1470   self->priv->search = g_object_ref (search);
1471
1472   g_signal_connect (self->priv->search, "notify::text",
1473       G_CALLBACK (search_text_notify_cb), self);
1474   g_signal_connect (self->priv->search, "activate",
1475       G_CALLBACK (search_activate_cb), self);
1476 }
1477
1478 gboolean
1479 empathy_roster_view_is_empty (EmpathyRosterView *self)
1480 {
1481   return self->priv->empty;
1482 }
1483
1484 gboolean
1485 empathy_roster_view_is_searching (EmpathyRosterView *self)
1486 {
1487   return (self->priv->search != NULL &&
1488       gtk_widget_get_visible (GTK_WIDGET (self->priv->search)));
1489 }
1490
1491 /* Don't use EmpathyEvent as I prefer to keep this object not too specific to
1492  * Empathy's internals. */
1493 guint
1494 empathy_roster_view_add_event (EmpathyRosterView *self,
1495     FolksIndividual *individual,
1496     const gchar *icon,
1497     gpointer user_data)
1498 {
1499   GHashTable *contacts;
1500
1501   contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
1502   if (contacts == NULL)
1503     return 0;
1504
1505   self->priv->last_event_id++;
1506
1507   g_queue_push_head (self->priv->events,
1508       event_new (self->priv->last_event_id, individual, icon, user_data));
1509
1510   start_flashing (self);
1511
1512   return self->priv->last_event_id;
1513 }
1514
1515 void
1516 empathy_roster_view_remove_event (EmpathyRosterView *self,
1517     guint event_id)
1518 {
1519   GList *l;
1520
1521   for (l = g_queue_peek_head_link (self->priv->events); l != NULL;
1522       l = g_list_next (l))
1523     {
1524       Event *event = l->data;
1525
1526       if (event->id == event_id)
1527         {
1528           remove_event (self, event);
1529           return;
1530         }
1531     }
1532 }
1533
1534 FolksIndividual *
1535 empathy_roster_view_get_selected_individual (EmpathyRosterView *self)
1536 {
1537   GtkWidget *child;
1538
1539   child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
1540
1541   if (!EMPATHY_IS_ROSTER_CONTACT (child))
1542     return NULL;
1543
1544   return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
1545 }