[gnome-clocks] Add add_location action



commit 40e35694f911139e0e453c08d644a2120bb1ce54
Author: Jonas Danielsson <jonas danielsson threetimestwo org>
Date:   Wed Nov 19 06:58:25 2014 -0500

    Add add_location action
    
    Add an action to add a location to world. The parameter is
    a serialized GWeather.Location which is unfortunate but for the
    moment might be the best.
    
    This is needed to allow other applications, such as Maps, to share
    locations with us.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740356

 src/application.vala |   19 ++++++++++++++++++-
 src/window.vala      |    4 ++++
 src/world.vala       |   14 +++++++++++---
 3 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index 294737c..0ab75f4 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -27,7 +27,8 @@ public class Application : Gtk.Application {
     const GLib.ActionEntry[] action_entries = {
         { "stop-alarm", null, "s" },
         { "snooze-alarm", null, "s" },
-        { "quit", on_quit_activate }
+        { "quit", on_quit_activate },
+        { "add-location", on_add_location_activate, "v" }
     };
 
     private SearchProvider search_provider;
@@ -101,6 +102,22 @@ public class Application : Gtk.Application {
         return -1;
     }
 
+    public void on_add_location_activate (GLib.SimpleAction action, GLib.Variant? parameter) {
+        if (parameter == null) {
+            return;
+        }
+
+        ensure_window ();
+        window.show_world ();
+        window.present ();
+
+        var world = GWeather.Location.get_world ();
+        var location = world.deserialize (parameter.get_child_value(0));
+        if (location != null) {
+            window.add_world_location (location);
+        }
+    }
+
     void on_quit_activate () {
         quit ();
     }
diff --git a/src/window.vala b/src/window.vala
index 27e40e3..eb4bc16 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -137,6 +137,10 @@ public class Window : Gtk.ApplicationWindow {
         stack.visible_child = panels[PanelId.WORLD];;
     }
 
+    public void add_world_location (GWeather.Location location) {
+        ((World.Face) panels[PanelId.WORLD]).add_location (location);
+    }
+
     public override bool key_press_event (Gdk.EventKey event) {
         uint keyval;
         if (((Gdk.Event*)(&event))->get_keyval (out keyval) && keyval == Gdk.Key.Escape) {
diff --git a/src/world.vala b/src/world.vala
index 2bf8ce1..59b4fe4 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -389,15 +389,23 @@ public class Face : Gtk.Stack, Clocks.Clock {
         yield geo_info.seek ();
     }
 
+    private void add_location_item (Item item) {
+        locations.append (item);
+        content_view.add_item (item);
+        save ();
+    }
+
+    public void add_location (GWeather.Location location) {
+        add_location_item (new Item (location));
+    }
+
     public void activate_new () {
         var dialog = new LocationDialog ((Gtk.Window) get_toplevel ());
 
         dialog.response.connect ((dialog, response) => {
             if (response == 1) {
                 var location = ((LocationDialog) dialog).get_location ();
-                locations.append (location);
-                content_view.add_item (location);
-                save ();
+                add_location_item (location);
             }
             dialog.destroy ();
         });


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