diff --git a/src/Helpers/LocaleHelper.vala b/src/Helpers/LocaleHelper.vala index 48f94d54..876dfb45 100644 --- a/src/Helpers/LocaleHelper.vala +++ b/src/Helpers/LocaleHelper.vala @@ -17,6 +17,30 @@ */ namespace LocaleHelper { + [DBus (name = "org.freedesktop.locale1")] + interface Locale1 : Object { + [DBus (name = "SetLocale")] + public abstract void set_locale (string[] locale, bool user_interaction) throws GLib.Error; + [DBus (name = "SetVConsoleKeyboard")] + public abstract void set_vconsole_keyboard (string keymap, string keymap_toggle, bool convert, bool user_interaction) throws GLib.Error; + [DBus (name = "SetX11Keyboard")] + public abstract void set_x11_keyboard (string layout, string model, string variant, string options, bool convert, bool user_interaction) throws GLib.Error; + [DBus (name = "Locale")] + public abstract string[] locale { owned get; } + [DBus (name = "VConsoleKeymap")] + public abstract string vconsole_keymap { owned get; } + [DBus (name = "VConsoleKeymapToggle")] + public abstract string vconsole_keymap_toggle { owned get; } + [DBus (name = "X11Layout")] + public abstract string x11_layout { owned get; } + [DBus (name = "X11Model")] + public abstract string x11_model { owned get; } + [DBus (name = "X11Variant")] + public abstract string x11_variant { owned get; } + [DBus (name = "X11Options")] + public abstract string x11_options { owned get; } + } + public class LangEntry { public string alpha_3; public string? alpha_2; @@ -27,11 +51,12 @@ namespace LocaleHelper { countries = {}; } - public string get_code () { + public unowned string get_code () { return alpha_2 ?? alpha_3; } public void add_country (CountryEntry country_entry) { + country_entry.lang = this; var _countries = countries; _countries += country_entry; countries = _countries; @@ -42,10 +67,15 @@ namespace LocaleHelper { public string alpha_2; public string alpha_3; public string name; + public unowned LangEntry lang; - public string get_code () { + public unowned string get_code () { return alpha_2 ?? alpha_3; } + + public string get_full_code () { + return "%s_%s".printf (lang.get_code (), get_code ()); + } } private static Gee.HashMap lang_entries; diff --git a/src/Objects/Configuration.vala b/src/Objects/Configuration.vala index fd1ca76f..c5cd722a 100644 --- a/src/Objects/Configuration.vala +++ b/src/Objects/Configuration.vala @@ -32,5 +32,4 @@ public class Configuration : GLib.Object { public string? country { get; set; default = null; } public string keyboard_layout { get; set; } public string? keyboard_variant { get; set; default = null; } - public string keyboard { get; set; } } diff --git a/src/Views/KeyboardLayoutView.vala b/src/Views/KeyboardLayoutView.vala index 8069119a..321f8c80 100644 --- a/src/Views/KeyboardLayoutView.vala +++ b/src/Views/KeyboardLayoutView.vala @@ -87,6 +87,18 @@ public class KeyboardLayoutView : AbstractInstallerView { var settings = new Settings ("org.gnome.desktop.input-sources"); settings.set_value ("sources", list); settings.set_uint ("current", 0); + + try { + LocaleHelper.Locale1 locale1 = Bus.get_proxy_sync ( + BusType.SYSTEM, + "org.freedesktop.locale1", + "/org/freedesktop/locale1" + ); + + locale1.set_x11_keyboard (configuration.keyboard_layout, "", configuration.keyboard_variant ?? "", "", true, true); + } catch (Error e) { + critical ("Unable to get Locale1 interface"); + } } }); diff --git a/src/Views/LanguageView.vala b/src/Views/LanguageView.vala index 9b6403de..8dd0071d 100644 --- a/src/Views/LanguageView.vala +++ b/src/Views/LanguageView.vala @@ -71,6 +71,7 @@ public class Installer.LanguageView : AbstractInstallerView { size_group.add_widget (image); lang_variant_widget = new VariantWidget (); + lang_variant_widget.variant_listbox.set_sort_func ((Gtk.ListBoxSortFunc) CountryRow.compare); lang_variant_widget.variant_listbox.row_activated.connect (() => { next_button.activate (); @@ -128,12 +129,13 @@ public class Installer.LanguageView : AbstractInstallerView { } private void row_selected (Gtk.ListBoxRow? row) { - var lang_entry = ((LangRow) row).lang_entry; + unowned LocaleHelper.LangEntry lang_entry = ((LangRow) row).lang_entry; + unowned string lang_code = lang_entry.get_code (); - foreach (Gtk.Widget child in lang_variant_widget.main_listbox.get_children ()) { + foreach (weak Gtk.Widget child in lang_variant_widget.main_listbox.get_children ()) { if (child is LangRow) { - var lang_row = (LangRow) child; - if (lang_row.lang_entry.get_code () == lang_entry.get_code ()) { + weak LangRow lang_row = (LangRow) child; + if (lang_row.lang_entry.get_code () == lang_code) { lang_row.selected = true; } else { lang_row.selected = false; @@ -145,10 +147,10 @@ public class Installer.LanguageView : AbstractInstallerView { } private void variant_row_selected (Gtk.ListBoxRow? row) { - var country_entry = ((CountryRow) row).country_entry; - foreach (Gtk.Widget child in lang_variant_widget.variant_listbox.get_children ()) { + unowned LocaleHelper.CountryEntry country_entry = ((CountryRow) row).country_entry; + foreach (weak Gtk.Widget child in lang_variant_widget.variant_listbox.get_children ()) { if (child is CountryRow) { - var country_row = (CountryRow) child; + weak CountryRow country_row = (CountryRow) child; if (country_row.country_entry.alpha_2 == country_entry.alpha_2) { country_row.selected = true; } else { @@ -157,28 +159,38 @@ public class Installer.LanguageView : AbstractInstallerView { } } + next_button.label = LocaleHelper.lang_gettext (N_("Select"), country_entry.get_full_code ()); next_button.sensitive = true; } private void row_activated (Gtk.ListBoxRow row) { var lang_entry = ((LangRow) row).lang_entry; - var countries = lang_entry.countries; + unowned LocaleHelper.CountryEntry[] countries = lang_entry.countries; if (countries.length == 0) { next_button.sensitive = true; return; } + unowned string lang_code = lang_entry.get_code (); + string? main_country = LocaleHelper.get_main_country (lang_code); + lang_variant_widget.variant_listbox.row_selected.disconnect (variant_row_selected); lang_variant_widget.clear_variants (); lang_variant_widget.variant_listbox.row_selected.connect (variant_row_selected); - foreach (var country in countries) { - lang_variant_widget.variant_listbox.add (new CountryRow (country)); + foreach (unowned LocaleHelper.CountryEntry country in countries) { + var country_row = new CountryRow (country); + lang_variant_widget.variant_listbox.add (country_row); + if (country.get_code () == main_country) { + lang_variant_widget.variant_listbox.select_row (country_row); + } } - lang_variant_widget.variant_listbox.select_row (lang_variant_widget.variant_listbox.get_row_at_index (0)); + if (main_country == null || lang_variant_widget.variant_listbox.get_selected_row () == null) { + lang_variant_widget.variant_listbox.select_row (lang_variant_widget.variant_listbox.get_row_at_index (0)); + } lang_variant_widget.variant_listbox.show_all (); - Environment.set_variable ("LANGUAGE", lang_entry.get_code (), true); + Environment.set_variable ("LANGUAGE", lang_code, true); Intl.textdomain (Build.GETTEXT_PACKAGE); lang_variant_widget.show_variants (_("Languages"), "%s".printf (lang_entry.name)); } @@ -195,11 +207,13 @@ public class Installer.LanguageView : AbstractInstallerView { if (lang_entry.countries.length > 0) { row = lang_variant_widget.variant_listbox.get_selected_row (); if (row != null) { - var country = ((CountryRow) row).country_entry; - configuration.country = country.alpha_2; - lang += "_%s".printf (country.get_code ()); + unowned LocaleHelper.CountryEntry country = ((CountryRow) row).country_entry; + configuration.country = country.get_code (); + lang = country.get_full_code (); } else { - lang += "_%s".printf (lang_entry.countries[0].get_code ()); + unowned string country = lang_entry.countries[0].get_code (); + lang += "_%s".printf (country); + configuration.country = country; } } @@ -328,6 +342,11 @@ public class Installer.LanguageView : AbstractInstallerView { add (grid); } + + + public static int compare (CountryRow countryrow1, CountryRow countryrow2) { + return countryrow1.country_entry.name.collate (countryrow2.country_entry.name); + } } }