aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--calendar/ChangeLog13
-rw-r--r--calendar/alarm.c40
-rw-r--r--calendar/alarm.h4
-rw-r--r--calendar/calendar.c4
-rw-r--r--calendar/calendar.h2
-rw-r--r--calendar/gnome-cal.c42
-rw-r--r--calendar/gui/alarm-notify/alarm.c40
-rw-r--r--calendar/gui/alarm-notify/alarm.h4
-rw-r--r--calendar/gui/alarm.c40
-rw-r--r--calendar/gui/alarm.h4
-rw-r--r--calendar/gui/calendar.c4
-rw-r--r--calendar/gui/calendar.h2
-rw-r--r--calendar/gui/gnome-cal.c42
-rw-r--r--calendar/gui/main.c2
-rw-r--r--calendar/main.c2
15 files changed, 198 insertions, 47 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index b7a83c1b83..4d3f0404ca 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -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
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 <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);
diff --git a/calendar/alarm.h b/calendar/alarm.h
index d37ff0c1bf..3c2ab18ff1 100644
--- a/calendar/alarm.h
+++ b/calendar/alarm.h
@@ -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
diff --git a/calendar/calendar.c b/calendar/calendar.c
index 3f4b10aeaf..e510f1f1b1 100644
--- a/calendar/calendar.c
+++ b/calendar/calendar.c
@@ -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
diff --git a/calendar/calendar.h b/calendar/calendar.h
index c12ce639b7..bd0bf84b90 100644
--- a/calendar/calendar.h
+++ b/calendar/calendar.h
@@ -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
diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c
index 4468eeb483..5403fd3a94 100644
--- a/calendar/gnome-cal.c
+++ b/calendar/gnome-cal.c
@@ -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;
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);
diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h
index d37ff0c1bf..3c2ab18ff1 100644
--- a/calendar/gui/alarm-notify/alarm.h
+++ b/calendar/gui/alarm-notify/alarm.h
@@ -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
diff --git a/calendar/gui/alarm.c b/calendar/gui/alarm.c
index 280d4125e3..30d3534955 100644
--- a/calendar/gui/alarm.c
+++ b/calendar/gui/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);
diff --git a/calendar/gui/alarm.h b/calendar/gui/alarm.h
index d37ff0c1bf..3c2ab18ff1 100644
--- a/calendar/gui/alarm.h
+++ b/calendar/gui/alarm.h
@@ -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
diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c
index 3f4b10aeaf..e510f1f1b1 100644
--- a/calendar/gui/calendar.c
+++ b/calendar/gui/calendar.c
@@ -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
diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h
index c12ce639b7..bd0bf84b90 100644
--- a/calendar/gui/calendar.h
+++ b/calendar/gui/calendar.h
@@ -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
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index 4468eeb483..5403fd3a94 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -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;
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index ea7b5efdb9..d6d7d71bb4 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -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"
diff --git a/calendar/main.c b/calendar/main.c
index ea7b5efdb9..d6d7d71bb4 100644
--- a/calendar/main.c
+++ b/calendar/main.c
@@ -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"