[gnome-boxes/get-preferred-keyboard] unattended-installer: Pass a better keyboard id to osinfo



commit 91cafb4cbb028a964ba6bcf03479c411eee8ccb9
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jan 15 17:53:05 2019 +0100

    unattended-installer: Pass a better keyboard id to osinfo
    
    We used to pass the same LANG identifier for both language and
    keyboard.
    
    These changes lookup on the user's default keyboard layout and
    uses it for the express installs. We also make sure that the
    current keyboard set in the user's system's is supported by osinfo
    by checking against the database.
    
    This should fix #240 and https://bugzilla.redhat.com/1666320

 src/os-database.vala          |  4 ++++
 src/unattended-installer.vala | 23 ++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/src/os-database.vala b/src/os-database.vala
index e1c9dda6..3e5ffb57 100644
--- a/src/os-database.vala
+++ b/src/os-database.vala
@@ -199,6 +199,10 @@ public Resources get_resources_for_os (Os? os, string? architecture) {
         return get_prefered_resources (list, prefs);
     }
 
+    public Datamap? get_datamap (string id) {
+        return db.get_datamap (id);
+    }
+
     private Resources get_resources_from_os_resources (Resources? minimum, Resources? recommended) {
         var resources = get_default_resources ();
 
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index e3fd115b..239b13bf 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -108,7 +108,7 @@ private static string escape_mkisofs_path (string path) {
 
         timezone = get_timezone ();
         lang = get_preferred_language ();
-        kbd = lang;
+        kbd = get_preferred_keyboard (lang);
 
         var product_key_format = get_product_key_format ();
         setup_box = new UnattendedSetupBox (this, product_key_format, needs_internet);
@@ -665,6 +665,27 @@ else if (compatibility == CPUArchCompatibility.COMPATIBLE && drivers.lookup (loc
         return scripts;
     }
 
+    private string get_preferred_keyboard (string lang) {
+        var input_settings = new GLib.Settings ("org.gnome.desktop.input-sources");
+        var sources = input_settings.get_value ("sources");
+
+        string kbd_layout;
+        if (sources != null) {
+            kbd_layout = sources.get_child_value (0).get_child_value (1).get_string ();
+
+            return kbd_layout.replace ("+", "-");
+        }
+
+        var os_db = MediaManager.get_instance ().os_db;
+        var datamap = os_db.get_datamap ("http://x.org/x11-keyboard";);
+
+        kbd_layout = datamap.lookup (lang);
+        if (kbd_layout != null) {
+            return kbd_layout;
+        }
+
+        return lang;
+    }
 
     private string get_preferred_language () {
         var system_langs = Intl.get_language_names ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]