aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Terry <michael.terry@canonical.com>2011-06-28 15:32:04 +0100
committerMichael Terry <michael.terry@canonical.com>2011-06-28 15:32:04 +0100
commitf57128cae925df888e1e0cafb9ba988c665ecff8 (patch)
tree2badc6eec3bf64e8e5e650bce5064ed5aec5b095
parent3c5f6a06ff0e44945f788254c44ede18f4061724 (diff)
downloadayatana-indicator-datetime-f57128cae925df888e1e0cafb9ba988c665ecff8.tar.gz
ayatana-indicator-datetime-f57128cae925df888e1e0cafb9ba988c665ecff8.tar.bz2
ayatana-indicator-datetime-f57128cae925df888e1e0cafb9ba988c665ecff8.zip
update to handle latest gnome-settings-daemon dbus API for setting timezones; be more fool-proof when looking up current timezone in indicator
-rw-r--r--src/Makefile.am2
-rw-r--r--src/datetime-prefs.c4
-rw-r--r--src/datetime-service.c22
-rw-r--r--src/indicator-datetime.c18
-rw-r--r--src/utils.c24
-rw-r--r--src/utils.h1
6 files changed, 45 insertions, 26 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 6d388c7..c48cbd5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ libdatetime_la_SOURCES = \
libdatetime_la_CFLAGS = \
$(INDICATOR_CFLAGS) \
-Wall -Werror \
+ -DTIMEZONE_FILE="\"/etc/timezone\"" \
-DG_LOG_DOMAIN=\"Indicator-Datetime\"
libdatetime_la_LIBADD = \
$(INDICATOR_LIBS)
@@ -55,6 +56,7 @@ indicator_datetime_preferences_CFLAGS = \
-Werror \
-I$(top_srcdir)/libmap \
$(PREF_CFLAGS) \
+ -DTIMEZONE_FILE="\"/etc/timezone\"" \
-DPKGDATADIR="\"$(pkgdatadir)\""
indicator_datetime_preferences_LDADD = \
$(top_builddir)/libmap/libmap.la \
diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c
index 85068c7..4bb231b 100644
--- a/src/datetime-prefs.c
+++ b/src/datetime-prefs.c
@@ -223,10 +223,8 @@ tz_changed (CcTimezoneMap * map, TzLocation * location)
if (location == NULL)
return;
- gchar * file = g_build_filename ("/usr/share/zoneinfo", location->zone, NULL);
- g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", file),
+ g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", location->zone),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "timezone");
- g_free (file);
sync_entry (location->zone);
}
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 08ff9ad..30bf9eb 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -221,29 +221,15 @@ update_current_timezone (void) {
current_timezone = NULL;
}
- GError * error = NULL;
- gchar * tempzone = NULL;
- if (!g_file_get_contents(TIMEZONE_FILE, &tempzone, NULL, &error)) {
- g_warning("Unable to read timezone file '" TIMEZONE_FILE "': %s", error->message);
- g_error_free(error);
+ current_timezone = read_timezone ();
+ if (current_timezone == NULL) {
return;
}
- /* This shouldn't happen, so let's make it a big boom! */
- g_return_if_fail(tempzone != NULL);
-
- /* Note: this really makes sense as strstrip works in place
- so we end up with something a little odd without the dup
- so we have the dup to make sure everything is as expected
- for everyone else. */
- current_timezone = g_strdup(g_strstrip(tempzone));
- g_free(tempzone);
-
g_debug("System timezone is: %s", current_timezone);
check_timezone_sync();
- if (error != NULL) g_error_free(error);
return;
}
@@ -276,10 +262,8 @@ quick_set_tz_proxy_cb (GObject *object, GAsyncResult *res, gpointer zone)
return;
}
- gchar * file = g_build_filename ("/usr/share/zoneinfo", (char *)zone, NULL);
- g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", file),
+ g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", zone),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, quick_set_tz_cb, NULL);
- g_free (file);
g_free (zone);
g_object_unref (proxy);
}
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index 800fa87..cd1fbb9 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -761,11 +761,18 @@ set_label_to_time_in_zone (IndicatorDatetime * self, GtkLabel * label,
GTimeZone * tz, const gchar * format,
GDateTime ** datetime)
{
+ gboolean unref_tz = FALSE;
+ if (tz == NULL) {
+ gchar * zone = read_timezone ();
+ if (zone == NULL)
+ return;
+ tz = g_time_zone_new(zone);
+ unref_tz = TRUE;
+ g_free (zone);
+ }
+
GDateTime * datetime_now;
- if (tz == NULL)
- datetime_now = g_date_time_new_now_local();
- else
- datetime_now = g_date_time_new_now(tz);
+ datetime_now = g_date_time_new_now(tz);
gchar * timestr;
if (format == NULL) {
@@ -793,6 +800,9 @@ set_label_to_time_in_zone (IndicatorDatetime * self, GtkLabel * label,
else
g_date_time_unref(datetime_now);
+ if (unref_tz)
+ g_time_zone_unref(tz);
+
return;
}
diff --git a/src/utils.c b/src/utils.c
index ab93ecf..73c8ab2 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -117,6 +117,30 @@ get_current_zone_name (const gchar * location)
return rv;
}
+gchar *
+read_timezone ()
+{
+ GError * error = NULL;
+ gchar * tempzone = NULL;
+ if (!g_file_get_contents(TIMEZONE_FILE, &tempzone, NULL, &error)) {
+ g_warning("Unable to read timezone file '" TIMEZONE_FILE "': %s", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ /* This shouldn't happen, so let's make it a big boom! */
+ g_return_val_if_fail(tempzone != NULL, NULL);
+
+ /* Note: this really makes sense as strstrip works in place
+ so we end up with something a little odd without the dup
+ so we have the dup to make sure everything is as expected
+ for everyone else. */
+ gchar * rv = g_strdup(g_strstrip(tempzone));
+ g_free(tempzone);
+
+ return rv;
+}
+
/* Translate msg according to the locale specified by LC_TIME */
static char *
T_(const char *msg)
diff --git a/src/utils.h b/src/utils.h
index c2bc0c5..788d516 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
gboolean is_locale_12h (void);
void split_settings_location (const gchar * location, gchar ** zone, gchar ** name);
gchar * get_current_zone_name (const gchar * location);
+gchar * read_timezone ();
gchar * generate_format_string_full (gboolean show_day, gboolean show_date);
gchar * generate_format_string_at_time (GDateTime * time);