[libgweather] Add location_get_country_name
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] Add location_get_country_name
- Date: Wed, 27 Aug 2014 14:47:17 +0000 (UTC)
commit 6cdc854a62df60cdebfb7aabe040ee462d3e99bc
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Aug 15 19:41:41 2014 +0200
Add location_get_country_name
Both Weather and Clocks reimplement this utility, so we may as well
expose it in the API
libgweather/gweather-location.c | 29 +++++++++++++++++++++++++++++
libgweather/gweather-location.h | 1 +
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 2eabdad..9553883 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -1044,6 +1044,35 @@ gweather_location_get_city_name (GWeatherLocation *loc)
return NULL;
}
+/**
+ * gweather_location_get_country_name:
+ * @loc: a #GWeatherLocation
+ *
+ * Gets the country name of loc.
+ * For a %GWEATHER_LOCATION_COUNTRY location, this is equivalent to
+ * gweather_location_get_name().
+ * For a %GWEATHER_LOCATION_REGION and GWEATHER_LOCATION_WORLD location it
+ * will return %NULL.
+ * For other locations it will find the parent %GWEATHER_LOCATION_COUNTRY
+ * and return its name.
+ *
+ * Return value: (allow-none): @loc's country name, or %NULL
+ **/
+char *
+gweather_location_get_country_name (GWeatherLocation *loc)
+{
+ GWeatherLocation *country;
+
+ g_return_val_if_fail (loc != NULL, NULL);
+
+ country = loc;
+ while (country != NULL && country->level != GWEATHER_LOCATION_COUNTRY) {
+ country = country->parent;
+ }
+
+ return country != NULL ? g_strdup (country->local_name) : NULL;
+}
+
void
_gweather_location_update_weather_location (GWeatherLocation *gloc,
WeatherLocation *loc)
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index ae960bc..5d02e5a 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -99,6 +99,7 @@ void gweather_location_free_timezones (GWeatherLocation *loc,
const char *gweather_location_get_code (GWeatherLocation *loc);
char *gweather_location_get_city_name (GWeatherLocation *loc);
+char *gweather_location_get_country_name (GWeatherLocation *loc);
GWeatherLocation *gweather_location_find_by_station_code (GWeatherLocation *world,
const gchar *station_code);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]