[Xfce4-commits] <xfce4-weather-plugin:master> Factor out code to dump timeslice data.

Harald Judt noreply at xfce.org
Sun Dec 9 23:44:11 CET 2012


Updating branch refs/heads/master
         to 4b609e943be937964aa92cef313a7dcfd5e018eb (commit)
       from 4cafe32a4c565414ae88b27894f821788f3ac7a6 (commit)

commit 4b609e943be937964aa92cef313a7dcfd5e018eb
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Dec 9 19:24:22 2012 +0100

    Factor out code to dump timeslice data.

 panel-plugin/weather-debug.c |   52 +++++++++++++++++++++++++++--------------
 panel-plugin/weather-debug.h |    2 +
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index cf211c1..594352c 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -340,12 +340,40 @@ weather_dump_units_config(const units_config *units)
 
 
 gchar *
-weather_dump_weatherdata(const xml_weather *wd)
+weather_dump_timeslice(const xml_time *timeslice)
 {
     GString *out;
-    xml_time *timeslice;
     gchar *start, *end, *loc, *result;
     gboolean is_interval;
+
+    if (G_UNLIKELY(timeslice == NULL))
+        return g_strdup("No timeslice data.");
+
+    out = g_string_sized_new(512);
+    start = weather_debug_strftime_t(timeslice->start);
+    end = weather_debug_strftime_t(timeslice->end);
+    is_interval = (gboolean) strcmp(start, end);
+    loc = weather_dump_location((timeslice) ? timeslice->location : NULL,
+                                is_interval);
+    g_string_append_printf(out, "[%s %s %s] %s\n", start,
+                           is_interval ? "-" : "=", end, loc);
+    g_free(start);
+    g_free(end);
+    g_free(loc);
+
+    /* Free GString only and return its character data */
+    result = out->str;
+    g_string_free(out, FALSE);
+    return result;
+}
+
+
+gchar *
+weather_dump_weatherdata(const xml_weather *wd)
+{
+    GString *out;
+    xml_time *timeslice;
+    gchar *result, *tmp;
     guint i;
 
     if (G_UNLIKELY(wd == NULL))
@@ -360,23 +388,11 @@ weather_dump_weatherdata(const xml_weather *wd)
                            wd->timeslices->len);
     for (i = 0; i < wd->timeslices->len; i++) {
         timeslice = g_array_index(wd->timeslices, xml_time*, i);
-        if (timeslice) {
-            start = weather_debug_strftime_t(timeslice->start);
-            end = weather_debug_strftime_t(timeslice->end);
-        } else {
-            start = g_strdup("-");
-            end = g_strdup("-");
-        }
-        is_interval = (gboolean) strcmp(start, end);
-        loc = weather_dump_location((timeslice) ? timeslice->location : NULL,
-                                    is_interval);
-        g_string_append_printf(out, "  #%3d: [%s %s %s] %s\n",
-                               i + 1, start, is_interval ? "-" : "=",
-                               end, loc);
-        g_free(start);
-        g_free(end);
-        g_free(loc);
+        tmp = weather_dump_timeslice(timeslice);
+        g_string_append_printf(out, "  #%3d: %s", i + 1, tmp);
+        g_free(tmp);
     }
+
     /* Remove trailing newline */
     if (out->str[out->len - 1] == '\n')
         out->str[--out->len] = '\0';
diff --git a/panel-plugin/weather-debug.h b/panel-plugin/weather-debug.h
index 43465c0..727f6d0 100644
--- a/panel-plugin/weather-debug.h
+++ b/panel-plugin/weather-debug.h
@@ -72,6 +72,8 @@ gchar *weather_dump_astrodata(const xml_astro *astrodata);
 
 gchar *weather_dump_units_config(const units_config *units);
 
+gchar *weather_dump_timeslice(const xml_time *timeslice);
+
 gchar *weather_dump_weatherdata(const xml_weather *wd);
 
 gchar *weather_dump_plugindata(const xfceweather_data *data);


More information about the Xfce4-commits mailing list