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