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.
This commit is contained in:
Georges Basile Stavracas Neto
2023-08-17 18:26:49 -03:00
parent 4042f43f46
commit 904ae8c4f6
2 changed files with 48 additions and 14 deletions
+31
View File
@@ -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.
+17 -14
View File
@@ -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