[gnome-logs/wip/monospace: 3/9] Factor out timestamp handling



commit 62161f93787367cfcba6c0d8477f3ffcd002e524
Author: David King <davidk gnome org>
Date:   Thu Oct 10 15:34:28 2013 +0100

    Factor out timestamp handling
    
    Add gl_util_timestamp_to_display() and move microseconds-to-string
    handling to it.

 src/gl-eventview.c |   25 +++----------------------
 src/gl-util.c      |   25 +++++++++++++++++++++++++
 src/gl-util.h      |    2 +-
 3 files changed, 29 insertions(+), 23 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 9f883b6..01409b8 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -26,6 +26,7 @@
 #include "gl-enums.h"
 #include "gl-eventtoolbar.h"
 #include "gl-journal.h"
+#include "gl-util.h"
 
 enum
 {
@@ -101,7 +102,6 @@ on_listbox_row_activated (GtkListBox *listbox,
     GlEventViewPrivate *priv;
     gchar *cursor;
     GlJournalResult *result;
-    GDateTime *datetime;
     gchar *time;
     GtkWidget *grid;
     GtkWidget *label;
@@ -125,26 +125,8 @@ on_listbox_row_activated (GtkListBox *listbox,
     gtk_style_context_add_class (context, "detail-comm");
     gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
 
-    datetime = g_date_time_new_from_unix_utc (result->timestamp
-                                              / G_TIME_SPAN_SECOND);
-
-    if (datetime == NULL)
-    {
-        g_warning ("Error converting timestamp to time value");
-        goto out;
-    }
-
-    /* TODO: Localize? */
-    time = g_date_time_format (datetime, "%F %T");
-    g_date_time_unref (datetime);
-
-    if (time == NULL)
-    {
-        g_warning ("Error converting datetime to string");
-        goto out;
-    }
-
-    label = gtk_label_new (time);
+    time = gl_util_timestamp_to_display (result->timestamp);
+    label = gtk_label_new (gl_util_timestamp_to_display (result->timestamp));
     gtk_widget_set_hexpand (label, TRUE);
     gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
     gtk_label_set_selectable (GTK_LABEL (label), TRUE);
@@ -174,7 +156,6 @@ on_listbox_row_activated (GtkListBox *listbox,
     gtk_stack_add_named (stack, grid, "detail");
     gl_event_view_set_mode (view, GL_EVENT_VIEW_MODE_DETAIL);
 
-out:
     gl_journal_result_free (priv->journal, result);
     return;
 }
diff --git a/src/gl-util.c b/src/gl-util.c
index 2ee98fc..1db8f67 100644
--- a/src/gl-util.c
+++ b/src/gl-util.c
@@ -30,4 +30,29 @@ gl_util_on_css_provider_parsing_error (GtkCssProvider *provider,
                 error->message);
 }
 
+gchar *
+gl_util_timestamp_to_display (guint64 microsecs)
+{
+    GDateTime *datetime;
+    gchar *time = NULL;
+
+    datetime = g_date_time_new_from_unix_utc (microsecs / G_TIME_SPAN_SECOND);
+
+    if (datetime == NULL)
+    {
+        g_warning ("Error converting timestamp to time value");
+        goto out;
+    }
 
+    /* TODO: Localize? */
+    time = g_date_time_format (datetime, "%F %T");
+    g_date_time_unref (datetime);
+
+    if (time == NULL)
+    {
+        g_warning ("Error converting datetime to string");
+    }
+
+out:
+    return time;
+}
diff --git a/src/gl-util.h b/src/gl-util.h
index bc6eaba..db73de6 100644
--- a/src/gl-util.h
+++ b/src/gl-util.h
@@ -27,7 +27,7 @@ void gl_util_on_css_provider_parsing_error (GtkCssProvider *provider,
                                             GtkCssSection *section,
                                             GError *error,
                                             G_GNUC_UNUSED gpointer user_data);
-
+gchar * gl_util_timestamp_to_display (guint64 microsecs);
 
 G_END_DECLS
 


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