1 #include <gtk/gtk.h>
2 #include "cc-timezone-map.h"
3 
4 #define TZ_DIR "/usr/share/zoneinfo/"
5 
6 static GList *
get_timezone_list(GList * tzs,const char * top_path,const char * subpath)7 get_timezone_list (GList *tzs,
8 		   const char *top_path,
9 		   const char *subpath)
10 {
11 	GDir *dir;
12 	char *fullpath;
13 	const char *name;
14 
15 	if (subpath == NULL)
16 		fullpath = g_strdup (top_path);
17 	else
18 		fullpath = g_build_filename (top_path, subpath, NULL);
19 	dir = g_dir_open (fullpath, 0, NULL);
20 	if (dir == NULL) {
21 		g_warning ("Could not open %s", fullpath);
22 		return NULL;
23 	}
24 	while ((name = g_dir_read_name (dir)) != NULL) {
25 		char *path;
26 
27 		if (g_str_has_suffix (name, ".tab"))
28 			continue;
29 
30 		if (subpath != NULL)
31 			path = g_build_filename (top_path, subpath, name, NULL);
32 		else
33 			path = g_build_filename (top_path, name, NULL);
34 		if (g_file_test (path, G_FILE_TEST_IS_DIR)) {
35 			if (subpath == NULL) {
36 				tzs = get_timezone_list (tzs, top_path, name);
37 			} else {
38 				char *new_subpath;
39 				new_subpath = g_strdup_printf ("%s/%s", subpath, name);
40 				tzs = get_timezone_list (tzs, top_path, new_subpath);
41 				g_free (new_subpath);
42 			}
43 		} else if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
44 			if (subpath == NULL)
45 				tzs = g_list_prepend (tzs, g_strdup (name));
46 			else {
47 				char *tz;
48 				tz = g_strdup_printf ("%s/%s", subpath, name);
49 				tzs = g_list_prepend (tzs, tz);
50 			}
51 		}
52 		g_free (path);
53 	}
54 	g_dir_close (dir);
55 
56 	return tzs;
57 }
58 
main(int argc,char ** argv)59 int main (int argc, char **argv)
60 {
61 	CcTimezoneMap *map;
62 	TzDB *tz_db;
63 	GList *tzs, *l;
64 	GHashTable *ht;
65 	int ret = 0;
66 
67 	gtk_init (&argc, &argv);
68 
69 	ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
70 	map = cc_timezone_map_new ();
71 	tz_db = tz_load_db ();
72 	tzs = get_timezone_list (NULL, TZ_DIR, NULL);
73 	for (l = tzs; l != NULL; l = l->next) {
74 		char *timezone = l->data;
75 		char *clean_tz;
76 
77 		clean_tz = tz_info_get_clean_name (tz_db, timezone);
78 
79 		if (cc_timezone_map_set_timezone (map, clean_tz) == FALSE) {
80 			if (g_hash_table_lookup (ht, clean_tz) == NULL) {
81 				if (g_strcmp0 (clean_tz, timezone) == 0)
82 					g_print ("Failed to locate timezone '%s'\n", timezone);
83 				else
84 					g_print ("Failed to locate timezone '%s' (original name: '%s')\n", clean_tz, timezone);
85 				g_hash_table_insert (ht, g_strdup (clean_tz), GINT_TO_POINTER (TRUE));
86 			}
87 			/* We don't warn for those two, we'll just fallback
88 			 * in the panel code */
89 			if (!g_str_equal (clean_tz, "posixrules") &&
90 			    !g_str_equal (clean_tz, "Factory"))
91 				ret = 1;
92 		}
93 		g_free (timezone);
94 		g_free (clean_tz);
95 	}
96 	g_list_free (tzs);
97 	tz_db_free (tz_db);
98 	g_hash_table_destroy (ht);
99 
100 	return ret;
101 }
102