summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@src.gnome.org>2015-06-16 14:22:58 +0900
committerDaiki Ueno <dueno@src.gnome.org>2015-07-02 11:33:52 +0900
commitb1c0a99db9f117c9fb84720d599570c27120e2a1 (patch)
tree18c41375c479ae79bdb0a25c7c2661d195276c8a
parent783caa7882bdfa39b08ed1834457de030c365508 (diff)
downloadgnome-desktop-b1c0a99db9f117c9fb84720d599570c27120e2a1.tar.gz
gnome-xkb-info: Add method to get languages from layout
-rw-r--r--libgnome-desktop/gnome-xkb-info.c51
-rw-r--r--libgnome-desktop/gnome-xkb-info.h2
2 files changed, 53 insertions, 0 deletions
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