From 01f527676426e649da9bca30510ee6f198a8b26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erick=20P=C3=A9rez=20Castellanos?= Date: Mon, 19 Jan 2015 01:42:19 -0500 Subject: [PATCH] manager: retrieve events on a range --- src/gcal-manager.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/gcal-manager.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/src/gcal-manager.c b/src/gcal-manager.c index 4ba2de90..03d985e2 100644 --- a/src/gcal-manager.c +++ b/src/gcal-manager.c @@ -234,6 +234,25 @@ free_unit_data (GcalManagerUnit *data) g_free (data); } +static gboolean +gather_components (ECalDataModel *data_model, + ECalClient *client, + const ECalComponentId *id, + ECalComponent *comp, + time_t instance_start, + time_t instance_end, + gpointer user_data) +{ + GList **result = user_data; + GcalEventData *new_data = g_new0 (GcalEventData, 1); + + new_data->source = e_client_get_source (E_CLIENT (client)); + new_data->event_component = g_object_ref (comp); + *result = g_list_append (*result, new_data);/* FIXME: add me sorted */ + + return TRUE; +} + /** * load_source: * @manager: Manager instance @@ -1022,3 +1041,28 @@ gcal_manager_move_event_to_source (GcalManager *manager, /* FIXME: add code, fix stub method */ ; } + +/** + * gcal_manager_get_events: + * + * Returns a list with {@link GcalEventData} objects owned by the caller, the list and the objects. + * The components inside the list are owned by the caller as well. So, don't ref the component. + * + * Returns: An {@link GList} object + */ +GList* +gcal_manager_get_events (GcalManager *manager, + icaltimetype *start_date, + icaltimetype *end_date) +{ + GcalManagerPrivate *priv = gcal_manager_get_instance_private (manager); + time_t range_start, range_end; + GList *list = NULL; + + range_start = icaltime_as_timet_with_zone (*start_date, priv->system_timezone); + range_end = icaltime_as_timet_with_zone (*end_date, priv->system_timezone); + + e_cal_data_model_foreach_component (priv->e_data_model, range_start, range_end, gather_components, &list); + return list; +} + diff --git a/src/gcal-manager.h b/src/gcal-manager.h index 923d948c..1ecd3c6b 100644 --- a/src/gcal-manager.h +++ b/src/gcal-manager.h @@ -119,6 +119,10 @@ void gcal_manager_move_event_to_source (GcalManager *manager const gchar *event_uid, const gchar *new_source_uid); +GList* gcal_manager_get_events (GcalManager *manager, + icaltimetype *range_start, + icaltimetype *range_end); + G_END_DECLS #endif /* __GCAL_MANAGER_H__ */