[gnome-clocks: 1/2] app: Expose world clock locations to gnome-shell



commit dc1b32f9a47ac86530a711a38ad145f9bafc20a0
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 1 15:51:08 2019 +0200

    app: Expose world clock locations to gnome-shell
    
    Currently gnome-shell integrates with Clocks by picking up our settings
    and showing the time of the "World Clocks" locations in the calendar
    drop-down. However that only works when gnome-clocks is installed on
    the host, but not from flatpak, as the setting is "hidden away" in a
    container in that case.
    
    To address this, export the relevant information over D-Bus instead,
    so that gnome-shell can pick it up without poking at our GSettings
    schema.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/1158

 src/application.vala | 14 ++++++++++++++
 src/world.vala       | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
---
diff --git a/src/application.vala b/src/application.vala
index 9bd9a19..0292426 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -33,6 +33,8 @@ public class Application : Gtk.Application {
 
     private SearchProvider search_provider;
     private uint search_provider_id = 0;
+    private World.ShellWorldClocks world_clocks;
+    private uint world_clocks_id = 0;
     private Window window;
     private List<string> system_notifications;
 
@@ -70,6 +72,13 @@ public class Application : Gtk.Application {
             printerr ("Could not register search provider service: %s\n", error.message);
         }
 
+        try {
+            world_clocks = new World.ShellWorldClocks (connection, object_path);
+            world_clocks_id = connection.register_object (object_path, world_clocks);
+        } catch (IOError error) {
+            printerr ("Could not register world clocks service: %s\n", error.message);
+        }
+
         return true;
     }
 
@@ -78,6 +87,11 @@ public class Application : Gtk.Application {
             connection.unregister_object (search_provider_id);
             search_provider_id = 0;
         }
+
+        if (world_clocks_id != 0) {
+            connection.unregister_object (world_clocks_id);
+            world_clocks_id = 0;
+        }
     }
 
     protected override void activate () {
diff --git a/src/world.vala b/src/world.vala
index c1d1eb9..b472495 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -19,6 +19,50 @@
 namespace Clocks {
 namespace World {
 
+// Export world clock locations to GNOME Shell
+[DBus (name = "org.gnome.Shell.ClocksIntegration")]
+public class ShellWorldClocks : Object {
+    public GLib.Variant[] locations {
+        owned get {
+            GLib.Variant[] rv = {};
+            GLib.Variant locations = settings.get_value ("world-clocks");
+
+            for (int i = 0; i < locations.n_children(); i++) {
+                rv += locations.get_child_value (i).lookup_value ("location", null);
+            }
+            return rv;
+        }
+    }
+
+    private DBusConnection connection;
+    private string object_path;
+
+    private GLib.Settings settings;
+
+    public ShellWorldClocks (DBusConnection connection, string object_path) {
+        this.connection = connection;
+        this.object_path = object_path;
+
+        settings = new GLib.Settings ("org.gnome.clocks");
+        settings.changed["world-clocks"].connect (() => {
+            var builder = new VariantBuilder (VariantType.ARRAY);
+            var invalid_builder = new VariantBuilder (new VariantType ("as"));
+
+            Variant v = locations;
+            builder.add ("{sv}", "Locations", v);
+
+            this.connection.emit_signal (null,
+                                         this.object_path,
+                                         "org.freedesktop.DBus.Properties",
+                                         "PropertiesChanged",
+                                         new Variant ("(sa{sv}as)",
+                                                      "org.gnome.Shell.ClocksIntegration",
+                                                      builder,
+                                                      invalid_builder));
+        });
+    }
+}
+
 public class Item : Object, ContentItem {
     public GWeather.Location location { get; set; }
 


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