From adac6994268794b434973701ed5f20386eed02c9 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Thu, 17 Dec 1998 04:40:38 +0000 Subject: Rewrote the old and broken alarm system. It never actually worked 1998-12-16 Miguel de Icaza Rewrote the old and broken alarm system. It never actually worked properly. Now it works properly, and I figured a nice way to get the Audio alarm do something nicer (it is now like an alarm clock :-). * gnome-cal.c (calendar_notify): Now we take a CalendarAlarm to actually distinguish which alarm was triggered. * alarm.c (alarm_ready): The code was only activating the first alarm. Reschedule the timer upon delivery of an alarm. svn path=/trunk/; revision=535 --- calendar/alarm.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'calendar/alarm.c') diff --git a/calendar/alarm.c b/calendar/alarm.c index 280d4125e3..30d3534955 100644 --- a/calendar/alarm.c +++ b/calendar/alarm.c @@ -11,6 +11,7 @@ #include #include #include +#include "calobj.h" #include "alarm.h" /* The pipes used to notify about an alarm */ @@ -25,6 +26,7 @@ typedef struct { time_t activation_time; AlarmFunction fn; void *closure; + CalendarAlarm *alarm; } AlarmRecord; /* @@ -42,6 +44,7 @@ static void alarm_ready (void *closure, int fd, GdkInputCondition cond) { AlarmRecord *ar = head_alarm; + time_t now = time (NULL); char c; if (read (alarm_pipes [0], &c, 1) != 1) @@ -51,12 +54,33 @@ alarm_ready (void *closure, int fd, GdkInputCondition cond) g_warning ("Empty events. This should not happen\n"); return; } - (*ar->fn)(ar->activation_time, ar->closure); - alarms = g_list_remove (alarms, head_alarm); - if (alarms) - head_alarm = alarms->data; - else - head_alarm = NULL; + + while (head_alarm){ + (*ar->fn)(ar->activation_time, ar->alarm, ar->closure); + alarms = g_list_remove (alarms, head_alarm); + + /* Schedule next alarm */ + if (alarms){ + AlarmRecord *next; + + head_alarm = alarms->data; + next = head_alarm; + + if (next->activation_time > now){ + struct itimerval itimer; + + itimer.it_interval.tv_sec = 0; + itimer.it_interval.tv_usec = 0; + itimer.it_value.tv_sec = next->activation_time - now; + itimer.it_value.tv_usec = 0; + setitimer (ITIMER_REAL, &itimer, NULL); + } else { + g_free (ar); + ar = next; + } + } else + head_alarm = NULL; + } g_free (ar); } @@ -72,10 +96,11 @@ alarm_compare_by_time (gconstpointer a, gconstpointer b) } void -alarm_add (time_t alarm_time, AlarmFunction fn, void *closure) +alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) { time_t now = time (NULL); AlarmRecord *ar; + time_t alarm_time = alarm->trigger; /* If it already expired, do not add it */ if (alarm_time < now) @@ -85,6 +110,7 @@ alarm_add (time_t alarm_time, AlarmFunction fn, void *closure) ar->activation_time = alarm_time; ar->fn = fn; ar->closure = closure; + ar->alarm = alarm; alarms = g_list_insert_sorted (alarms, ar, alarm_compare_by_time); -- cgit v1.2.3