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
This commit is contained in:

committed by
Arturo Espinosa

parent
52f6c4b4fe
commit
adac699426
@ -1,3 +1,16 @@
|
||||
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.
|
||||
|
||||
1998-12-14 Federico Mena Quintero <federico@nuclecu.unam.mx>
|
||||
|
||||
* year-view.c (idle_handler): Use the allocation size instead of
|
||||
|
@ -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);
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
typedef void (*AlarmFunction)(time_t time, void *closuse);
|
||||
typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse);
|
||||
|
||||
void alarm_init (void);
|
||||
void alarm_add (time_t alarm_time, AlarmFunction fn, void *closure);
|
||||
void alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure);
|
||||
int alarm_kill (void *closure);
|
||||
|
||||
#endif
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <unistd.h>
|
||||
#include "alarm.h"
|
||||
#include "calendar.h"
|
||||
#include "alarm.h"
|
||||
#include "timeutil.h"
|
||||
#include "../libversit/vcc.h"
|
||||
|
||||
@ -42,7 +42,7 @@ try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end)
|
||||
return;
|
||||
if (alarm->trigger > calendar_day_end)
|
||||
return;
|
||||
alarm_add (alarm->trigger, calendar_notify, ico);
|
||||
alarm_add (alarm, &calendar_notify, ico);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -59,7 +59,7 @@ void calendar_destroy_event_list (GList *l);
|
||||
/* Informs the calendar that obj information has changed */
|
||||
void calendar_object_changed (Calendar *cal, iCalObject *obj, int flags);
|
||||
|
||||
void calendar_notify (time_t, void *data);
|
||||
void calendar_notify (time_t time, CalendarAlarm *which, void *data);
|
||||
END_GNOME_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -338,29 +338,59 @@ mail_notify (char *mail_address, char *text, time_t app_time)
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
static void
|
||||
stop_beeping (GtkObject *object, gpointer tagp)
|
||||
{
|
||||
guint tag = GPOINTER_TO_INT (tagp);
|
||||
|
||||
gtk_timeout_remove (tag);
|
||||
}
|
||||
|
||||
static gint
|
||||
start_beeping (gpointer data)
|
||||
{
|
||||
gdk_beep ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
calendar_notify (time_t time, void *data)
|
||||
calendar_notify (time_t time, CalendarAlarm *which, void *data)
|
||||
{
|
||||
iCalObject *ico = data;
|
||||
guint tag;
|
||||
|
||||
if (&ico->aalarm == which){
|
||||
time_t app = ico->dalarm.trigger + ico->dalarm.offset;
|
||||
GtkWidget *w;
|
||||
char *msg;
|
||||
|
||||
msg = g_copy_strings (_("Reminder of your appointment at "),
|
||||
ctime (&app), "`",
|
||||
ico->summary, "'", NULL);
|
||||
|
||||
/* Idea: we need Snooze option :-) */
|
||||
w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, "Ok", NULL);
|
||||
tag = gtk_timeout_add (1000, start_beeping, NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (w), "destroy", stop_beeping, GINT_TO_POINTER (tag));
|
||||
gtk_widget_show (w);
|
||||
|
||||
if (ico->aalarm.enabled && ico->aalarm.trigger == time){
|
||||
printf ("bip\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ico->palarm.enabled && ico->palarm.trigger == time){
|
||||
if (&ico->palarm == which){
|
||||
execute (ico->palarm.data, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ico->malarm.enabled && ico->malarm.trigger == time){
|
||||
if (&ico->malarm == which){
|
||||
time_t app = ico->malarm.trigger + ico->malarm.offset;
|
||||
|
||||
mail_notify (ico->malarm.data, ico->summary, app);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ico->dalarm.enabled && ico->dalarm.trigger == time){
|
||||
if (&ico->dalarm == which){
|
||||
time_t app = ico->dalarm.trigger + ico->dalarm.offset;
|
||||
GtkWidget *w;
|
||||
char *msg;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
typedef void (*AlarmFunction)(time_t time, void *closuse);
|
||||
typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse);
|
||||
|
||||
void alarm_init (void);
|
||||
void alarm_add (time_t alarm_time, AlarmFunction fn, void *closure);
|
||||
void alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure);
|
||||
int alarm_kill (void *closure);
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
typedef void (*AlarmFunction)(time_t time, void *closuse);
|
||||
typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse);
|
||||
|
||||
void alarm_init (void);
|
||||
void alarm_add (time_t alarm_time, AlarmFunction fn, void *closure);
|
||||
void alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure);
|
||||
int alarm_kill (void *closure);
|
||||
|
||||
#endif
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <unistd.h>
|
||||
#include "alarm.h"
|
||||
#include "calendar.h"
|
||||
#include "alarm.h"
|
||||
#include "timeutil.h"
|
||||
#include "../libversit/vcc.h"
|
||||
|
||||
@ -42,7 +42,7 @@ try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end)
|
||||
return;
|
||||
if (alarm->trigger > calendar_day_end)
|
||||
return;
|
||||
alarm_add (alarm->trigger, calendar_notify, ico);
|
||||
alarm_add (alarm, &calendar_notify, ico);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -59,7 +59,7 @@ void calendar_destroy_event_list (GList *l);
|
||||
/* Informs the calendar that obj information has changed */
|
||||
void calendar_object_changed (Calendar *cal, iCalObject *obj, int flags);
|
||||
|
||||
void calendar_notify (time_t, void *data);
|
||||
void calendar_notify (time_t time, CalendarAlarm *which, void *data);
|
||||
END_GNOME_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -338,29 +338,59 @@ mail_notify (char *mail_address, char *text, time_t app_time)
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
static void
|
||||
stop_beeping (GtkObject *object, gpointer tagp)
|
||||
{
|
||||
guint tag = GPOINTER_TO_INT (tagp);
|
||||
|
||||
gtk_timeout_remove (tag);
|
||||
}
|
||||
|
||||
static gint
|
||||
start_beeping (gpointer data)
|
||||
{
|
||||
gdk_beep ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
calendar_notify (time_t time, void *data)
|
||||
calendar_notify (time_t time, CalendarAlarm *which, void *data)
|
||||
{
|
||||
iCalObject *ico = data;
|
||||
guint tag;
|
||||
|
||||
if (&ico->aalarm == which){
|
||||
time_t app = ico->dalarm.trigger + ico->dalarm.offset;
|
||||
GtkWidget *w;
|
||||
char *msg;
|
||||
|
||||
msg = g_copy_strings (_("Reminder of your appointment at "),
|
||||
ctime (&app), "`",
|
||||
ico->summary, "'", NULL);
|
||||
|
||||
/* Idea: we need Snooze option :-) */
|
||||
w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, "Ok", NULL);
|
||||
tag = gtk_timeout_add (1000, start_beeping, NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (w), "destroy", stop_beeping, GINT_TO_POINTER (tag));
|
||||
gtk_widget_show (w);
|
||||
|
||||
if (ico->aalarm.enabled && ico->aalarm.trigger == time){
|
||||
printf ("bip\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ico->palarm.enabled && ico->palarm.trigger == time){
|
||||
if (&ico->palarm == which){
|
||||
execute (ico->palarm.data, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ico->malarm.enabled && ico->malarm.trigger == time){
|
||||
if (&ico->malarm == which){
|
||||
time_t app = ico->malarm.trigger + ico->malarm.offset;
|
||||
|
||||
mail_notify (ico->malarm.data, ico->summary, app);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ico->dalarm.enabled && ico->dalarm.trigger == time){
|
||||
if (&ico->dalarm == which){
|
||||
time_t app = ico->dalarm.trigger + ico->dalarm.offset;
|
||||
GtkWidget *w;
|
||||
char *msg;
|
||||
|
@ -13,8 +13,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "alarm.h"
|
||||
#include "calendar.h"
|
||||
#include "alarm.h"
|
||||
#include "eventedit.h"
|
||||
#include "gnome-cal.h"
|
||||
#include "main.h"
|
||||
|
@ -13,8 +13,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "alarm.h"
|
||||
#include "calendar.h"
|
||||
#include "alarm.h"
|
||||
#include "eventedit.h"
|
||||
#include "gnome-cal.h"
|
||||
#include "main.h"
|
||||
|
Reference in New Issue
Block a user