From 9c879c999cea43712c451fdeeda45b42091859c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20G=C3=B6llnitz?= Date: Mon, 15 Jan 2024 20:31:10 +0100 Subject: [PATCH] weather-service: split activate/deactivate from start/stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Splitting an activation flag from starting and stopping the service makes it possible to flag the service as wanted from the settings and still due use counting in a subsequent commit. Signed-off-by: Markus Göllnitz --- src/gui/gcal-weather-settings.c | 4 +-- src/weather/gcal-weather-service.c | 45 ++++++++++++++++++++++++++++++ src/weather/gcal-weather-service.h | 4 +++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/gui/gcal-weather-settings.c b/src/gui/gcal-weather-settings.c index e7dd3de6..3744c639 100644 --- a/src/gui/gcal-weather-settings.c +++ b/src/gui/gcal-weather-settings.c @@ -202,11 +202,11 @@ manage_weather_service (GcalWeatherSettings *self) } gcal_weather_service_set_location (weather_service, location); - gcal_weather_service_start (weather_service); + gcal_weather_service_activate (weather_service); } else { - gcal_weather_service_stop (weather_service); + gcal_weather_service_deactivate (weather_service); } GCAL_EXIT; diff --git a/src/weather/gcal-weather-service.c b/src/weather/gcal-weather-service.c index 43565a4b..bda26e96 100644 --- a/src/weather/gcal-weather-service.c +++ b/src/weather/gcal-weather-service.c @@ -65,6 +65,7 @@ typedef struct * @valid_timespan: Amount of seconds weather information are considered valid. * @gweather_info: The weather info to query. * @max_days: Number of days we want weather information for. + * @weather_service_active: True if weather service is requested to be active, regardless of being in use. * @weather_service_running: True if weather service is active. * * This service listens to location and weather changes and reports them. @@ -103,6 +104,7 @@ struct _GcalWeatherService gint64 valid_timespan; GWeatherInfo *gweather_info; /* owned, nullable */ guint max_days; + gboolean weather_service_active; gboolean weather_service_running; }; @@ -686,6 +688,15 @@ update_gclue_location (GcalWeatherService *self, update_location (self, wlocation); } +static void +start_or_stop_weather_service (GcalWeatherService *self) +{ + if (self->weather_service_active) + gcal_weather_service_start (self); + else + gcal_weather_service_stop (self); +} + /* * Callbacks @@ -1179,6 +1190,40 @@ gcal_weather_service_update (GcalWeatherService *self) } } + +/** + * gcal_weather_service_activate: + * @self: The #GcalWeatherService instance. + * + * Activates weather service if needed. + * Use ::weather-changed to catch responses. + */ +void +gcal_weather_service_activate (GcalWeatherService *self) +{ + g_return_if_fail (GCAL_IS_WEATHER_SERVICE (self)); + + self->weather_service_active = TRUE; + + start_or_stop_weather_service (self); +} + +/** + * gcal_weather_service_deactivate: + * @self: The #GcalWeatherService instance. + * + * Stops the service. + */ +void +gcal_weather_service_deactivate (GcalWeatherService *self) +{ + g_return_if_fail (GCAL_IS_WEATHER_SERVICE (self)); + + self->weather_service_active = FALSE; + + start_or_stop_weather_service (self); +} + /** * gcal_weather_service_start: * @self: The #GcalWeatherService instance. diff --git a/src/weather/gcal-weather-service.h b/src/weather/gcal-weather-service.h index a7302eb7..c4947b64 100644 --- a/src/weather/gcal-weather-service.h +++ b/src/weather/gcal-weather-service.h @@ -50,6 +50,10 @@ const gchar* gcal_weather_service_get_attribution (GcalWeather void gcal_weather_service_update (GcalWeatherService *self); +void gcal_weather_service_activate (GcalWeatherService *self); + +void gcal_weather_service_deactivate (GcalWeatherService *self); + void gcal_weather_service_start (GcalWeatherService *self); void gcal_weather_service_stop (GcalWeatherService *self);