[gnome-settings-daemon] datetime: Honor location enabled setting
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] datetime: Honor location enabled setting
- Date: Mon, 24 Jul 2017 15:04:49 +0000 (UTC)
commit 50aa59bea9544db74fff6425519090e1f414f12a
Author: Rui Matos <tiagomatos gmail com>
Date: Mon Jul 24 15:15:22 2017 +0200
datetime: Honor location enabled setting
If location is disabled session wide we shouldn't use the service.
https://bugzilla.gnome.org/show_bug.cgi?id=785343
plugins/datetime/gsd-timezone-monitor.c | 52 +++++++++++++++++++++++++-----
1 files changed, 43 insertions(+), 9 deletions(-)
---
diff --git a/plugins/datetime/gsd-timezone-monitor.c b/plugins/datetime/gsd-timezone-monitor.c
index 2ac8648..1955acd 100644
--- a/plugins/datetime/gsd-timezone-monitor.c
+++ b/plugins/datetime/gsd-timezone-monitor.c
@@ -43,13 +43,17 @@ typedef struct
{
GCancellable *cancellable;
GPermission *permission;
+ Timedate1 *dtm;
+
GClueClient *geoclue_client;
GClueSimple *geoclue_simple;
- Timedate1 *dtm;
+ GCancellable *geoclue_cancellable;
TzDB *tzdb;
WeatherTzDB *weather_tzdb;
gchar *current_timezone;
+
+ GSettings *location_settings;
} GsdTimezoneMonitorPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GsdTimezoneMonitor, gsd_timezone_monitor, G_TYPE_OBJECT)
@@ -257,7 +261,7 @@ start_reverse_geocoding (GsdTimezoneMonitor *self,
reverse = geocode_reverse_new_for_location (location);
geocode_reverse_resolve_async (reverse,
- priv->cancellable,
+ priv->geoclue_cancellable,
on_reverse_geocoding_ready,
self);
@@ -312,18 +316,35 @@ on_geoclue_simple_ready (GObject *source_object,
}
static void
-register_geoclue (GsdTimezoneMonitor *self)
+start_geoclue (GsdTimezoneMonitor *self)
{
GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
+ priv->geoclue_cancellable = g_cancellable_new ();
gclue_simple_new (DESKTOP_ID,
GCLUE_ACCURACY_LEVEL_CITY,
- priv->cancellable,
+ priv->geoclue_cancellable,
on_geoclue_simple_ready,
self);
}
+static void
+stop_geoclue (GsdTimezoneMonitor *self)
+{
+ GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
+
+ g_cancellable_cancel (priv->geoclue_cancellable);
+ g_clear_object (&priv->geoclue_cancellable);
+
+ if (priv->geoclue_client) {
+ gclue_client_call_stop (priv->geoclue_client, NULL, NULL, NULL);
+ priv->geoclue_client = NULL;
+ }
+
+ g_clear_object (&priv->geoclue_simple);
+}
+
GsdTimezoneMonitor *
gsd_timezone_monitor_new (void)
{
@@ -338,21 +359,21 @@ gsd_timezone_monitor_finalize (GObject *obj)
g_debug ("Stopping timezone monitor");
+ stop_geoclue (monitor);
+
if (priv->cancellable) {
g_cancellable_cancel (priv->cancellable);
g_clear_object (&priv->cancellable);
}
- if (priv->geoclue_client)
- gclue_client_call_stop (priv->geoclue_client, NULL, NULL, NULL);
-
g_clear_object (&priv->dtm);
- 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);
g_clear_pointer (&priv->weather_tzdb, weather_tz_db_free);
+ g_clear_object (&priv->location_settings);
+
G_OBJECT_CLASS (gsd_timezone_monitor_parent_class)->finalize (obj);
}
@@ -374,6 +395,16 @@ gsd_timezone_monitor_class_init (GsdTimezoneMonitorClass *klass)
}
static void
+check_location_settings (GsdTimezoneMonitor *self)
+{
+ GsdTimezoneMonitorPrivate *priv = gsd_timezone_monitor_get_instance_private (self);
+ if (g_settings_get_boolean (priv->location_settings, "enabled"))
+ start_geoclue (self);
+ else
+ stop_geoclue (self);
+}
+
+static void
gsd_timezone_monitor_init (GsdTimezoneMonitor *self)
{
GError *error = NULL;
@@ -414,5 +445,8 @@ gsd_timezone_monitor_init (GsdTimezoneMonitor *self)
priv->tzdb = tz_load_db ();
priv->weather_tzdb = weather_tz_db_new ();
- register_geoclue (self);
+ priv->location_settings = g_settings_new ("org.gnome.system.location");
+ g_signal_connect_swapped (priv->location_settings, "changed::enabled",
+ G_CALLBACK (check_location_settings), self);
+ check_location_settings (self);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]