[gnome-control-center] datetime: Fix crash when TZ is an alias
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] datetime: Fix crash when TZ is an alias
- Date: Fri, 4 Feb 2011 02:37:00 +0000 (UTC)
commit 5448188cc4ed04e3835439ba0f2076ca126a4915
Author: Bastien Nocera <hadess hadess net>
Date: Fri Feb 4 02:35:05 2011 +0000
datetime: Fix crash when TZ is an alias
Using the "backward" file from tzdata (available under the public
domain), we load the aliases for real timezones, to look them up
against our database.
https://bugzilla.gnome.org/show_bug.cgi?id=641360
panels/datetime/Makefile.am | 2 +
panels/datetime/backward | 118 +++++++++++++++++++++++++++++++++++++
panels/datetime/cc-timezone-map.c | 70 ++++++++++++++++++++--
3 files changed, 183 insertions(+), 7 deletions(-)
---
diff --git a/panels/datetime/Makefile.am b/panels/datetime/Makefile.am
index 4526bfc..2b235d6 100644
--- a/panels/datetime/Makefile.am
+++ b/panels/datetime/Makefile.am
@@ -61,6 +61,8 @@ dist_ui_DATA = \
data/timezone_-9.5.png \
data/timezone_9.5.png
+tzdatadir = $(pkgdatadir)/datetime
+dist_tzdata_DATA = backward
INCLUDES = \
$(PANEL_CFLAGS) \
diff --git a/panels/datetime/backward b/panels/datetime/backward
new file mode 100644
index 0000000..f1f95a8
--- /dev/null
+++ b/panels/datetime/backward
@@ -0,0 +1,118 @@
+# <pre>
+# @(#)backward 8.9
+# This file is in the public domain, so clarified as of
+# 2009-05-17 by Arthur David Olson.
+
+# This file provides links between current names for time zones
+# and their old names. Many names changed in late 1993.
+
+Link Africa/Asmara Africa/Asmera
+Link Africa/Bamako Africa/Timbuktu
+Link America/Argentina/Catamarca America/Argentina/ComodRivadavia
+Link America/Adak America/Atka
+Link America/Argentina/Buenos_Aires America/Buenos_Aires
+Link America/Argentina/Catamarca America/Catamarca
+Link America/Atikokan America/Coral_Harbour
+Link America/Argentina/Cordoba America/Cordoba
+Link America/Tijuana America/Ensenada
+Link America/Indiana/Indianapolis America/Fort_Wayne
+Link America/Indiana/Indianapolis America/Indianapolis
+Link America/Argentina/Jujuy America/Jujuy
+Link America/Indiana/Knox America/Knox_IN
+Link America/Kentucky/Louisville America/Louisville
+Link America/Argentina/Mendoza America/Mendoza
+Link America/Rio_Branco America/Porto_Acre
+Link America/Argentina/Cordoba America/Rosario
+Link America/St_Thomas America/Virgin
+Link Asia/Ashgabat Asia/Ashkhabad
+Link Asia/Chongqing Asia/Chungking
+Link Asia/Dhaka Asia/Dacca
+Link Asia/Kathmandu Asia/Katmandu
+Link Asia/Kolkata Asia/Calcutta
+Link Asia/Macau Asia/Macao
+Link Asia/Jerusalem Asia/Tel_Aviv
+Link Asia/Ho_Chi_Minh Asia/Saigon
+Link Asia/Thimphu Asia/Thimbu
+Link Asia/Makassar Asia/Ujung_Pandang
+Link Asia/Ulaanbaatar Asia/Ulan_Bator
+Link Atlantic/Faroe Atlantic/Faeroe
+Link Europe/Oslo Atlantic/Jan_Mayen
+Link Australia/Sydney Australia/ACT
+Link Australia/Sydney Australia/Canberra
+Link Australia/Lord_Howe Australia/LHI
+Link Australia/Sydney Australia/NSW
+Link Australia/Darwin Australia/North
+Link Australia/Brisbane Australia/Queensland
+Link Australia/Adelaide Australia/South
+Link Australia/Hobart Australia/Tasmania
+Link Australia/Melbourne Australia/Victoria
+Link Australia/Perth Australia/West
+Link Australia/Broken_Hill Australia/Yancowinna
+Link America/Rio_Branco Brazil/Acre
+Link America/Noronha Brazil/DeNoronha
+Link America/Sao_Paulo Brazil/East
+Link America/Manaus Brazil/West
+Link America/Halifax Canada/Atlantic
+Link America/Winnipeg Canada/Central
+Link America/Regina Canada/East-Saskatchewan
+Link America/Toronto Canada/Eastern
+Link America/Edmonton Canada/Mountain
+Link America/St_Johns Canada/Newfoundland
+Link America/Vancouver Canada/Pacific
+Link America/Regina Canada/Saskatchewan
+Link America/Whitehorse Canada/Yukon
+Link America/Santiago Chile/Continental
+Link Pacific/Easter Chile/EasterIsland
+Link America/Havana Cuba
+Link Africa/Cairo Egypt
+Link Europe/Dublin Eire
+Link Europe/London Europe/Belfast
+Link Europe/Chisinau Europe/Tiraspol
+Link Europe/London GB
+Link Europe/London GB-Eire
+Link Etc/GMT GMT+0
+Link Etc/GMT GMT-0
+Link Etc/GMT GMT0
+Link Etc/GMT Greenwich
+Link Asia/Hong_Kong Hongkong
+Link Atlantic/Reykjavik Iceland
+Link Asia/Tehran Iran
+Link Asia/Jerusalem Israel
+Link America/Jamaica Jamaica
+Link Asia/Tokyo Japan
+Link Pacific/Kwajalein Kwajalein
+Link Africa/Tripoli Libya
+Link America/Tijuana Mexico/BajaNorte
+Link America/Mazatlan Mexico/BajaSur
+Link America/Mexico_City Mexico/General
+Link Pacific/Auckland NZ
+Link Pacific/Chatham NZ-CHAT
+Link America/Denver Navajo
+Link Asia/Shanghai PRC
+Link Pacific/Pago_Pago Pacific/Samoa
+Link Pacific/Chuuk Pacific/Yap
+Link Pacific/Chuuk Pacific/Truk
+Link Pacific/Pohnpei Pacific/Ponape
+Link Europe/Warsaw Poland
+Link Europe/Lisbon Portugal
+Link Asia/Taipei ROC
+Link Asia/Seoul ROK
+Link Asia/Singapore Singapore
+Link Europe/Istanbul Turkey
+Link Etc/UCT UCT
+Link America/Anchorage US/Alaska
+Link America/Adak US/Aleutian
+Link America/Phoenix US/Arizona
+Link America/Chicago US/Central
+Link America/Indiana/Indianapolis US/East-Indiana
+Link America/New_York US/Eastern
+Link Pacific/Honolulu US/Hawaii
+Link America/Indiana/Knox US/Indiana-Starke
+Link America/Detroit US/Michigan
+Link America/Denver US/Mountain
+Link America/Los_Angeles US/Pacific
+Link Pacific/Pago_Pago US/Samoa
+Link Etc/UTC UTC
+Link Etc/UTC Universal
+Link Europe/Moscow W-SU
+Link Etc/UTC Zulu
diff --git a/panels/datetime/cc-timezone-map.c b/panels/datetime/cc-timezone-map.c
index 54fd370..5f7a0db 100644
--- a/panels/datetime/cc-timezone-map.c
+++ b/panels/datetime/cc-timezone-map.c
@@ -56,6 +56,7 @@ struct _CcTimezoneMapPrivate
TzDB *tzdb;
TzLocation *location;
+ GHashTable *alias_db;
};
enum
@@ -169,6 +170,12 @@ cc_timezone_map_dispose (GObject *object)
priv->visible_map_rowstride = 0;
}
+ if (priv->alias_db)
+ {
+ g_hash_table_destroy (priv->alias_db);
+ priv->alias_db = NULL;
+ }
+
G_OBJECT_CLASS (cc_timezone_map_parent_class)->dispose (object);
}
@@ -193,8 +200,6 @@ cc_timezone_map_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural)
{
- CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
-
/* choose a minimum size small enough to prevent the window
* from growing horizontally
*/
@@ -540,6 +545,57 @@ button_press_event (GtkWidget *widget,
}
static void
+load_backward_tz (CcTimezoneMap *self)
+{
+ GError *error = NULL;
+ char **lines, *contents;
+ guint i;
+
+ self->priv->alias_db = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ if (g_file_get_contents (GNOMECC_DATA_DIR "/datetime/backward", &contents, NULL, &error) == FALSE)
+ {
+ g_warning ("Failed to load 'backward' file: %s", error->message);
+ return;
+ }
+ lines = g_strsplit (contents, "\n", -1);
+ g_free (contents);
+ for (i = 0; lines[i] != NULL; i++)
+ {
+ char **items;
+ guint j;
+ char *real, *alias;
+
+ if (g_ascii_strncasecmp (lines[i], "Link\t", 5) != 0)
+ continue;
+
+ items = g_strsplit (lines[i], "\t", -1);
+ real = NULL;
+ alias = NULL;
+ /* Skip the "Link<tab>" part */
+ for (j = 1; items[j] != NULL; j++)
+ {
+ if (items[j][0] == '\0')
+ continue;
+ if (real == NULL)
+ {
+ real = items[j];
+ continue;
+ }
+ alias = items[j];
+ break;
+ }
+
+ if (real == NULL || alias == NULL)
+ g_warning ("Could not parse line: %s", lines[i]);
+
+ g_hash_table_insert (self->priv->alias_db, g_strdup (alias), g_strdup (real));
+ g_strfreev (items);
+ }
+ g_strfreev (lines);
+}
+
+static void
cc_timezone_map_init (CcTimezoneMap *self)
{
CcTimezoneMapPrivate *priv;
@@ -571,10 +627,7 @@ cc_timezone_map_init (CcTimezoneMap *self)
g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event),
NULL);
- /*
- g_signal_connect (self, "map-event", G_CALLBACK (map_event), NULL);
- g_signal_connect (self, "unmap-event", G_CALLBACK (unmap_event), NULL);
- */
+ load_backward_tz (self);
}
CcTimezoneMap *
@@ -589,6 +642,9 @@ cc_timezone_map_set_timezone (CcTimezoneMap *map,
{
GPtrArray *locations;
guint i;
+ char *real_tz;
+
+ real_tz = g_hash_table_lookup (map->priv->alias_db, timezone);
locations = tz_get_locations (map->priv->tzdb);
@@ -596,7 +652,7 @@ cc_timezone_map_set_timezone (CcTimezoneMap *map,
{
TzLocation *loc = locations->pdata[i];
- if (!g_strcmp0 (loc->zone, timezone))
+ if (!g_strcmp0 (loc->zone, real_tz ? real_tz : timezone))
{
set_location (map, loc);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]