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