diff options
author | Teemu Ikonen <tpikonen@mailbox.org> | 2021-11-22 11:44:16 +0200 |
---|---|---|
committer | Teemu Ikonen <tpikonen@mailbox.org> | 2021-11-28 10:38:52 +0200 |
commit | e4c61f8f76a3d6aa15a1d9b83c68aa1474fd0e82 (patch) | |
tree | 967c5b045cb97f24796e9daf22f0cebb7fd22448 | |
parent | 7a9575055936bfd1c9157949917b47a7126bd7ae (diff) |
config, location-source: Allow disabling compass in config
config: Add 'compass' group with 'enable' key
location-source: Leave priv->compass to NULL and don't connect compass
signal handler, if compass is disabled in config.
-rw-r--r-- | data/geoclue.conf.in | 8 | ||||
-rw-r--r-- | src/gclue-config.c | 17 | ||||
-rw-r--r-- | src/gclue-config.h | 1 | ||||
-rw-r--r-- | src/gclue-location-source.c | 20 |
4 files changed, 38 insertions, 8 deletions
diff --git a/data/geoclue.conf.in b/data/geoclue.conf.in index 14056c7..650470d 100644 --- a/data/geoclue.conf.in +++ b/data/geoclue.conf.in @@ -74,6 +74,12 @@ submit-data=false # A nickname to submit network data with. A nickname must be 2-32 characters long. submission-nick=geoclue +# Compass configuration options +[compass] + +# Enable Compass +enable=true + # Application configuration options # # NOTE: Having an entry here for an application with allowed=true means that @@ -140,4 +146,4 @@ users= [lipstick] allowed=true system=true -users=
\ No newline at end of file +users= diff --git a/src/gclue-config.c b/src/gclue-config.c index 83f29b6..8c1cc3d 100644 --- a/src/gclue-config.c +++ b/src/gclue-config.c @@ -43,6 +43,7 @@ struct _GClueConfigPrivate gboolean enable_cdma_source; gboolean enable_modem_gps_source; gboolean enable_wifi_source; + gboolean enable_compass; char *wifi_submit_url; char *wifi_submit_nick; char *nmea_socket; @@ -122,7 +123,7 @@ static void load_app_configs (GClueConfig *config) { const char *known_groups[] = { "agent", "wifi", "3g", "cdma", - "modem-gps", "network-nmea", + "modem-gps", "network-nmea", "compass", NULL }; GClueConfigPrivate *priv = config->priv; gsize num_groups = 0, i; @@ -316,6 +317,13 @@ load_network_nmea_config (GClueConfig *config) } static void +load_compass_config (GClueConfig *config) +{ + config->priv->enable_compass = + load_enable_source_config (config, "compass"); +} + +static void gclue_config_init (GClueConfig *config) { GError *error = NULL; @@ -341,6 +349,7 @@ gclue_config_init (GClueConfig *config) load_cdma_config (config); load_modem_gps_config (config); load_network_nmea_config (config); + load_compass_config (config); } GClueConfig * @@ -523,3 +532,9 @@ gclue_config_set_nmea_socket (GClueConfig *config, { config->priv->nmea_socket = g_strdup(nmea_socket); } + +gboolean +gclue_config_get_enable_compass (GClueConfig *config) +{ + return config->priv->enable_compass; +} diff --git a/src/gclue-config.h b/src/gclue-config.h index 1ea8a9d..1231d56 100644 --- a/src/gclue-config.h +++ b/src/gclue-config.h @@ -91,6 +91,7 @@ gboolean gclue_config_get_enable_cdma_source (GClueConfig *config gboolean gclue_config_get_enable_modem_gps_source (GClueConfig *config); gboolean gclue_config_get_enable_nmea_source (GClueConfig *config); +gboolean gclue_config_get_enable_compass (GClueConfig *config); G_END_DECLS diff --git a/src/gclue-location-source.c b/src/gclue-location-source.c index c31bbbc..6ca59b8 100644 --- a/src/gclue-location-source.c +++ b/src/gclue-location-source.c @@ -22,6 +22,7 @@ #include <glib.h> #include "gclue-location-source.h" #include "gclue-compass.h" +#include "gclue-config.h" /** * SECTION:gclue-location-source @@ -293,12 +294,19 @@ start_source (GClueLocationSource *source) } if (source->priv->compute_movement) { - source->priv->compass = gclue_compass_get_singleton (); - source->priv->heading_changed_id = g_signal_connect - (G_OBJECT (source->priv->compass), - "notify::heading", - G_CALLBACK (on_compass_heading_changed), - source); + GClueConfig *config = gclue_config_get_singleton (); + + if (gclue_config_get_enable_compass (config)) { + source->priv->compass = gclue_compass_get_singleton (); + source->priv->heading_changed_id = g_signal_connect + (G_OBJECT (source->priv->compass), + "notify::heading", + G_CALLBACK (on_compass_heading_changed), + source); + } else { + source->priv->compass = NULL; + g_debug ("Compass is disabled in config"); + } } g_object_notify (G_OBJECT (source), "active"); |