[Xfce4-commits] <xfce4-weather-plugin:master> Move get_current_timeslice calls out of get_data() and get_unit().

Harald Judt noreply at xfce.org
Mon Jul 2 12:38:01 CEST 2012


Updating branch refs/heads/master
         to 3710b8ff4330ac96386fb9872b225d5c62aa5ceb (commit)
       from ebd65cb01e277d1e1243d5b920cc979ebfaf0e25 (commit)

commit 3710b8ff4330ac96386fb9872b225d5c62aa5ceb
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Jun 26 01:10:41 2012 +0200

    Move get_current_timeslice calls out of get_data() and get_unit().
    
    Make get_data and get_unit usable for other timeslices than the
    current one, and move the selection of the timeslice up to the
    calling function. This will be needed for forecasts, but maybe
    useful in other cases too.

 panel-plugin/weather-data.c      |   19 ++-----------------
 panel-plugin/weather-data.h      |    4 ++--
 panel-plugin/weather-parsers.c   |    3 +++
 panel-plugin/weather-summary.c   |   20 +++++++++++---------
 panel-plugin/weather-translate.c |    7 ++++---
 panel-plugin/weather-translate.h |    2 +-
 panel-plugin/weather.c           |   26 ++++++++++++++++++--------
 7 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 5c17a8d..00ed50f 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -27,21 +27,11 @@
 
 #define CHK_NULL(s) ((s) ? (s):"")
 
-static gboolean need_interval(datas type)
-{
-	return type == PRECIPITATIONS || type == SYMBOL;
-}
-
 const gchar *
-get_data (xml_weather *data, datas type)
+get_data (xml_time *timeslice, datas type)
 {
-	const xml_time *timeslice = NULL;
 	const xml_location *loc = NULL;
 
-	if (data == NULL)
-		return "";
-
-	timeslice = get_current_timeslice(data, need_interval(type));
 	if (timeslice == NULL)
 		return "";
 
@@ -79,15 +69,10 @@ get_data (xml_weather *data, datas type)
 }
 
 const gchar *
-get_unit (xml_weather *data, units unit, datas type)
+get_unit (xml_time *timeslice, units unit, datas type)
 {
-	const xml_time *timeslice = NULL;
 	const xml_location *loc = NULL;
 
-	if (data == NULL)
-		return "";
-
-	timeslice = get_current_timeslice(data, need_interval(type));
 	if (timeslice == NULL)
 		return "";
 
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index 5e80763..e4b81e5 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -42,9 +42,9 @@ typedef enum {
 } units;
 
 const gchar *
-get_data (xml_weather *data, datas type);
+get_data (xml_time *timeslice, datas type);
 const gchar *
-get_unit (xml_weather *data, units unit, datas type);
+get_unit (xml_time *timeslice, units unit, datas type);
 G_END_DECLS
 
 #endif
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index fd16609..e6dc2d4 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -165,6 +165,9 @@ xml_time *get_current_timeslice(xml_weather *data, gboolean interval)
 	int min_found = 7 * 24 * 3600;
 	int i;
 
+	if (data == NULL)
+		return NULL;
+
 	for (i = 0; i < data->num_timeslices; i++) {
 		if (interval != 
 		    (data->timeslice[i]->start != data->timeslice[i]->end))
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index b0a4aae..4edbac6 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -43,8 +43,8 @@ static gboolean lnk_clicked (GtkTextTag *tag, GObject *obj,
                                          g_free (value);
 #define APPEND_TEXT_ITEM(text, item)     value = g_strdup_printf("\t%s%s%s %s\n",\
                                                                  text, text?": ":"", \
-                                                                 get_data(data->weatherdata, item),\
-                                                                 get_unit(data->weatherdata, data->unit, item));\
+                                                                 get_data(timeslice, item), \
+                                                                 get_unit(timeslice, data->unit, item)); \
                                          APPEND_TEXT_ITEM_REAL(value);
 #define APPEND_LINK_ITEM(prefix, text, url, lnk_tag) \
 					 gtk_text_buffer_insert(GTK_TEXT_BUFFER(buffer), \
@@ -278,17 +278,17 @@ create_summary_tab (xfceweather_data *data)
 
   /* Wind */
   APPEND_BTEXT (_("\nWind\n"));
-  wind = translate_wind_speed (data->weatherdata, get_data (data->weatherdata, WIND_SPEED), data->unit);
+  wind = translate_wind_speed (timeslice, get_data (timeslice, WIND_SPEED), data->unit);
   value = g_strdup_printf ("\t%s: %s (%s on the Beaufort scale)\n", _("Speed"), wind,
-		get_data (data->weatherdata, WIND_BEAUFORT));
+                           get_data (timeslice, WIND_BEAUFORT));
   g_free (wind);
   APPEND_TEXT_ITEM_REAL (value);
 
-  wind = translate_wind_direction (get_data (data->weatherdata, WIND_DIRECTION));
+  wind = translate_wind_direction (get_data (timeslice, WIND_DIRECTION));
   value = g_strdup_printf ("\t%s: %s (%s%s)\n", _("Direction"),
-                           wind ? wind : get_data (data->weatherdata, WIND_DIRECTION),
-			   get_data (data->weatherdata, WIND_DIRECTION_DEG),
-			   get_unit (data->weatherdata, data->unit, WIND_DIRECTION_DEG));
+                           wind ? wind : get_data (timeslice, WIND_DIRECTION),
+                           get_data (timeslice, WIND_DIRECTION_DEG),
+                           get_unit (timeslice, data->unit, WIND_DIRECTION_DEG));
   g_free (wind);
   APPEND_TEXT_ITEM_REAL (value);
 
@@ -537,6 +537,7 @@ create_summary_window (xfceweather_data *data)
   GtkWidget *window, *notebook, *vbox;
   gchar     *title;
   GdkPixbuf *icon;
+  xml_time  *timeslice;
 
   window = xfce_titled_dialog_new_with_buttons (_("Weather Update"),
                                                 NULL,
@@ -555,7 +556,8 @@ create_summary_window (xfceweather_data *data)
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE,
                       0);
 
-  icon = get_icon (get_data (data->weatherdata, SYMBOL), 48);
+  timeslice = get_current_timeslice(data->weatherdata, TRUE);
+  icon = get_icon (get_data (timeslice, SYMBOL), 48);
 
   if (!icon)
     icon = get_icon ("99", 48);
diff --git a/panel-plugin/weather-translate.c b/panel-plugin/weather-translate.c
index 6ba9c2f..d8a3040 100644
--- a/panel-plugin/weather-translate.c
+++ b/panel-plugin/weather-translate.c
@@ -474,7 +474,7 @@ translate_wind_direction (const gchar *wdir)
 
 /* calm or a number */
 gchar *
-translate_wind_speed (xml_weather *data,
+translate_wind_speed (xml_time *timeslice,
                       const gchar *wspeed,
                       units        unit)
 {
@@ -484,9 +484,10 @@ translate_wind_speed (xml_weather *data,
     wspeed_loc = g_strdup (_("calm"));
   else if (g_ascii_strcasecmp (wspeed, "N/A") == 0)
     wspeed_loc = g_strdup (_("N/A"));
-  else
+  else {
     wspeed_loc =
-      g_strdup_printf ("%s %s", wspeed, get_unit (data, unit, WIND_SPEED));
+      g_strdup_printf ("%s %s", wspeed, get_unit (timeslice, unit, WIND_SPEED));
+  }
 
   return wspeed_loc;
 }
diff --git a/panel-plugin/weather-translate.h b/panel-plugin/weather-translate.h
index 7ef4674..b1529eb 100644
--- a/panel-plugin/weather-translate.h
+++ b/panel-plugin/weather-translate.h
@@ -36,7 +36,7 @@ gchar *translate_day (const gchar *);
 
 gchar *translate_wind_direction (const gchar *);
 
-gchar *translate_wind_speed (xml_weather *data, const gchar *, units);
+gchar *translate_wind_speed (xml_time *timeslice, const gchar *, units);
 
 gchar *translate_time (const gchar *);
 
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 7b75c4b..b344a2d 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -102,6 +102,7 @@ make_label (xml_weather    *weatherdata,
 {
 
   gchar       *str, *value;
+  xml_time    *timeslice;
   const gchar *rawvalue, *lbl, *txtsize;
 
   switch (opt)
@@ -153,7 +154,10 @@ make_label (xml_weather    *weatherdata,
   else
     txtsize = "xx-small";
 
-  rawvalue = get_data (weatherdata, opt);
+  /* get data from current timeslice */
+  timeslice = get_current_timeslice(weatherdata,
+                                    opt == PRECIPITATIONS || opt == SYMBOL);
+  rawvalue = get_data(timeslice, opt);
 
   switch (opt)
     {
@@ -161,7 +165,7 @@ make_label (xml_weather    *weatherdata,
       value = translate_wind_direction (rawvalue);
       break;
     case WIND_SPEED:
-      value = translate_wind_speed (weatherdata, rawvalue, unit);
+      value = translate_wind_speed (timeslice, rawvalue, unit);
       break;
     default:
       value = NULL;
@@ -179,7 +183,7 @@ make_label (xml_weather    *weatherdata,
     else
       {
 	str = g_strdup_printf ("<span size=\"%s\">%s: %s %s</span>",
-                               txtsize, lbl, rawvalue, get_unit (weatherdata, unit, opt));
+                               txtsize, lbl, rawvalue, get_unit (timeslice, unit, opt));
       }
   } else {
     if (value != NULL)
@@ -191,7 +195,7 @@ make_label (xml_weather    *weatherdata,
     else
       {
 	str = g_strdup_printf ("<span size=\"%s\">%s %s</span>",
-                               txtsize, rawvalue, get_unit (weatherdata, unit, opt));
+                               txtsize, rawvalue, get_unit (timeslice, unit, opt));
       }
   }
   return str;
@@ -256,6 +260,7 @@ set_icon_error (xfceweather_data *data)
 static void
 set_icon_current (xfceweather_data *data)
 {
+  xml_time       *timeslice;
   guint           i;
   GdkPixbuf      *icon = NULL;
   datas           opt;
@@ -286,7 +291,9 @@ set_icon_current (xfceweather_data *data)
         size = data->size;
     }
  
-  icon = get_icon (get_data (data->weatherdata, SYMBOL), size);
+  /* get data from current timeslice */
+  timeslice = get_current_timeslice(data->weatherdata, TRUE);
+  icon = get_icon (get_data (timeslice, SYMBOL), size);
  
   gtk_image_set_from_pixbuf (GTK_IMAGE (data->iconimage), icon);
 
@@ -295,7 +302,7 @@ set_icon_current (xfceweather_data *data)
 
 #if !GTK_CHECK_VERSION(2,12,0)
   gtk_tooltips_set_tip (data->tooltips, data->tooltipbox,
-                        translate_desc (get_data (data->weatherdata, SYMBOL)),
+                        translate_desc (get_data (timeslice, SYMBOL)),
                         NULL);
 #endif
 }
@@ -757,6 +764,9 @@ static gboolean weather_get_tooltip_cb (GtkWidget        *widget,
 {
   GdkPixbuf *icon;
   gchar *markup_text;
+  xml_time *timeslice;
+
+  timeslice = get_current_timeslice(data->weatherdata, TRUE);
 
   if (data->weatherdata == NULL) {
     gtk_tooltip_set_text (tooltip, _("Cannot update weather data"));
@@ -765,12 +775,12 @@ static gboolean weather_get_tooltip_cb (GtkWidget        *widget,
   	  "<b>%s</b>\n"
 	  "%s",
 	  data->location_name,
-	  translate_desc (get_data (data->weatherdata, SYMBOL))
+	  translate_desc (get_data (timeslice, SYMBOL))
 	  );
     gtk_tooltip_set_markup (tooltip, markup_text);
     g_free(markup_text);
   }
-  icon = get_icon (get_data (data->weatherdata, SYMBOL), 32);
+  icon = get_icon (get_data (timeslice, SYMBOL), 32);
   gtk_tooltip_set_icon (tooltip, icon);
   g_object_unref (G_OBJECT(icon));
 


More information about the Xfce4-commits mailing list