aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/alarm-notify/alarm.c
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@nuclecu.unam.mx>1998-12-17 12:40:38 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-12-17 12:40:38 +0800
commitadac6994268794b434973701ed5f20386eed02c9 (patch)
treec611807515f7815b4d5ac8a7be5069b2bf012461 /calendar/gui/alarm-notify/alarm.c
parent52f6c4b4fe2c9ed4bed484b9e9d20a378275de61 (diff)
downloadgsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.tar
gsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.tar.gz
gsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.tar.bz2
gsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.tar.lz
gsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.tar.xz
gsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.tar.zst
gsoc2013-evolution-adac6994268794b434973701ed5f20386eed02c9.zip
Rewrote the old and broken alarm system. It never actually worked
1998-12-16 Miguel de Icaza <miguel@nuclecu.unam.mx> 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
Diffstat (limited to 'calendar/gui/alarm-notify/alarm.c')
-rw-r--r--calendar/gui/alarm-notify/alarm.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c
index 280d4125e3..30d3534955 100644
--- a/calendar/gui/alarm-notify/alarm.c
+++ b/calendar/gui/alarm-notify/alarm.c
@@ -11,6 +11,7 @@
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
+#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);