[libgweather] yr.no backend: include the right link to the new style attribution label



commit 624c4534eae8a7bbbc75ac548c7f6cfc472a4d01
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Mar 9 01:11:59 2013 +0100

    yr.no backend: include the right link to the new style attribution label
    
    Instead of a link to the home page, build a link using the data in our
    database, in the same format as the old style API.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695407

 libgweather/weather-yrno.c |   55 ++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 20 deletions(-)
---
diff --git a/libgweather/weather-yrno.c b/libgweather/weather-yrno.c
index 072cb1d..ec61af2 100644
--- a/libgweather/weather-yrno.c
+++ b/libgweather/weather-yrno.c
@@ -333,6 +333,33 @@ parse_forecast_xml_old (GWeatherInfo    *master_info,
     xmlFreeDoc (doc);
 }
 
+static char *
+build_yrno_url_geonames (GWeatherLocation *glocation,
+                        const char       *append)
+{
+    const char *country = NULL;
+    const char *adm_division = NULL;
+    const char *city_name = NULL;
+
+    while (glocation) {
+       if (glocation->level == GWEATHER_LOCATION_CITY)
+           city_name = glocation->name;
+       if (glocation->level == GWEATHER_LOCATION_ADM1 ||
+           glocation->level == GWEATHER_LOCATION_ADM2)
+           adm_division = glocation->name;
+       if (glocation->level == GWEATHER_LOCATION_COUNTRY)
+           country = glocation->name;
+       glocation = glocation->parent;
+    }
+
+    if (city_name == NULL || country == NULL)
+       return NULL;
+
+    if (adm_division != NULL)
+       return g_strdup_printf("http://yr.no/place/%s/%s/%s/%s";, country, adm_division, city_name, append);
+    else
+       return g_strdup_printf("http://yr.no/place/%s/%s/%s";, country, city_name, append);
+}
 
 
 static void
@@ -343,6 +370,7 @@ parse_forecast_xml_new (GWeatherInfo    *master_info,
     xmlDocPtr doc;
     xmlXPathContextPtr xpath_ctx;
     xmlXPathObjectPtr xpath_result;
+    char *attribution_url;
     int i;
 
     priv = master_info->priv;
@@ -415,7 +443,11 @@ parse_forecast_xml_new (GWeatherInfo    *master_info,
 
        That's very nice of them!
     */
-    priv->forecast_attribution = g_strdup(_("Weather data from the <a href=\"http://yr.no/\";>Norwegian 
Meteorological Institute</a>"));
+    attribution_url = build_yrno_url_geonames (priv->glocation, "");
+    if (attribution_url == NULL)
+       attribution_url = g_strdup ("http://yr.no/";);
+    priv->forecast_attribution = g_strdup_printf(_("Weather data from the <a href=\"%s\">Norwegian 
Meteorological Institute</a>"), attribution_url);
+    g_free (attribution_url);
 
  out:
     xmlXPathFreeContext (xpath_ctx);
@@ -447,33 +479,16 @@ yrno_start_open_old (GWeatherInfo *info)
     GWeatherInfoPrivate *priv;
     gchar *url;
     SoupMessage *message;
-    const char *country = NULL;
-    const char *adm_division = NULL;
-    char *city_name = NULL;
-    GWeatherLocation *glocation;
 
     priv = info->priv;
 
     if (priv->forecast_type != GWEATHER_FORECAST_LIST)
        return FALSE;
 
-    glocation = priv->glocation;
-    while (glocation) {
-       if (glocation->level == GWEATHER_LOCATION_CITY)
-           city_name = glocation->name;
-       if (glocation->level == GWEATHER_LOCATION_ADM1 ||
-           glocation->level == GWEATHER_LOCATION_ADM2)
-           adm_division = glocation->name;
-       if (glocation->level == GWEATHER_LOCATION_COUNTRY)
-           country = glocation->name;
-       glocation = glocation->parent;
-    }
-
-    if (city_name == NULL || adm_division == NULL || country == NULL)
+    url = build_yrno_url_geonames (priv->glocation, "forecast.xml");
+    if (url == NULL)
        return FALSE;
 
-    url = g_strdup_printf("http://yr.no/place/%s/%s/%s/forecast.xml";, country, adm_division, city_name);
-
     message = soup_message_new ("GET", url);
     soup_session_queue_message (priv->session, message, yrno_finish_old, info);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]