diff options
author | Ted Gould <ted@gould.cx> | 2010-10-07 10:03:23 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-10-07 10:03:23 -0600 |
commit | 32c2357c2aa4033d612a52a56767bb375814fdab (patch) | |
tree | 90769266ce8efab6ae907f56739410dd1367d599 | |
parent | 90339ca506cda5ee32b15d5273827abbb0fff55b (diff) | |
download | ayatana-indicator-datetime-32c2357c2aa4033d612a52a56767bb375814fdab.tar.gz ayatana-indicator-datetime-32c2357c2aa4033d612a52a56767bb375814fdab.tar.bz2 ayatana-indicator-datetime-32c2357c2aa4033d612a52a56767bb375814fdab.zip |
Caching the system timezone so we can compare against it
-rw-r--r-- | src/datetime-service.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c index de17065..0ca4051 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -43,6 +43,7 @@ static GMainLoop * mainloop = NULL; static DbusmenuServer * server = NULL; static DbusmenuMenuitem * root = NULL; static DatetimeInterface * dbus = NULL; +static gchar * current_timezone = NULL; /* Global Items */ static DbusmenuMenuitem * date = NULL; @@ -54,6 +55,38 @@ static DbusmenuMenuitem * tzchange = NULL; static GeoclueMasterClient * geo_master = NULL; static GeoclueAddress * geo_address = NULL; +/* Update the current timezone */ +static void +update_current_timezone (void) { + /* Clear old data */ + if (current_timezone != NULL) { + g_free(current_timezone); + 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); + 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); + + return; +} + /* Updates the label in the date menuitem */ static gboolean update_datetime (gpointer user_data) @@ -328,6 +361,9 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); + /* Cache the timezone */ + update_current_timezone(); + /* Building the base menu */ server = dbusmenu_server_new(MENU_OBJ); root = dbusmenu_menuitem_new(); |