From 35c4220f495a85db3d32df86d0a62a1039cdc915 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 2 Oct 2012 14:59:55 +0200 Subject: roster-view: add some delay before actually starting the live search This avoid stacking a bunch of useless searches while user is typing as we can't stop the old search before starting the new one. https://bugzilla.gnome.org/show_bug.cgi?id=685278 --- libempathy-gtk/empathy-roster-view.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'libempathy-gtk/empathy-roster-view.c') diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c index d54bd052c..c3ae66e25 100644 --- a/libempathy-gtk/empathy-roster-view.c +++ b/libempathy-gtk/empathy-roster-view.c @@ -17,6 +17,10 @@ G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX) /* Flashing delay for icons (milliseconds). */ #define FLASH_TIMEOUT 500 +/* Delay in milliseconds between the last stroke on the keyboard and the start + * of the live search. */ +#define SEARCH_TIMEOUT 500 + enum { PROP_MODEL = 1, @@ -61,6 +65,8 @@ struct _EmpathyRosterViewPriv guint flash_id; gboolean display_flash_event; + guint search_id; + gboolean show_offline; gboolean show_groups; gboolean empty; @@ -1078,6 +1084,12 @@ empathy_roster_view_dispose (GObject *object) empathy_roster_view_set_live_search (self, NULL); g_clear_object (&self->priv->model); + if (self->priv->search_id != 0) + { + g_source_remove (self->priv->search_id); + self->priv->search_id = 0; + } + if (chain_up != NULL) chain_up (object); } @@ -1437,14 +1449,27 @@ select_first_contact (EmpathyRosterView *self) g_list_free (children); } +static gboolean +search_timeout_cb (EmpathyRosterView *self) +{ + egg_list_box_refilter (EGG_LIST_BOX (self)); + + select_first_contact (self); + + self->priv->search_id = 0; + return G_SOURCE_REMOVE; +} + static void search_text_notify_cb (EmpathyLiveSearch *search, GParamSpec *pspec, EmpathyRosterView *self) { - egg_list_box_refilter (EGG_LIST_BOX (self)); + if (self->priv->search_id != 0) + g_source_remove (self->priv->search_id); - select_first_contact (self); + self->priv->search_id = g_timeout_add (SEARCH_TIMEOUT, + (GSourceFunc) search_timeout_cb, self); } static void -- cgit v1.2.3