Merge lp:~charlesk/indicator-datetime/lp-917236 into lp:indicator-datetime/12.10

Proposed by Charles Kerr
Status: Merged
Approved by: Lars Karlitski
Approved revision: 192
Merged at revision: 185
Proposed branch: lp:~charlesk/indicator-datetime/lp-917236
Merge into: lp:indicator-datetime/12.10
Diff against target: 185 lines (+64/-23)
2 files modified
src/datetime-service.c (+59/-23)
src/indicator-datetime.c (+5/-0)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-917236
Reviewer Review Type Date Requested Status
jenkins (community) continuous-integration Approve
Lars Karlitski (community) Approve
Review via email: mp+125388@code.launchpad.net

Commit message

When clock skew is detected, rebuild the date/time labels.

Description of the change

Add a timer to monitor for clock skew, and when it's detected, rebuild the datetime menuitems that need it.

Larsu, I'd also like a second opinion on whether or not the SystemIdleHintChanged callback is still needed, since the clock skew code should have the same results...

To post a comment you must log in.
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
188. By Charles Kerr

clocks don't skew very often, so let's reduce the frequency that we test for this.

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Why are SKEW_CHECK_INTERVAL_SEC and SKEW_DIFF_THRESHOLD_SEC enums instead of #defines or const ints? I prefer having those kinds of definitions at the top of the file.

If we remove the SystemIdleHintChanged callback, the clock in the menu will be updated after a maximum of SKEW_CHECK_INTERVAL_SEC seconds, right? I don't like that, even if it is only the clock in the menu.

Why are the timers running when the menu is not open?

review: Needs Information
Revision history for this message
Charles Kerr (charlesk) wrote :

> I prefer having those kinds of definitions at the top of the file.

Agreed, r189.

> Why are SKEW_CHECK_INTERVAL_SEC and SKEW_DIFF_THRESHOLD_SEC enums instead of #defines or const ints?

const ints aren't legal when you define threshold in terms of interval. enums in general safer than preprocessor tokens. But, in terms of our codebase, you're right #defines are way more common. r190.

> Why are the timers running when the menu is not open?

To ensure that the indicator's label gets updated via the UpdateTime signal.

189. By Charles Kerr

move declaration of SKEW_CHECK_INTERVAL_SEC and SKEW_DIFF_THRESHOLD_SEC to the top of the file.

190. By Charles Kerr

for SKEW_DIFF_THRESHOLD_SEC and SKEW_CHECK_INTERVAL_SEC, use #define instead of enum

Revision history for this message
Charles Kerr (charlesk) wrote :
191. By Charles Kerr

Fix r190 typo. Yet another reminder to drink my morning coffee /before/ pushing.

Revision history for this message
Charles Kerr (charlesk) wrote :

Moreover, without the label we wouldn't need the timer at all -- we could connect to the menu's about-to-show event.

Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
192. By Charles Kerr

copyediting: typo tweak

Revision history for this message
Lars Karlitski (larsu) wrote :

> > Why are the timers running when the menu is not open?
>
> To ensure that the indicator's label gets updated via the UpdateTime signal.

Oh, I thought that was handled in the plugin and we're only talking about the label on the top of the menu here. Sorry.

Thanks for the other fixes.

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/datetime-service.c'
2--- src/datetime-service.c 2012-09-12 21:59:02 +0000
3+++ src/datetime-service.c 2012-09-20 11:51:18 +0000
4@@ -52,6 +52,11 @@
5 #include "settings-shared.h"
6 #include "utils.h"
7
8+/* how often to check for clock skew */
9+#define SKEW_CHECK_INTERVAL_SEC 10
10+
11+#define SKEW_DIFF_THRESHOLD_SEC (SKEW_CHECK_INTERVAL_SEC + 5)
12+
13 #ifdef HAVE_CCPANEL
14 #define SETTINGS_APP_INVOCATION "gnome-control-center indicator-datetime"
15 #else
16@@ -61,7 +66,7 @@
17 static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data);
18 static gboolean update_appointment_menu_items (gpointer user_data);
19 static void update_location_menu_items (void);
20-static void setup_timer (void);
21+static void day_timer_reset (void);
22 static void geo_client_invalid (GeoclueMasterClient * client, gpointer user_data);
23 static gboolean get_greeter_mode (void);
24
25@@ -355,7 +360,7 @@
26 g_date_time_unref (datetime);
27 g_free(utf8);
28
29- return FALSE;
30+ return G_SOURCE_REMOVE;
31 }
32
33 /* Run a particular program based on an activation */
34@@ -1106,14 +1111,26 @@
35 return;
36 }
37
38+static void
39+on_clock_skew (void)
40+{
41+ /* tell the indicators to refresh */
42+ if (IS_DATETIME_INTERFACE (dbus))
43+ datetime_interface_update (DATETIME_INTERFACE(dbus));
44+
45+ /* update our day label */
46+ update_datetime (NULL);
47+ day_timer_reset();
48+
49+ return;
50+}
51+
52 /* Run when the timezone file changes */
53 static void
54 timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)
55 {
56 update_current_timezone();
57- datetime_interface_update(DATETIME_INTERFACE(user_data));
58- update_datetime(NULL);
59- setup_timer();
60+ on_clock_skew();
61 return;
62 }
63
64@@ -1133,42 +1150,58 @@
65 }
66
67 /* Source ID for the timer */
68-static guint timer = 0;
69+static guint day_timer = 0;
70
71 /* Execute at a given time, update and setup a new
72 timer to go again. */
73 static gboolean
74-timer_func (gpointer user_data)
75+day_timer_func (gpointer user_data)
76 {
77- timer = 0;
78+ day_timer = 0;
79 /* Reset up each time to reduce error */
80- setup_timer();
81+ day_timer_reset();
82 update_datetime(NULL);
83- return FALSE;
84+ return G_SOURCE_REMOVE;
85 }
86
87 /* Sets up the time to launch the timer to update the
88 date in the datetime entry */
89 static void
90-setup_timer (void)
91+day_timer_reset (void)
92 {
93- if (timer != 0) {
94- g_source_remove(timer);
95- timer = 0;
96+ if (day_timer != 0) {
97+ g_source_remove(day_timer);
98+ day_timer = 0;
99 }
100
101 time_t t;
102 t = time(NULL);
103 struct tm * ltime = localtime(&t);
104
105- timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) +
106- ((59 - ltime->tm_min) * 60) +
107- ((60 - ltime->tm_sec)) + 60 /* one minute past */,
108- timer_func, NULL);
109+ day_timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) +
110+ ((59 - ltime->tm_min) * 60) +
111+ ((60 - ltime->tm_sec)) + 60 /* one minute past */,
112+ day_timer_func, NULL);
113
114 return;
115 }
116
117+static gboolean
118+skew_check_timer_func (gpointer unused G_GNUC_UNUSED)
119+{
120+ static time_t prev_time = 0;
121+ const time_t cur_time = time (NULL);
122+ const double diff_sec = fabs (difftime (cur_time, prev_time));
123+
124+ if (prev_time && (diff_sec > SKEW_DIFF_THRESHOLD_SEC)) {
125+ g_debug (G_STRLOC" clock skew detected (%.0f seconds)", diff_sec);
126+ on_clock_skew ();
127+ }
128+
129+ prev_time = cur_time;
130+ return G_SOURCE_CONTINUE;
131+}
132+
133 static void
134 session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
135 GVariant * parameters, gpointer user_data)
136@@ -1178,9 +1211,7 @@
137 gboolean idle = FALSE;
138 g_variant_get(parameters, "(b)", &idle);
139 if (!idle) {
140- datetime_interface_update(DATETIME_INTERFACE(user_data));
141- update_datetime(NULL);
142- setup_timer();
143+ on_clock_skew ();
144 }
145 }
146 return;
147@@ -1427,8 +1458,13 @@
148 /* Setup timezone watch */
149 build_timezone(dbus);
150
151- /* Setup the timer */
152- setup_timer();
153+ /* Set up the day timer */
154+ day_timer_reset();
155+
156+ /* Set up the skew-check timer */
157+ g_timeout_add_seconds (SKEW_CHECK_INTERVAL_SEC,
158+ skew_check_timer_func,
159+ NULL);
160
161 /* And watch for system resumes */
162 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
163
164=== modified file 'src/indicator-datetime.c'
165--- src/indicator-datetime.c 2012-05-07 23:48:29 +0000
166+++ src/indicator-datetime.c 2012-09-20 11:51:18 +0000
167@@ -154,6 +154,7 @@
168
169 static void indicator_datetime_class_init (IndicatorDatetimeClass *klass);
170 static void indicator_datetime_init (IndicatorDatetime *self);
171+static void timezone_update_all_labels (IndicatorDatetime *self);
172 static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec);
173 static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
174 static void indicator_datetime_dispose (GObject *object);
175@@ -280,6 +281,10 @@
176 // Set the calendar to todays date
177 ido_calendar_menu_item_set_date (self->priv->ido_calendar, y, m-1, d);
178
179+ /* Update in case date was changed outside of indicator-datetime */
180+ update_label(self, NULL);
181+ timezone_update_all_labels(self);
182+
183 // Make sure the day-selected signal is sent so the menu updates - may duplicate
184 /*GVariant *variant = g_variant_new_uint32((guint)curtime);
185 guint timestamp = (guint)time(NULL);

Subscribers

People subscribed via source and target branches