[libgweather/wip/forecasts: 6/6] Expose legal attribution for applications
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/wip/forecasts: 6/6] Expose legal attribution for applications
- Date: Sat, 1 Dec 2012 15:10:01 +0000 (UTC)
commit e9ffc08edd3186bf8364f8df6e6a94809191b4fe
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sat Dec 1 03:00:35 2012 +0100
Expose legal attribution for applications
This is required to be compliant with the term and conditions of the
yr.no service
libgweather/gweather-weather.h | 1 +
libgweather/weather-priv.h | 1 +
libgweather/weather-yrno.c | 38 +++++++++++++++++++++++++++++++++++++-
libgweather/weather.c | 26 ++++++++++++++++++++++++--
4 files changed, 63 insertions(+), 3 deletions(-)
---
diff --git a/libgweather/gweather-weather.h b/libgweather/gweather-weather.h
index 70f43e1..ed8146b 100644
--- a/libgweather/gweather-weather.h
+++ b/libgweather/gweather-weather.h
@@ -113,6 +113,7 @@ gchar * gweather_info_get_sunset (GWeatherInfo *info);
gchar * gweather_info_get_forecast (GWeatherInfo *info);
GSList * gweather_info_get_forecast_list (GWeatherInfo *info);
GdkPixbufAnimation * gweather_info_get_radar (GWeatherInfo *info);
+const gchar *gweather_info_get_attribution (GWeatherInfo *info);
gchar * gweather_info_get_temp_summary (GWeatherInfo *info);
gchar * gweather_info_get_weather_summary (GWeatherInfo *info);
diff --git a/libgweather/weather-priv.h b/libgweather/weather-priv.h
index 1e71075..0ea27f2 100644
--- a/libgweather/weather-priv.h
+++ b/libgweather/weather-priv.h
@@ -135,6 +135,7 @@ struct _GWeatherInfoPrivate {
GWeatherMoonLatitude moonlatitude;
gchar *forecast;
GSList *forecast_list; /* list of GWeatherInfo* for the forecast, NULL if not available */
+ gchar *forecast_attribution;
gchar *radar_buffer;
gchar *radar_url;
GdkPixbufLoader *radar_loader;
diff --git a/libgweather/weather-yrno.c b/libgweather/weather-yrno.c
index 2ba0954..338badd 100644
--- a/libgweather/weather-yrno.c
+++ b/libgweather/weather-yrno.c
@@ -233,6 +233,36 @@ make_info_from_node (GWeatherInfo *master_info,
return info;
}
+static char *
+make_attribution_from_node (xmlNodePtr node)
+{
+ xmlChar *url;
+ xmlChar *text;
+ char *res;
+
+ url = xmlGetProp (node, XC("url"));
+ text = xmlGetProp (node, XC("text"));
+
+ /* Small hack to avoid linking the entire label, and to have
+ This is still compliant with the guidelines, as far as I
+ understand it.
+ The label is a legal attribution and cannot be translated.
+ */
+ if (strcmp ((char*) text,
+ "Weather forecast from yr.no, delivered by the"
+ " Norwegian Meteorological Institute and the NRK") == 0)
+ res = g_strdup_printf ("Weather forecast from yr.no, delivered by"
+ " the <a href=\"%s\">Norwegian Meteorological"
+ " Institude and the NRK</a>", url);
+ else
+ res = g_strdup_printf ("<a href=\"%s\">%s</a>", url, text);
+
+ xmlFree (url);
+ xmlFree (text);
+
+ return res;
+}
+
static void
parse_forecast_xml (GWeatherInfo *master_info,
SoupMessageBody *body)
@@ -250,7 +280,7 @@ parse_forecast_xml (GWeatherInfo *master_info,
return;
xpath_ctx = xmlXPathNewContext (doc);
-xpath_result = xmlXPathEval (XC("/weatherdata/forecast/tabular/time"), xpath_ctx);
+ xpath_result = xmlXPathEval (XC("/weatherdata/forecast/tabular/time"), xpath_ctx);
if (!xpath_result || xpath_result->type != XPATH_NODESET)
goto out;
@@ -267,6 +297,12 @@ xpath_result = xmlXPathEval (XC("/weatherdata/forecast/tabular/time"), xpath_ctx
xmlXPathFreeObject (xpath_result);
+ xpath_result = xmlXPathEval (XC("/weatherdata/credit/link"), xpath_ctx);
+ if (!xpath_result || xpath_result->type != XPATH_NODESET)
+ goto out;
+
+ priv->forecast_attribution = make_attribution_from_node (xpath_result->nodesetval->nodeTab[0]);
+
out:
xmlXPathFreeContext (xpath_ctx);
xmlFreeDoc (doc);
diff --git a/libgweather/weather.c b/libgweather/weather.c
index 6f70317..61f0a3d 100644
--- a/libgweather/weather.c
+++ b/libgweather/weather.c
@@ -450,10 +450,12 @@ gweather_info_reset (GWeatherInfo *info)
{
GWeatherInfoPrivate *priv = info->priv;
- if (priv->forecast)
- g_free (priv->forecast);
+ g_free (priv->forecast);
priv->forecast = NULL;
+ g_free (priv->forecast_attribution);
+ priv->forecast_attribution = NULL;
+
free_forecast_list (info);
if (priv->radar != NULL) {
@@ -1048,6 +1050,26 @@ gweather_info_get_radar (GWeatherInfo *info)
return info->priv->radar;
}
+/**
+ * gweather_info_get_attribution:
+ * @info: a #GWeatherInfo
+ *
+ * Some weather services require the application showing the
+ * data to include an attribution text, possibly including links
+ * to the service website.
+ * This must be shown prominently toghether with the data.
+ *
+ * Returns: (transfer none): the required attribution text, in Pango
+ * markup form, or %NULL if not required
+ */
+const gchar *
+gweather_info_get_attribution (GWeatherInfo *info)
+{
+ g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
+
+ return info->priv->forecast_attribution;
+}
+
gchar *
gweather_info_get_temp_summary (GWeatherInfo *info)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]