[gnome-settings-daemon] datetime: Make use of new Geoclue convenience library



commit 07c756c04f64a681a2d830a5d3245ba44862f530
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Oct 16 14:11:55 2015 +0100

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

 configure.ac                            |   10 +--
 plugins/datetime/Makefile.am            |   10 --
 plugins/datetime/gsd-timezone-monitor.c |  160 ++++++-------------------------
 3 files changed, 31 insertions(+), 149 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 62bad7e..c2ec2f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,7 +58,7 @@ POLKIT_REQUIRED_VERSION=0.103
 UPOWER_REQUIRED_VERSION=0.99.0
 GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION=3.15.4
 GEOCODE_GLIB_REQUIRED_VERSION=3.10.0
-GEOCLUE_REQUIRED_VERSION=2.1.2
+GEOCLUE_REQUIRED_VERSION=2.3.1
 NM_REQUIRED_VERSION=0.9.9.1
 
 EXTRA_COMPILE_WARNINGS(yes)
@@ -244,18 +244,12 @@ AC_CHECK_LIBM
 AC_SUBST(LIBM)
 
 PKG_CHECK_MODULES(DATETIME,
-        geoclue-2.0 >= $GEOCLUE_REQUIRED_VERSION
+        libgeoclue-2.0 >= $GEOCLUE_REQUIRED_VERSION
        geocode-glib-1.0 >= $GEOCODE_GLIB_REQUIRED_VERSION
        gweather-3.0 >= $LIBGWEATHER_REQUIRED_VERSION
        polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
 )
 
-GEOCLUE_DBUS_INTERFACE_XML=`pkg-config --variable=dbus_interface geoclue-2.0`
-if test "x$GEOCLUE_DBUS_INTERFACE_XML" = "x"; then
-       AC_MSG_ERROR([Cannot find dbus_interface variable in geoclue-2.0.pc])
-fi
-AC_SUBST(GEOCLUE_DBUS_INTERFACE_XML)
-
 dnl ---------------------------------------------------------------------------
 dnl - wacom (disabled for s390/s390x and non Linux platforms)
 dnl ---------------------------------------------------------------------------
diff --git a/plugins/datetime/Makefile.am b/plugins/datetime/Makefile.am
index 9d5e37e..e8d8a4d 100644
--- a/plugins/datetime/Makefile.am
+++ b/plugins/datetime/Makefile.am
@@ -1,13 +1,5 @@
 plugin_name = datetime
 
-geoclue.c: geoclue.h
-geoclue.h: Makefile.am $(GEOCLUE_DBUS_INTERFACE_XML)
-       gdbus-codegen                                           \
-               --interface-prefix org.freedesktop.GeoClue2     \
-               --generate-c-code geoclue                       \
-               --c-namespace Geoclue                           \
-               $(GEOCLUE_DBUS_INTERFACE_XML)
-
 timedated.c: timedated.h
 timedated.h: Makefile.am timedated1-interface.xml
        gdbus-codegen                                           \
@@ -16,8 +8,6 @@ timedated.h: Makefile.am timedated1-interface.xml
                $(srcdir)/timedated1-interface.xml
 
 BUILT_SOURCES =                        \
-       geoclue.c               \
-       geoclue.h               \
        timedated.c             \
        timedated.h
 
diff --git a/plugins/datetime/gsd-timezone-monitor.c b/plugins/datetime/gsd-timezone-monitor.c
index 689f281..4b9f030 100644
--- a/plugins/datetime/gsd-timezone-monitor.c
+++ b/plugins/datetime/gsd-timezone-monitor.c
@@ -21,20 +21,17 @@
 
 #include "gsd-timezone-monitor.h"
 
-#include "geoclue.h"
 #include "timedated.h"
 #include "tz.h"
 #include "weather-tz.h"
 
+#include <geoclue.h>
 #include <geocode-glib/geocode-glib.h>
 #include <polkit/polkit.h>
 
 #define DESKTOP_ID "gnome-datetime-panel"
 #define SET_TIMEZONE_PERMISSION "org.freedesktop.timedate1.set-timezone"
 
-/* Defines from geoclue private header src/public-api/gclue-enums.h */
-#define GCLUE_ACCURACY_LEVEL_CITY 4
-
 enum {
         TIMEZONE_CHANGED,
         LAST_SIGNAL
@@ -46,8 +43,8 @@ typedef struct
 {
         GCancellable *cancellable;
         GPermission *permission;
-        GeoclueClient *geoclue_client;
-        GeoclueManager *geoclue_manager;
+        GClueClient *geoclue_client;
+        GClueSimple *geoclue_simple;
         Timedate1 *dtm;
 
         TzDB *tzdb;
@@ -268,144 +265,46 @@ start_reverse_geocoding (GsdTimezoneMonitor *self,
 }
 
 static void
-on_location_proxy_ready (GObject      *source_object,
-                         GAsyncResult *res,
-                         gpointer      user_data)
+on_location_notify (GClueSimple *simple,
+                    GParamSpec  *pspec,
+                    gpointer     user_data)
 {
-        GeoclueLocation *location;
-        gdouble latitude, longitude;
-        GError *error = NULL;
         GsdTimezoneMonitor *self = user_data;
+        GClueLocation *location;
+        gdouble latitude, longitude;
 
-        location = geoclue_location_proxy_new_for_bus_finish (res, &error);
-        if (error != NULL) {
-                g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
-                g_error_free (error);
-                return;
-        }
+        location = gclue_simple_get_location (simple);
 
-        latitude = geoclue_location_get_latitude (location);
-        longitude = geoclue_location_get_longitude (location);
+        latitude = gclue_location_get_latitude (location);
+        longitude = gclue_location_get_longitude (location);
 
         start_reverse_geocoding (self, latitude, longitude);
-
-        g_object_unref (location);
-}
-
-static void
-on_location_updated (GDBusProxy *client,
-                     gchar      *location_path_old,
-                     gchar      *location_path_new,
-                     gpointer    user_data)
-{
-        GsdTimezoneMonitor *self = user_data;
-        GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
-
-        geoclue_location_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
-                                            G_DBUS_PROXY_FLAGS_NONE,
-                                            "org.freedesktop.GeoClue2",
-                                            location_path_new,
-                                            priv->cancellable,
-                                            on_location_proxy_ready,
-                                            self);
 }
 
 static void
-on_start_ready (GObject      *source_object,
-                GAsyncResult *res,
-                gpointer      user_data)
-{
-        GError *error = NULL;
-
-        if (!geoclue_client_call_start_finish (GEOCLUE_CLIENT (source_object),
-                                               res,
-                                               &error)) {
-                g_critical ("Failed to start GeoClue2 client: %s", error->message);
-                g_error_free (error);
-                return;
-        }
-}
-
-static void
-on_client_proxy_ready (GObject      *source_object,
-                       GAsyncResult *res,
-                       gpointer      user_data)
+on_geoclue_simple_ready (GObject      *source_object,
+                         GAsyncResult *res,
+                         gpointer      user_data)
 {
         GError *error = NULL;
         GsdTimezoneMonitor *self = user_data;
         GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
 
-        priv->geoclue_client = geoclue_client_proxy_new_for_bus_finish (res, &error);
+        priv->geoclue_simple = gclue_simple_new_finish (res, &error);
         if (error != NULL) {
                 g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
                 g_error_free (error);
                 return;
         }
 
-        geoclue_client_set_desktop_id (priv->geoclue_client, DESKTOP_ID);
-        geoclue_client_set_distance_threshold (priv->geoclue_client,
-                                               GEOCODE_LOCATION_ACCURACY_CITY);
-        geoclue_client_set_requested_accuracy_level (priv->geoclue_client,
-                                                     GCLUE_ACCURACY_LEVEL_CITY);
-
-        g_signal_connect (priv->geoclue_client, "location-updated",
-                          G_CALLBACK (on_location_updated), self);
-
-        geoclue_client_call_start (priv->geoclue_client,
-                                   priv->cancellable,
-                                   on_start_ready,
-                                   self);
-}
-
-static void
-on_get_client_ready (GObject      *source_object,
-                     GAsyncResult *res,
-                     gpointer      user_data)
-{
-        gchar *client_path;
-        GError *error = NULL;
-        GsdTimezoneMonitor *self = user_data;
-        GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
-
-        if (!geoclue_manager_call_get_client_finish (GEOCLUE_MANAGER (source_object),
-                                                     &client_path,
-                                                     res,
-                                                     &error)) {
-                g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
-                g_error_free (error);
-                return;
-        }
-
-        geoclue_client_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
-                                          G_DBUS_PROXY_FLAGS_NONE,
-                                          "org.freedesktop.GeoClue2",
-                                          client_path,
-                                          priv->cancellable,
-                                          on_client_proxy_ready,
-                                          self);
-}
-
-static void
-on_manager_proxy_ready (GObject      *source_object,
-                        GAsyncResult *res,
-                        gpointer      user_data)
-{
+        priv->geoclue_client = gclue_simple_get_client (priv->geoclue_simple);
+        gclue_client_set_distance_threshold (priv->geoclue_client,
+                                             GEOCODE_LOCATION_ACCURACY_CITY);
 
-        GError *error = NULL;
-        GsdTimezoneMonitor *self = user_data;
-        GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
+        g_signal_connect (priv->geoclue_simple, "notify::location",
+                          G_CALLBACK (on_location_notify), self);
 
-        priv->geoclue_manager = geoclue_manager_proxy_new_for_bus_finish (res, &error);
-        if (error != NULL) {
-                g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
-                g_error_free (error);
-                return;
-        }
-
-        geoclue_manager_call_get_client (priv->geoclue_manager,
-                                         priv->cancellable,
-                                         on_get_client_ready,
-                                         self);
+        on_location_notify (priv->geoclue_simple, NULL, self);
 }
 
 static void
@@ -413,13 +312,12 @@ register_geoclue (GsdTimezoneMonitor *self)
 {
         GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
 
-        geoclue_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
-                                           G_DBUS_PROXY_FLAGS_NONE,
-                                           "org.freedesktop.GeoClue2",
-                                           "/org/freedesktop/GeoClue2/Manager",
-                                           priv->cancellable,
-                                           on_manager_proxy_ready,
-                                           self);
+        gclue_simple_new (DESKTOP_ID,
+                          GCLUE_ACCURACY_LEVEL_CITY,
+                          priv->cancellable,
+                          on_geoclue_simple_ready,
+                          self);
+
 }
 
 GsdTimezoneMonitor *
@@ -442,12 +340,12 @@ gsd_timezone_monitor_finalize (GObject *obj)
         }
 
         if (priv->geoclue_client) {
-                geoclue_client_call_stop (priv->geoclue_client, NULL, NULL, NULL);
+                gclue_client_call_stop (priv->geoclue_client, NULL, NULL, NULL);
                 g_clear_object (&priv->geoclue_client);
         }
 
         g_clear_object (&priv->dtm);
-        g_clear_object (&priv->geoclue_manager);
+        g_clear_object (&priv->geoclue_simple);
         g_clear_object (&priv->permission);
         g_clear_pointer (&priv->current_timezone, g_free);
         g_clear_pointer (&priv->tzdb, tz_db_free);


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