diff options
author | Bastien Nocera <hadess@hadess.net> | 2011-03-15 01:56:24 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2011-03-15 01:58:29 +0000 |
commit | 33fb810c846c68a2cde2a784057b965287322aa6 (patch) | |
tree | 0e6e3b5938a9efb92cf2f17eadf8852ba9ff8c5e /panels/datetime/test-timezone.c | |
parent | 31be5be9c7d1333bde7eedb98c938fc12c814bca (diff) | |
download | gnome-control-center-33fb810c846c68a2cde2a784057b965287322aa6.tar.gz |
datetime: Add test program for missing TZ support
We don't handle a number of timezones currently, including
things like "posixrules", or even "Etc/GMT".
Diffstat (limited to 'panels/datetime/test-timezone.c')
-rw-r--r-- | panels/datetime/test-timezone.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/panels/datetime/test-timezone.c b/panels/datetime/test-timezone.c new file mode 100644 index 000000000..2dc744e9f --- /dev/null +++ b/panels/datetime/test-timezone.c @@ -0,0 +1,81 @@ +#include <gtk/gtk.h> +#include "cc-timezone-map.h" + +#define TZ_DIR "/usr/share/zoneinfo/" + +static GList * +get_timezone_list (GList *tzs, + const char *top_path, + const char *subpath) +{ + GDir *dir; + char *fullpath; + const char *name; + + if (subpath == NULL) + fullpath = g_strdup (top_path); + else + fullpath = g_build_filename (top_path, subpath, NULL); + dir = g_dir_open (fullpath, 0, NULL); + if (dir == NULL) { + g_warning ("Could not open %s", fullpath); + return NULL; + } + while ((name = g_dir_read_name (dir)) != NULL) { + char *path; + + if (g_str_has_suffix (name, ".tab")) + continue; + + if (subpath != NULL) + path = g_build_filename (top_path, subpath, name, NULL); + else + path = g_build_filename (top_path, name, NULL); + if (g_file_test (path, G_FILE_TEST_IS_DIR)) { + if (subpath == NULL) { + tzs = get_timezone_list (tzs, top_path, name); + } else { + char *new_subpath; + new_subpath = g_strdup_printf ("%s/%s", subpath, name); + tzs = get_timezone_list (tzs, top_path, new_subpath); + g_free (new_subpath); + } + } else if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { + if (subpath == NULL) + tzs = g_list_prepend (tzs, g_strdup (name)); + else { + char *tz; + tz = g_strdup_printf ("%s/%s", subpath, name); + tzs = g_list_prepend (tzs, tz); + } + } + g_free (path); + } + g_dir_close (dir); + + return tzs; +} + +int main (int argc, char **argv) +{ + CcTimezoneMap *map; + GList *tzs, *l; + int ret = 0; + + gtk_init (&argc, &argv); + + map = cc_timezone_map_new (); + tzs = get_timezone_list (NULL, TZ_DIR, NULL); + for (l = tzs; l != NULL; l = l->next) { + char *timezone = l->data; + + if (cc_timezone_map_set_timezone (map, timezone) == FALSE) { + g_warning ("Failed to locate timezone '%s'", timezone); + ret = 1; + } + g_free (timezone); + } + g_list_free (tzs); + + return ret; +} |