From b1c0a99db9f117c9fb84720d599570c27120e2a1 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Tue, 16 Jun 2015 14:22:58 +0900 Subject: gnome-xkb-info: Add method to get languages from layout --- libgnome-desktop/gnome-xkb-info.c | 51 +++++++++++++++++++++++++++++++++++++++ libgnome-desktop/gnome-xkb-info.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/libgnome-desktop/gnome-xkb-info.c b/libgnome-desktop/gnome-xkb-info.c index 1d10939d..d9e5c2c6 100644 --- a/libgnome-desktop/gnome-xkb-info.c +++ b/libgnome-desktop/gnome-xkb-info.c @@ -1002,3 +1002,54 @@ gnome_xkb_info_get_layouts_for_country (GnomeXkbInfo *self, return list; } + +static void +collect_languages (gpointer value, + gpointer data) +{ + gchar *language = value; + GList **list = data; + + *list = g_list_append (*list, language); +} + +/** + * gnome_xkb_info_get_languages_for_layout: + * @self: a #GnomeXkbInfo + * @layout_id: a layout identifier + * + * Returns a list of all languages supported by a layout, given by + * @layout_id. + * + * Return value: (transfer container) (element-type utf8): the list of + * ISO 639 code strings. The caller takes ownership of the #GList but + * not of the strings themselves, those are internally allocated and + * must not be modified. + * + * Since: 3.18 + */ +GList * +gnome_xkb_info_get_languages_for_layout (GnomeXkbInfo *self, + const gchar *layout_id) +{ + GnomeXkbInfoPrivate *priv; + Layout *layout; + GList *list; + + g_return_val_if_fail (GNOME_IS_XKB_INFO (self), NULL); + + priv = self->priv; + + if (!ensure_rules_are_parsed (self)) + return NULL; + + layout = g_hash_table_lookup (priv->layouts_table, layout_id); + + if (!layout) + return NULL; + + list = NULL; + g_slist_foreach (layout->iso639Ids, collect_languages, &list); + + return list; +} diff --git a/libgnome-desktop/gnome-xkb-info.h b/libgnome-desktop/gnome-xkb-info.h index 8fc96c72..a373f81f 100644 --- a/libgnome-desktop/gnome-xkb-info.h +++ b/libgnome-desktop/gnome-xkb-info.h @@ -76,6 +76,8 @@ GList *gnome_xkb_info_get_layouts_for_language (GnomeXkbInfo *s const gchar *language_code); GList *gnome_xkb_info_get_layouts_for_country (GnomeXkbInfo *self, const gchar *country_code); +GList *gnome_xkb_info_get_languages_for_layout (GnomeXkbInfo *self, + const gchar *layout_id); G_END_DECLS -- cgit v1.2.1