From 47c9fef15abc15c678e4cde60ee71d741dfe23bf Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 12 May 2000 04:16:46 +0000 Subject: New function to add today's alarms for a single object. 2000-05-11 Federico Mena Quintero * gui/gnome-cal.c (add_alarms_for_object): New function to add today's alarms for a single object. (gnome_calendar_object_updated_cb): Update the object's alarms. * idl/evolution-calendar.idl (Cal): Added a get_alarms_for_object() method. * pcs/cal.c (Cal_get_alarms_for_object): Implemented method. * pcs/cal-backend.c (cal_backend_get_alarms_for_object): New function. * pcs/cal-backend-imc.c (cal_backend_imc_get_alarms_for_object): Implemented. * cal-client/cal-client.c (cal_client_get_alarms_for_object): New function. svn path=/trunk/; revision=3003 --- calendar/pcs/cal-backend-imc.c | 40 +++++++++++++++++++++++++++++++ calendar/pcs/cal-backend.c | 29 +++++++++++++++++++++++ calendar/pcs/cal-backend.h | 7 ++++++ calendar/pcs/cal.c | 53 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 124 insertions(+), 5 deletions(-) (limited to 'calendar/pcs') diff --git a/calendar/pcs/cal-backend-imc.c b/calendar/pcs/cal-backend-imc.c index 9492ad1241..3c50078d12 100644 --- a/calendar/pcs/cal-backend-imc.c +++ b/calendar/pcs/cal-backend-imc.c @@ -78,6 +78,9 @@ static char *cal_backend_imc_get_object (CalBackend *backend, const char *uid); static GList *cal_backend_imc_get_uids (CalBackend *backend, CalObjType type); static GList *cal_backend_imc_get_events_in_range (CalBackend *backend, time_t start, time_t end); static GList *cal_backend_imc_get_alarms_in_range (CalBackend *backend, time_t start, time_t end); +static gboolean cal_backend_imc_get_alarms_for_object (CalBackend *backend, const char *uid, + time_t start, time_t end, + GList **alarms); static gboolean cal_backend_imc_update_object (CalBackend *backend, const char *uid, const char *calobj); static gboolean cal_backend_imc_remove_object (CalBackend *backend, const char *uid); @@ -138,6 +141,7 @@ cal_backend_imc_class_init (CalBackendIMCClass *class) backend_class->get_uids = cal_backend_imc_get_uids; backend_class->get_events_in_range = cal_backend_imc_get_events_in_range; backend_class->get_alarms_in_range = cal_backend_imc_get_alarms_in_range; + backend_class->get_alarms_for_object = cal_backend_imc_get_alarms_for_object; backend_class->update_object = cal_backend_imc_update_object; backend_class->remove_object = cal_backend_imc_remove_object; @@ -1147,6 +1151,42 @@ cal_backend_imc_get_alarms_in_range (CalBackend *backend, time_t start, time_t e return alarms; } +/* Get_alarms_for_object handler for the IMC backend */ +static gboolean +cal_backend_imc_get_alarms_for_object (CalBackend *backend, const char *uid, + time_t start, time_t end, + GList **alarms) +{ + CalBackendIMC *cbimc; + IMCPrivate *priv; + iCalObject *ico; + + cbimc = CAL_BACKEND_IMC (backend); + priv = cbimc->priv; + + g_return_val_if_fail (priv->loaded, FALSE); + g_return_val_if_fail (uid != NULL, FALSE); + g_return_val_if_fail (start != -1 && end != -1, FALSE); + g_return_val_if_fail (start <= end, FALSE); + g_return_val_if_fail (alarms != NULL, FALSE); + + *alarms = NULL; + + ico = lookup_object (cbimc, uid); + if (!ico) + return FALSE; + + /* Only VEVENT and VTODO components can have alarms */ + + if (ico->type != ICAL_EVENT && ico->type != ICAL_TODO) + return TRUE; + + *alarms = add_alarms_for_object (*alarms, ico, start, end); + *alarms = g_list_sort (*alarms, compare_instance_func); + + return TRUE; +} + /* Notifies a backend's clients that an object was updated */ static void notify_update (CalBackendIMC *cbimc, const char *uid) diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index e9c18d6f86..15cfb1e7bc 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -266,6 +266,35 @@ cal_backend_get_alarms_in_range (CalBackend *backend, time_t start, time_t end) return (* CLASS (backend)->get_alarms_in_range) (backend, start, end); } +/** + * cal_backend_get_alarms_for_object: + * @backend: A calendar backend. + * @uid: Unique identifier for a calendar object. + * @start: Start time for query. + * @end: End time for query. + * @alarms: Return value for the list of alarm instances. + * + * Builds a sorted list of the alarms of the specified event that trigger in a + * particular time range. + * + * Return value: TRUE on success, FALSE if the object was not found. + **/ +gboolean +cal_backend_get_alarms_for_object (CalBackend *backend, const char *uid, + time_t start, time_t end, + GList **alarms) +{ + g_return_val_if_fail (backend != NULL, FALSE); + g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE); + g_return_val_if_fail (uid != NULL, FALSE); + g_return_val_if_fail (start != -1 && end != -1, FALSE); + g_return_val_if_fail (start <= end, FALSE); + g_return_val_if_fail (alarms != NULL, FALSE); + + g_assert (CLASS (backend)->get_alarms_for_object != NULL); + return (* CLASS (backend)->get_alarms_for_object) (backend, uid, start, end, alarms); +} + /** * cal_backend_update_object: * @backend: A calendar backend. diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index 5ce9027415..2bbac4b3d4 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -68,6 +68,9 @@ struct _CalBackendClass { GList *(* get_uids) (CalBackend *backend, CalObjType type); GList *(* get_events_in_range) (CalBackend *backend, time_t start, time_t end); GList *(* get_alarms_in_range) (CalBackend *backend, time_t start, time_t end); + gboolean (* get_alarms_for_object) (CalBackend *backend, const char *uid, + time_t start, time_t end, + GList **alarms); gboolean (* update_object) (CalBackend *backend, const char *uid, const char *calobj); gboolean (* remove_object) (CalBackend *backend, const char *uid); }; @@ -90,6 +93,10 @@ GList *cal_backend_get_events_in_range (CalBackend *backend, time_t start, time_ GList *cal_backend_get_alarms_in_range (CalBackend *backend, time_t start, time_t end); +gboolean cal_backend_get_alarms_for_object (CalBackend *backend, const char *uid, + time_t start, time_t end, + GList **alarms); + gboolean cal_backend_update_object (CalBackend *backend, const char *uid, const char *calobj); gboolean cal_backend_remove_object (CalBackend *backend, const char *uid); diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index 8fc1de51b2..13fab067f8 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -201,7 +201,7 @@ Cal_get_object (PortableServer_Servant servant, /* Cal::get_uids method */ static Evolution_Calendar_CalObjUIDSeq * Cal_get_uids (PortableServer_Servant servant, - const Evolution_Calendar_CalObjType type, + Evolution_Calendar_CalObjType type, CORBA_Environment *ev) { Cal *cal; @@ -287,8 +287,8 @@ build_object_instance_seq (GList *list) /* Cal::get_events_in_range method */ static Evolution_Calendar_CalObjInstanceSeq * Cal_get_events_in_range (PortableServer_Servant servant, - const Evolution_Calendar_Time_t start, - const Evolution_Calendar_Time_t end, + Evolution_Calendar_Time_t start, + Evolution_Calendar_Time_t end, CORBA_Environment *ev) { Cal *cal; @@ -378,8 +378,8 @@ build_alarm_instance_seq (GList *alarms) /* Cal::get_alarms_in_range method */ static Evolution_Calendar_CalAlarmInstanceSeq * Cal_get_alarms_in_range (PortableServer_Servant servant, - const Evolution_Calendar_Time_t start, - const Evolution_Calendar_Time_t end, + Evolution_Calendar_Time_t start, + Evolution_Calendar_Time_t end, CORBA_Environment *ev) { Cal *cal; @@ -410,6 +410,48 @@ Cal_get_alarms_in_range (PortableServer_Servant servant, return seq; } +/* Cal::get_alarms_for_object method */ +static Evolution_Calendar_CalAlarmInstanceSeq * +Cal_get_alarms_for_object (PortableServer_Servant servant, + const Evolution_Calendar_CalObjUID uid, + Evolution_Calendar_Time_t start, + Evolution_Calendar_Time_t end, + CORBA_Environment *ev) +{ + Cal *cal; + CalPrivate *priv; + time_t t_start, t_end; + Evolution_Calendar_CalAlarmInstanceSeq *seq; + GList *alarms; + gboolean result; + + cal = CAL (bonobo_object_from_servant (servant)); + priv = cal->priv; + + t_start = (time_t) start; + t_end = (time_t) end; + + if (t_start > t_end || t_start == -1 || t_end == -1) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_Evolution_Calendar_Cal_InvalidRange, + NULL); + return NULL; + } + + result = cal_backend_get_alarms_for_object (priv->backend, uid, t_start, t_end, &alarms); + if (!result) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_Evolution_Calendar_Cal_NotFound, + NULL); + return NULL; + } + + seq = build_alarm_instance_seq (alarms); + cal_alarm_instance_list_free (alarms); + + return seq; +} + /* Cal::update_object method */ static void Cal_update_object (PortableServer_Servant servant, @@ -466,6 +508,7 @@ cal_get_epv (void) epv->get_uids = Cal_get_uids; epv->get_events_in_range = Cal_get_events_in_range; epv->get_alarms_in_range = Cal_get_alarms_in_range; + epv->get_alarms_for_object = Cal_get_alarms_for_object; epv->update_object = Cal_update_object; epv->remove_object = Cal_remove_object; -- cgit