[gnome-clocks] world: Do not add duplicate locations



commit 5ae988626bd25eb92d0a337b61ca492bb2fc8adc
Author: Jonas Danielsson <jonas danielsson threetimestwo org>
Date:   Wed Nov 19 08:28:12 2014 -0500

    world: Do not add duplicate locations
    
    Add checks to see if the location already exists before adding.
    In the case of adding through the 'add-location' action just
    silently omit to add.
    
    When adding through the LocationDialog do not allow adding
    if the location exists.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740356

 src/world.vala |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/src/world.vala b/src/world.vala
index 59b4fe4..a24e1aa 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -177,9 +177,12 @@ public class Item : Object, ContentItem {
 private class LocationDialog : Gtk.Dialog {
     [GtkChild]
     private GWeather.LocationEntry location_entry;
+    private Face world;
 
-    public LocationDialog (Gtk.Window parent) {
+    public LocationDialog (Gtk.Window parent, Face world_face) {
         Object (transient_for: parent, use_header_bar: 1);
+
+        world = world_face;
     }
 
     [GtkCallback]
@@ -197,7 +200,7 @@ private class LocationDialog : Gtk.Dialog {
         if (location_entry.get_text () != "") {
             l = location_entry.get_location ();
 
-            if (l != null) {
+            if (l != null && !world.location_exists (l)) {
                 t = l.get_timezone ();
 
                 if (t == null) {
@@ -395,12 +398,26 @@ public class Face : Gtk.Stack, Clocks.Clock {
         save ();
     }
 
+    public bool location_exists (GWeather.Location location) {
+        var exists = false;
+
+        foreach (Item i in locations) {
+            if (i.location.equal(location)) {
+                exists = true;
+                break;
+            }
+        }
+        return exists;
+    }
+
     public void add_location (GWeather.Location location) {
-        add_location_item (new Item (location));
+        if (!location_exists (location)) {
+            add_location_item (new Item (location));
+        }
     }
 
     public void activate_new () {
-        var dialog = new LocationDialog ((Gtk.Window) get_toplevel ());
+        var dialog = new LocationDialog ((Gtk.Window) get_toplevel (), this);
 
         dialog.response.connect ((dialog, response) => {
             if (response == 1) {


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