From 6c2bba29f7cfa297e4fb0a9f60ac90f430c1e3e2 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Mon, 10 Mar 2003 11:53:36 +0000 Subject: if we already have the client loaded, don't remove it, just increment its 2003-03-09 Rodrigo Moya * gui/alarm-notify/alarm-notify.c (alarm_notify_add_calendar): if we already have the client loaded, don't remove it, just increment its reference count. * gui/alarm-notify/alarm-queue.c (remove_queued_alarm): added new argument to specify whether we want the component's structure removed if no more alarms exist, and only free the structure if TRUE. (remove_alarms): added same new argument and pass it over to remove_queued_alarm. (remove_comp, obj_updated_cb): passed new argument to remove_alarms. (procedure_notification): passed new argument to remove_queued_alarm. (obj_removed_cb): set all freed pointers to NULL. (notify_dialog_cb): only remove the alarm if the pointers are not NULL. svn path=/trunk/; revision=20232 --- calendar/gui/alarm-notify/alarm-queue.c | 38 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'calendar/gui/alarm-notify/alarm-queue.c') diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index 50a36fe4f1..58f3429ab6 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -192,7 +192,7 @@ lookup_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id) * the last one listed for the component, it removes the component itself. */ static void -remove_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id) +remove_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id, gboolean free_object) { QueuedAlarm *qa; const char *uid; @@ -221,14 +221,16 @@ remove_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id) if (cqa->queued_alarms != NULL) return; - cal_component_get_uid (cqa->alarms->comp, &uid); - g_hash_table_remove (cqa->parent_client->uid_alarms_hash, uid); - cqa->parent_client = NULL; - - cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - - g_free (cqa); + if (free_object) { + cal_component_get_uid (cqa->alarms->comp, &uid); + g_hash_table_remove (cqa->parent_client->uid_alarms_hash, uid); + cqa->parent_client = NULL; + cal_component_alarms_free (cqa->alarms); + g_free (cqa); + } else { + cal_component_alarms_free (cqa->alarms); + cqa->alarms = NULL; + } } /* Callback used when an alarm triggers */ @@ -424,7 +426,7 @@ lookup_comp_queued_alarms (ClientAlarms *ca, const char *uid) } static void -remove_alarms (CompQueuedAlarms *cqa) +remove_alarms (CompQueuedAlarms *cqa, gboolean free_object) { GSList *l; @@ -440,7 +442,7 @@ remove_alarms (CompQueuedAlarms *cqa) l = l->next; alarm_remove (qa->alarm_id); - remove_queued_alarm (cqa, qa->alarm_id); + remove_queued_alarm (cqa, qa->alarm_id, free_object); } } @@ -460,7 +462,7 @@ remove_comp (ClientAlarms *ca, const char *uid) */ g_assert (cqa->queued_alarms != NULL); - remove_alarms (cqa); + remove_alarms (cqa, TRUE); /* The list should be empty now, and thus the queued component alarms * structure should have been freed and removed from the hash table. @@ -503,7 +505,7 @@ obj_updated_cb (CalClient *client, const char *uid, gpointer data) GSList *l; /* if already in the list, just update it */ - remove_alarms (cqa); + remove_alarms (cqa, FALSE); cqa->alarms = alarms; cqa->queued_alarms = NULL; @@ -664,8 +666,11 @@ on_dialog_obj_removed_cb (CalClient *client, const char *uid, gpointer data) cal_component_get_uid (c->comp, &our_uid); g_return_if_fail (our_uid && *our_uid); - if (!strcmp (uid, our_uid)) + if (!strcmp (uid, our_uid)) { alarm_notify_dialog_disable_buttons (c->dialog); + c->cqa = NULL; + c->alarm_id = NULL; + } } /* Callback used from the alarm notify dialog */ @@ -698,7 +703,8 @@ notify_dialog_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) g_assert_not_reached (); } - remove_queued_alarm (c->cqa, c->alarm_id); + if (c->cqa != NULL) + remove_queued_alarm (c->cqa, c->alarm_id, TRUE); g_object_unref (c->comp); g_object_unref (c->client); g_free (c); @@ -935,7 +941,7 @@ procedure_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id if (result < 0) goto fallback; - remove_queued_alarm (cqa, alarm_id); + remove_queued_alarm (cqa, alarm_id, TRUE); return; fallback: -- cgit v1.2.3