From 32c2357c2aa4033d612a52a56767bb375814fdab Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Oct 2010 10:03:23 -0600 Subject: Caching the system timezone so we can compare against it --- src/datetime-service.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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(); -- cgit v1.2.3