aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calendar/ChangeLog8
-rw-r--r--calendar/alarm.c14
-rw-r--r--calendar/alarm.h6
-rw-r--r--calendar/calendar.c41
-rw-r--r--calendar/gui/alarm-notify/alarm.c14
-rw-r--r--calendar/gui/alarm-notify/alarm.h6
-rw-r--r--calendar/gui/alarm.c14
-rw-r--r--calendar/gui/alarm.h6
-rw-r--r--calendar/gui/calendar.c41
-rw-r--r--calendar/gui/main.c4
-rw-r--r--calendar/main.c4
11 files changed, 127 insertions, 31 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index fa06cdd37e..8edc312dd7 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,11 @@
+1999-01-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
+
+ * calendar.c (calendar_init_alarms): Schedule an alarm for
+ midnight to change the calendar_day_begin/calendar_day_end.
+
+ * alarm.c (alarm_ready): If we reschedule, there is no need to
+ activate any pending alarms.
+
1999-01-28 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gncal-full-day.c (child_new): Insert the summary text here.
diff --git a/calendar/alarm.c b/calendar/alarm.c
index 30d3534955..3848fb87fd 100644
--- a/calendar/alarm.c
+++ b/calendar/alarm.c
@@ -74,6 +74,7 @@ alarm_ready (void *closure, int fd, GdkInputCondition cond)
itimer.it_value.tv_sec = next->activation_time - now;
itimer.it_value.tv_usec = 0;
setitimer (ITIMER_REAL, &itimer, NULL);
+ break;
} else {
g_free (ar);
ar = next;
@@ -95,7 +96,14 @@ alarm_compare_by_time (gconstpointer a, gconstpointer b)
return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
-void
+/**
+ * alarm_add:
+ *
+ * Tries to schedule @alarm.
+ *
+ * Returns TRUE if the alarm was scheduled.
+ */
+gboolean
alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
{
time_t now = time (NULL);
@@ -104,7 +112,7 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
/* If it already expired, do not add it */
if (alarm_time < now)
- return;
+ return FALSE;
ar = g_new0 (AlarmRecord, 1);
ar->activation_time = alarm_time;
@@ -127,6 +135,8 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
v = setitimer (ITIMER_REAL, &itimer, NULL);
head_alarm = alarms->data;
}
+
+ return TRUE;
}
int
diff --git a/calendar/alarm.h b/calendar/alarm.h
index 3c2ab18ff1..81710bda5e 100644
--- a/calendar/alarm.h
+++ b/calendar/alarm.h
@@ -5,8 +5,8 @@
typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse);
-void alarm_init (void);
-void alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure);
-int alarm_kill (void *closure);
+void alarm_init (void);
+gboolean 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 e5b050620e..c9f4dc9493 100644
--- a/calendar/calendar.c
+++ b/calendar/calendar.c
@@ -23,14 +23,19 @@
/* Our day range */
time_t calendar_day_begin, calendar_day_end;
+static void calendar_init_alarms (Calendar *cal);
+
Calendar *
calendar_new (char *title)
{
Calendar *cal;
cal = g_new0 (Calendar, 1);
+
cal->title = g_strdup (title);
+ calendar_init_alarms (cal);
+
return cal;
}
@@ -47,7 +52,7 @@ try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end)
}
static int
-add_alarm (iCalObject *obj, time_t start, time_t end, void *closure)
+add_object_alarms (iCalObject *obj, time_t start, time_t end, void *closure)
{
if (obj->aalarm.enabled)
try_add (obj, &obj->aalarm, start, end);
@@ -78,7 +83,7 @@ ical_object_try_alarms (iCalObject *obj)
if (max_o == -1)
return;
- ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_alarm, obj);
+ ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_object_alarms, obj);
}
void
@@ -275,12 +280,21 @@ calendar_load_from_vobject (Calendar *cal, VObject *vcal)
}
}
+static void
+calendar_set_day (void)
+{
+ time_t calendar_today;
+
+ calendar_today = time (NULL);
+ calendar_day_begin = time_day_begin (calendar_today);
+ calendar_day_end = time_day_end (calendar_today);
+}
+
/* Loads a calendar from a file */
char *
calendar_load (Calendar *cal, char *fname)
{
VObject *vcal;
- time_t calendar_today;
struct stat s;
if (cal->filename){
@@ -295,9 +309,8 @@ calendar_load (Calendar *cal, char *fname)
stat (fname, &s);
cal->file_time = s.st_mtime;
- calendar_today = time (NULL);
- calendar_day_begin = time_day_begin (calendar_today);
- calendar_day_end = time_day_end (calendar_today);
+
+ calendar_set_day ();
calendar_load_from_vobject (cal, vcal);
cleanVObject (vcal);
@@ -417,3 +430,19 @@ calendar_object_changed (Calendar *cal, iCalObject *obj, int flags)
;
ical_object_try_alarms (obj);
}
+
+static void
+calendar_day_change (time_t time, CalendarAlarm *which, void *closure)
+{
+ calendar_set_day ();
+}
+
+static void
+calendar_init_alarms (Calendar *cal)
+{
+ CalendarAlarm day_change_alarm;
+
+ day_change_alarm.trigger = calendar_day_end;
+ alarm_add (&day_change_alarm, calendar_day_change, cal);
+}
+
diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c
index 30d3534955..3848fb87fd 100644
--- a/calendar/gui/alarm-notify/alarm.c
+++ b/calendar/gui/alarm-notify/alarm.c
@@ -74,6 +74,7 @@ alarm_ready (void *closure, int fd, GdkInputCondition cond)
itimer.it_value.tv_sec = next->activation_time - now;
itimer.it_value.tv_usec = 0;
setitimer (ITIMER_REAL, &itimer, NULL);
+ break;
} else {
g_free (ar);
ar = next;
@@ -95,7 +96,14 @@ alarm_compare_by_time (gconstpointer a, gconstpointer b)
return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
-void
+/**
+ * alarm_add:
+ *
+ * Tries to schedule @alarm.
+ *
+ * Returns TRUE if the alarm was scheduled.
+ */
+gboolean
alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
{
time_t now = time (NULL);
@@ -104,7 +112,7 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
/* If it already expired, do not add it */
if (alarm_time < now)
- return;
+ return FALSE;
ar = g_new0 (AlarmRecord, 1);
ar->activation_time = alarm_time;
@@ -127,6 +135,8 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
v = setitimer (ITIMER_REAL, &itimer, NULL);
head_alarm = alarms->data;
}
+
+ return TRUE;
}
int
diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h
index 3c2ab18ff1..81710bda5e 100644
--- a/calendar/gui/alarm-notify/alarm.h
+++ b/calendar/gui/alarm-notify/alarm.h
@@ -5,8 +5,8 @@
typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse);
-void alarm_init (void);
-void alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure);
-int alarm_kill (void *closure);
+void alarm_init (void);
+gboolean 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 30d3534955..3848fb87fd 100644
--- a/calendar/gui/alarm.c
+++ b/calendar/gui/alarm.c
@@ -74,6 +74,7 @@ alarm_ready (void *closure, int fd, GdkInputCondition cond)
itimer.it_value.tv_sec = next->activation_time - now;
itimer.it_value.tv_usec = 0;
setitimer (ITIMER_REAL, &itimer, NULL);
+ break;
} else {
g_free (ar);
ar = next;
@@ -95,7 +96,14 @@ alarm_compare_by_time (gconstpointer a, gconstpointer b)
return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
-void
+/**
+ * alarm_add:
+ *
+ * Tries to schedule @alarm.
+ *
+ * Returns TRUE if the alarm was scheduled.
+ */
+gboolean
alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
{
time_t now = time (NULL);
@@ -104,7 +112,7 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
/* If it already expired, do not add it */
if (alarm_time < now)
- return;
+ return FALSE;
ar = g_new0 (AlarmRecord, 1);
ar->activation_time = alarm_time;
@@ -127,6 +135,8 @@ alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure)
v = setitimer (ITIMER_REAL, &itimer, NULL);
head_alarm = alarms->data;
}
+
+ return TRUE;
}
int
diff --git a/calendar/gui/alarm.h b/calendar/gui/alarm.h
index 3c2ab18ff1..81710bda5e 100644
--- a/calendar/gui/alarm.h
+++ b/calendar/gui/alarm.h
@@ -5,8 +5,8 @@
typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse);
-void alarm_init (void);
-void alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure);
-int alarm_kill (void *closure);
+void alarm_init (void);
+gboolean 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 e5b050620e..c9f4dc9493 100644
--- a/calendar/gui/calendar.c
+++ b/calendar/gui/calendar.c
@@ -23,14 +23,19 @@
/* Our day range */
time_t calendar_day_begin, calendar_day_end;
+static void calendar_init_alarms (Calendar *cal);
+
Calendar *
calendar_new (char *title)
{
Calendar *cal;
cal = g_new0 (Calendar, 1);
+
cal->title = g_strdup (title);
+ calendar_init_alarms (cal);
+
return cal;
}
@@ -47,7 +52,7 @@ try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end)
}
static int
-add_alarm (iCalObject *obj, time_t start, time_t end, void *closure)
+add_object_alarms (iCalObject *obj, time_t start, time_t end, void *closure)
{
if (obj->aalarm.enabled)
try_add (obj, &obj->aalarm, start, end);
@@ -78,7 +83,7 @@ ical_object_try_alarms (iCalObject *obj)
if (max_o == -1)
return;
- ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_alarm, obj);
+ ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_object_alarms, obj);
}
void
@@ -275,12 +280,21 @@ calendar_load_from_vobject (Calendar *cal, VObject *vcal)
}
}
+static void
+calendar_set_day (void)
+{
+ time_t calendar_today;
+
+ calendar_today = time (NULL);
+ calendar_day_begin = time_day_begin (calendar_today);
+ calendar_day_end = time_day_end (calendar_today);
+}
+
/* Loads a calendar from a file */
char *
calendar_load (Calendar *cal, char *fname)
{
VObject *vcal;
- time_t calendar_today;
struct stat s;
if (cal->filename){
@@ -295,9 +309,8 @@ calendar_load (Calendar *cal, char *fname)
stat (fname, &s);
cal->file_time = s.st_mtime;
- calendar_today = time (NULL);
- calendar_day_begin = time_day_begin (calendar_today);
- calendar_day_end = time_day_end (calendar_today);
+
+ calendar_set_day ();
calendar_load_from_vobject (cal, vcal);
cleanVObject (vcal);
@@ -417,3 +430,19 @@ calendar_object_changed (Calendar *cal, iCalObject *obj, int flags)
;
ical_object_try_alarms (obj);
}
+
+static void
+calendar_day_change (time_t time, CalendarAlarm *which, void *closure)
+{
+ calendar_set_day ();
+}
+
+static void
+calendar_init_alarms (Calendar *cal)
+{
+ CalendarAlarm day_change_alarm;
+
+ day_change_alarm.trigger = calendar_day_end;
+ alarm_add (&day_change_alarm, calendar_day_change, cal);
+}
+
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index 16072c221c..23409be930 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -505,8 +505,8 @@ setup_appbar (GtkWidget *gcal)
{
GnomeAppBar *appbar;
- appbar = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER);
- gnome_app_set_statusbar(GNOME_APP (gcal), GTK_WIDGET(appbar));
+ appbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_USER);
+ gnome_app_set_statusbar (GNOME_APP (gcal), GTK_WIDGET(appbar));
}
static gint
diff --git a/calendar/main.c b/calendar/main.c
index 16072c221c..23409be930 100644
--- a/calendar/main.c
+++ b/calendar/main.c
@@ -505,8 +505,8 @@ setup_appbar (GtkWidget *gcal)
{
GnomeAppBar *appbar;
- appbar = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER);
- gnome_app_set_statusbar(GNOME_APP (gcal), GTK_WIDGET(appbar));
+ appbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_USER);
+ gnome_app_set_statusbar (GNOME_APP (gcal), GTK_WIDGET(appbar));
}
static gint