[Xfce4-commits] <xfce4-weather-plugin:master> Move make_current_conditions to weather-data.

Harald Judt noreply at xfce.org
Fri Jul 13 16:50:09 CEST 2012


Updating branch refs/heads/master
         to 47284ab74fe32c11838d139721636092165083da (commit)
       from b1eeec784bf1bd903e5164ddbb9f783065dcb2f6 (commit)

commit 47284ab74fe32c11838d139721636092165083da
Author: Harald Judt <h.judt at gmx.at>
Date:   Wed Jul 11 14:13:42 2012 +0200

    Move make_current_conditions to weather-data.
    
    It doesn't have to do some much with parsing.

 panel-plugin/weather-data.c    |   44 ++++++++++++++++++++++++++++++++++++++++
 panel-plugin/weather-data.h    |    2 +
 panel-plugin/weather-parsers.c |   44 ----------------------------------------
 panel-plugin/weather-parsers.h |    1 -
 4 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index bfe41be..e34b1cf 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -391,6 +391,50 @@ make_combined_timeslice(xml_time *point, xml_time *interval)
     return forecast;
 }
 
+xml_time *make_current_conditions(xml_weather *data)
+{
+    xml_time *conditions, *point_data, *interval_data;
+    struct tm now_tm, start_tm, end_tm;
+    time_t now_t, start_t, end_t;
+    gint interval;
+
+    /* get the current time */
+    time(&now_t);
+    now_tm = *localtime(&now_t);
+
+    /* find nearest point data, starting with the current hour, with a
+     * deviation of 1 hour into the past and 6 hours into the future */
+    point_data = find_timeslice(data, now_tm, now_tm, -1, 6);
+    if (point_data == NULL)
+        return NULL;
+
+    /* now search for the nearest and shortest interval data
+     * available, using a maximum interval of 6 hours */
+    end_tm = start_tm = now_tm;
+    start_t = mktime(&start_tm);
+
+    /* set interval to 1 hour as minimum, we don't want to retrieve point data */
+    end_t = time_calc_hour(end_tm, 1);
+    end_tm = *localtime(&end_t);
+
+    /* We want to keep the hour deviation as small as possible,
+     * so let's try an interval with ±1 hour deviation first */
+    interval_data = find_shortest_timeslice(data, start_tm, end_tm, -1, 1, 6);
+    if (interval_data == NULL) {
+        /* in case we were unsuccessful we might need to enlarge the search radius */
+        interval_data = find_shortest_timeslice(data, start_tm, end_tm, -3, 3, 6);
+        if (interval_data == NULL)
+            /* and maybe it's necessary to try even harder... */
+            interval_data = find_shortest_timeslice(data, start_tm, end_tm, -3, 6, 6);
+    }
+    if (interval_data == NULL)
+        return NULL;
+
+    /* create a new timeslice with combined point and interval data */
+    conditions = make_combined_timeslice(point_data, interval_data);
+    return conditions;
+}
+
 /*
  * Get forecast data for a given daytime for the day (today + day).
  */
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index ab60ac4..5223abc 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -67,6 +67,8 @@ time_calc_day(struct tm time_tm, gint days);
 xml_time *
 get_current_conditions(xml_weather *data);
 xml_time *
+make_current_conditions(xml_weather *data);
+xml_time *
 make_forecast_data(xml_weather *data, int day, daytime dt);
 G_END_DECLS
 
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index ea937a8..6136f32 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -157,50 +157,6 @@ xml_time *get_timeslice(xml_weather *data, time_t start_t, time_t end_t)
 	return data->timeslice[data->num_timeslices - 1];
 }
 
-xml_time *make_current_conditions(xml_weather *data)
-{
-    xml_time *conditions, *point_data, *interval_data;
-    struct tm now_tm, start_tm, end_tm;
-    time_t now_t, start_t, end_t;
-    gint interval;
-
-    /* get the current time */
-    time(&now_t);
-    now_tm = *localtime(&now_t);
-
-    /* find nearest point data, starting with the current hour, with a
-     * deviation of 1 hour into the past and 6 hours into the future */
-    point_data = find_timeslice(data, now_tm, now_tm, -1, 6);
-    if (point_data == NULL)
-        return NULL;
-
-    /* now search for the nearest and shortest interval data
-     * available, using a maximum interval of 6 hours */
-    end_tm = start_tm = now_tm;
-    start_t = mktime(&start_tm);
-
-    /* set interval to 1 hour as minimum, we don't want to retrieve point data */
-    end_t = time_calc_hour(end_tm, 1);
-    end_tm = *localtime(&end_t);
-
-    /* We want to keep the hour deviation as small as possible,
-     * so let's try an interval with ±1 hour deviation first */
-    interval_data = find_shortest_timeslice(data, start_tm, end_tm, -1, 1, 6);
-    if (interval_data == NULL) {
-        /* in case we were unsuccessful we might need to enlarge the search radius */
-        interval_data = find_shortest_timeslice(data, start_tm, end_tm, -3, 3, 6);
-        if (interval_data == NULL)
-            /* and maybe it's necessary to try even harder... */
-            interval_data = find_shortest_timeslice(data, start_tm, end_tm, -3, 6, 6);
-    }
-    if (interval_data == NULL)
-        return NULL;
-
-    /* create a new timeslice with combined point and interval data */
-    conditions = make_combined_timeslice(point_data, interval_data);
-    return conditions;
-}
-
 void parse_location (xmlNode * cur_node, xml_location *loc)
 {
 	xmlNode *child_node;
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index ed8d560..e859531 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -92,7 +92,6 @@ void parse_time (xmlNode *cur_node, xml_weather * data);
 void parse_location (xmlNode *cur_node, xml_location *location);
 
 xml_time *get_timeslice(xml_weather *data, time_t start_t, time_t end_t);
-xml_time *make_current_conditions(xml_weather *data);
 
 void xml_time_free(xml_time *timeslice);
 void xml_weather_free (xml_weather *data);


More information about the Xfce4-commits mailing list