[gnome-clocks/gnome-3-18] geo: Make use of new Geoclue convenience library



commit dee56cd2aa8f522271f96f808ece4341dddcf4bc
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Oct 14 19:41:16 2015 +0100

    geo: Make use of new Geoclue convenience library
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756586

 Makefile.am        |    1 +
 configure.ac       |    2 +-
 src/geocoding.vala |   98 +++++----------------------------------------------
 3 files changed, 12 insertions(+), 89 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index cecabef..1447cc8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -88,6 +88,7 @@ AM_VALAFLAGS = \
        --pkg gweather-3.0 \
        --pkg gsound \
        --pkg geocode-glib-1.0 \
+       --pkg Geoclue-2.0 \
        --gresources  $(top_srcdir)/data/gnome-clocks.gresource.xml
 
 bin_PROGRAMS = gnome-clocks
diff --git a/configure.ac b/configure.ac
index f046460..0ce70dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,7 +56,7 @@ PKG_CHECK_MODULES(CLOCKS, [
     gweather-3.0 >= 3.13.91
     gnome-desktop-3.0 >= 3.7.90
     geocode-glib-1.0 >= 0.99.4
-    geoclue-2.0 >= 1.99.3
+    libgeoclue-2.0 >= 2.3.1
 ])
 
 YELP_HELP_INIT
diff --git a/src/geocoding.vala b/src/geocoding.vala
index 2c06ba3..7aa096b 100644
--- a/src/geocoding.vala
+++ b/src/geocoding.vala
@@ -19,50 +19,14 @@
 namespace Clocks {
 namespace Geo {
 
-private enum AccuracyLevel {
-    COUNTRY = 1,
-    CITY = 4,
-    STREET = 6,
-    EXACT = 8,
-}
-
-[DBus (name = "org.freedesktop.GeoClue2.Manager")]
-private interface Manager : Object {
-    public abstract async void get_client (out string client_path) throws IOError;
-}
-
-[DBus (name = "org.freedesktop.GeoClue2.Location")]
-public interface Location : Object {
-    public abstract double latitude { get; }
-    public abstract double longitude { get; }
-    public abstract double accuracy { get; }
-    public abstract string description { owned get; }
-}
-
-[DBus (name = "org.freedesktop.GeoClue2.Client")]
-private interface Client : Object {
-    public abstract ObjectPath location { owned get; }
-    public abstract string desktop_id { owned get; set; }
-    public abstract uint distance_threshold { get; set; }
-    public abstract uint requested_accuracy_level { get; set; }
-
-    public signal void location_updated (ObjectPath old_path, ObjectPath new_path);
-
-    public abstract async void start () throws IOError;
-
-    // This function belongs to the Geoclue interface, however it is not used here
-    // public abstract async void stop () throws IOError;
-}
-
 public class Info : Object {
-    public Geo.Location? geo_location { get; private set; default = null; }
+    public GClue.Location? geo_location { get; private set; default = null; }
 
     private const string DESKTOP_ID = "org.gnome.clocks";
 
     private GWeather.Location? found_location;
     private string? country_code;
-    private Geo.Manager manager;
-    private Geo.Client client;
+    private GClue.Simple simple;
     private double minimal_distance;
 
     public signal void location_changed (GWeather.Location location);
@@ -74,64 +38,22 @@ public class Info : Object {
     }
 
     public async void seek () {
-        string? client_path = null;
-
-        try {
-            manager = yield Bus.get_proxy (GLib.BusType.SYSTEM,
-                                           "org.freedesktop.GeoClue2",
-                                           "/org/freedesktop/GeoClue2/Manager");
-        } catch (IOError e) {
-            warning ("Failed to connect to GeoClue2 Manager service: %s", e.message);
-            return;
-        }
-
         try {
-            yield manager.get_client (out client_path);
-        } catch (IOError e) {
-            warning ("Failed to connect to GeoClue2 Manager service: %s", e.message);
-            return;
-        }
-
-        if (client_path == null) {
-            warning ("The client path is not set");
-            return;
-        }
-
-        try {
-            client = yield Bus.get_proxy (GLib.BusType.SYSTEM,
-                                          "org.freedesktop.GeoClue2",
-                                          client_path);
-        } catch (IOError e) {
-            warning ("Failed to connect to GeoClue2 Client service: %s", e.message);
+            simple = yield new GClue.Simple (DESKTOP_ID, GClue.AccuracyLevel.CITY, null);
+        } catch (Error e) {
+            warning ("Failed to connect to GeoClue2 service: %s", e.message);
             return;
         }
 
-        client.desktop_id = DESKTOP_ID;
-        client.requested_accuracy_level = AccuracyLevel.CITY;
-
-        client.location_updated.connect ((old_path, new_path) => {
-            on_location_updated.begin (old_path, new_path, (obj, res) => {
-                on_location_updated.end (res);
-            });
+        simple.notify["location"].connect (() => {
+            on_location_updated.begin ();
         });
 
-        try {
-            yield client.start ();
-        } catch (IOError e) {
-            warning ("Failed to start client: %s", e.message);
-            return;
-        }
+        on_location_updated.begin ();
     }
 
-    public async void on_location_updated (ObjectPath old_path, ObjectPath new_path) {
-        try {
-            geo_location = yield Bus.get_proxy (GLib.BusType.SYSTEM,
-                                                "org.freedesktop.GeoClue2",
-                                                new_path);
-        } catch (IOError e) {
-            warning ("Failed to connect to GeoClue2 Location service: %s", e.message);
-            return;
-        }
+    public async void on_location_updated () {
+        geo_location = simple.get_location ();
 
         yield seek_country_code ();
 


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