weather-service: split activate/deactivate from start/stop

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 <camelcasenick@bewares.it>
This commit is contained in:
Markus Göllnitz
2024-01-27 16:09:02 +00:00
committed by Georges Basile Stavracas Neto
parent faa6e91d8b
commit 9c879c999c
3 changed files with 51 additions and 2 deletions
+2 -2
View File
@@ -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;
+45
View File
@@ -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.
+4
View File
@@ -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);