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



commit a586045780ffec57ae8c4de035bf0dbaec090242
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 | 16 +++++++++++++++-
 2 files changed, 19 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..c60e001b 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,20 @@ else if (compatibility == CPUArchCompatibility.COMPATIBLE && drivers.lookup (loc
         return scripts;
     }
 
+    private string get_preferred_keyboard (string lang) {
+        var os_db = MediaManager.get_instance ().os_db;
+        var datamap = os_db.get_datamap ("http://x.org/x11-keyboard";);
+
+        var input_settings = new GLib.Settings ("org.gnome.desktop.input-sources");
+        var source = input_settings.get_value ("sources").get_child_value (0);
+        var kbd_layout = source.get_child_value (1).get_string ();
+
+        if (datamap.reverse_lookup (kbd_layout) != null) {
+            return kbd_layout;
+        }
+
+        return datamap.lookup (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]