~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/datetime/test-timezone.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <gtk/gtk.h>
 
2
#include "cc-timezone-map.h"
 
3
 
 
4
#define TZ_DIR "/usr/share/zoneinfo/"
 
5
 
 
6
static GList *
 
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
 
 
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
}