From 409f65de28ab57035c7d6945060573a32a69b6cc Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Sep 2012 20:09:14 -0500 Subject: update all of the indicator's labels when the menu's visibility changes to true --- src/indicator-datetime.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 9e34a65..2356c6d 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -154,6 +154,7 @@ GType indicator_datetime_get_type (void) G_GNUC_CONST; static void indicator_datetime_class_init (IndicatorDatetimeClass *klass); static void indicator_datetime_init (IndicatorDatetime *self); +static void timezone_update_all_labels (IndicatorDatetime *self); static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void indicator_datetime_dispose (GObject *object); @@ -280,6 +281,10 @@ menu_visible_notfy_cb(GtkWidget * menu, G_GNUC_UNUSED GParamSpec *pspec, gpointe // Set the calendar to todays date ido_calendar_menu_item_set_date (self->priv->ido_calendar, y, m-1, d); + /* Update in case date was changed outside of indicator-datetime */ + update_label(self, NULL); + timezone_update_all_labels(self); + // Make sure the day-selected signal is sent so the menu updates - may duplicate /*GVariant *variant = g_variant_new_uint32((guint)curtime); guint timestamp = (guint)time(NULL); -- cgit v1.2.3 From 69aed01b36ca189487a27e044b57bb4936258b0f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Sep 2012 20:51:59 -0500 Subject: rename 'timer' as 'day_timer' to make room in the namespace for a second timer --- src/datetime-service.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 6b06b45..453bb9b 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -61,7 +61,7 @@ with this program. If not, see . static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data); static gboolean update_appointment_menu_items (gpointer user_data); static void update_location_menu_items (void); -static void setup_timer (void); +static void day_timer_reset (void); static void geo_client_invalid (GeoclueMasterClient * client, gpointer user_data); static gboolean get_greeter_mode (void); @@ -355,7 +355,7 @@ update_datetime (gpointer user_data) g_date_time_unref (datetime); g_free(utf8); - return FALSE; + return G_SOURCE_REMOVE; } /* Run a particular program based on an activation */ @@ -1113,7 +1113,7 @@ timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFile update_current_timezone(); datetime_interface_update(DATETIME_INTERFACE(user_data)); update_datetime(NULL); - setup_timer(); + day_timer_reset(); return; } @@ -1133,38 +1133,38 @@ build_timezone (DatetimeInterface * dbus) } /* Source ID for the timer */ -static guint timer = 0; +static guint day_timer = 0; /* Execute at a given time, update and setup a new timer to go again. */ static gboolean -timer_func (gpointer user_data) +day_timer_func (gpointer user_data) { - timer = 0; + day_timer = 0; /* Reset up each time to reduce error */ - setup_timer(); + day_timer_reset(); update_datetime(NULL); - return FALSE; + return G_SOURCE_REMOVE; } /* Sets up the time to launch the timer to update the date in the datetime entry */ static void -setup_timer (void) +day_timer_reset (void) { - if (timer != 0) { - g_source_remove(timer); - timer = 0; + if (day_timer != 0) { + g_source_remove(day_timer); + day_timer = 0; } time_t t; t = time(NULL); struct tm * ltime = localtime(&t); - timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) + - ((59 - ltime->tm_min) * 60) + - ((60 - ltime->tm_sec)) + 60 /* one minute past */, - timer_func, NULL); + day_timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) + + ((59 - ltime->tm_min) * 60) + + ((60 - ltime->tm_sec)) + 60 /* one minute past */, + day_timer_func, NULL); return; } @@ -1180,7 +1180,7 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa if (!idle) { datetime_interface_update(DATETIME_INTERFACE(user_data)); update_datetime(NULL); - setup_timer(); + day_timer_reset(); } } return; @@ -1428,7 +1428,7 @@ main (int argc, char ** argv) build_timezone(dbus); /* Setup the timer */ - setup_timer(); + day_timer_reset(); /* And watch for system resumes */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, -- cgit v1.2.3 From 6145a631d5d1095ac937d28ba812f7e3cb315c1c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Sep 2012 21:13:15 -0500 Subject: in datetime-service, add a seconds timer that watches for clock skew and rebuilds the labels when it finds it --- src/datetime-service.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file 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, -- cgit v1.2.3 From 1a48f285e56954ba589cb4cb12d0fa7c0da558e8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Sep 2012 22:34:12 -0500 Subject: clocks don't skew very often, so let's reduce the frequency that we test for this. --- src/datetime-service.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 88689b7..d2a9a63 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1181,16 +1181,22 @@ day_timer_reset (void) return; } -static guint second_timer = 0; +enum { + /* how often to check for clock skew */ + SKEW_CHECK_INTERVAL_SEC = 10, + + SKEW_DIFF_THRESHOLD_SEC = SKEW_CHECK_INTERVAL_SEC + 5 +}; static gboolean -second_timer_func (gpointer unused G_GNUC_UNUSED) +skew_check_timer_func (gpointer unused G_GNUC_UNUSED) { - static time_t prev_time =0; + static time_t prev_time = 0; const time_t cur_time = time (NULL); + const double diff_sec = fabs (difftime (cur_time, prev_time)); - if (prev_time && (fabs (difftime (cur_time, prev_time)) > 5)) { - g_debug (G_STRLOC" clock skew detected"); + if (prev_time && (diff_sec > SKEW_DIFF_THRESHOLD_SEC)) { + g_debug (G_STRLOC" clock skew detected (%.0f seconds)", diff_sec); on_clock_skew (); } @@ -1458,7 +1464,9 @@ main (int argc, char ** argv) day_timer_reset(); /* Set up the second timer */ - second_timer = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1, second_timer_func, NULL, NULL); + g_timeout_add_seconds (SKEW_CHECK_INTERVAL_SEC, + skew_check_timer_func, + NULL); /* And watch for system resumes */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, -- cgit v1.2.3 From 1ffd530753901cb424ddd64bc44b126296f33ca2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Sep 2012 06:18:22 -0500 Subject: move declaration of SKEW_CHECK_INTERVAL_SEC and SKEW_DIFF_THRESHOLD_SEC to the top of the file. --- src/datetime-service.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index d2a9a63..8db3c73 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -52,6 +52,13 @@ with this program. If not, see . #include "settings-shared.h" #include "utils.h" +enum { + /* how often to check for clock skew */ + SKEW_CHECK_INTERVAL_SEC = 10, + + SKEW_DIFF_THRESHOLD_SEC = SKEW_CHECK_INTERVAL_SEC + 5 +}; + #ifdef HAVE_CCPANEL #define SETTINGS_APP_INVOCATION "gnome-control-center indicator-datetime" #else @@ -1181,13 +1188,6 @@ day_timer_reset (void) return; } -enum { - /* how often to check for clock skew */ - SKEW_CHECK_INTERVAL_SEC = 10, - - SKEW_DIFF_THRESHOLD_SEC = SKEW_CHECK_INTERVAL_SEC + 5 -}; - static gboolean skew_check_timer_func (gpointer unused G_GNUC_UNUSED) { -- cgit v1.2.3 From 38c2ed7d7b0b8f068ea166316fd1c882d4ca35b5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Sep 2012 06:28:10 -0500 Subject: for SKEW_DIFF_THRESHOLD_SEC and SKEW_CHECK_INTERVAL_SEC, use #define instead of enum --- src/datetime-service.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 8db3c73..c01121e 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -52,12 +52,10 @@ with this program. If not, see . #include "settings-shared.h" #include "utils.h" -enum { - /* how often to check for clock skew */ - SKEW_CHECK_INTERVAL_SEC = 10, +/* how often to check for clock skew */ +#define SKEW_CHECK_INTERVAL_SEC 19 - SKEW_DIFF_THRESHOLD_SEC = SKEW_CHECK_INTERVAL_SEC + 5 -}; +#define SKEW_DIFF_THRESHOLD_SEC (SKEW_CHECK_INTERVAL_SEC + 5) #ifdef HAVE_CCPANEL #define SETTINGS_APP_INVOCATION "gnome-control-center indicator-datetime" -- cgit v1.2.3 From b576f93979293efbe9bf31641bf1fa47596aac98 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Sep 2012 06:37:25 -0500 Subject: Fix r190 typo. Yet another reminder to drink my morning coffee /before/ pushing. --- src/datetime-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index c01121e..e97ec10 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -53,7 +53,7 @@ with this program. If not, see . #include "utils.h" /* how often to check for clock skew */ -#define SKEW_CHECK_INTERVAL_SEC 19 +#define SKEW_CHECK_INTERVAL_SEC 10 #define SKEW_DIFF_THRESHOLD_SEC (SKEW_CHECK_INTERVAL_SEC + 5) -- cgit v1.2.3 From 3f4134737085a73ab0b9379922d1db941f66137e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Sep 2012 06:47:43 -0500 Subject: copyediting: typo tweak --- src/datetime-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index e97ec10..ccdfe14 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1461,7 +1461,7 @@ main (int argc, char ** argv) /* Set up the day timer */ day_timer_reset(); - /* Set up the second timer */ + /* Set up the skew-check timer */ g_timeout_add_seconds (SKEW_CHECK_INTERVAL_SEC, skew_check_timer_func, NULL); -- cgit v1.2.3