[virt-tools-list] [PATCH 5/6] Add function to fetch console keyboard layout
Fabiano Fidêncio
fabiano at fidencio.org
Tue Jul 24 20:05:17 UTC 2012
Similar as found on Boxes, this function can be useful for all linuxes,
so, is better put it into our API
---
osinfo/libosinfo.syms | 1 +
osinfo/osinfo_install_script.c | 121 ++++++++++++++++++++++++++++++++++++++++
osinfo/osinfo_install_script.h | 3 +
3 files changed, 125 insertions(+)
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 2d64ebb..ba8f045 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -278,6 +278,7 @@ LIBOSINFO_0.2.0 {
osinfo_install_script_get_uri;
osinfo_install_script_is_config;
osinfo_install_script_is_config_required;
+ osinfo_install_script_get_console_keyboard_layout;
osinfo_install_scriptlist_new;
osinfo_install_scriptlist_new_filtered;
osinfo_install_scriptlist_new_union;
diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index 6ce1c55..37467aa 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -383,6 +383,127 @@ gboolean osinfo_install_script_is_config_required(OsinfoInstallScript *script,
return TRUE;
}
+struct KbdLayout {
+ const gchar *xkb_layout;
+ const gchar *xkb_variant;
+ const gchar *console_layout;
+};
+
+struct KbdLayout kbd_layouts[] = {
+ { "ara", NULL, "ar-azerty" },
+ { "ara", "azerty", "ar-azerty" },
+ { "ara", "azerty_digits", "ar-azerty-digits" },
+ { "ara", "digits", "ar-digits" },
+ { "ara", "qwerty", "ar-qwerty" },
+ { "ara", "qwerty_digits", "ar-qwerty-digits" },
+ { "be", NULL, "be-latin1" },
+ { "bg", NULL, "bg_bds-utf8" },
+ { "bg", "phonetic", "bg_pho-utf8" },
+ { "bg", "bas_phonetic", "bg_pho-utf8" },
+ { "br", NULL, "br-abnt2" },
+ { "ca(fr)", NULL, "cf" },
+ { "hr", NULL, "croat" },
+ { "cz", NULL, "cz-us-qwertz" },
+ { "cz", "qwerty", "cz-lat2" },
+ { "cz", "", "cz-us-qwertz" },
+ { "de", NULL, "de" },
+ { "de", "nodeadkeys", "de-latin1-nodeadkeys" },
+ { "dev", NULL, "dev" },
+ { "dk", NULL, "dk" },
+ { "dk", "dvorak", "dk-dvorak" },
+ { "es", NULL, "es" },
+ { "ee", NULL, "et" },
+ { "fi", NULL, "fi" },
+ { "fr", NULL, "fr" },
+ { "fr", "latin9", "fr-latin9" },
+ { "gr", NULL, "gr" },
+ { "gur", NULL, "gur" },
+ { "hu", NULL, "hu" },
+ { "hu", "qwerty", "hu101" },
+ { "ie", NULL, "ie" },
+ { "in", NULL, "us" },
+ { "in", "ben", "ben" },
+ { "in", "ben-probhat", "ben_probhat" },
+ { "in", "guj", "guj" },
+ { "in", "tam", "tml-inscript" },
+ { "in", "tam_TAB", "tml-uni" },
+ { "is", NULL, "is-latin1" },
+ { "it", NULL, "it" },
+ { "jp", NULL, "jp106" },
+ { "kr", NULL, "ko" },
+ { "latam", NULL, "la-latin1" },
+ { "mkd", NULL, "mk-utf" },
+ { "nl", NULL, "nl" },
+ { "no", NULL, "no" },
+ { "pl", NULL, "pl2" },
+ { "pt", NULL, "pt-latin1" },
+ { "ro", NULL, "ro" },
+ { "ro", "std", "ro-std" },
+ { "ro", "cedilla", "ro-cedilla" },
+ { "ro", "std_cedilla", "ro-std-cedilla" },
+ { "ru", NULL, "ru" },
+ { "rs", NULL, "sr-cy" },
+ { "rs", "latin", "sr-latin"},
+ { "se", NULL, "sv-latin1" },
+ { "ch", "de_nodeadkeys", "sg" },
+ { "ch", "fr", "fr_CH" },
+ { "sk", NULL, "sk-qwerty" },
+ { "si", NULL, "slovene" },
+ { "tj", NULL, "tj" },
+ { "tr", NULL, "trq" },
+ { "gb", NULL, "uk" },
+ { "ua", NULL, "ua-utf" },
+ { "us", NULL, "us" },
+ { "us", "intl", "us-acentos" }
+};
+
+const gchar *osinfo_install_script_get_console_keyboard_layout (OsinfoInstallScript *script)
+{
+ GSettings *settings = g_settings_new("org.gnome.libgnomekbd.keyboard");
+ gchar **tokens, **layouts;
+ gchar *layout_str, *xkb_layout, *xkb_variant;
+ const gchar *console_layout = NULL;
+ gint i;
+
+ layouts = g_settings_get_strv(settings, "layouts");
+ layout_str = layouts[0];
+
+ if (layout_str == NULL || g_strcmp0(layout_str, "") == 0) {
+ g_printerr ("Failed to fetch prefered keyboard layout from user settings, falling back to 'us'..");
+
+ console_layout = "us";
+ goto finish;
+ }
+
+ tokens = g_strsplit(layout_str, "\t", 0);
+ xkb_layout = tokens[0];
+ xkb_variant = tokens[1];
+
+ for (i = 0; i < G_N_ELEMENTS(kbd_layouts); i++) {
+ if (xkb_layout == kbd_layouts[i].xkb_layout) {
+ if (xkb_variant == kbd_layouts[i].xkb_variant) {
+ console_layout = kbd_layouts[i].console_layout;
+ break;
+ } else if (kbd_layouts[i].xkb_variant == NULL)
+ console_layout = kbd_layouts[i].console_layout;
+ }
+ }
+
+ if (console_layout == NULL)
+ console_layout = "us";
+
+ for (i = 0; i < G_N_ELEMENTS(tokens); i++)
+ g_free(tokens[i]);
+ g_free(tokens);
+
+finish:
+ for (i = 0; i < G_N_ELEMENTS(layouts); i++)
+ g_free(layouts[i]);
+ g_free(layouts);
+
+ return console_layout;
+}
+
struct OsinfoInstallScriptGenerate {
GSimpleAsyncResult *res;
OsinfoOs *os;
diff --git a/osinfo/osinfo_install_script.h b/osinfo/osinfo_install_script.h
index cca257a..d141e06 100644
--- a/osinfo/osinfo_install_script.h
+++ b/osinfo/osinfo_install_script.h
@@ -135,6 +135,9 @@ gboolean osinfo_install_script_is_config(OsinfoInstallScript *script,
gboolean osinfo_install_script_is_config_required(OsinfoInstallScript *script,
const gchar *config);
+const gchar *osinfo_install_script_get_console_keyboard_layout (OsinfoInstallScript *script);
+
+
#endif /* __OSINFO_INSTALL_SCRIPT_H__ */
/*
* Local variables:
--
1.7.10.4
More information about the virt-tools-list
mailing list