diff options
author | Rui Matos <tiagomatos@gmail.com> | 2013-02-06 01:06:43 +0100 |
---|---|---|
committer | Rui Matos <tiagomatos@gmail.com> | 2013-02-18 13:53:11 +0100 |
commit | 84a941a565ee5d94b6a454ba4754a859bf5800f5 (patch) | |
tree | c8828565cbdd6314884bf0376fe756d328b9eb42 | |
parent | c07dedb448ddb755be3e9f9030ca992f678a0e37 (diff) | |
download | gnome-desktop-wip/locale-info.tar.gz |
gnome-xkb-info: Add API to get layouts for language and countrywip/locale-info
https://bugzilla.gnome.org/show_bug.cgi?id=693775
-rw-r--r-- | libgnome-desktop/gnome-xkb-info.c | 97 | ||||
-rw-r--r-- | libgnome-desktop/gnome-xkb-info.h | 4 |
2 files changed, 101 insertions, 0 deletions
diff --git a/libgnome-desktop/gnome-xkb-info.c b/libgnome-desktop/gnome-xkb-info.c index c726f5c5..cc43f91d 100644 --- a/libgnome-desktop/gnome-xkb-info.c +++ b/libgnome-desktop/gnome-xkb-info.c @@ -923,3 +923,100 @@ gnome_xkb_info_get_layout_info (GnomeXkbInfo *self, return TRUE; } + +static void +collect_layout_ids (gpointer key, + gpointer value, + gpointer data) +{ + Layout *layout = value; + GList **list = data; + + *list = g_list_prepend (*list, layout->id); +} + +/** + * gnome_xkb_info_get_layouts_for_language: + * @self: a #GnomeXkbInfo + * @language_code: an ISO 639 code string + * + * Returns a list of all layout identifiers we know about for + * @language_code. + * + * Return value: (transfer container) (element-type utf8): the list + * of layout ids. The caller takes ownership of the #GList but not of + * the strings themselves, those are internally allocated and must not + * be modified. + * + * Since: 3.8 + */ +GList * +gnome_xkb_info_get_layouts_for_language (GnomeXkbInfo *self, + const gchar *language_code) +{ + GnomeXkbInfoPrivate *priv; + GHashTable *layouts_for_language; + gchar *language; + GList *list; + + g_return_val_if_fail (GNOME_IS_XKB_INFO (self), NULL); + + priv = self->priv; + + if (!ensure_rules_are_parsed (self)) + return NULL; + + language = gnome_get_language_from_code (language_code, NULL); + + layouts_for_language = g_hash_table_lookup (priv->layouts_by_language, language); + if (!layouts_for_language) + return NULL; + + list = NULL; + g_hash_table_foreach (layouts_for_language, collect_layout_ids, &list); + + return list; +} + +/** + * gnome_xkb_info_get_layouts_for_country: + * @self: a #GnomeXkbInfo + * @country_code: an ISO 3166 code string + * + * Returns a list of all layout identifiers we know about for + * @country_code. + * + * Return value: (transfer container) (element-type utf8): the list + * of layout ids. The caller takes ownership of the #GList but not of + * the strings themselves, those are internally allocated and must not + * be modified. + * + * Since: 3.8 + */ +GList * +gnome_xkb_info_get_layouts_for_country (GnomeXkbInfo *self, + const gchar *country_code) +{ + GnomeXkbInfoPrivate *priv; + GHashTable *layouts_for_country; + gchar *country; + GList *list; + + g_return_val_if_fail (GNOME_IS_XKB_INFO (self), NULL); + + priv = self->priv; + + if (!ensure_rules_are_parsed (self)) + return NULL; + + country = gnome_get_country_from_code (country_code, NULL); + + layouts_for_country = g_hash_table_lookup (priv->layouts_by_country, country); + if (!layouts_for_country) + return NULL; + + list = NULL; + g_hash_table_foreach (layouts_for_country, collect_layout_ids, &list); + + return list; +} diff --git a/libgnome-desktop/gnome-xkb-info.h b/libgnome-desktop/gnome-xkb-info.h index d93f0dbc..4abb6ef1 100644 --- a/libgnome-desktop/gnome-xkb-info.h +++ b/libgnome-desktop/gnome-xkb-info.h @@ -75,6 +75,10 @@ GList *gnome_xkb_info_get_options_for_group (GnomeXkbInfo *s const gchar *gnome_xkb_info_description_for_option (GnomeXkbInfo *self, const gchar *group_id, const gchar *id); +GList *gnome_xkb_info_get_layouts_for_language (GnomeXkbInfo *self, + const gchar *language_code); +GList *gnome_xkb_info_get_layouts_for_country (GnomeXkbInfo *self, + const gchar *country_code); void gnome_xkb_info_get_var_defs (gchar **rules, XkbRF_VarDefsRec **var_defs); |