[gnome-logs/wip/larsu/listmodel: 17/18] Rename GlJournalResult to GlJournalEntry



commit 7a42a67745d7f11250eb5ed94c81cda8cf69ad4c
Author: Lars Uebernickel <lars uebernic de>
Date:   Sat Feb 14 19:42:27 2015 +0100

    Rename GlJournalResult to GlJournalEntry
    
    This is more in tune with systemd's parlance.
    
    Also make it a GObject so that we can put it into a GListModel soon.

 src/gl-eventview.c       |    6 +-
 src/gl-eventviewdetail.c |   52 +++++++-------
 src/gl-eventviewdetail.h |    2 +-
 src/gl-eventviewlist.c   |   95 +++++++++++++++-----------
 src/gl-eventviewlist.h   |    2 +-
 src/gl-eventviewrow.c    |   59 ++++++++--------
 src/gl-eventviewrow.h    |    4 +-
 src/gl-journal.c         |  173 +++++++++++++++++++++++++++++++---------------
 src/gl-journal.h         |   31 +++-----
 9 files changed, 246 insertions(+), 178 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 975df63..772b160 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -41,7 +41,7 @@ enum
 typedef struct
 {
     GtkWidget *events;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     GlUtilClockFormat clock_format;
     GlEventViewMode mode;
 } GlEventViewPrivate;
@@ -62,7 +62,7 @@ gl_event_view_show_detail (GlEventView *view)
 
     priv = gl_event_view_get_instance_private (view);
     events = GL_EVENT_VIEW_LIST (priv->events);
-    priv->result = gl_event_view_list_get_detail_result (events);
+    priv->entry = gl_event_view_list_get_detail_entry (events);
 }
 
 gboolean
@@ -146,7 +146,7 @@ on_notify_mode (GlEventView *view,
         case GL_EVENT_VIEW_MODE_DETAIL:
             {
                 gl_event_view_show_detail (view);
-                detail = gl_event_view_detail_new (priv->result,
+                detail = gl_event_view_detail_new (priv->entry,
                                                    priv->clock_format);
                 gtk_widget_show_all (detail);
                 gtk_stack_add_named (stack, detail, "detail");
diff --git a/src/gl-eventviewdetail.c b/src/gl-eventviewdetail.c
index a9f1e35..12c24ec 100644
--- a/src/gl-eventviewdetail.c
+++ b/src/gl-eventviewdetail.c
@@ -27,13 +27,13 @@ enum
 {
     PROP_0,
     PROP_CLOCK_FORMAT,
-    PROP_RESULT,
+    PROP_ENTRY,
     N_PROPERTIES
 };
 
 typedef struct
 {
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     GlUtilClockFormat clock_format;
     GtkWidget *grid;
     GtkWidget *comm_image;
@@ -64,7 +64,7 @@ static void
 gl_event_view_detail_create_detail (GlEventViewDetail *detail)
 {
     GlEventViewDetailPrivate *priv;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     gchar *str;
     gchar *str_field;
     gchar *str_message;
@@ -73,7 +73,7 @@ gl_event_view_detail_create_detail (GlEventViewDetail *detail)
 
     priv = gl_event_view_detail_get_instance_private (detail);
 
-    result = priv->result;
+    entry = priv->entry;
 
     /* Force LTR direction also for RTL languages */
     gtk_widget_set_direction (priv->grid, GTK_TEXT_DIR_LTR);
@@ -87,13 +87,13 @@ gl_event_view_detail_create_detail (GlEventViewDetail *detail)
     gtk_widget_set_direction (priv->documentation_label, GTK_TEXT_DIR_LTR);
     gtk_widget_set_direction (priv->detailed_message_label, GTK_TEXT_DIR_LTR);
 
-    if (result->comm && *result->comm)
+    if (gl_journal_entry_get_command_line (entry))
     {
         /* Command-line, look for a desktop file. */
         GDesktopAppInfo *desktop;
 
         /* TODO: Use g_desktop_app_info_search? */
-        str = g_strconcat (result->comm, ".desktop", NULL);
+        str = g_strconcat (gl_journal_entry_get_command_line (entry), ".desktop", NULL);
         desktop = g_desktop_app_info_new (str);
         g_free (str);
 
@@ -112,46 +112,46 @@ gl_event_view_detail_create_detail (GlEventViewDetail *detail)
         }
         else
         {
-            gtk_label_set_text (GTK_LABEL (priv->comm_label), result->comm);
+            gtk_label_set_text (GTK_LABEL (priv->comm_label), gl_journal_entry_get_command_line (entry));
         }
     }
 
     now = g_date_time_new_now_local ();
-    str = gl_util_timestamp_to_display (result->timestamp, now,
+    str = gl_util_timestamp_to_display (gl_journal_entry_get_timestamp (entry), now,
                                         priv->clock_format);
     g_date_time_unref (now);
     gtk_label_set_text (GTK_LABEL (priv->time_label), str);
     g_free (str);
 
-    gtk_label_set_text (GTK_LABEL (priv->message_label), result->message);
+    gtk_label_set_text (GTK_LABEL (priv->message_label), gl_journal_entry_get_message (entry));
 
-    if (result->audit_session && *result->audit_session)
+    if (gl_journal_entry_get_audit_session (entry))
     {
-        gtk_label_set_text (GTK_LABEL (priv->audit_label), result->audit_session);
+        gtk_label_set_text (GTK_LABEL (priv->audit_label), gl_journal_entry_get_audit_session (entry));
         gtk_widget_show (priv->audit_field_label);
         gtk_widget_show (priv->audit_label);
     }
 
-    if (result->kernel_device && *result->kernel_device)
+    if (gl_journal_entry_get_kernel_device (entry))
     {
-        gtk_label_set_text (GTK_LABEL (priv->device_label), result->kernel_device);
+        gtk_label_set_text (GTK_LABEL (priv->device_label), gl_journal_entry_get_kernel_device (entry));
         gtk_widget_show (priv->device_field_label);
         gtk_widget_show (priv->device_label);
     }
 
     /* TODO: Give a user-friendly representation of the priority. */
-    str = g_strdup_printf ("%d", result->priority);
+    str = g_strdup_printf ("%d", gl_journal_entry_get_priority (entry));
     gtk_label_set_text (GTK_LABEL (priv->priority_label), str);
     g_free (str);
 
-    if (result->catalog != NULL)
+    if (gl_journal_entry_get_catalog (entry) != NULL)
     {
         gint subject_count = 0;
         gint definedby_count = 0;
         gint support_count = 0;
         gint documentation_count = 0;
 
-        str_copy = g_strdup (result->catalog);
+        str_copy = g_strdup (gl_journal_entry_get_catalog (entry));
 
         do
         {
@@ -325,7 +325,7 @@ gl_event_view_detail_finalize (GObject *object)
     GlEventViewDetail *detail = GL_EVENT_VIEW_DETAIL (object);
     GlEventViewDetailPrivate *priv = gl_event_view_detail_get_instance_private (detail);
 
-    g_clear_pointer (&priv->result, gl_journal_result_unref);
+    g_clear_object (&priv->entry);
 }
 
 static void
@@ -342,8 +342,8 @@ gl_event_view_detail_get_property (GObject *object,
         case PROP_CLOCK_FORMAT:
             g_value_set_enum (value, priv->clock_format);
             break;
-        case PROP_RESULT:
-            g_value_set_boxed (value, priv->result);
+        case PROP_ENTRY:
+            g_value_set_object (value, priv->entry);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -365,8 +365,8 @@ gl_event_view_detail_set_property (GObject *object,
         case PROP_CLOCK_FORMAT:
             priv->clock_format = g_value_get_enum (value);
             break;
-        case PROP_RESULT:
-            priv->result = g_value_dup_boxed (value);
+        case PROP_ENTRY:
+            priv->entry = g_value_dup_object (value);
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -404,9 +404,9 @@ gl_event_view_detail_class_init (GlEventViewDetailClass *klass)
                                                            G_PARAM_CONSTRUCT_ONLY |
                                                            G_PARAM_STATIC_STRINGS);
 
-    obj_properties[PROP_RESULT] = g_param_spec_boxed ("result", "Result",
-                                                      "Journal query result for this detailed view",
-                                                      GL_TYPE_JOURNAL_RESULT,
+    obj_properties[PROP_ENTRY] = g_param_spec_object ("entry", "Entry",
+                                                      "Journal entry for this detailed view",
+                                                      GL_TYPE_JOURNAL_ENTRY,
                                                       G_PARAM_READWRITE |
                                                       G_PARAM_CONSTRUCT_ONLY |
                                                       G_PARAM_STATIC_STRINGS);
@@ -463,9 +463,9 @@ gl_event_view_detail_init (GlEventViewDetail *detail)
 }
 
 GtkWidget *
-gl_event_view_detail_new (GlJournalResult *result,
+gl_event_view_detail_new (GlJournalEntry *entry,
                           GlUtilClockFormat clock_format)
 {
-    return g_object_new (GL_TYPE_EVENT_VIEW_DETAIL, "result", result,
+    return g_object_new (GL_TYPE_EVENT_VIEW_DETAIL, "entry", entry,
                          "clock-format", clock_format, NULL);
 }
diff --git a/src/gl-eventviewdetail.h b/src/gl-eventviewdetail.h
index b15d3bb..0e4d7a5 100644
--- a/src/gl-eventviewdetail.h
+++ b/src/gl-eventviewdetail.h
@@ -42,7 +42,7 @@ typedef struct
 #define GL_EVENT_VIEW_DETAIL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_EVENT_VIEW_DETAIL, 
GlEventViewDetail))
 
 GType gl_event_view_detail_get_type (void);
-GtkWidget * gl_event_view_detail_new (GlJournalResult *result, GlUtilClockFormat clock_format);
+GtkWidget * gl_event_view_detail_new (GlJournalEntry *result, GlUtilClockFormat clock_format);
 
 G_END_DECLS
 
diff --git a/src/gl-eventviewlist.c b/src/gl-eventviewlist.c
index 110afd8..6602223 100644
--- a/src/gl-eventviewlist.c
+++ b/src/gl-eventviewlist.c
@@ -34,7 +34,7 @@
 typedef struct
 {
     GlJournal *journal;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     GlUtilClockFormat clock_format;
     GtkListBox *active_listbox;
     GtkWidget *categories;
@@ -80,15 +80,23 @@ gl_event_view_search_is_case_sensitive (GlEventViewList *view)
 }
 
 static gboolean
-search_in_result (GlJournalResult *result,
+search_in_result (GlJournalEntry *entry,
                   const gchar *search_text)
 {
-    if ((result->comm ? strstr (result->comm, search_text) : NULL)
-        || (result->message ? strstr (result->message, search_text) : NULL)
-        || (result->kernel_device ? strstr (result->kernel_device, search_text)
-                                  : NULL)
-        || (result->audit_session ? strstr (result->audit_session, search_text)
-                                  : NULL))
+    const gchar *comm;
+    const gchar *message;
+    const gchar *kernel_device;
+    const gchar *audit_session;
+
+    comm = gl_journal_entry_get_command_line (entry);
+    message = gl_journal_entry_get_message (entry);
+    kernel_device = gl_journal_entry_get_kernel_device (entry);
+    audit_session = gl_journal_entry_get_audit_session (entry);
+
+    if ((comm ? strstr (comm, search_text) : NULL)
+        || (message ? strstr (message, search_text) : NULL)
+        || (kernel_device ? strstr (kernel_device, search_text) : NULL)
+        || (audit_session ? strstr (audit_session, search_text) : NULL))
     {
         return TRUE;
     }
@@ -110,33 +118,39 @@ listbox_search_filter_func (GtkListBoxRow *row,
     }
     else
     {
-        GlJournalResult *result;
+        GlJournalEntry *entry;
 
-        result = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row));
+        entry = gl_event_view_row_get_entry (GL_EVENT_VIEW_ROW (row));
 
         if (gl_event_view_search_is_case_sensitive (view))
         {
-            if (search_in_result (result, priv->search_text))
+            if (search_in_result (entry, priv->search_text))
             {
                 return TRUE;
             }
         }
+#if 0
         else
         {
             gchar *casefolded_text;
             GlJournalResult casefolded;
+            const gchar *comm;
+            const gchar *message;
+            const gchar *kernel_device;
+            const gchar *audit_session;
+
+            comm = gl_journal_entry_get_command_line (entry);
+            message = gl_journal_entry_get_message (entry);
+            kernel_device = gl_journal_entry_get_kernel_device (entry);
+            audit_session = gl_journal_entry_get_audit_session (entry);
 
             /* Case-insensitive search. */
             casefolded_text = g_utf8_casefold (priv->search_text, -1);
 
-            casefolded.comm = result->comm ? g_utf8_casefold (result->comm, -1)
-                                           : NULL;
-            casefolded.message = result->message ? g_utf8_casefold (result->message, -1)
-                                                 : NULL;
-            casefolded.kernel_device = result->kernel_device ? g_utf8_casefold (result->kernel_device, -1)
-                                                             : NULL;
-            casefolded.audit_session = result->audit_session ? g_utf8_casefold (result->audit_session, -1)
-                                                             : NULL;
+            casefolded.comm = comm ? g_utf8_casefold (comm, -1) : NULL;
+            casefolded.message = message ? g_utf8_casefold (message, -1) : NULL;
+            casefolded.kernel_device = kernel_device ? g_utf8_casefold (kernel_device, -1) : NULL;
+            casefolded.audit_session = audit_session ? g_utf8_casefold (audit_session, -1) : NULL;
 
             if (search_in_result (&casefolded, casefolded_text))
             {
@@ -155,6 +169,7 @@ listbox_search_filter_func (GtkListBoxRow *row,
             g_free (casefolded.audit_session);
             g_free (casefolded_text);
         }
+#endif
     }
 
     return FALSE;
@@ -169,7 +184,7 @@ on_listbox_row_activated (GtkListBox *listbox,
     GtkWidget *toplevel;
 
     priv = gl_event_view_list_get_instance_private (view);
-    priv->result = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row));
+    priv->entry = gl_event_view_row_get_entry (GL_EVENT_VIEW_ROW (row));
 
     toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
 
@@ -193,14 +208,14 @@ on_listbox_row_activated (GtkListBox *listbox,
     }
 }
 
-GlJournalResult *
-gl_event_view_list_get_detail_result (GlEventViewList *view)
+GlJournalEntry *
+gl_event_view_list_get_detail_entry (GlEventViewList *view)
 {
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
 
-    return priv->result;
+    return priv->entry;
 }
 
 gboolean
@@ -314,19 +329,19 @@ insert_idle (gpointer data)
 
     for (i = 0; i < N_RESULTS_IDLE; i++)
     {
-        GlJournalResult *result;
+        GlJournalEntry *entry;
         GtkWidget *row;
 
-        result = gl_journal_previous (priv->journal);
-        if (result)
+        entry = gl_journal_previous (priv->journal);
+        if (entry)
         {
-            row = gl_event_view_row_new (result,
+            row = gl_event_view_row_new (entry,
                                          priv->current_row_style,
                                          priv->clock_format);
             gtk_container_add (GTK_CONTAINER (priv->active_listbox), row);
             gtk_widget_show_all (row);
 
-            gl_journal_result_unref (result);
+            g_object_unref (entry);
         }
         else
         {
@@ -473,15 +488,15 @@ static gint
 gl_event_view_sort_by_ascending_time (GtkListBoxRow *row1,
                                       GtkListBoxRow *row2)
 {
-    GlJournalResult *result1;
-    GlJournalResult *result2;
+    GlJournalEntry *entry1;
+    GlJournalEntry *entry2;
     guint64 time1;
     guint64 time2;
 
-    result1 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row1));
-    result2 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row2));
-    time1 = result1->timestamp;
-    time2 = result2->timestamp;
+    entry1 = gl_event_view_row_get_entry (GL_EVENT_VIEW_ROW (row1));
+    entry2 = gl_event_view_row_get_entry (GL_EVENT_VIEW_ROW (row2));
+    time1 = gl_journal_entry_get_timestamp (entry1);
+    time2 = gl_journal_entry_get_timestamp (entry2);
 
     if (time1 > time2)
     {
@@ -501,15 +516,15 @@ static gint
 gl_event_view_sort_by_descending_time (GtkListBoxRow *row1,
                                        GtkListBoxRow *row2)
 {
-    GlJournalResult *result1;
-    GlJournalResult *result2;
+    GlJournalEntry *entry1;
+    GlJournalEntry *entry2;
     guint64 time1;
     guint64 time2;
 
-    result1 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row1));
-    result2 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row2));
-    time1 = result1->timestamp;
-    time2 = result2->timestamp;
+    entry1 = gl_event_view_row_get_entry (GL_EVENT_VIEW_ROW (row1));
+    entry2 = gl_event_view_row_get_entry (GL_EVENT_VIEW_ROW (row2));
+    time1 = gl_journal_entry_get_timestamp (entry1);
+    time2 = gl_journal_entry_get_timestamp (entry2);
 
     if (time1 > time2)
     {
diff --git a/src/gl-eventviewlist.h b/src/gl-eventviewlist.h
index 64956d0..bd3b023 100644
--- a/src/gl-eventviewlist.h
+++ b/src/gl-eventviewlist.h
@@ -44,7 +44,7 @@ typedef struct
 GType gl_event_view_list_get_type (void);
 GtkWidget * gl_event_view_list_new (void);
 void gl_event_view_list_search (GlEventViewList *view, const gchar *needle);
-GlJournalResult *gl_event_view_list_get_detail_result (GlEventViewList *view);
+GlJournalEntry *gl_event_view_list_get_detail_entry (GlEventViewList *view);
 gboolean gl_event_view_list_handle_search_event (GlEventViewList *view,
                                                  GAction *action,
                                                  GdkEvent *event);
diff --git a/src/gl-eventviewrow.c b/src/gl-eventviewrow.c
index 5d3df33..ce9aac3 100644
--- a/src/gl-eventviewrow.c
+++ b/src/gl-eventviewrow.c
@@ -28,7 +28,7 @@ enum
 {
     PROP_0,
     PROP_CLOCK_FORMAT,
-    PROP_RESULT,
+    PROP_ENTRY,
     PROP_STYLE,
     N_PROPERTIES
 };
@@ -36,7 +36,7 @@ enum
 typedef struct
 {
     GlUtilClockFormat clock_format;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     GlEventViewRowStyle style;
 } GlEventViewRowPrivate;
 
@@ -50,7 +50,7 @@ gl_event_view_row_finalize (GObject *object)
     GlEventViewRow *row = GL_EVENT_VIEW_ROW (object);
     GlEventViewRowPrivate *priv = gl_event_view_row_get_instance_private (row);
 
-    g_clear_pointer (&priv->result, gl_journal_result_unref);
+    g_clear_object (&priv->entry);
 }
 
 static void
@@ -67,8 +67,8 @@ gl_event_view_row_get_property (GObject *object,
         case PROP_CLOCK_FORMAT:
             g_value_set_enum (value, priv->clock_format);
             break;
-        case PROP_RESULT:
-            g_value_set_boxed (value, priv->result);
+        case PROP_ENTRY:
+            g_value_set_object (value, priv->entry);
             break;
         case PROP_STYLE:
             g_value_set_enum (value, priv->style);
@@ -93,8 +93,8 @@ gl_event_view_row_set_property (GObject *object,
         case PROP_CLOCK_FORMAT:
             priv->clock_format = g_value_get_enum (value);
             break;
-        case PROP_RESULT:
-            priv->result = g_value_dup_boxed (value);
+        case PROP_ENTRY:
+            priv->entry = g_value_dup_object (value);
             break;
         case PROP_STYLE:
             priv->style = g_value_get_enum (value);
@@ -116,11 +116,11 @@ gl_event_view_row_create_cmdline (GlEventViewRow *row)
     gchar *time;
     gboolean rtl;
     GtkWidget *image;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     GDateTime *now;
 
     priv = gl_event_view_row_get_instance_private (row);
-    result = priv->result;
+    entry = priv->entry;
 
     rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
 
@@ -130,8 +130,11 @@ gl_event_view_row_create_cmdline (GlEventViewRow *row)
     gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
     gtk_container_add (GTK_CONTAINER (row), grid);
 
-    markup = g_markup_printf_escaped ("<b>%s</b>",
-                                      result->comm ? result->comm : "");
+    if (gl_journal_entry_get_command_line (entry))
+      markup = g_markup_printf_escaped ("<b>%s</b>", gl_journal_entry_get_command_line (entry));
+    else
+      markup = g_strdup ("");
+
     label = gtk_label_new (NULL);
     gtk_widget_set_direction (label, GTK_TEXT_DIR_LTR);
     gtk_widget_set_hexpand (label, TRUE);
@@ -141,7 +144,7 @@ gl_event_view_row_create_cmdline (GlEventViewRow *row)
     g_free (markup);
     gtk_grid_attach (GTK_GRID (grid), label, rtl ? 1 : 0, 0, 1, 1);
 
-    label = gtk_label_new (result->message);
+    label = gtk_label_new (gl_journal_entry_get_message (entry));
     gtk_widget_set_direction (label, GTK_TEXT_DIR_LTR);
     context = gtk_widget_get_style_context (GTK_WIDGET (label));
     gtk_style_context_add_class (context, "event-monospace");
@@ -150,8 +153,8 @@ gl_event_view_row_create_cmdline (GlEventViewRow *row)
     gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 2, 1);
 
     now = g_date_time_new_now_local ();
-    time = gl_util_timestamp_to_display (result->timestamp, now,
-                                         priv->clock_format);
+    time = gl_util_timestamp_to_display (gl_journal_entry_get_timestamp (entry),
+                                         now, priv->clock_format);
     g_date_time_unref (now);
     label = gtk_label_new (time);
     context = gtk_widget_get_style_context (GTK_WIDGET (label));
@@ -177,11 +180,11 @@ gl_event_view_row_create_simple (GlEventViewRow *row)
     gchar *time;
     gboolean rtl;
     GtkWidget *image;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     GDateTime *now;
 
     priv = gl_event_view_row_get_instance_private (row);
-    result = priv->result;
+    entry = priv->entry;
 
     rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
 
@@ -191,7 +194,7 @@ gl_event_view_row_create_simple (GlEventViewRow *row)
     gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
     gtk_container_add (GTK_CONTAINER (row), grid);
 
-    label = gtk_label_new (result->message);
+    label = gtk_label_new (gl_journal_entry_get_message (entry));
     gtk_widget_set_direction (label, GTK_TEXT_DIR_LTR);
     context = gtk_widget_get_style_context (GTK_WIDGET (label));
     gtk_style_context_add_class (context, "event-monospace");
@@ -201,8 +204,8 @@ gl_event_view_row_create_simple (GlEventViewRow *row)
     gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
 
     now = g_date_time_new_now_local ();
-    time = gl_util_timestamp_to_display (result->timestamp, now,
-                                         priv->clock_format);
+    time = gl_util_timestamp_to_display (gl_journal_entry_get_timestamp (entry),
+                                         now, priv->clock_format);
     g_date_time_unref (now);
     label = gtk_label_new (time);
     context = gtk_widget_get_style_context (GTK_WIDGET (label));
@@ -260,9 +263,9 @@ gl_event_view_row_class_init (GlEventViewRowClass *klass)
                                                            G_PARAM_CONSTRUCT_ONLY |
                                                            G_PARAM_STATIC_STRINGS);
 
-    obj_properties[PROP_RESULT] = g_param_spec_boxed ("result", "Result",
-                                                      "Journal query result for this row",
-                                                      GL_TYPE_JOURNAL_RESULT,
+    obj_properties[PROP_ENTRY] = g_param_spec_object ("entry", "Entry",
+                                                      "Journal entry for this row",
+                                                      GL_TYPE_JOURNAL_ENTRY,
                                                       G_PARAM_READWRITE |
                                                       G_PARAM_CONSTRUCT_ONLY |
                                                       G_PARAM_STATIC_STRINGS);
@@ -285,8 +288,8 @@ gl_event_view_row_init (GlEventViewRow *row)
     /* See gl_event_view_row_constructed (). */
 }
 
-GlJournalResult *
-gl_event_view_row_get_result (GlEventViewRow *row)
+GlJournalEntry *
+gl_event_view_row_get_entry (GlEventViewRow *row)
 {
     GlEventViewRowPrivate *priv;
 
@@ -294,14 +297,14 @@ gl_event_view_row_get_result (GlEventViewRow *row)
 
     priv = gl_event_view_row_get_instance_private (row);
 
-    return priv->result;
+    return priv->entry;
 }
 
 GtkWidget *
-gl_event_view_row_new (GlJournalResult *result,
+gl_event_view_row_new (GlJournalEntry *entry,
                        GlEventViewRowStyle style,
                        GlUtilClockFormat clock_format)
 {
-    return g_object_new (GL_TYPE_EVENT_VIEW_ROW, "style", style, "result",
-                         result, "clock-format", clock_format, NULL);
+    return g_object_new (GL_TYPE_EVENT_VIEW_ROW, "style", style, "entry",
+                         entry, "clock-format", clock_format, NULL);
 }
diff --git a/src/gl-eventviewrow.h b/src/gl-eventviewrow.h
index b6c9eac..33559e6 100644
--- a/src/gl-eventviewrow.h
+++ b/src/gl-eventviewrow.h
@@ -56,8 +56,8 @@ typedef enum
 #define GL_EVENT_VIEW_ROW(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_EVENT_VIEW_ROW, 
GlEventViewRow))
 
 GType gl_event_view_row_get_type (void);
-GtkWidget * gl_event_view_row_new (GlJournalResult *result, GlEventViewRowStyle style, GlUtilClockFormat 
clock_format);
-GlJournalResult * gl_event_view_row_get_result (GlEventViewRow *row);
+GtkWidget * gl_event_view_row_new (GlJournalEntry *entry, GlEventViewRowStyle style, GlUtilClockFormat 
clock_format);
+GlJournalEntry * gl_event_view_row_get_entry (GlEventViewRow *row);
 
 G_END_DECLS
 
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 6ae4479..8da0f31 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -23,6 +23,22 @@
 #include <stdlib.h>
 #include <systemd/sd-journal.h>
 
+struct _GlJournalEntry
+{
+  GObject parent_instance;
+
+  guint64 timestamp;
+  gchar *cursor;
+  gchar *message;
+  gchar *comm;
+  gchar *kernel_device;
+  gchar *audit_session;
+  gchar *catalog;
+  guint priority;
+};
+
+G_DEFINE_TYPE (GlJournalEntry, gl_journal_entry, G_TYPE_OBJECT);
+
 typedef struct
 {
     sd_journal *journal;
@@ -33,9 +49,6 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (GlJournal, gl_journal, G_TYPE_OBJECT)
 
-G_DEFINE_BOXED_TYPE (GlJournalResult, gl_journal_result, gl_journal_result_ref,
-                     gl_journal_result_unref)
-
 GQuark
 gl_journal_error_quark (void)
 {
@@ -193,11 +206,11 @@ gl_journal_get_data (GlJournal *self,
     return g_strndup ((const gchar *)data + prefix_len, length - prefix_len);
 }
 
-static GlJournalResult *
-_gl_journal_query_result (GlJournal *self)
+static GlJournalEntry *
+_gl_journal_query_entry (GlJournal *self)
 {
     GlJournalPrivate *priv;
-    GlJournalResult *result;
+    GlJournalEntry *entry;
     gint ret;
     sd_journal *journal;
     GError *error = NULL;
@@ -206,11 +219,9 @@ _gl_journal_query_result (GlJournal *self)
     priv = gl_journal_get_instance_private (self);
     journal = priv->journal;
 
-    result = g_slice_new (GlJournalResult);
-
-    result->ref_count = 1;
+    entry = g_object_new (GL_TYPE_JOURNAL_ENTRY, NULL);
 
-    ret = sd_journal_get_realtime_usec (journal, &result->timestamp);
+    ret = sd_journal_get_realtime_usec (journal, &entry->timestamp);
 
     if (ret < 0)
     {
@@ -219,7 +230,7 @@ _gl_journal_query_result (GlJournal *self)
         goto out;
     }
 
-    ret = sd_journal_get_cursor (journal, &result->cursor);
+    ret = sd_journal_get_cursor (journal, &entry->cursor);
 
     if (ret < 0)
     {
@@ -228,13 +239,13 @@ _gl_journal_query_result (GlJournal *self)
         goto out;
     }
 
-    ret = sd_journal_test_cursor (journal, result->cursor);
+    ret = sd_journal_test_cursor (journal, entry->cursor);
 
     if (ret < 0)
     {
         g_warning ("Error testing cursor string: %s", g_strerror (-ret));
-        free (result->cursor);
-        result->cursor = NULL;
+        free (entry->cursor);
+        entry->cursor = NULL;
         goto out;
     }
     else if (ret == 0)
@@ -244,29 +255,29 @@ _gl_journal_query_result (GlJournal *self)
          * later on. */
     }
 
-    ret = sd_journal_get_catalog (journal, &result->catalog);
+    ret = sd_journal_get_catalog (journal, &entry->catalog);
 
     if (ret == -ENOENT)
     {
         g_debug ("No message for this log entry was found in the catalog");
-        result->catalog = NULL;
+        entry->catalog = NULL;
     }
     else if (ret < 0)
     {
         g_warning ("Error while getting message from catalog: %s",
                    g_strerror (-ret));
-        free (result->cursor);
+        free (entry->cursor);
         goto out;
     }
 
-    result->message = gl_journal_get_data (self, "MESSAGE", NULL);
+    entry->message = gl_journal_get_data (self, "MESSAGE", NULL);
 
     if (error != NULL)
     {
         g_warning ("%s", error->message);
         g_clear_error (&error);
-        free (result->cursor);
-        free (result->catalog);
+        free (entry->cursor);
+        free (entry->catalog);
         goto out;
     }
 
@@ -276,16 +287,16 @@ _gl_journal_query_result (GlJournal *self)
     {
         g_warning ("%s", error->message);
         g_clear_error (&error);
-        free (result->cursor);
-        free (result->catalog);
-        g_free (result->message);
+        free (entry->cursor);
+        free (entry->catalog);
+        g_free (entry->message);
         goto out;
     }
 
-    result->priority = priority ? atoi (priority) : LOG_INFO;
+    entry->priority = priority ? atoi (priority) : LOG_INFO;
     g_free (priority);
 
-    result->comm = gl_journal_get_data (self, "_COMM", &error);
+    entry->comm = gl_journal_get_data (self, "_COMM", &error);
 
     if (error != NULL)
     {
@@ -293,7 +304,7 @@ _gl_journal_query_result (GlJournal *self)
         g_clear_error (&error);
     }
 
-    result->kernel_device = gl_journal_get_data (self, "_KERNEL_DEVICE", NULL);
+    entry->kernel_device = gl_journal_get_data (self, "_KERNEL_DEVICE", NULL);
 
     if (error != NULL)
     {
@@ -301,12 +312,12 @@ _gl_journal_query_result (GlJournal *self)
         g_clear_error (&error);
     }
 
-    result->audit_session = gl_journal_get_data (self, "_AUDIT_SESSION", NULL);
+    entry->audit_session = gl_journal_get_data (self, "_AUDIT_SESSION", NULL);
 
-    return result;
+    return entry;
 
 out:
-    g_slice_free (GlJournalResult, result);
+    g_object_unref (entry);
 
     return NULL;
 }
@@ -440,7 +451,7 @@ gl_journal_set_matches (GlJournal           *journal,
         g_warning ("Error seeking to start of systemd journal: %s", g_strerror (-r));
 }
 
-GlJournalResult *
+GlJournalEntry *
 gl_journal_previous (GlJournal *journal)
 {
     GlJournalPrivate *priv = gl_journal_get_instance_private (journal);
@@ -460,47 +471,95 @@ gl_journal_previous (GlJournal *journal)
     if (!gl_journal_query_match (priv->journal, (const gchar * const *) priv->mandatory_fields))
         return gl_journal_previous (journal);
 
-    return _gl_journal_query_result (journal);
+    return _gl_journal_query_entry (journal);
+}
+
+GlJournal *
+gl_journal_new (void)
+{
+    return g_object_new (GL_TYPE_JOURNAL, NULL);
 }
 
 static void
-gl_journal_result_free (GlJournalResult *result,
-                        G_GNUC_UNUSED gpointer user_data)
+gl_journal_entry_init (GlJournalEntry *entry)
 {
-    gl_journal_result_unref (result);
 }
 
-void
-gl_journal_results_free (GList *results)
+static void
+gl_journal_entry_finalize (GObject *object)
 {
-    g_list_foreach (results, (GFunc)gl_journal_result_free, NULL);
-    g_list_free (results);
+  GlJournalEntry *entry = GL_JOURNAL_ENTRY (object);
+
+  free (entry->cursor);
+  free (entry->catalog);
+  g_free (entry->message);
+  g_free (entry->comm);
+  g_free (entry->kernel_device);
+  g_free (entry->audit_session);
+
+  G_OBJECT_CLASS (gl_journal_entry_parent_class)->finalize (object);
 }
 
-GlJournalResult *
-gl_journal_result_ref (GlJournalResult *result)
+static void
+gl_journal_entry_class_init (GlJournalEntryClass *class)
 {
-    g_atomic_int_inc (&result->ref_count);
-    return result;
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = gl_journal_entry_finalize;
 }
 
-void
-gl_journal_result_unref (GlJournalResult *result)
+guint64
+gl_journal_entry_get_timestamp (GlJournalEntry *entry)
 {
-    if (g_atomic_int_dec_and_test (&result->ref_count))
-    {
-        free (result->cursor);
-        free (result->catalog);
-        g_free (result->message);
-        g_free (result->comm);
-        g_free (result->kernel_device);
-        g_free (result->audit_session);
-        g_slice_free (GlJournalResult, result);
-    }
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), 0);
+
+  return entry->timestamp;
 }
 
-GlJournal *
-gl_journal_new (void)
+const gchar *
+gl_journal_entry_get_message (GlJournalEntry *entry)
 {
-    return g_object_new (GL_TYPE_JOURNAL, NULL);
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->message;
+}
+
+const gchar *
+gl_journal_entry_get_command_line (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->comm;
+}
+
+const gchar *
+gl_journal_entry_get_kernel_device (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->kernel_device;
+}
+
+const gchar *
+gl_journal_entry_get_audit_session (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->audit_session;
+}
+
+const gchar *
+gl_journal_entry_get_catalog (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->catalog;
+}
+
+guint
+gl_journal_entry_get_priority (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), 0);
+
+  return entry->priority;
 }
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 4b0cb64..e9b392f 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -42,21 +42,8 @@ typedef enum
 
 GQuark gl_journal_error_quark (void);
 
-typedef struct
-{
-    /*< private >*/
-    guint ref_count;
-
-    /*< public >*/
-    guint64 timestamp;
-    gchar *cursor;
-    gchar *message;
-    gchar *comm;
-    gchar *kernel_device;
-    gchar *audit_session;
-    gchar *catalog;
-    guint priority;
-} GlJournalResult;
+#define GL_TYPE_JOURNAL_ENTRY gl_journal_entry_get_type()
+G_DECLARE_FINAL_TYPE (GlJournalEntry, gl_journal_entry, GL, JOURNAL_ENTRY, GObject)
 
 typedef struct
 {
@@ -70,19 +57,23 @@ typedef struct
     GObjectClass parent_class;
 } GlJournalClass;
 
-#define GL_TYPE_JOURNAL_RESULT (gl_journal_result_get_type ())
 #define GL_TYPE_JOURNAL (gl_journal_get_type ())
 #define GL_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_JOURNAL, GlJournal))
 
 GType gl_journal_result_get_type (void);
 GType gl_journal_get_type (void);
 void gl_journal_set_matches (GlJournal *journal, const gchar * const *matches);
-GlJournalResult * gl_journal_previous (GlJournal *journal);
-GlJournalResult * gl_journal_result_ref (GlJournalResult *result);
-void gl_journal_result_unref (GlJournalResult *result);
-void gl_journal_results_free (GList *results);
+GlJournalEntry * gl_journal_previous (GlJournal *journal);
 GlJournal * gl_journal_new (void);
 
+guint64                 gl_journal_entry_get_timestamp                  (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_message                    (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_command_line               (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_kernel_device              (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_audit_session              (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_catalog                    (GlJournalEntry *entry);
+guint                   gl_journal_entry_get_priority                   (GlJournalEntry *entry);
+
 G_END_DECLS
 
 #endif /* GL_JOURNAL_H_ */


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