aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/alarm-notify/alarm.c
diff options
context:
space:
mode:
authorJP Rosevear <jpr@novell.com>2004-05-18 21:33:40 +0800
committerJP Rosevear <jpr@src.gnome.org>2004-05-18 21:33:40 +0800
commit8f8ecd25e13165724e6e4cc71af09a383d44d727 (patch)
treed0ef937163862fb6bab7b79c4a4ac8202fee6a05 /calendar/gui/alarm-notify/alarm.c
parenta2a2f0b03919f44d467d5a3ef30bda33d7ed28e8 (diff)
downloadgsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.tar
gsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.tar.gz
gsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.tar.bz2
gsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.tar.lz
gsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.tar.xz
gsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.tar.zst
gsoc2013-evolution-8f8ecd25e13165724e6e4cc71af09a383d44d727.zip
just set up the alarm notify object
2004-05-18 JP Rosevear <jpr@novell.com> * gui/alarm-notify/notify-main.c (init_alarm_service): just set up the alarm notify object * gui/alarm-notify/alarm-notify.h: update proto * gui/alarm-notify/alarm-notify.c (process_removal_in_hash): process removals using the source list (list_changed_cb): when the list changes, update (load_calendars): initially load the calendars (alarm_notify_init): load the calendars here and don't listen for a selection notification (alarm_notify_add_calendar): get the source type when adding a calendar * gui/alarm-notify/notify-main.c (main): no need to init/shutdown gnome vfs * gui/alarm-notify/config-data.h: new proto * gui/alarm-notify/config-data.c (config_data_get_notify_with_tray): routine to get schema value * gui/alarm-notify/alarm.c (alarm_ready_cb): no timeout checking here, setup_timeout does that (queue_alarm): ditto (setup_timeout): calculate the timeout better * gui/alarm-notify/alarm-queue.c (query_objects_changed_cb): tidy (edit_component): clean up exception handling (display_notification): don't show the tray icon if we aren't notifying with the tray * gui/apps_evolution_calendar.schemas.in.in: add notify_with_tray option svn path=/trunk/; revision=25958
Diffstat (limited to 'calendar/gui/alarm-notify/alarm.c')
-rw-r--r--calendar/gui/alarm-notify/alarm.c77
1 files changed, 36 insertions, 41 deletions
diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c
index 8c6c4c59cd..3054cfa8f5 100644
--- a/calendar/gui/alarm-notify/alarm.c
+++ b/calendar/gui/alarm-notify/alarm.c
@@ -45,7 +45,7 @@ typedef struct {
AlarmDestroyNotify destroy_notify_fn;
} AlarmRecord;
-static void setup_timeout (time_t now);
+static void setup_timeout (void);
@@ -78,6 +78,7 @@ alarm_ready_cb (gpointer data)
now = time (NULL);
+ g_message ("Alarm callback!");
while (alarms) {
AlarmRecord *notify_id, *ar;
AlarmRecord ar_copy;
@@ -87,6 +88,7 @@ alarm_ready_cb (gpointer data)
if (ar->trigger > now)
break;
+ g_message ("Process alarm with trigger %lu", ar->trigger);
notify_id = ar;
ar_copy = *ar;
@@ -100,15 +102,12 @@ alarm_ready_cb (gpointer data)
(* ar->destroy_notify_fn) (notify_id, ar->data);
}
- if (alarms) {
- /* We need this check because one of the alarm_fn above may have
- * re-entered and added an alarm of its own, so the timer will
- * already be set up.
- */
- if (timeout_id == 0)
- setup_timeout (now);
- } else
- g_assert (timeout_id == 0);
+ /* We need this check because one of the alarm_fn above may have
+ * re-entered and added an alarm of its own, so the timer will
+ * already be set up.
+ */
+ if (alarms)
+ setup_timeout ();
return FALSE;
}
@@ -117,24 +116,30 @@ alarm_ready_cb (gpointer data)
* timezones here, as this is just a periodic check on the alarm queue.
*/
static void
-setup_timeout (time_t now)
+setup_timeout (void)
{
- time_t next, diff;
- struct tm tm;
-
- g_assert (timeout_id == 0);
+ const AlarmRecord *ar;
+ guint diff;
+ time_t now;
g_assert (alarms != NULL);
- tm = *localtime (&now);
- tm.tm_sec = 0;
- tm.tm_min++; /* next minute */
-
- next = mktime (&tm);
- g_assert (next != -1);
+ ar = alarms->data;
- diff = next - now;
+ /* Remove the existing time out */
+ if (timeout_id != 0) {
+ g_source_remove (timeout_id);
+ timeout_id = 0;
+ }
- g_assert (diff >= 0);
+ /* Ensure that if the trigger managed to get behind the
+ * current time we timeout immediately */
+ diff = MAX (0, ar->trigger - time (NULL));
+ now = time (NULL);
+
+ /* Add the time out */
+ g_message ("Setting timeout for %d %lu %lu", diff, ar->trigger, now);
+ g_message (" %s", ctime (&ar->trigger));
+ g_message (" %s", ctime (&now));
timeout_id = g_timeout_add (diff * 1000, alarm_ready_cb, NULL);
}
@@ -154,30 +159,20 @@ compare_alarm_by_time (gconstpointer a, gconstpointer b)
static void
queue_alarm (AlarmRecord *ar)
{
- time_t now;
- AlarmRecord *old_head;
-
- if (alarms) {
- g_assert (timeout_id != 0);
-
- old_head = alarms->data;
- } else {
- g_assert (timeout_id == 0);
+ GList *old_head;
- old_head = NULL;
- }
+ /* Track the current head of the list in case there are changes */
+ old_head = alarms;
+ /* Insert the new alarm in order */
alarms = g_list_insert_sorted (alarms, ar, compare_alarm_by_time);
- if (old_head == alarms->data)
+ /* If there first item on the list didn't change, the time out is fine */
+ if (old_head == alarms)
return;
/* Set the timer for removal upon activation */
-
- if (!old_head) {
- now = time (NULL);
- setup_timeout (now);
- }
+ setup_timeout ();
}
@@ -235,7 +230,7 @@ alarm_remove (gpointer alarm)
l = g_list_find (alarms, ar);
if (!l) {
- g_message ("alarm_remove(): Requested removal of nonexistent alarm!");
+ g_message (G_STRLOC ": Requested removal of nonexistent alarm!");
return;
}