[gnome-logs] Show similar timestamps once only



commit 1f529a54536d78d50abb9671bb182429a4179a4a
Author: ankritisachan <ankritisachan gmail com>
Date:   Thu Mar 15 14:51:55 2018 +0530

    Show similar timestamps once only
    
    This patch shows time labels only for those entries whose time label is
    different from their previous one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752680

 src/gl-eventviewrow.c  |   12 +++++++++++-
 src/gl-journal-model.c |   30 ++++++++++++++++++++++++++++++
 src/gl-journal.c       |   19 +++++++++++++++++++
 src/gl-journal.h       |    2 ++
 4 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/src/gl-eventviewrow.c b/src/gl-eventviewrow.c
index 09160df..77bfb66 100644
--- a/src/gl-eventviewrow.c
+++ b/src/gl-eventviewrow.c
@@ -370,7 +370,17 @@ gl_event_view_row_constructed (GObject *object)
     time = gl_util_timestamp_to_display (gl_journal_entry_get_timestamp (entry),
                                          now, priv->clock_format, FALSE);
     g_date_time_unref (now);
-    priv->time_label = gtk_label_new (time);
+
+    if (gl_journal_entry_get_display_time_label (entry))
+    {
+        priv->time_label = gtk_label_new (time);
+    }
+    else
+    {
+       /* Blank space is necessary to avoid message_label to extend in place of time_label. */
+        priv->time_label = gtk_label_new ("      ");
+    }
+
     context = gtk_widget_get_style_context (GTK_WIDGET (priv->time_label));
     gtk_style_context_add_class (context, "dim-label");
     gtk_style_context_add_class (context, "event-monospace");
diff --git a/src/gl-journal-model.c b/src/gl-journal-model.c
index 0b1d901..4bb2030 100644
--- a/src/gl-journal-model.c
+++ b/src/gl-journal-model.c
@@ -18,6 +18,7 @@
 
 #include "gl-journal-model.h"
 #include "gl-journal.h"
+#include "gl-util.h"
 
 /* Details of match fields */
 typedef struct GlQueryItem
@@ -110,6 +111,11 @@ gl_journal_model_fetch_idle (gpointer user_data)
 
             if (last > 0)
             {
+               GlJournalEntry *previous_entry;
+                gchar *previous_entry_time_label;
+                gchar *current_entry_time_label;
+                GDateTime *now;
+
                 GlRowEntry *prev_row_entry = g_ptr_array_index (model->entries, last - 1);
 
                 if (gl_row_entry_check_message_similarity (row_entry,
@@ -155,6 +161,30 @@ gl_journal_model_fetch_idle (gpointer user_data)
                     model->n_entries_to_fetch--;
 
                 }
+
+               previous_entry = gl_row_entry_get_journal_entry (prev_row_entry);
+
+               now = g_date_time_new_now_local ();
+
+                previous_entry_time_label = gl_util_timestamp_to_display (gl_journal_entry_get_timestamp 
(previous_entry),
+                                                                          now, GL_UTIL_CLOCK_FORMAT_24HR, 
FALSE);
+
+                current_entry_time_label = gl_util_timestamp_to_display (gl_journal_entry_get_timestamp 
(entry),
+                                                                         now, GL_UTIL_CLOCK_FORMAT_24HR, 
FALSE);
+
+                /* TODO: Timestamp should be compared directly in future. */
+                if (g_strcmp0 (previous_entry_time_label, current_entry_time_label) == 0)
+                {
+                    gl_journal_entry_set_display_time_label (entry, FALSE);
+               }
+                else
+               {
+                    gl_journal_entry_set_display_time_label (entry, TRUE);
+               }
+
+                g_free (previous_entry_time_label);
+                g_free (current_entry_time_label);
+                g_date_time_unref (now);
             }
 
             last = model->entries->len;
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 0070865..4edb1a6 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -43,6 +43,7 @@ struct _GlJournalEntry
   gchar *gid;
   gchar *systemd_unit;
   gchar *executable_path;
+  gboolean display_time_label;
 };
 
 G_DEFINE_TYPE (GlJournalEntry, gl_journal_entry, G_TYPE_OBJECT);
@@ -574,6 +575,8 @@ _gl_journal_query_entry (GlJournal *self)
         g_clear_error (&error);
     }
 
+    entry->display_time_label = TRUE;
+
     return entry;
 
 out:
@@ -868,3 +871,19 @@ gl_journal_entry_get_executable_path (GlJournalEntry *entry)
 
   return entry->executable_path;
 }
+
+gboolean
+gl_journal_entry_get_display_time_label (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), FALSE);
+
+  return entry->display_time_label;
+}
+
+void
+gl_journal_entry_set_display_time_label (GlJournalEntry *entry, gboolean value)
+{
+  g_return_if_fail (GL_IS_JOURNAL_ENTRY (entry));
+
+  entry->display_time_label = value;
+}
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 91612da..9ddfb06 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -92,6 +92,8 @@ const gchar *           gl_journal_entry_get_pid                        (GlJourn
 const gchar *           gl_journal_entry_get_gid                        (GlJournalEntry *entry);
 const gchar *           gl_journal_entry_get_systemd_unit               (GlJournalEntry *entry);
 const gchar *           gl_journal_entry_get_executable_path            (GlJournalEntry *entry);
+gboolean                gl_journal_entry_get_display_time_label         (GlJournalEntry *entry);
+void                    gl_journal_entry_set_display_time_label         (GlJournalEntry *entry, gboolean 
value);
 
 G_END_DECLS
 


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