[gnome-clocks/wip/geolocation] Do not add similar auto-detected locations



commit ee9b381edd9b7249b9d11e92d4f64f4f292ddb98
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Fri Sep 6 14:56:06 2013 +0200

    Do not add similar auto-detected locations

 src/geoclue.vala |   20 +++++++++++++++++++-
 src/world.vala   |   29 ++++++++++-------------------
 2 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/src/geoclue.vala b/src/geoclue.vala
index afb2769..5e8ea6e 100644
--- a/src/geoclue.vala
+++ b/src/geoclue.vala
@@ -27,10 +27,12 @@ public interface Location : Object {
 public class GeoInfo : Object {
     public signal void location_changed (GWeather.Location location);
     public GClue.Location? geo_location { get; private set; default = null; }
+    private GWeather.Location? found_location;
     private string? country_code;
 
     public GeoInfo () {
         country_code = null;
+        found_location = null;
     }
 
     public async void seek () {
@@ -94,7 +96,11 @@ public class GeoInfo : Object {
 
         yield seek_country_code ();
 
-        location_changed (search_locations ());
+        this.found_location = search_locations ();
+
+        if (found_location != null) {
+            location_changed (found_location);
+        }
     }
 
     private async void seek_country_code () {
@@ -169,6 +175,18 @@ public class GeoInfo : Object {
 
         return found_location;
     }
+
+    public bool is_location_similar (GWeather.Location location) {
+        if (this.found_location != null) {
+            string? city_name = location.get_city_name ();
+            string? found_city_name = found_location.get_city_name ();
+            if (city_name == found_city_name) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }
 
 } // GClue
diff --git a/src/world.vala b/src/world.vala
index 8f5674d..7d4ba90 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -363,28 +363,19 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
 
     private async void use_geolocation () {
         GClue.GeoInfo geo_info = new GClue.GeoInfo ();
-        
-        geo_info.location_changed.connect ((found_location) => {
-            if (found_location != null) {
-                bool not_included = true;
-            
-                stdout.printf ("name : %s\n", found_location.get_name());
-
-                foreach (Item i in locations) {
-                    stdout.printf ("name : %s\n", i.location.get_name());
-                    if (i.location == found_location) {
-                        not_included = false;
-                    }
-                }
 
-                if (not_included) {
-                    var item = new Item (found_location);
-                    
-                    item.automatic = true;
-                    locations.append (item);
-                    content_view.add_first (item);
+        geo_info.location_changed.connect ((found_location) => {
+            foreach (Item i in locations) {
+                if (geo_info.is_location_similar (i.location)) {
+                    return;
                 }
             }
+
+            var item = new Item (found_location);
+
+            item.automatic = true;
+            locations.append (item);
+            content_view.add_first (item);
         });
 
         yield geo_info.seek ();


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