aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-09-19 21:13:15 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-09-19 21:13:15 -0500
commit6145a631d5d1095ac937d28ba812f7e3cb315c1c (patch)
tree4d4acfdc5f47b45a7c68c15a72461188bd70456d /src
parent69aed01b36ca189487a27e044b57bb4936258b0f (diff)
downloadayatana-indicator-datetime-6145a631d5d1095ac937d28ba812f7e3cb315c1c.tar.gz
ayatana-indicator-datetime-6145a631d5d1095ac937d28ba812f7e3cb315c1c.tar.bz2
ayatana-indicator-datetime-6145a631d5d1095ac937d28ba812f7e3cb315c1c.zip
in datetime-service, add a seconds timer that watches for clock skew and rebuilds the labels when it finds it
Diffstat (limited to 'src')
-rw-r--r--src/datetime-service.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 453bb9b..88689b7 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -1106,14 +1106,26 @@ build_menus (DbusmenuMenuitem * root)
return;
}
+static void
+on_clock_skew (void)
+{
+ /* tell the indicators to refresh */
+ if (IS_DATETIME_INTERFACE (dbus))
+ datetime_interface_update (DATETIME_INTERFACE(dbus));
+
+ /* update our day label */
+ update_datetime (NULL);
+ day_timer_reset();
+
+ return;
+}
+
/* Run when the timezone file changes */
static void
timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)
{
update_current_timezone();
- datetime_interface_update(DATETIME_INTERFACE(user_data));
- update_datetime(NULL);
- day_timer_reset();
+ on_clock_skew();
return;
}
@@ -1169,6 +1181,23 @@ day_timer_reset (void)
return;
}
+static guint second_timer = 0;
+
+static gboolean
+second_timer_func (gpointer unused G_GNUC_UNUSED)
+{
+ static time_t prev_time =0;
+ const time_t cur_time = time (NULL);
+
+ if (prev_time && (fabs (difftime (cur_time, prev_time)) > 5)) {
+ g_debug (G_STRLOC" clock skew detected");
+ on_clock_skew ();
+ }
+
+ prev_time = cur_time;
+ return G_SOURCE_CONTINUE;
+}
+
static void
session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
GVariant * parameters, gpointer user_data)
@@ -1178,9 +1207,7 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa
gboolean idle = FALSE;
g_variant_get(parameters, "(b)", &idle);
if (!idle) {
- datetime_interface_update(DATETIME_INTERFACE(user_data));
- update_datetime(NULL);
- day_timer_reset();
+ on_clock_skew ();
}
}
return;
@@ -1427,9 +1454,12 @@ main (int argc, char ** argv)
/* Setup timezone watch */
build_timezone(dbus);
- /* Setup the timer */
+ /* Set up the day timer */
day_timer_reset();
+ /* Set up the second timer */
+ second_timer = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1, second_timer_func, NULL, NULL);
+
/* And watch for system resumes */
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,