diff options
author | Milan Crha <mcrha@redhat.com> | 2012-09-12 16:11:29 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2012-09-12 16:12:05 +0800 |
commit | 48d30dcad171fe84928ba1888a45f7baa3669bda (patch) | |
tree | 24b170449c2e953905f2132860d5f73c997fd0fc /calendar | |
parent | df13734c655e21db9c4f2a3b7d588412a921fd9d (diff) | |
download | gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.tar gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.tar.gz gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.tar.bz2 gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.tar.lz gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.tar.xz gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.tar.zst gsoc2013-evolution-48d30dcad171fe84928ba1888a45f7baa3669bda.zip |
Bug #680611 - Hibernation shifts alarm notification time
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/alarm-notify/alarm-queue.c | 35 | ||||
-rw-r--r-- | calendar/alarm-notify/alarm.c | 12 | ||||
-rw-r--r-- | 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 148bfa973f..788988be72 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 2797d44b0a..cf586dfea2 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 d6e9ff4a4e..ad2b7f8e4b 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 |