From 904ae8c4f6228e8be87990569be6784a0b3bfaad Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 17 Aug 2023 18:12:48 -0300 Subject: [PATCH] weather-service: Add method to fetch info for date This will be used by next commit to reintroduce weather data in the Month view. Patch originally made by camelCaseNick. --- src/weather/gcal-weather-service.c | 31 ++++++++++++++++++++++++++++++ src/weather/gcal-weather-service.h | 31 ++++++++++++++++-------------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/weather/gcal-weather-service.c b/src/weather/gcal-weather-service.c index 174f06bd..690efc9b 100644 --- a/src/weather/gcal-weather-service.c +++ b/src/weather/gcal-weather-service.c @@ -1033,6 +1033,37 @@ gcal_weather_service_set_time_zone (GcalWeatherService *self, g_object_notify (G_OBJECT (self), "time-zone"); } +/** + * gcal_weather_service_get_weather_info_for_date: + * @self: The #GcalWeatherService instance. + * @date: The #GDate for which to get the current forecast. + * + * Retrieves the available weather information for @date. + * + * Returns: (transfer none)(nullable): a #GcalWeatherInfo + */ +GcalWeatherInfo* +gcal_weather_service_get_weather_info_for_date (GcalWeatherService *self, + GDate *date) +{ + g_return_val_if_fail (GCAL_IS_WEATHER_SERVICE (self), NULL); + + for (guint i = 0; self->weather_infos && i < self->weather_infos->len; i++) + { + GcalWeatherInfo *info; + GDate weather_date; + + info = g_ptr_array_index (self->weather_infos, i); + + gcal_weather_info_get_date (info, &weather_date); + + if (g_date_compare (&weather_date, date) == 0) + return info; + } + + return NULL; +} + /** * gcal_weather_service_get_weather_infos: * @self: The #GcalWeatherService instance. diff --git a/src/weather/gcal-weather-service.h b/src/weather/gcal-weather-service.h index 80717ab6..6ac45def 100644 --- a/src/weather/gcal-weather-service.h +++ b/src/weather/gcal-weather-service.h @@ -31,28 +31,31 @@ G_DECLARE_FINAL_TYPE (GcalWeatherService, gcal_weather_service, GCAL, WEATHER_SE typedef void (*GcalWeatherUpdateFunc) (GtkWidget *widget); -GcalWeatherService* gcal_weather_service_new (void); +GcalWeatherService* gcal_weather_service_new (void); -GTimeZone* gcal_weather_service_get_time_zone (GcalWeatherService *self); +GTimeZone* gcal_weather_service_get_time_zone (GcalWeatherService *self); -void gcal_weather_service_set_time_zone (GcalWeatherService *self, - GTimeZone *value); +void gcal_weather_service_set_time_zone (GcalWeatherService *self, + GTimeZone *value); -GPtrArray* gcal_weather_service_get_weather_infos (GcalWeatherService *self); +GcalWeatherInfo* gcal_weather_service_get_weather_info_for_date (GcalWeatherService *self, + GDate *date); -const gchar* gcal_weather_service_get_attribution (GcalWeatherService *self); +GPtrArray* gcal_weather_service_get_weather_infos (GcalWeatherService *self); -void gcal_weather_service_update (GcalWeatherService *self); +const gchar* gcal_weather_service_get_attribution (GcalWeatherService *self); -void gcal_weather_service_run (GcalWeatherService *self, - GWeatherLocation *location); +void gcal_weather_service_update (GcalWeatherService *self); -void gcal_weather_service_stop (GcalWeatherService *self); +void gcal_weather_service_run (GcalWeatherService *self, + GWeatherLocation *location); -void gcal_weather_service_connect_widget (GcalWeatherService *self, - GcalWeatherUpdateFunc update_func, - GCallback weather_changed_cb, - GtkWidget *data); +void gcal_weather_service_stop (GcalWeatherService *self); + +void gcal_weather_service_connect_widget (GcalWeatherService *self, + GcalWeatherUpdateFunc update_func, + GCallback weather_changed_cb, + GtkWidget *data); G_END_DECLS