[Xfce4-commits] <xfce4-weather-plugin:master> Generate current conditions once and save it in weather data.

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


Updating branch refs/heads/master
         to e86cff008bd00d502cd88aea29e2b9edf2c5f511 (commit)
       from b32baac2903304331f0109c92a2f0a4aaac74d45 (commit)

commit e86cff008bd00d502cd88aea29e2b9edf2c5f511
Author: Harald Judt <h.judt at gmx.at>
Date:   Wed Jul 11 13:05:29 2012 +0200

    Generate current conditions once and save it in weather data.
    
    Instead of recreating the current conditions again and again on
    different occasions, make them once on update and save it in
    xml_weather->current_conditions. This should be a bit more
    consistent too.

 panel-plugin/weather-data.c    |   10 ++++++++++
 panel-plugin/weather-data.h    |    2 ++
 panel-plugin/weather-parsers.c |    4 ++--
 panel-plugin/weather-parsers.h |    3 ++-
 panel-plugin/weather-summary.c |    4 ++--
 panel-plugin/weather.c         |    7 ++++---
 6 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 253037c..73acc39 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -195,6 +195,16 @@ get_daytime_interval(struct tm *start_t, struct tm *end_t, daytime dt)
 }
 
 /*
+ * Return current weather conditions, or NULL if not available.
+ */
+xml_time *get_current_conditions(xml_weather *data)
+{
+    if (data == NULL)
+        return NULL;
+    return data->current_conditions;
+}
+
+/*
  * Check whether it is night or day. Until we have a way to get the
  * exact times for sunrise and sunset, we'll have to use reasonable
  * hardcoded values.
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index 70edc3a..b5537d1 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -65,6 +65,8 @@ time_calc_hour(struct tm tm_time, gint hours);
 time_t
 time_calc_day(struct tm tm_time, gint days);
 xml_time *
+get_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 9384fae..1720331 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -158,7 +158,7 @@ xml_time *get_timeslice(xml_weather *data, time_t start, time_t end)
 	return data->timeslice[data->num_timeslices - 1];
 }
 
-xml_time *get_current_timeslice(xml_weather *data)
+xml_time *make_current_conditions(xml_weather *data)
 {
     xml_time *forecast, *point_data, *interval_data;
     struct tm tm_now, tm_start, tm_end;
@@ -320,6 +320,6 @@ void xml_weather_free (xml_weather *data)
   for (i = 0; i < data->num_timeslices; i++) {
     xml_time_free(data->timeslice[i]);
   }
-
+  xml_time_free(data->current_conditions);
   g_slice_free (xml_weather, data);
 }
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index 66854a9..d45dcea 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -81,6 +81,7 @@ typedef struct
 {
   xml_time *timeslice[MAX_TIMESLICE];
   guint num_timeslices;
+  xml_time *current_conditions;
 }
 xml_weather;
 
@@ -91,7 +92,7 @@ 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, time_t end);
-xml_time *get_current_timeslice(xml_weather *data);
+xml_time *make_current_conditions(xml_weather *data);
 
 void xml_time_free(xml_time *timeslice);
 void xml_weather_free (xml_weather * data);
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 82a893f..3d6cd06 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -274,7 +274,7 @@ create_summary_tab (xfceweather_data *data)
   APPEND_BTEXT (value);
   g_free (value);
 
-  timeslice = get_current_timeslice(data->weatherdata);
+  timeslice = get_current_conditions(data->weatherdata);
   APPEND_BTEXT(_("Coordinates\n"));
   APPEND_TEXT_ITEM (_("Altitude"), ALTITUDE);
   APPEND_TEXT_ITEM (_("Latitude"), LATITUDE);
@@ -573,7 +573,7 @@ create_summary_window (xfceweather_data *data)
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE,
                       0);
 
-  timeslice = get_current_timeslice(data->weatherdata);
+  timeslice = get_current_conditions(data->weatherdata);
 
   rawvalue = get_data (timeslice, data->unit, SYMBOL);
   icon = get_icon (rawvalue, 48, is_night_time());
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 4c9f9e8..a0d3c24 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -157,7 +157,7 @@ make_label (xml_weather    *weatherdata,
     txtsize = "xx-small";
 
   /* get data from current timeslice */
-  timeslice = get_current_timeslice(weatherdata);
+  timeslice = get_current_conditions(weatherdata);
   rawvalue = get_data(timeslice, unit, opt);
 
   switch (opt)
@@ -313,7 +313,7 @@ set_icon_current (xfceweather_data *data)
     }
  
   /* get data from current timeslice */
-  timeslice = get_current_timeslice(data->weatherdata);
+  timeslice = get_current_conditions(data->weatherdata);
   nighttime = is_night_time();
 
   str = get_data (timeslice, data->unit, SYMBOL);
@@ -373,6 +373,7 @@ cb_update (gboolean  succeed,
 
   if (weather)
     {
+      weather->current_conditions = make_current_conditions(weather);
       if (data->weatherdata)
         xml_weather_free (data->weatherdata);
 
@@ -804,7 +805,7 @@ static gboolean weather_get_tooltip_cb (GtkWidget        *widget,
   xml_time *timeslice;
   gboolean nighttime;
 
-  timeslice = get_current_timeslice(data->weatherdata);
+  timeslice = get_current_conditions(data->weatherdata);
   nighttime = is_night_time();
   if (data->weatherdata == NULL) {
     gtk_tooltip_set_text (tooltip, _("Cannot update weather data"));


More information about the Xfce4-commits mailing list