datetime: Move backward TZ DB to tz.[ch]
So we can add hacks in one location
This commit is contained in:
parent
f8c3b0c59e
commit
8d15af48c8
4 changed files with 96 additions and 87 deletions
|
@ -57,7 +57,6 @@ struct _CcTimezoneMapPrivate
|
|||
|
||||
TzDB *tzdb;
|
||||
TzLocation *location;
|
||||
GHashTable *alias_db;
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -171,12 +170,6 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -540,57 +533,6 @@ button_press_event (GtkWidget *widget,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -622,8 +564,6 @@ cc_timezone_map_init (CcTimezoneMap *self)
|
|||
|
||||
g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event),
|
||||
NULL);
|
||||
|
||||
load_backward_tz (self);
|
||||
}
|
||||
|
||||
CcTimezoneMap *
|
||||
|
@ -632,26 +572,6 @@ cc_timezone_map_new (void)
|
|||
return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
get_clean_tz (CcTimezoneMap *map,
|
||||
const char *tz)
|
||||
{
|
||||
char *ret;
|
||||
const char *timezone;
|
||||
|
||||
if (g_str_has_prefix (tz, "right/"))
|
||||
timezone = tz + strlen ("right/");
|
||||
else if (g_str_has_prefix (tz, "posix/"))
|
||||
timezone = tz + strlen ("posix/");
|
||||
else
|
||||
timezone = tz;
|
||||
|
||||
ret = g_hash_table_lookup (map->priv->alias_db, timezone);
|
||||
if (ret == NULL)
|
||||
return g_strdup (timezone);
|
||||
return g_strdup (ret);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cc_timezone_map_set_timezone (CcTimezoneMap *map,
|
||||
const gchar *timezone)
|
||||
|
@ -661,7 +581,7 @@ cc_timezone_map_set_timezone (CcTimezoneMap *map,
|
|||
char *real_tz;
|
||||
gboolean ret;
|
||||
|
||||
real_tz = get_clean_tz (map, timezone);
|
||||
real_tz = tz_info_get_clean_name (map->priv->tzdb, timezone);
|
||||
|
||||
locations = tz_get_locations (map->priv->tzdb);
|
||||
ret = FALSE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue