Merge lp:~mterry/indicator-datetime/can-haz-dublin into lp:indicator-datetime/0.3

Proposed by Michael Terry
Status: Merged
Merged at revision: 116
Proposed branch: lp:~mterry/indicator-datetime/can-haz-dublin
Merge into: lp:indicator-datetime/0.3
Diff against target: 166 lines (+45/-26)
6 files modified
src/Makefile.am (+2/-0)
src/datetime-prefs.c (+1/-3)
src/datetime-service.c (+3/-19)
src/indicator-datetime.c (+14/-4)
src/utils.c (+24/-0)
src/utils.h (+1/-0)
To merge this branch: bzr merge lp:~mterry/indicator-datetime/can-haz-dublin
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+66157@code.launchpad.net

Description of the change

This one goes out to the folks Rallying in Dublin.

There are two things preventing setting your timezone to work correctly in oneiric:

1) gnome-settings-daemon changed from accepting full paths for timezones to merely timezone identifiers over DBus. So this branch now follows suit.

2) The indicator was relying on GLib to give it back the very latest timezone value when it called g_time_zone_new(NULL). GLib likes to cache that value, depending on whether anyone else has a copy of a time zone extant or not. It's not very robust to assume that GLib will give us the right answer here for a long-running process like an indicator. So this branch looks it up from /etc/timezone directly, like the service does.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2011-02-23 20:13:42 +0000
3+++ src/Makefile.am 2011-06-28 14:36:07 +0000
4@@ -34,6 +34,7 @@
5 libdatetime_la_CFLAGS = \
6 $(INDICATOR_CFLAGS) \
7 -Wall -Werror \
8+ -DTIMEZONE_FILE="\"/etc/timezone\"" \
9 -DG_LOG_DOMAIN=\"Indicator-Datetime\"
10 libdatetime_la_LIBADD = \
11 $(INDICATOR_LIBS)
12@@ -55,6 +56,7 @@
13 -Werror \
14 -I$(top_srcdir)/libmap \
15 $(PREF_CFLAGS) \
16+ -DTIMEZONE_FILE="\"/etc/timezone\"" \
17 -DPKGDATADIR="\"$(pkgdatadir)\""
18 indicator_datetime_preferences_LDADD = \
19 $(top_builddir)/libmap/libmap.la \
20
21=== modified file 'src/datetime-prefs.c'
22--- src/datetime-prefs.c 2011-06-15 14:44:57 +0000
23+++ src/datetime-prefs.c 2011-06-28 14:36:07 +0000
24@@ -223,10 +223,8 @@
25 if (location == NULL)
26 return;
27
28- gchar * file = g_build_filename ("/usr/share/zoneinfo", location->zone, NULL);
29- g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", file),
30+ g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", location->zone),
31 G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "timezone");
32- g_free (file);
33
34 sync_entry (location->zone);
35 }
36
37=== modified file 'src/datetime-service.c'
38--- src/datetime-service.c 2011-04-13 19:32:18 +0000
39+++ src/datetime-service.c 2011-06-28 14:36:07 +0000
40@@ -221,29 +221,15 @@
41 current_timezone = NULL;
42 }
43
44- GError * error = NULL;
45- gchar * tempzone = NULL;
46- if (!g_file_get_contents(TIMEZONE_FILE, &tempzone, NULL, &error)) {
47- g_warning("Unable to read timezone file '" TIMEZONE_FILE "': %s", error->message);
48- g_error_free(error);
49+ current_timezone = read_timezone ();
50+ if (current_timezone == NULL) {
51 return;
52 }
53
54- /* This shouldn't happen, so let's make it a big boom! */
55- g_return_if_fail(tempzone != NULL);
56-
57- /* Note: this really makes sense as strstrip works in place
58- so we end up with something a little odd without the dup
59- so we have the dup to make sure everything is as expected
60- for everyone else. */
61- current_timezone = g_strdup(g_strstrip(tempzone));
62- g_free(tempzone);
63-
64 g_debug("System timezone is: %s", current_timezone);
65
66 check_timezone_sync();
67
68- if (error != NULL) g_error_free(error);
69 return;
70 }
71
72@@ -276,10 +262,8 @@
73 return;
74 }
75
76- gchar * file = g_build_filename ("/usr/share/zoneinfo", (char *)zone, NULL);
77- g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", file),
78+ g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", zone),
79 G_DBUS_CALL_FLAGS_NONE, -1, NULL, quick_set_tz_cb, NULL);
80- g_free (file);
81 g_free (zone);
82 g_object_unref (proxy);
83 }
84
85=== modified file 'src/indicator-datetime.c'
86--- src/indicator-datetime.c 2011-06-05 18:45:28 +0000
87+++ src/indicator-datetime.c 2011-06-28 14:36:07 +0000
88@@ -761,11 +761,18 @@
89 GTimeZone * tz, const gchar * format,
90 GDateTime ** datetime)
91 {
92+ gboolean unref_tz = FALSE;
93+ if (tz == NULL) {
94+ gchar * zone = read_timezone ();
95+ if (zone == NULL)
96+ return;
97+ tz = g_time_zone_new(zone);
98+ unref_tz = TRUE;
99+ g_free (zone);
100+ }
101+
102 GDateTime * datetime_now;
103- if (tz == NULL)
104- datetime_now = g_date_time_new_now_local();
105- else
106- datetime_now = g_date_time_new_now(tz);
107+ datetime_now = g_date_time_new_now(tz);
108
109 gchar * timestr;
110 if (format == NULL) {
111@@ -793,6 +800,9 @@
112 else
113 g_date_time_unref(datetime_now);
114
115+ if (unref_tz)
116+ g_time_zone_unref(tz);
117+
118 return;
119 }
120
121
122=== modified file 'src/utils.c'
123--- src/utils.c 2011-04-07 15:48:50 +0000
124+++ src/utils.c 2011-06-28 14:36:07 +0000
125@@ -117,6 +117,30 @@
126 return rv;
127 }
128
129+gchar *
130+read_timezone ()
131+{
132+ GError * error = NULL;
133+ gchar * tempzone = NULL;
134+ if (!g_file_get_contents(TIMEZONE_FILE, &tempzone, NULL, &error)) {
135+ g_warning("Unable to read timezone file '" TIMEZONE_FILE "': %s", error->message);
136+ g_error_free(error);
137+ return NULL;
138+ }
139+
140+ /* This shouldn't happen, so let's make it a big boom! */
141+ g_return_val_if_fail(tempzone != NULL, NULL);
142+
143+ /* Note: this really makes sense as strstrip works in place
144+ so we end up with something a little odd without the dup
145+ so we have the dup to make sure everything is as expected
146+ for everyone else. */
147+ gchar * rv = g_strdup(g_strstrip(tempzone));
148+ g_free(tempzone);
149+
150+ return rv;
151+}
152+
153 /* Translate msg according to the locale specified by LC_TIME */
154 static char *
155 T_(const char *msg)
156
157=== modified file 'src/utils.h'
158--- src/utils.h 2011-04-07 15:48:50 +0000
159+++ src/utils.h 2011-06-28 14:36:07 +0000
160@@ -30,6 +30,7 @@
161 gboolean is_locale_12h (void);
162 void split_settings_location (const gchar * location, gchar ** zone, gchar ** name);
163 gchar * get_current_zone_name (const gchar * location);
164+gchar * read_timezone ();
165 gchar * generate_format_string_full (gboolean show_day, gboolean show_date);
166 gchar * generate_format_string_at_time (GDateTime * time);
167

Subscribers

People subscribed via source and target branches