[evolution] Bug #680611 - Hibernation shifts alarm notification time



commit 48d30dcad171fe84928ba1888a45f7baa3669bda
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 12 10:11:29 2012 +0200

    Bug #680611 - Hibernation shifts alarm notification time

 calendar/alarm-notify/alarm-queue.c |   35 +++++++++++++++++++++++++++++++++--
 calendar/alarm-notify/alarm.c       |   12 ++++++++++++
 calendar/alarm-notify/alarm.h       |    2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/calendar/alarm-notify/alarm-queue.c b/calendar/alarm-notify/alarm-queue.c
index 148bfa9..788988b 100644
--- a/calendar/alarm-notify/alarm-queue.c
+++ b/calendar/alarm-notify/alarm-queue.c
@@ -662,7 +662,9 @@ load_alarms_for_today (ClientAlarms *ca)
 	if (from <= 0)
 		from = MAX (from, day_start);
 
-	day_end = time_day_end_with_zone (now, zone);
+	/* Add one hour after midnight, just to cover the delay in 30 minutes
+	   midnight checking. */
+	day_end = time_day_end_with_zone (now, zone) + (60 * 60);
 	debug (("From %s to %s", e_ctime (&from), e_ctime (&day_end)));
 	load_alarms (ca, from, day_end);
 }
@@ -2021,6 +2023,31 @@ check_midnight_refresh (gpointer user_data)
 	return TRUE;
 }
 
+static gboolean
+check_wall_clock_time_changed (gpointer user_data)
+{
+	static gint64 expected_wall_clock_time = 0;
+	gint64 wall_clock_time;
+
+	#define ADD_SECONDS(to, secs) ((to) + ((secs) * 1000000))
+
+	wall_clock_time = g_get_real_time ();
+
+	/* use one second margin */
+	if (wall_clock_time > ADD_SECONDS (expected_wall_clock_time, 1) ||
+	    wall_clock_time < ADD_SECONDS (expected_wall_clock_time, -1)) {
+		debug (("Current wall-clock time differs from expected, rescheduling alarms"));
+		check_midnight_refresh (NULL);
+		alarm_reschedule_timeout ();
+	}
+
+	expected_wall_clock_time = ADD_SECONDS (wall_clock_time, 60);
+
+	#undef ADD_SECONDS
+
+	return TRUE;
+}
+
 /**
  * alarm_queue_init:
  *
@@ -2045,7 +2072,11 @@ alarm_queue_init (gpointer data)
 	}
 
 	/* install timeout handler (every 30 mins) for not missing the midnight refresh */
-	g_timeout_add_seconds (1800, (GSourceFunc) check_midnight_refresh, NULL);
+	g_timeout_add_seconds (1800, check_midnight_refresh, NULL);
+
+	/* monotonic time doesn't change during hibernation, while the wall clock time does,
+	   thus check for wall clock time changes and reschedule alarms when it changes */
+	g_timeout_add_seconds (60, check_wall_clock_time_changed, NULL);
 
 #ifdef HAVE_LIBNOTIFY
 	notify_init ("Evolution Alarms");
diff --git a/calendar/alarm-notify/alarm.c b/calendar/alarm-notify/alarm.c
index 2797d44..cf586df 100644
--- a/calendar/alarm-notify/alarm.c
+++ b/calendar/alarm-notify/alarm.c
@@ -322,3 +322,15 @@ alarm_done (void)
 	g_list_free (alarms);
 	alarms = NULL;
 }
+
+/**
+ * alarm_reschedule_timeout:
+ *
+ * Re-sets timeout for alarms, if any.
+ **/
+void
+alarm_reschedule_timeout (void)
+{
+	if (alarms)
+		setup_timeout ();
+}
diff --git a/calendar/alarm-notify/alarm.h b/calendar/alarm-notify/alarm.h
index d6e9ff4..ad2b7f8 100644
--- a/calendar/alarm-notify/alarm.h
+++ b/calendar/alarm-notify/alarm.h
@@ -38,4 +38,6 @@ gpointer alarm_add (time_t trigger, AlarmFunction alarm_fn, gpointer data,
 		    AlarmDestroyNotify destroy_notify_fn);
 void alarm_remove (gpointer alarm);
 
+void alarm_reschedule_timeout (void);
+
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]