[gnome-calendar] search-view: add a timeout for displaying the 'no results' page



commit a12e3cb59de364a25ca2439a0484f8cf789ec3ec
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Jan 4 11:23:28 2015 -0200

    search-view: add a timeout for displaying the 'no results' page
    
    When the user types, *all* entries are removed, then readded.
    
    Because of it, the 'No results' page keeps flickering. This patch fixes this.

 src/gcal-search-view.c |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/src/gcal-search-view.c b/src/gcal-search-view.c
index 9ddd129..484241e 100644
--- a/src/gcal-search-view.c
+++ b/src/gcal-search-view.c
@@ -36,6 +36,7 @@ typedef struct
   GtkWidget      *no_results_grid;
 
   /* misc */
+  gint            no_results_timeout_id;
   gint            num_results;
   gchar          *time_mask;
   gchar          *date_mask;
@@ -52,6 +53,8 @@ enum
   PROP_MANAGER  /* manager inherited property */
 };
 
+#define NO_RESULT_TIMEOUT 250 /* ms */
+
 static GtkWidget*     get_event_from_grid                       (GtkWidget            *grid);
 
 static GtkWidget*     make_grid_for_event                       (GcalSearchView       *view,
@@ -64,6 +67,8 @@ static gint           sort_by_event                             (GtkListBoxRow
 static void           open_event                                (GcalEventWidget      *event_widget,
                                                                  gpointer              user_data);
 
+static gboolean       show_no_results_page                      (GcalSearchView       *view);
+
 static void           gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface);
 
 static void           gcal_view_interface_init                  (GcalViewIface  *iface);
@@ -221,6 +226,20 @@ open_event (GcalEventWidget *event_widget,
   g_signal_emit_by_name (GCAL_VIEW (user_data), "event-activated", event_widget);
 }
 
+static gboolean
+show_no_results_page (GcalSearchView *view)
+{
+  GcalSearchViewPrivate *priv;
+
+  priv = gcal_search_view_get_instance_private (view);
+  priv->no_results_timeout_id = 0;
+
+  gtk_widget_set_visible (priv->frame, priv->num_results != 0);
+  gtk_widget_set_visible (priv->no_results_grid, priv->num_results == 0);
+
+  return G_SOURCE_REMOVE;
+}
+
 static void
 gcal_search_view_class_init (GcalSearchViewClass *klass)
 {
@@ -406,8 +425,11 @@ gcal_search_view_component_added (ECalDataModelSubscriber *subscriber,
   gtk_container_add (GTK_CONTAINER (priv->listbox), grid);
   priv->num_results++;
 
-  gtk_widget_set_visible (priv->frame, priv->num_results != 0);
-  gtk_widget_set_visible (priv->no_results_grid, priv->num_results == 0);
+  /* show the 'no results' page with a delay */
+  if (priv->no_results_timeout_id != 0)
+    g_source_remove (priv->no_results_timeout_id);
+
+  priv->no_results_timeout_id = g_timeout_add (NO_RESULT_TIMEOUT, (GSourceFunc) show_no_results_page, 
subscriber);
 }
 
 static void
@@ -460,8 +482,11 @@ gcal_search_view_component_removed (ECalDataModelSubscriber *subscriber,
   g_list_free (children);
   priv->num_results--;
 
-  gtk_widget_set_visible (priv->frame, priv->num_results != 0);
-  gtk_widget_set_visible (priv->no_results_grid, priv->num_results == 0);
+  /* show the 'no results' page with a delay */
+  if (priv->no_results_timeout_id != 0)
+    g_source_remove (priv->no_results_timeout_id);
+
+  priv->no_results_timeout_id = g_timeout_add (NO_RESULT_TIMEOUT, (GSourceFunc) show_no_results_page, 
subscriber);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]