From 02ee28bf7749fd4f6cc764d1765405edf2e9293e Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 2 Jan 2001 22:47:28 +0000 Subject: If the component has no alarms, do not try to queue them. 2001-01-02 Federico Mena Quintero * gui/alarm-notify.c (add_component_alarms): If the component has no alarms, do not try to queue them. (remove_client_alarms): New function to remove all the queued alarms for a calendar client. (alarm_notify_remove_client): Remove the client's alarms. svn path=/trunk/; revision=7218 --- calendar/gui/alarm-notify.c | 48 ++++++++++++++++++++++++++++++++- calendar/gui/alarm-notify/alarm-queue.c | 48 ++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/alarm-notify.c b/calendar/gui/alarm-notify.c index 805b29f81d..d824b2a189 100644 --- a/calendar/gui/alarm-notify.c +++ b/calendar/gui/alarm-notify.c @@ -204,6 +204,12 @@ add_component_alarms (ClientAlarms *ca, CalComponentAlarms *alarms) CompQueuedAlarms *cqa; GSList *l; + /* No alarms? */ + if (alarms->alarms == NULL) { + cal_component_alarms_free (alarms); + return; + } + cqa = g_new (CompQueuedAlarms, 1); cqa->parent_client = ca; cqa->alarms = alarms; @@ -469,6 +475,46 @@ alarm_notify_add_client (CalClient *client) load_alarms (ca); } +/* Called from g_hash_table_foreach(); adds a component UID to a list */ +static void +add_uid_cb (gpointer key, gpointer value, gpointer data) +{ + GSList **uids; + const char *uid; + + uids = data; + uid = key; + + *uids = g_slist_prepend (*uids, (char *) uid); +} + +/* Removes all the alarms queued for a particular calendar client */ +static void +remove_client_alarms (ClientAlarms *ca) +{ + GSList *uids; + GSList *l; + + /* First we build a list of UIDs so that we can remove them one by one */ + + uids = NULL; + g_hash_table_foreach (ca->uid_alarms_hash, add_uid_cb, &uids); + + for (l = uids; l; l = l->next) { + const char *uid; + + uid = l->data; + + remove_comp (ca, uid); + } + + g_slist_free (uids); + + /* The hash table should be empty now */ + + g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0); +} + /** * alarm_notify_remove_client: * @client: A calendar client. @@ -493,7 +539,7 @@ alarm_notify_remove_client (CalClient *client) if (ca->refcount > 0) return; - /* FIXME: remove alarms */ + remove_client_alarms (ca); /* Clean up */ diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index 805b29f81d..d824b2a189 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -204,6 +204,12 @@ add_component_alarms (ClientAlarms *ca, CalComponentAlarms *alarms) CompQueuedAlarms *cqa; GSList *l; + /* No alarms? */ + if (alarms->alarms == NULL) { + cal_component_alarms_free (alarms); + return; + } + cqa = g_new (CompQueuedAlarms, 1); cqa->parent_client = ca; cqa->alarms = alarms; @@ -469,6 +475,46 @@ alarm_notify_add_client (CalClient *client) load_alarms (ca); } +/* Called from g_hash_table_foreach(); adds a component UID to a list */ +static void +add_uid_cb (gpointer key, gpointer value, gpointer data) +{ + GSList **uids; + const char *uid; + + uids = data; + uid = key; + + *uids = g_slist_prepend (*uids, (char *) uid); +} + +/* Removes all the alarms queued for a particular calendar client */ +static void +remove_client_alarms (ClientAlarms *ca) +{ + GSList *uids; + GSList *l; + + /* First we build a list of UIDs so that we can remove them one by one */ + + uids = NULL; + g_hash_table_foreach (ca->uid_alarms_hash, add_uid_cb, &uids); + + for (l = uids; l; l = l->next) { + const char *uid; + + uid = l->data; + + remove_comp (ca, uid); + } + + g_slist_free (uids); + + /* The hash table should be empty now */ + + g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0); +} + /** * alarm_notify_remove_client: * @client: A calendar client. @@ -493,7 +539,7 @@ alarm_notify_remove_client (CalClient *client) if (ca->refcount > 0) return; - /* FIXME: remove alarms */ + remove_client_alarms (ca); /* Clean up */ -- cgit