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



commit e394293204977f46523b003af278890a714cee59
Author: David King <davidk gnome org>
Date:   Thu Feb 13 12:07:56 2014 +0000

    Add security event view rows in an idle handler

 src/gl-eventview.c |   79 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 61 insertions(+), 18 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index f1d7e49..b3561e9 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -280,44 +280,87 @@ insert_journal_query_devices (GlEventView *view,
     gl_journal_results_free (results);
 }
 
+static gboolean
+insert_security_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)
+            {
+                if (result->audit_session == NULL)
+                {
+                    continue;
+                }
+
+                row = gl_event_view_row_new (result,
+                                             GL_EVENT_VIEW_ROW_STYLE_CMDLINE,
+                                             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_security (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))
-    {
-        GtkWidget *row;
-        GlJournalResult *result = (GlJournalResult *)l->data;
-
-        /* Skip if the journal entry does not have an associated audit
-         * session. */
-        if (result->audit_session == NULL)
-        {
-            continue;
-        }
+    priv->pending_results = g_queue_new ();
 
-        row = gl_event_view_row_new (result, GL_EVENT_VIEW_ROW_STYLE_CMDLINE,
-                                     priv->clock_format);
-        gtk_container_add (GTK_CONTAINER (listbox), row);
+    for (l = priv->results; l != NULL; l = g_list_next (l))
+    {
+        g_queue_push_tail (priv->pending_results, l->data);
     }
 
-    gl_journal_results_free (results);
+    idle_id = g_idle_add ((GSourceFunc) insert_security_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]