[gnome-clocks/wip/geolocation] Use country code instead of country name for location searching



commit f102f369846e28faa638f4fed6c6d157154bc6af
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Tue Aug 27 22:48:42 2013 +0200

    Use country code instead of country name for location searching

 src/geolocation-info.vala    |    1 +
 src/geolocation-monitor.vala |    4 ++++
 src/geolocation-utils.vala   |   18 ++++--------------
 3 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/src/geolocation-info.vala b/src/geolocation-info.vala
index f1abd65..e2250fd 100644
--- a/src/geolocation-info.vala
+++ b/src/geolocation-info.vala
@@ -50,6 +50,7 @@ public class LocationInfo : GLib.Object {
     public LocationAccuracy accuracy { get; set; default = LocationAccuracy.UNKNOWN; }
     public string? description { get; set; default = null; }
     public string? country_name { get; set; default = null; }
+    public string? country_code { get; set; default = null; }
     public uint64 timestamp { get; set; default = 0; }
     
     public LocationInfo (double lat, double lon, LocationAccuracy acc = LocationAccuracy.UNKNOWN) {
diff --git a/src/geolocation-monitor.vala b/src/geolocation-monitor.vala
index 9f110c2..8a2b590 100644
--- a/src/geolocation-monitor.vala
+++ b/src/geolocation-monitor.vala
@@ -66,6 +66,10 @@ public class LocationMonitor : GLib.Object {
             location.country_name = root_object.get_string_member ("country_name");
         }
 
+        if (root_object.has_member ("country_code")) {
+            location.country_code = root_object.get_string_member ("country_code");
+        }
+
         return location;
     }
 
diff --git a/src/geolocation-utils.vala b/src/geolocation-utils.vala
index bf9f52c..1f41c06 100644
--- a/src/geolocation-utils.vala
+++ b/src/geolocation-utils.vala
@@ -16,10 +16,10 @@ private double get_distance (double latitude1, double longitude1, double latitud
 }
 
 private void search_locations_helper (GeoInfo.LocationInfo geo_location, GWeather.Location location, ref 
double minimal_distance,  ref GWeather.Location? found_location) {
-    if (geo_location.country_name != null) {
-        string? country_name = get_country_name (location);
-        if (country_name != null) {
-            if (country_name != geo_location.country_name) {
+    if (geo_location.country_code != null) {
+        string? country_code = location.get_country ();
+        if (country_code != null) {
+            if (country_code != geo_location.country_code) {
                 return;
             }
         }
@@ -47,16 +47,6 @@ private void search_locations_helper (GeoInfo.LocationInfo geo_location, GWeathe
     }
 }
 
-private string? get_country_name (GWeather.Location location) {
-     var nation = location;
-
-     while (nation != null && nation.get_level () != GWeather.LocationLevel.COUNTRY) {
-        nation = nation.get_parent ();
-     }
-
-     return nation != null ? nation.get_name () : null;
-}
-
 public GWeather.Location? search_locations (GeoInfo.LocationInfo geo_location) {
     GWeather.Location locations = new GWeather.Location.world (true);
     GWeather.Location? found_location = null;


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