[gnome-logs/wip/batching: 2/4] Add simple event view rows in an idle handler



commit ff03be3273931a3444354316283e58a3e6ee195b
Author: David King <davidk gnome org>
Date:   Thu Feb 13 11:55:12 2014 +0000

    Add simple event view rows in an idle handler

 src/gl-eventview.c |   66 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 55 insertions(+), 11 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index c17da12..f1d7e49 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -320,37 +320,81 @@ insert_journal_query_security (GlEventView *view,
     gl_journal_results_free (results);
 }
 
+static gboolean
+insert_simple_idle (GlEventView *view)
+{
+    GlEventViewPrivate *priv;
+
+    priv = gl_event_view_get_instance_private (view);
+
+    if (priv->pending_results)
+    {
+        gssize i;
+
+        for (i = 0; i < N_RESULTS_IDLE; i++)
+        {
+            GlJournalResult *result;
+            GtkWidget *row;
+
+            result = g_queue_pop_head (priv->pending_results);
+
+            if (result)
+            {
+                row = gl_event_view_row_new (result,
+                                             GL_EVENT_VIEW_ROW_STYLE_SIMPLE,
+                                             priv->clock_format);
+                gtk_container_add (GTK_CONTAINER (priv->results_listbox), row);
+                gtk_widget_show_all (row);
+            }
+            else
+            {
+                g_queue_free (priv->pending_results);
+                gl_journal_results_free (priv->results);
+                priv->pending_results = NULL;
+                priv->results_listbox = NULL;
+                priv->results = NULL;
+
+                return G_SOURCE_REMOVE;
+            }
+        }
+
+        return G_SOURCE_CONTINUE;
+    }
+    else
+    {
+        return G_SOURCE_REMOVE;
+    }
+}
+
 static void
 insert_journal_query_simple (GlEventView *view,
                              const GlJournalQuery *query,
                              GtkListBox *listbox)
 {
     GlEventViewPrivate *priv;
-    GList *results = NULL;
     GList *l;
     gsize n_results;
+    guint idle_id;
 
     priv = gl_event_view_get_instance_private (view);
-    results = gl_journal_query (priv->journal, query);
+    priv->results = gl_journal_query (priv->journal, query);
+    priv->results_listbox = listbox;
 
-    n_results = g_list_length (results);
+    n_results = g_list_length (priv->results);
 
     if ((n_results != -1) && (n_results != N_RESULTS))
     {
         g_debug ("Number of results different than requested");
     }
 
-    for (l = results; l != NULL; l = g_list_next (l))
+    priv->pending_results = g_queue_new ();
+    for (l = priv->results; l != NULL; l = g_list_next (l))
     {
-        GtkWidget *row;
-
-        row = gl_event_view_row_new ((GlJournalResult *)l->data,
-                                     GL_EVENT_VIEW_ROW_STYLE_SIMPLE,
-                                     priv->clock_format);
-        gtk_container_add (GTK_CONTAINER (listbox), row);
+        g_queue_push_tail (priv->pending_results, l->data);
     }
 
-    gl_journal_results_free (results);
+    idle_id = g_idle_add ((GSourceFunc) insert_simple_idle, view);
+    g_source_set_name_by_id (idle_id, G_STRFUNC);
 }
 
 static gboolean


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