[libgweather] GWeatherLocation: add named timezones



commit cd8464f336d5e9a797d49f3c9d904b9af4415849
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Dec 5 08:56:35 2017 -0800

    GWeatherLocation: add named timezones
    
    Named timezones represent things like UTC, which are locations
    enough that some apps want them in a GWeatherLocationEntry, but not
    not quite cities or weather stations.
    
    They are stored in Locations.xml as usual, as children of the world
    location.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791066

 data/Locations.xml                    |   17 +++++++++++++++++
 data/locations.dtd                    |    3 ++-
 libgweather/gweather-location-entry.c |    3 +++
 libgweather/gweather-location.c       |   23 ++++++++++++++++++++---
 libgweather/gweather-location.h       |    3 ++-
 5 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/data/Locations.xml b/data/Locations.xml
index 786b369..0c8116a 100644
--- a/data/Locations.xml
+++ b/data/Locations.xml
@@ -1,6 +1,23 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE gweather SYSTEM "locations.dtd">
 <gweather format="1.0">
+  <named-timezone>
+    <_name>Coordinated Universal Time (UTC)</_name>
+    <timezones>
+      <timezone id="UTC" />
+    </timezones>
+    <tz-hint>UTC</tz-hint>
+    <code>@UTC</code>
+  </named-timezone>
+  <named-timezone>
+    <!-- TRANSLATORS: This is the designation for the last (most west) timezone on Earth -->
+    <_name>Anywhere on Earth (AoE)</_name>
+    <timezones>
+      <timezone id="Etc/UTC-12" />
+    </timezones>
+    <tz-hint>Etc/UTC-12</tz-hint>
+    <code>@AoE</code>
+  </named-timezone>
   <region>
     <_name>Africa</_name>
     <country>
diff --git a/data/locations.dtd b/data/locations.dtd
index 7a3c99b..86acbde 100644
--- a/data/locations.dtd
+++ b/data/locations.dtd
@@ -1,4 +1,4 @@
-<!ELEMENT gweather (region+) >
+<!ELEMENT gweather (named-timezone*, region+) >
 <!ATTLIST gweather
   format CDATA #FIXED '1.0' >
 
@@ -10,6 +10,7 @@
 <!ELEMENT province (%name;, (location|city)*) >
 <!ELEMENT city (%name;, coordinates?, tz-hint?, location+) >
 <!ELEMENT location (%name;, code, zone?, radar?, coordinates?) >
+<!ELEMENT named-timezone (%name;, timezones, tz-hint, code)>
 
 <!ELEMENT timezones (timezone+) >
 <!ELEMENT timezone (_name?, name*, obsoletes*) >
diff --git a/libgweather/gweather-location-entry.c b/libgweather/gweather-location-entry.c
index 5af429c..e9755c7 100644
--- a/libgweather/gweather-location-entry.c
+++ b/libgweather/gweather-location-entry.c
@@ -553,6 +553,9 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc,
        g_free (english_compare_name);
        break;
 
+    case GWEATHER_LOCATION_NAMED_TIMEZONE:
+               break;
+
     case GWEATHER_LOCATION_DETACHED:
        g_assert_not_reached ();
     }
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index acafcc3..d273ff4 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -68,6 +68,8 @@
  * database, for example because it was loaded from external storage
  * and could not be fully recovered. The parent of this location is
  * the nearest weather station.
+ * @GWEATHER_LOCATION_NAMED_TIMEZONE: A location representing a named
+ * or special timezone in the world, such as UTC
  *
  * The size/scope of a particular #GWeatherLocation.
  *
@@ -260,6 +262,12 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
                goto error_out;
            g_ptr_array_add (children, child);
 
+       } else if (!strcmp (tagname, "named-timezone")) {
+           child = location_new_from_xml (parser, GWEATHER_LOCATION_NAMED_TIMEZONE, loc);
+           if (!child)
+               goto error_out;
+           g_ptr_array_add (children, child);
+
        } else if (!strcmp (tagname, "timezones")) {
            loc->zones = _gweather_timezones_parse_xml (parser);
            if (!loc->zones)
@@ -273,7 +281,8 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
     if (xmlTextReaderRead (parser->xml) != 1 && parent)
        goto error_out;
 
-    if (level == GWEATHER_LOCATION_WEATHER_STATION) {
+    if (level == GWEATHER_LOCATION_WEATHER_STATION ||
+       level == GWEATHER_LOCATION_NAMED_TIMEZONE) {
        /* Cache weather stations by METAR code */
        GList *a, *b;
 
@@ -690,7 +699,8 @@ gweather_location_find_nearest_city_full (GWeatherLocation  *loc,
      * an O(n) search. */
     struct FindNearestCityData data;
 
-    g_return_val_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY, NULL);
+    g_return_val_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY ||
+                         loc->level == GWEATHER_LOCATION_NAMED_TIMEZONE, NULL);
 
     if (loc == NULL)
         loc = gweather_location_get_world ();
@@ -782,7 +792,8 @@ gweather_location_detect_nearest_city (GWeatherLocation    *loc,
     GeocodeReverse *reverse;
     GTask *task;
 
-    g_return_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY);
+    g_return_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY ||
+                     loc->level == GWEATHER_LOCATION_NAMED_TIMEZONE);
 
     if (loc == NULL)
         loc = gweather_location_get_world ();
@@ -1329,6 +1340,12 @@ gweather_location_common_deserialize (GWeatherLocation *world,
     /* First find the list of candidate locations */
     candidates = g_hash_table_lookup (world->metar_code_cache, station_code);
 
+    /* A station code beginning with @ indicates a named timezone entry, just
+     * return it directly
+     */
+    if (station_code[0] == '@')
+       return candidates->data;
+
     /* If we don't have coordinates, fallback immediately to making up
      * a location
      */
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index 5e50faa..946df7d 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -44,7 +44,8 @@ typedef enum { /*< underscore_name=gweather_location_level >*/
     GWEATHER_LOCATION_ADM2,
     GWEATHER_LOCATION_CITY,
     GWEATHER_LOCATION_WEATHER_STATION,
-    GWEATHER_LOCATION_DETACHED
+    GWEATHER_LOCATION_DETACHED,
+    GWEATHER_LOCATION_NAMED_TIMEZONE
 } GWeatherLocationLevel;
 
 GWEATHER_EXTERN


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