From c0a0114af0e7e1fcebe56fed272323d082573375 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 25 Jun 2020 19:02:06 +0200 Subject: [PATCH 01/17] Add option for 24 h format languages --- meson_options.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/meson_options.txt b/meson_options.txt index fefae3b5..d6a4fbde 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ option('supported_languages', type : 'string', value : 'aa;ab;ae;af;ak;am;an;ar;as;ast;av;ay;az;ba;be;bg;bh;bi;bm;bn;bo;br;bs;ca;ce;ch;ckb;co;cr;cs;cu;cv;cy;da;de;de_CH;de_DE;dv;dz;ee;el;en;en_US;en_AU;en_CA;en_GB;eo;es;et;eu;fa;ff;fi;fj;fo;fr;fr_BE;fr_CA;fr_FR;fy;ga;gd;gl;gn;gu;gv;ha;he;hi;ho;hr;ht;hu;hy;hz;ia;id;ie;ig;ii;ik;io;is;it;iu;ja;jv;ka;kab;kg;ki;kj;kk;kl;km;kn;ko;kr;ks;ku;kv;kw;ky;la;lb;lg;li;ln;lo;lt;lu;lv;mg;mh;mi;mk;ml;mn;mo;mr;ms;mt;my;na;nb;nd;ne;ng;nl;nn;no;nr;nv;ny;oc;oj;om;or;os;pa;pi;pl;ps;pt;pt_PT;pt_BR;qu;rm;rn;ro;ru;rue;rw;sa;sc;sd;se;sg;si;sk;sl;sm;sma;sn;so;sq;sr;ss;st;su;sv;sw;szl;ta;te;tg;th;ti;tk;tl;tn;to;tr;ts;tt;tw;ty;udm;ug;uk;ur;uz;ve;vi;vo;wa;wo;xh;yi;yo;za;zh;zh_CN;zh_HK;zh_TW;zu', description : 'The list of supported languages') option('preferred_languages', type : 'string', value : 'en;zh;es;fr;pt;ru;de', description : 'A prioritized list of languages') +option('24h_format_languages', type : 'string', value : 'de_DE', description : 'The list of languages that use 24 h format') From 13867ee8aac9a5f9b7e4bbb790fa0274a292af6d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 25 Jun 2020 19:02:49 +0200 Subject: [PATCH 02/17] Read option for 24 h format languages --- src/Config.vala.in | 1 + src/meson.build | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Config.vala.in b/src/Config.vala.in index 184e5218..a000b193 100644 --- a/src/Config.vala.in +++ b/src/Config.vala.in @@ -2,6 +2,7 @@ namespace Build { public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"; public const string LANG_LIST = "@LANG_LIST@"; public const string PREFERRED_LANG_LIST = "@PREFERRED_LANG_LIST@"; + public const string 24H_FORMAT_LANG_LIST = "@24H_FORMAT_LANG_LIST@"; public const string XKB_BASE = "@XKB_BASE@"; public const string ISO_CODES_LOCATION = "@ISO_CODES_LOCATION@"; } diff --git a/src/meson.build b/src/meson.build index bc87e1a6..468d5309 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,6 +19,7 @@ configuration_data = configuration_data() configuration_data.set('GETTEXT_PACKAGE', meson.project_name()) configuration_data.set('LANG_LIST', get_option('supported_languages')) configuration_data.set('PREFERRED_LANG_LIST', get_option('preferred_languages')) +configuration_data.set('24H_FORMAT_LANG_LIST', get_option('24h_format_languages')) xkbconf = dependency('xkeyboard-config') xkb_base = xkbconf.get_pkgconfig_variable('xkb_base') From 57ac1756649849662487c31951a39822a959d14a Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 25 Jun 2020 19:33:52 +0200 Subject: [PATCH 03/17] Add logic to set time format for user --- src/MainWindow.vala | 5 +++++ src/Utils.vala | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 01358763..1605c02c 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -90,6 +90,11 @@ public class Installer.MainWindow : Gtk.Window { private void on_finish () { if (account_view.created != null) { account_view.created.set_language (Configuration.get_default ().lang); + + var 24_format_lang_list = Build.24H_FORMAT_LANG_LIST.split (";"); + if (Configuration.get_default ().lang in 24_format_lang_list) { + Utils.set_time_format_for_user ("24h", account_view.created); + } } destroy (); diff --git a/src/Utils.vala b/src/Utils.vala index a09aeb08..a41eca3d 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -124,4 +124,10 @@ namespace Utils { return username; } + + public static void set_time_format_for_user (string time_format, Act.User user) { + // TODO get settings for new user + var clock_settings = new GLib.Settings ("org.gnome.desktop.interface"); + clock_settings.set_string ("clock-format", time_format); + } } From d2c5ab6c1ace2a57c610b081c36911cf720e8850 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 17 Sep 2020 19:10:25 +0200 Subject: [PATCH 04/17] Add view to set timezone --- meson_options.txt | 1 - src/Helpers/LocationHelper.vala | 127 +++++++++++++++++++++++ src/MainWindow.vala | 23 +++-- src/Objects/Configuration.vala | 3 + src/Objects/LocationLayout.vala | 87 ++++++++++++++++ src/Objects/LocationVariant.vala | 53 ++++++++++ src/Views/LocationView.vala | 166 +++++++++++++++++++++++++++++++ src/meson.build | 5 +- 8 files changed, 457 insertions(+), 8 deletions(-) create mode 100644 src/Helpers/LocationHelper.vala create mode 100644 src/Objects/LocationLayout.vala create mode 100644 src/Objects/LocationVariant.vala create mode 100644 src/Views/LocationView.vala diff --git a/meson_options.txt b/meson_options.txt index d6a4fbde..fefae3b5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,2 @@ option('supported_languages', type : 'string', value : 'aa;ab;ae;af;ak;am;an;ar;as;ast;av;ay;az;ba;be;bg;bh;bi;bm;bn;bo;br;bs;ca;ce;ch;ckb;co;cr;cs;cu;cv;cy;da;de;de_CH;de_DE;dv;dz;ee;el;en;en_US;en_AU;en_CA;en_GB;eo;es;et;eu;fa;ff;fi;fj;fo;fr;fr_BE;fr_CA;fr_FR;fy;ga;gd;gl;gn;gu;gv;ha;he;hi;ho;hr;ht;hu;hy;hz;ia;id;ie;ig;ii;ik;io;is;it;iu;ja;jv;ka;kab;kg;ki;kj;kk;kl;km;kn;ko;kr;ks;ku;kv;kw;ky;la;lb;lg;li;ln;lo;lt;lu;lv;mg;mh;mi;mk;ml;mn;mo;mr;ms;mt;my;na;nb;nd;ne;ng;nl;nn;no;nr;nv;ny;oc;oj;om;or;os;pa;pi;pl;ps;pt;pt_PT;pt_BR;qu;rm;rn;ro;ru;rue;rw;sa;sc;sd;se;sg;si;sk;sl;sm;sma;sn;so;sq;sr;ss;st;su;sv;sw;szl;ta;te;tg;th;ti;tk;tl;tn;to;tr;ts;tt;tw;ty;udm;ug;uk;ur;uz;ve;vi;vo;wa;wo;xh;yi;yo;za;zh;zh_CN;zh_HK;zh_TW;zu', description : 'The list of supported languages') option('preferred_languages', type : 'string', value : 'en;zh;es;fr;pt;ru;de', description : 'A prioritized list of languages') -option('24h_format_languages', type : 'string', value : 'de_DE', description : 'The list of languages that use 24 h format') diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala new file mode 100644 index 00000000..462e4283 --- /dev/null +++ b/src/Helpers/LocationHelper.vala @@ -0,0 +1,127 @@ +// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- +/*- + * Copyright (c) 2014 Pantheon Developers (http://launchpad.net/switchboard-plug-datetime) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Corentin Noël + */ + +public class LocationHelper : GLib.Object { + private static List lines; + private static LocationHelper? helper = null; + + public static LocationHelper get_default () { + if (helper == null) + helper = new LocationHelper (); + return helper; + } + private LocationHelper () { + var file = File.new_for_path ("/usr/share/zoneinfo/zone.tab"); + if (!file.query_exists ()) { + critical ("/usr/share/zoneinfo/zone.tab doesn't exist !"); + return; + } + + lines = new List (); + try { + var dis = new DataInputStream (file.read ()); + string line; + while ((line = dis.read_line (null)) != null) { + if (line.has_prefix ("#")) { + continue; + } + + lines.append (line); + } + } catch (Error e) { + critical (e.message); + } +#if GENERATE + generate_translation_template (); +#endif + } + + public HashTable get_timezones_from_continent (string continent) { + var timezones = new HashTable (str_hash, str_equal); + foreach (var line in lines) { + var items = line.split ("\t", 4); + string value = items[2]; + if (value.has_prefix (continent) == false) + continue; + + string tz_name_field; + // Take the original English string if there is something wrong with the translation + if (_(items[2]) == null || _(items[2]) == "") { + tz_name_field = items[2]; + } else { + tz_name_field = _(items[2]); + } + + string city = tz_name_field.split ("/", 2)[1]; + if (city != null && city != "") { + string key = format_city (city); + if (items[3] != null && items[3] != "") { + if (items[3] != "mainland" && items[3] != "most locations" && _(items[3]) != key) { + key = "%s - %s".printf (key, format_city (_(items[3]))); + } + } + + timezones.set (key, value); + } + } + + return timezones; + } + + public HashTable get_locations () { + var locations = new HashTable (str_hash, str_equal); + foreach (var line in lines) { + var items = line.split ("\t", 4); + string key = items[1]; + string value = items[2]; + locations.set (key, value); + } + + return locations; + } + + public static string format_city (string city) { + return city.replace ("_", " ").replace ("/", ", "); + } + +#if GENERATE + public void generate_translation_template () { + var file = GLib.File.new_for_path (GLib.Environment.get_home_dir () + "/Translations.vala"); + try { + var dos = new GLib.DataOutputStream (file.create (GLib.FileCreateFlags.REPLACE_DESTINATION)); + dos.put_string ("#if 0\n"); + foreach (var line in lines) { + var items = line.split ("\t", 4); + string key = items[2]; + string comment = items[3]; + dos.put_string ("///Translators: Secondary \"/\" and all \"_\" will be replaced by \", \" and \" \".\n"); + dos.put_string ("_(\""+ key + "\");\n"); + if (comment != null && comment != "") { + dos.put_string ("///Translators: Comment for Timezone %s\n".printf (key)); + dos.put_string ("_(\""+ comment + "\");\n"); + } + } + dos.put_string ("#endif\n"); + } catch (Error e) { + critical (e.message); + } + } +#endif +} \ No newline at end of file diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0827a36a..2bc38720 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -23,6 +23,7 @@ public class Installer.MainWindow : Gtk.Window { private AccountView account_view; private LanguageView language_view; + private LocationView location_view; private KeyboardLayoutView keyboard_layout_view; public MainWindow () { @@ -71,7 +72,20 @@ public class Installer.MainWindow : Gtk.Window { stack.add (keyboard_layout_view); stack.visible_child = keyboard_layout_view; - keyboard_layout_view.next_step.connect (() => load_account_view ()); + keyboard_layout_view.next_step.connect (() => load_location_view ()); + } + + private void load_location_view () { + if (location_view != null) { + location_view.destroy (); + } + + location_view = new LocationView (); + location_view.previous_view = keyboard_layout_view; + stack.add (location_view); + stack.visible_child = location_view; + + location_view.next_step.connect (() => load_account_view ()); } private void load_account_view () { @@ -80,7 +94,7 @@ public class Installer.MainWindow : Gtk.Window { } account_view = new AccountView (); - account_view.previous_view = keyboard_layout_view; + account_view.previous_view = location_view; stack.add (account_view); stack.visible_child = account_view; @@ -91,10 +105,7 @@ public class Installer.MainWindow : Gtk.Window { if (account_view.created != null) { account_view.created.set_language (Configuration.get_default ().lang); - var 24_format_lang_list = Build.24H_FORMAT_LANG_LIST.split (";"); - if (Configuration.get_default ().lang in 24_format_lang_list) { - Utils.set_time_format_for_user ("24h", account_view.created); - } + // TODO set time format based on timezone set_keyboard_layout.begin ((obj, res) => { set_keyboard_layout.end (res); diff --git a/src/Objects/Configuration.vala b/src/Objects/Configuration.vala index c5cd722a..d84ee935 100644 --- a/src/Objects/Configuration.vala +++ b/src/Objects/Configuration.vala @@ -32,4 +32,7 @@ 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 location_continent { get; set; } + public string location_city { get; set; } + public string clock_format { get; set; default = "24h"; } } diff --git a/src/Objects/LocationLayout.vala b/src/Objects/LocationLayout.vala new file mode 100644 index 00000000..002596f9 --- /dev/null +++ b/src/Objects/LocationLayout.vala @@ -0,0 +1,87 @@ +/*- + * Copyright 2019 elementary, Inc (https://elementary.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Corentin Noël + */ + +public class InitialSetup.LocationLayout : GLib.Object { + public string name { get; construct; } + public string original_name { get; construct; } + public string display_name { + get { + return name; + } + } + + private GLib.ListStore variants_store; + + public LocationLayout (string name, string original_name) { + Object (name: name, original_name: original_name); + } + + construct { + variants_store = new GLib.ListStore (typeof (LocationVariant)); + variants_store.append (new LocationVariant (this, null, null)); + } + + public void add_variant (string name, string original_name) { + var variant = new LocationVariant (this, name, original_name); + variants_store.insert_sorted (variant, (GLib.CompareDataFunc) LocationVariant.compare); + } + + public bool has_variants () { + return variants_store.get_n_items () > 1; + } + + public unowned GLib.ListStore get_variants () { + return variants_store; + } + + public GLib.Variant to_gsd_variant () { + return new GLib.Variant ("(ss)", "xkb", name); + } + + public static int compare (LocationLayout a, LocationLayout b) { + return a.display_name.collate (b.display_name); + } + + public static GLib.ListStore get_all () { + var layout_store = new GLib.ListStore (typeof (LocationLayout)); + + var continents = new List (); + continents.append ("Africa"); + continents.append ("America"); + continents.append ("Antarctica"); + continents.append ("Asia"); + continents.append ("Atlantic"); + continents.append ("Australia"); + continents.append ("Europe"); + continents.append ("Indian"); + continents.append ("Pacific"); + + continents.foreach ((continent) => { + var layout = new LocationLayout (_(continent), continent); + layout_store.insert_sorted (layout, (GLib.CompareDataFunc) LocationLayout.compare); + + var timezones = LocationHelper.get_default ().get_timezones_from_continent (continent); + timezones.foreach ((city, value) => { + layout.add_variant (_(city), city); + }); + }); + + return layout_store; + } +} diff --git a/src/Objects/LocationVariant.vala b/src/Objects/LocationVariant.vala new file mode 100644 index 00000000..4672453c --- /dev/null +++ b/src/Objects/LocationVariant.vala @@ -0,0 +1,53 @@ +/*- + * Copyright 2019 elementary, Inc (https://elementary.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Corentin Noël + */ + +public class InitialSetup.LocationVariant : GLib.Object { + public unowned LocationLayout layout { get; construct; } + public string? name { get; construct; } + public string? original_name { get; construct; } + public string display_name { + get { + return name; + } + } + + public LocationVariant (LocationLayout layout, string? name, string? original_name) { + Object (layout: layout, name: name, original_name: original_name); + } + + public GLib.Variant to_gsd_variant () { + if (name == null) { + return layout.to_gsd_variant (); + } else { + return new GLib.Variant ("(ss)", "xkb", "%s+%s".printf (layout.name, name)); + } + } + + public static int compare (LocationVariant a, LocationVariant b) { + if (a.name == null) { + return -1; + } + + if (b.name == null) { + return 1; + } + + return a.display_name.collate (b.display_name); + } +} diff --git a/src/Views/LocationView.vala b/src/Views/LocationView.vala new file mode 100644 index 00000000..501ce6fb --- /dev/null +++ b/src/Views/LocationView.vala @@ -0,0 +1,166 @@ +// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- +/*- + * Copyright (c) 2017 elementary LLC. (https://elementary.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +public class LocationView : AbstractInstallerView { + private VariantWidget location_variant_widget; + + construct { + var image = new Gtk.Image.from_icon_name ("preferences-system-time", Gtk.IconSize.DIALOG); + image.valign = Gtk.Align.END; + + var title_label = new Gtk.Label (_("Location")); + title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); + title_label.valign = Gtk.Align.START; + + location_variant_widget = new VariantWidget (); + + var helper = LocationHelper.get_default (); + + content_area.attach (image, 0, 0, 1, 1); + content_area.attach (title_label, 0, 1, 1, 1); + content_area.attach (location_variant_widget, 1, 0, 1, 2); + + var back_button = new Gtk.Button.with_label (_("Back")); + + var next_button = new Gtk.Button.with_label (_("Select")); + next_button.sensitive = false; + next_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + + action_area.add (back_button); + action_area.add (next_button); + + location_variant_widget.variant_listbox.row_activated.connect (() => { + next_button.activate (); + }); + + location_variant_widget.variant_listbox.row_selected.connect (() => { + unowned Gtk.ListBoxRow row = location_variant_widget.main_listbox.get_selected_row (); + if (row != null) { + var layout = ((LayoutRow) row).layout; + unowned Configuration configuration = Configuration.get_default (); + configuration.location_continent = layout.name; + GLib.Variant? layout_variant = null; + string second_variant = layout.name; + + unowned Gtk.ListBoxRow vrow = location_variant_widget.variant_listbox.get_selected_row (); + if (vrow != null) { + unowned InitialSetup.LocationVariant variant = ((VariantRow) vrow).variant; + configuration.location_city = variant.name; + if (variant != null) { + layout_variant = variant.to_gsd_variant (); + } + } else if (!layout.has_variants ()) { + configuration.location_city = null; + } + + if (layout_variant == null) { + layout_variant = layout.to_gsd_variant (); + } + } + }); + + back_button.clicked.connect (() => ((Gtk.Stack) get_parent ()).visible_child = previous_view); + + next_button.clicked.connect (() => { + unowned Gtk.ListBoxRow vrow = location_variant_widget.variant_listbox.get_selected_row (); + if (vrow == null) { + unowned Gtk.ListBoxRow row = location_variant_widget.main_listbox.get_selected_row (); + if (row != null) { + row.activate (); + return; + } else { + warning ("next_button enabled when no keyboard selected"); + next_button.sensitive = false; + return; + } + } + + next_step (); + }); + + location_variant_widget.main_listbox.row_activated.connect ((row) => { + unowned InitialSetup.LocationLayout layout = ((LayoutRow) row).layout; + if (!layout.has_variants ()) { + return; + } + + location_variant_widget.variant_listbox.bind_model (layout.get_variants (), (variant) => { return new VariantRow (variant as InitialSetup.LocationVariant); }); + location_variant_widget.variant_listbox.select_row (location_variant_widget.variant_listbox.get_row_at_index (0)); + + location_variant_widget.show_variants (_("Continent"), "%s".printf (layout.display_name)); + }); + + location_variant_widget.main_listbox.row_selected.connect ((row) => { + next_button.sensitive = true; + }); + + location_variant_widget.main_listbox.bind_model (InitialSetup.LocationLayout.get_all (), (layout) => { return new LayoutRow (layout as InitialSetup.LocationLayout); }); + + show_all (); + + Idle.add (() => { + unowned string? country = Configuration.get_default ().country; + if (country != null) { + string default_layout = country.down (); + + foreach (weak Gtk.Widget child in location_variant_widget.main_listbox.get_children ()) { + if (child is LayoutRow) { + weak LayoutRow row = (LayoutRow) child; + if (row.layout.name == default_layout) { + location_variant_widget.main_listbox.select_row (row); + row.grab_focus (); + break; + } + } + } + } + }); + } + + private class LayoutRow : Gtk.ListBoxRow { + public unowned InitialSetup.LocationLayout layout; + public LayoutRow (InitialSetup.LocationLayout layout) { + this.layout = layout; + + string layout_description = layout.display_name; + if (layout.has_variants ()) { + layout_description = _("%s…").printf (layout_description); + } + + var label = new Gtk.Label (layout_description); + label.margin = 6; + label.xalign = 0; + label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + add (label); + show_all (); + } + } + + private class VariantRow : Gtk.ListBoxRow { + public unowned InitialSetup.LocationVariant variant; + public VariantRow (InitialSetup.LocationVariant variant) { + this.variant = variant; + var label = new Gtk.Label (variant.display_name); + label.margin = 6; + label.xalign = 0; + label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + add (label); + show_all (); + } + } +} diff --git a/src/meson.build b/src/meson.build index 3e12462d..01637dd0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,14 +4,18 @@ vala_files = [ 'MainWindow.vala', 'Helpers/AccountsServiceInterface.vala', 'Helpers/LocaleHelper.vala', + 'Helpers/LocationHelper.vala', 'Objects/Configuration.vala', 'Objects/KeyboardLayout.vala', 'Objects/KeyboardVariant.vala', + 'Objects/LocationLayout.vala', + 'Objects/LocationVariant.vala', 'Utils.vala', 'Views/AbstractInstallerView.vala', 'Views/AccountView.vala', 'Views/KeyboardLayoutView.vala', 'Views/LanguageView.vala', + 'Views/LocationView.vala', 'Widgets/LayoutWidget.vala', 'Widgets/VariantWidget.vala' ] @@ -20,7 +24,6 @@ configuration_data = configuration_data() configuration_data.set('GETTEXT_PACKAGE', meson.project_name()) configuration_data.set('LANG_LIST', get_option('supported_languages')) configuration_data.set('PREFERRED_LANG_LIST', get_option('preferred_languages')) -configuration_data.set('24H_FORMAT_LANG_LIST', get_option('24h_format_languages')) xkbconf = dependency('xkeyboard-config') xkb_base = xkbconf.get_pkgconfig_variable('xkb_base') From 4e3f81c59510a94916c07cb123f83175b776c90b Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 17 Sep 2020 19:12:45 +0200 Subject: [PATCH 05/17] Satisfy linter --- src/Config.vala.in | 12 ++++++------ src/Helpers/LocationHelper.vala | 2 +- src/Objects/LocationLayout.vala | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Config.vala.in b/src/Config.vala.in index a000b193..2c9cb892 100644 --- a/src/Config.vala.in +++ b/src/Config.vala.in @@ -1,8 +1,8 @@ namespace Build { - public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"; - public const string LANG_LIST = "@LANG_LIST@"; - public const string PREFERRED_LANG_LIST = "@PREFERRED_LANG_LIST@"; - public const string 24H_FORMAT_LANG_LIST = "@24H_FORMAT_LANG_LIST@"; - public const string XKB_BASE = "@XKB_BASE@"; - public const string ISO_CODES_LOCATION = "@ISO_CODES_LOCATION@"; + public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"; + public const string LANG_LIST = "@LANG_LIST@"; + public const string PREFERRED_LANG_LIST = "@PREFERRED_LANG_LIST@"; + public const string 24H_FORMAT_LANG_LIST = "@24H_FORMAT_LANG_LIST@"; + public const string XKB_BASE = "@XKB_BASE@"; + public const string ISO_CODES_LOCATION = "@ISO_CODES_LOCATION@"; } diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index 462e4283..7c539ca4 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -124,4 +124,4 @@ public class LocationHelper : GLib.Object { } } #endif -} \ No newline at end of file +} diff --git a/src/Objects/LocationLayout.vala b/src/Objects/LocationLayout.vala index 002596f9..ec263406 100644 --- a/src/Objects/LocationLayout.vala +++ b/src/Objects/LocationLayout.vala @@ -17,7 +17,7 @@ * Authored by: Corentin Noël */ -public class InitialSetup.LocationLayout : GLib.Object { +public class InitialSetup.LocationLayout : GLib.Object { public string name { get; construct; } public string original_name { get; construct; } public string display_name { From 83aaa9ffb4883959fc789aa685d6822226e1f77e Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 17 Sep 2020 20:06:46 +0200 Subject: [PATCH 06/17] Set timezone on system --- src/Helpers/LocationHelper.vala | 14 +++++++++++++ src/MainWindow.vala | 11 ++++++++++ src/Objects/Configuration.vala | 3 +-- src/Objects/LocationLayout.vala | 4 ++-- src/Views/LocationView.vala | 36 +-------------------------------- 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index 7c539ca4..7220d576 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -19,6 +19,20 @@ */ public class LocationHelper : GLib.Object { + [DBus (name = "org.freedesktop.timedate1")] + public interface DateTime1 : Object { + public abstract string Timezone {public owned get;} + public abstract bool LocalRTC {public get;} + public abstract bool CanNTP {public get;} + public abstract bool NTP {public get;} + + //usec_utc expects number of microseconds since 1 Jan 1970 UTC + public abstract void set_time (int64 usec_utc, bool relative, bool user_interaction) throws GLib.Error; + public abstract void set_timezone (string timezone, bool user_interaction) throws GLib.Error; + public abstract void SetLocalRTC (bool local_rtc, bool fix_system, bool user_interaction) throws GLib.Error; //vala-lint=naming-convention + public abstract void SetNTP (bool use_ntp, bool user_interaction) throws GLib.Error; //vala-lint=naming-convention + } + private static List lines; private static LocationHelper? helper = null; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index b7f9d77e..110d2616 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -100,6 +100,7 @@ public class Installer.MainWindow : Hdy.Window { account_view.created.set_language (Configuration.get_default ().lang); // TODO set time format based on timezone + set_timezone (); set_keyboard_layout.begin ((obj, res) => { set_keyboard_layout.end (res); @@ -111,6 +112,16 @@ public class Installer.MainWindow : Hdy.Window { } + private void set_timezone () { + try { + LocationHelper.DateTime1 datetime1 = Bus.get_proxy_sync (BusType.SYSTEM, "org.freedesktop.timedate1", "/org/freedesktop/timedate1"); + unowned Configuration configuration = Configuration.get_default (); + datetime1.set_timezone (configuration.timezone, true); + } catch (Error e) { + warning (e.message); + } + } + private async void set_keyboard_layout () { AccountsService accounts_service = null; diff --git a/src/Objects/Configuration.vala b/src/Objects/Configuration.vala index d84ee935..a184822b 100644 --- a/src/Objects/Configuration.vala +++ b/src/Objects/Configuration.vala @@ -32,7 +32,6 @@ 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 location_continent { get; set; } - public string location_city { get; set; } + public string timezone { get; set; } public string clock_format { get; set; default = "24h"; } } diff --git a/src/Objects/LocationLayout.vala b/src/Objects/LocationLayout.vala index ec263406..c36bf046 100644 --- a/src/Objects/LocationLayout.vala +++ b/src/Objects/LocationLayout.vala @@ -77,8 +77,8 @@ public class InitialSetup.LocationLayout : GLib.Object { layout_store.insert_sorted (layout, (GLib.CompareDataFunc) LocationLayout.compare); var timezones = LocationHelper.get_default ().get_timezones_from_continent (continent); - timezones.foreach ((city, value) => { - layout.add_variant (_(city), city); + timezones.foreach ((city, timezone) => { + layout.add_variant (_(city), timezone); }); }); diff --git a/src/Views/LocationView.vala b/src/Views/LocationView.vala index 501ce6fb..1987b2e4 100644 --- a/src/Views/LocationView.vala +++ b/src/Views/LocationView.vala @@ -53,19 +53,16 @@ public class LocationView : AbstractInstallerView { if (row != null) { var layout = ((LayoutRow) row).layout; unowned Configuration configuration = Configuration.get_default (); - configuration.location_continent = layout.name; GLib.Variant? layout_variant = null; string second_variant = layout.name; unowned Gtk.ListBoxRow vrow = location_variant_widget.variant_listbox.get_selected_row (); if (vrow != null) { unowned InitialSetup.LocationVariant variant = ((VariantRow) vrow).variant; - configuration.location_city = variant.name; + configuration.timezone = variant.original_name; if (variant != null) { layout_variant = variant.to_gsd_variant (); } - } else if (!layout.has_variants ()) { - configuration.location_city = null; } if (layout_variant == null) { @@ -77,19 +74,6 @@ public class LocationView : AbstractInstallerView { back_button.clicked.connect (() => ((Gtk.Stack) get_parent ()).visible_child = previous_view); next_button.clicked.connect (() => { - unowned Gtk.ListBoxRow vrow = location_variant_widget.variant_listbox.get_selected_row (); - if (vrow == null) { - unowned Gtk.ListBoxRow row = location_variant_widget.main_listbox.get_selected_row (); - if (row != null) { - row.activate (); - return; - } else { - warning ("next_button enabled when no keyboard selected"); - next_button.sensitive = false; - return; - } - } - next_step (); }); @@ -112,24 +96,6 @@ public class LocationView : AbstractInstallerView { location_variant_widget.main_listbox.bind_model (InitialSetup.LocationLayout.get_all (), (layout) => { return new LayoutRow (layout as InitialSetup.LocationLayout); }); show_all (); - - Idle.add (() => { - unowned string? country = Configuration.get_default ().country; - if (country != null) { - string default_layout = country.down (); - - foreach (weak Gtk.Widget child in location_variant_widget.main_listbox.get_children ()) { - if (child is LayoutRow) { - weak LayoutRow row = (LayoutRow) child; - if (row.layout.name == default_layout) { - location_variant_widget.main_listbox.select_row (row); - row.grab_focus (); - break; - } - } - } - } - }); } private class LayoutRow : Gtk.ListBoxRow { From 3507df5cb85ba0006b13ed174567c8b52a494244 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 17 Sep 2020 20:54:44 +0200 Subject: [PATCH 07/17] Set clock format for user based on countrycode found by timezone --- meson_options.txt | 1 + src/Config.vala.in | 2 +- src/Helpers/LocationHelper.vala | 13 +++++++++++++ src/MainWindow.vala | 17 ++++++++++++++++- src/Utils.vala | 4 ++-- src/meson.build | 1 + 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index fefae3b5..0cea2126 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ option('supported_languages', type : 'string', value : 'aa;ab;ae;af;ak;am;an;ar;as;ast;av;ay;az;ba;be;bg;bh;bi;bm;bn;bo;br;bs;ca;ce;ch;ckb;co;cr;cs;cu;cv;cy;da;de;de_CH;de_DE;dv;dz;ee;el;en;en_US;en_AU;en_CA;en_GB;eo;es;et;eu;fa;ff;fi;fj;fo;fr;fr_BE;fr_CA;fr_FR;fy;ga;gd;gl;gn;gu;gv;ha;he;hi;ho;hr;ht;hu;hy;hz;ia;id;ie;ig;ii;ik;io;is;it;iu;ja;jv;ka;kab;kg;ki;kj;kk;kl;km;kn;ko;kr;ks;ku;kv;kw;ky;la;lb;lg;li;ln;lo;lt;lu;lv;mg;mh;mi;mk;ml;mn;mo;mr;ms;mt;my;na;nb;nd;ne;ng;nl;nn;no;nr;nv;ny;oc;oj;om;or;os;pa;pi;pl;ps;pt;pt_PT;pt_BR;qu;rm;rn;ro;ru;rue;rw;sa;sc;sd;se;sg;si;sk;sl;sm;sma;sn;so;sq;sr;ss;st;su;sv;sw;szl;ta;te;tg;th;ti;tk;tl;tn;to;tr;ts;tt;tw;ty;udm;ug;uk;ur;uz;ve;vi;vo;wa;wo;xh;yi;yo;za;zh;zh_CN;zh_HK;zh_TW;zu', description : 'The list of supported languages') option('preferred_languages', type : 'string', value : 'en;zh;es;fr;pt;ru;de', description : 'A prioritized list of languages') +option('12h_format_countries', type : 'string', value : 'AU;CA;CO;EG;IN;MY;NZ;PH;PK;SA;SG;UK;US;ZA', description : 'The list of countries using 12h format') diff --git a/src/Config.vala.in b/src/Config.vala.in index 2c9cb892..500b524f 100644 --- a/src/Config.vala.in +++ b/src/Config.vala.in @@ -2,7 +2,7 @@ namespace Build { public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"; public const string LANG_LIST = "@LANG_LIST@"; public const string PREFERRED_LANG_LIST = "@PREFERRED_LANG_LIST@"; - public const string 24H_FORMAT_LANG_LIST = "@24H_FORMAT_LANG_LIST@"; + public const string 12H_FORMAT_COUNTRIES_LIST = "@12H_FORMAT_COUNTRIES_LIST@"; public const string XKB_BASE = "@XKB_BASE@"; public const string ISO_CODES_LOCATION = "@ISO_CODES_LOCATION@"; } diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index 7220d576..f132b62d 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -99,6 +99,19 @@ public class LocationHelper : GLib.Object { return timezones; } + public string? get_countrycode_from_timezone (string timezone) { + foreach (var line in lines) { + var items = line.split ("\t", 4); + string value = items[2]; + + if (value == timezone) { + return items[0]; + } + } + + return null; + } + public HashTable get_locations () { var locations = new HashTable (str_hash, str_equal); foreach (var line in lines) { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 110d2616..0a795a26 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -99,7 +99,8 @@ public class Installer.MainWindow : Hdy.Window { if (account_view.created != null) { account_view.created.set_language (Configuration.get_default ().lang); - // TODO set time format based on timezone + set_clock_format_for_user (account_view.created); + set_timezone (); set_keyboard_layout.begin ((obj, res) => { @@ -122,6 +123,20 @@ public class Installer.MainWindow : Hdy.Window { } } + private void set_clock_format_for_user (Act.User user) { + unowned Configuration configuration = Configuration.get_default (); + + var countrycode = LocationHelper.get_default ().get_countrycode_from_timezone (Configuration.get_default ().timezone); + if (countrycode != null) { + var 12h_format_countries_list = Build.12H_FORMAT_COUNTRIES_LIST.split (";"); + if (countrycode in 12h_format_countries_list) { + configuration.clock_format = "12h"; + } + } + + Utils.set_clock_format_for_user (configuration.clock_format, user); + } + private async void set_keyboard_layout () { AccountsService accounts_service = null; diff --git a/src/Utils.vala b/src/Utils.vala index a41eca3d..336233fe 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -125,9 +125,9 @@ namespace Utils { return username; } - public static void set_time_format_for_user (string time_format, Act.User user) { + public static void set_clock_format_for_user (string clock_format, Act.User user) { // TODO get settings for new user var clock_settings = new GLib.Settings ("org.gnome.desktop.interface"); - clock_settings.set_string ("clock-format", time_format); + clock_settings.set_string ("clock-format", clock_format); } } diff --git a/src/meson.build b/src/meson.build index 01637dd0..61e3e78b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -24,6 +24,7 @@ configuration_data = configuration_data() configuration_data.set('GETTEXT_PACKAGE', meson.project_name()) configuration_data.set('LANG_LIST', get_option('supported_languages')) configuration_data.set('PREFERRED_LANG_LIST', get_option('preferred_languages')) +configuration_data.set('12H_FORMAT_COUNTRIES_LIST', get_option('12h_format_countries')) xkbconf = dependency('xkeyboard-config') xkb_base = xkbconf.get_pkgconfig_variable('xkb_base') From a2ad4dd04f3f7e986546b7ba9f9851687af05757 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 17 Sep 2020 20:55:31 +0200 Subject: [PATCH 08/17] Satisfy linter --- src/Helpers/LocationHelper.vala | 2 +- src/MainWindow.vala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index f132b62d..6b8c7e08 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -103,7 +103,7 @@ public class LocationHelper : GLib.Object { foreach (var line in lines) { var items = line.split ("\t", 4); string value = items[2]; - + if (value == timezone) { return items[0]; } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0a795a26..e5bb26dc 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -128,7 +128,7 @@ public class Installer.MainWindow : Hdy.Window { var countrycode = LocationHelper.get_default ().get_countrycode_from_timezone (Configuration.get_default ().timezone); if (countrycode != null) { - var 12h_format_countries_list = Build.12H_FORMAT_COUNTRIES_LIST.split (";"); + var 12h_format_countries_list = Build.12H_FORMAT_COUNTRIES_LIST.split (";"); if (countrycode in 12h_format_countries_list) { configuration.clock_format = "12h"; } From 0f749824786ebe9d2d4a869b2c514de53f98eac3 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 19 Sep 2020 11:07:29 +0200 Subject: [PATCH 09/17] Set clock format based on Posix.NLItem.T_FMT --- meson_options.txt | 1 - src/Config.vala.in | 1 - src/Helpers/LocationHelper.vala | 10 ++++++++++ src/MainWindow.vala | 12 +++--------- src/meson.build | 1 - 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index 0cea2126..fefae3b5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,2 @@ option('supported_languages', type : 'string', value : 'aa;ab;ae;af;ak;am;an;ar;as;ast;av;ay;az;ba;be;bg;bh;bi;bm;bn;bo;br;bs;ca;ce;ch;ckb;co;cr;cs;cu;cv;cy;da;de;de_CH;de_DE;dv;dz;ee;el;en;en_US;en_AU;en_CA;en_GB;eo;es;et;eu;fa;ff;fi;fj;fo;fr;fr_BE;fr_CA;fr_FR;fy;ga;gd;gl;gn;gu;gv;ha;he;hi;ho;hr;ht;hu;hy;hz;ia;id;ie;ig;ii;ik;io;is;it;iu;ja;jv;ka;kab;kg;ki;kj;kk;kl;km;kn;ko;kr;ks;ku;kv;kw;ky;la;lb;lg;li;ln;lo;lt;lu;lv;mg;mh;mi;mk;ml;mn;mo;mr;ms;mt;my;na;nb;nd;ne;ng;nl;nn;no;nr;nv;ny;oc;oj;om;or;os;pa;pi;pl;ps;pt;pt_PT;pt_BR;qu;rm;rn;ro;ru;rue;rw;sa;sc;sd;se;sg;si;sk;sl;sm;sma;sn;so;sq;sr;ss;st;su;sv;sw;szl;ta;te;tg;th;ti;tk;tl;tn;to;tr;ts;tt;tw;ty;udm;ug;uk;ur;uz;ve;vi;vo;wa;wo;xh;yi;yo;za;zh;zh_CN;zh_HK;zh_TW;zu', description : 'The list of supported languages') option('preferred_languages', type : 'string', value : 'en;zh;es;fr;pt;ru;de', description : 'A prioritized list of languages') -option('12h_format_countries', type : 'string', value : 'AU;CA;CO;EG;IN;MY;NZ;PH;PK;SA;SG;UK;US;ZA', description : 'The list of countries using 12h format') diff --git a/src/Config.vala.in b/src/Config.vala.in index 500b524f..550688d7 100644 --- a/src/Config.vala.in +++ b/src/Config.vala.in @@ -2,7 +2,6 @@ namespace Build { public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"; public const string LANG_LIST = "@LANG_LIST@"; public const string PREFERRED_LANG_LIST = "@PREFERRED_LANG_LIST@"; - public const string 12H_FORMAT_COUNTRIES_LIST = "@12H_FORMAT_COUNTRIES_LIST@"; public const string XKB_BASE = "@XKB_BASE@"; public const string ISO_CODES_LOCATION = "@ISO_CODES_LOCATION@"; } diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index 6b8c7e08..d0ebdb14 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -128,6 +128,16 @@ public class LocationHelper : GLib.Object { return city.replace ("_", " ").replace ("/", ", "); } + public static string get_clock_format () { + var T_FMT = Posix.nl_langinfo (Posix.NLItem.T_FMT); + + if (T_FMT.contains ("%r") || T_FMT.contains ("%l") || T_FMT.contains ("%I")) { + return "12h"; + } + + return "24h"; + } + #if GENERATE public void generate_translation_template () { var file = GLib.File.new_for_path (GLib.Environment.get_home_dir () + "/Translations.vala"); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e5bb26dc..f7da548e 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -99,10 +99,10 @@ public class Installer.MainWindow : Hdy.Window { if (account_view.created != null) { account_view.created.set_language (Configuration.get_default ().lang); - set_clock_format_for_user (account_view.created); - set_timezone (); + set_clock_format_for_user (account_view.created); + set_keyboard_layout.begin ((obj, res) => { set_keyboard_layout.end (res); destroy (); @@ -126,13 +126,7 @@ public class Installer.MainWindow : Hdy.Window { private void set_clock_format_for_user (Act.User user) { unowned Configuration configuration = Configuration.get_default (); - var countrycode = LocationHelper.get_default ().get_countrycode_from_timezone (Configuration.get_default ().timezone); - if (countrycode != null) { - var 12h_format_countries_list = Build.12H_FORMAT_COUNTRIES_LIST.split (";"); - if (countrycode in 12h_format_countries_list) { - configuration.clock_format = "12h"; - } - } + configuration.clock_format = LocationHelper.get_default ().get_clock_format (); Utils.set_clock_format_for_user (configuration.clock_format, user); } diff --git a/src/meson.build b/src/meson.build index 61e3e78b..01637dd0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -24,7 +24,6 @@ configuration_data = configuration_data() configuration_data.set('GETTEXT_PACKAGE', meson.project_name()) configuration_data.set('LANG_LIST', get_option('supported_languages')) configuration_data.set('PREFERRED_LANG_LIST', get_option('preferred_languages')) -configuration_data.set('12H_FORMAT_COUNTRIES_LIST', get_option('12h_format_countries')) xkbconf = dependency('xkeyboard-config') xkb_base = xkbconf.get_pkgconfig_variable('xkb_base') From 9014707b991d29c16f2d9436fea3f5f5be595a5d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 19 Sep 2020 11:08:12 +0200 Subject: [PATCH 10/17] Satisfy linter --- src/Helpers/LocationHelper.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index d0ebdb14..29a23710 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -129,7 +129,7 @@ public class LocationHelper : GLib.Object { } public static string get_clock_format () { - var T_FMT = Posix.nl_langinfo (Posix.NLItem.T_FMT); + const string T_FMT = Posix.nl_langinfo (Posix.NLItem.T_FMT); if (T_FMT.contains ("%r") || T_FMT.contains ("%l") || T_FMT.contains ("%I")) { return "12h"; From 2f8f2454d553e30e86144a93e84a8764425af40d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 19 Sep 2020 11:12:51 +0200 Subject: [PATCH 11/17] Refactor --- src/Helpers/LocationHelper.vala | 4 ++-- src/MainWindow.vala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Helpers/LocationHelper.vala b/src/Helpers/LocationHelper.vala index 29a23710..155c9c76 100644 --- a/src/Helpers/LocationHelper.vala +++ b/src/Helpers/LocationHelper.vala @@ -129,9 +129,9 @@ public class LocationHelper : GLib.Object { } public static string get_clock_format () { - const string T_FMT = Posix.nl_langinfo (Posix.NLItem.T_FMT); + var t_fmt = Posix.nl_langinfo (Posix.NLItem.T_FMT); - if (T_FMT.contains ("%r") || T_FMT.contains ("%l") || T_FMT.contains ("%I")) { + if (t_fmt.contains ("%r") || t_fmt.contains ("%l") || t_fmt.contains ("%I")) { return "12h"; } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f7da548e..e685931c 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -126,7 +126,7 @@ public class Installer.MainWindow : Hdy.Window { private void set_clock_format_for_user (Act.User user) { unowned Configuration configuration = Configuration.get_default (); - configuration.clock_format = LocationHelper.get_default ().get_clock_format (); + configuration.clock_format = LocationHelper.get_clock_format (); Utils.set_clock_format_for_user (configuration.clock_format, user); } From 9dc9cb7148541721ff9a7610b660a16f4e753131 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 23 Sep 2020 14:27:37 -0400 Subject: [PATCH 12/17] Set clock format for created user --- src/Utils.vala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Utils.vala b/src/Utils.vala index 336233fe..bc3bcd07 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -126,8 +126,13 @@ namespace Utils { } public static void set_clock_format_for_user (string clock_format, Act.User user) { - // TODO get settings for new user - var clock_settings = new GLib.Settings ("org.gnome.desktop.interface"); + var settings_backend = SettingsBackend.keyfile_settings_backend_new ( + "user", + "%s/.config/dconf/".printf (user.get_home_dir ()), + null + ); + + var clock_settings = new GLib.Settings.with_backend ("org.gnome.desktop.interface", settings_backend); clock_settings.set_string ("clock-format", clock_format); } } From b1b14712a169c11dd31d39d98b95972ac110ef3f Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 23 Sep 2020 20:28:57 +0200 Subject: [PATCH 13/17] Satisfy linter --- src/Utils.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils.vala b/src/Utils.vala index bc3bcd07..9b144af2 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -131,7 +131,7 @@ namespace Utils { "%s/.config/dconf/".printf (user.get_home_dir ()), null ); - + var clock_settings = new GLib.Settings.with_backend ("org.gnome.desktop.interface", settings_backend); clock_settings.set_string ("clock-format", clock_format); } From 0be493ca3a362ccbb52c48abe717c15746793d1d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 26 Sep 2020 08:37:54 +0200 Subject: [PATCH 14/17] Write clock format to accounts service --- src/Helpers/AccountsServiceInterface.vala | 1 + src/MainWindow.vala | 24 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Helpers/AccountsServiceInterface.vala b/src/Helpers/AccountsServiceInterface.vala index 05073f94..adeed0f5 100644 --- a/src/Helpers/AccountsServiceInterface.vala +++ b/src/Helpers/AccountsServiceInterface.vala @@ -7,6 +7,7 @@ interface Installer.AccountsService : Object { public abstract KeyboardLayout[] keyboard_layouts { owned get; set; } public abstract uint active_keyboard_layout { get; set; } + public abstract string clock_format { get; set; } } [DBus (name = "org.freedesktop.Accounts")] diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e685931c..0a0a5d02 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -101,7 +101,7 @@ public class Installer.MainWindow : Hdy.Window { set_timezone (); - set_clock_format_for_user (account_view.created); + set_clock_format (); set_keyboard_layout.begin ((obj, res) => { set_keyboard_layout.end (res); @@ -123,12 +123,26 @@ public class Installer.MainWindow : Hdy.Window { } } - private void set_clock_format_for_user (Act.User user) { - unowned Configuration configuration = Configuration.get_default (); + private void set_clock_format () { + AccountsService accounts_service = null; - configuration.clock_format = LocationHelper.get_clock_format (); + try { + var act_service = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM, + "org.freedesktop.Accounts", + "/org/freedesktop/Accounts"); + var user_path = act_service.find_user_by_name (account_view.created.user_name); - Utils.set_clock_format_for_user (configuration.clock_format, user); + accounts_service = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM, + "org.freedesktop.Accounts", + user_path, + GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES); + } catch (Error e) { + warning ("Unable to get AccountsService proxy, clock format on new user may be incorrect: %s", e.message); + } + + if (accounts_service != null) { + accounts_service.clock_format = Configuration.get_default ().clock_format; + } } private async void set_keyboard_layout () { From 49787b4c41305380c042b9457fcf16739b083254 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 26 Sep 2020 08:44:51 +0200 Subject: [PATCH 15/17] Change to owned get accessor --- src/Helpers/AccountsServiceInterface.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/AccountsServiceInterface.vala b/src/Helpers/AccountsServiceInterface.vala index adeed0f5..bc570e5f 100644 --- a/src/Helpers/AccountsServiceInterface.vala +++ b/src/Helpers/AccountsServiceInterface.vala @@ -7,7 +7,7 @@ interface Installer.AccountsService : Object { public abstract KeyboardLayout[] keyboard_layouts { owned get; set; } public abstract uint active_keyboard_layout { get; set; } - public abstract string clock_format { get; set; } + public abstract string clock_format { owned get; set; } } [DBus (name = "org.freedesktop.Accounts")] From a5ece22bb3f44b0bfa849de672dc2511166ed8e2 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 26 Sep 2020 08:50:36 +0200 Subject: [PATCH 16/17] Delete unused function --- src/Utils.vala | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Utils.vala b/src/Utils.vala index 9b144af2..a09aeb08 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -124,15 +124,4 @@ namespace Utils { return username; } - - public static void set_clock_format_for_user (string clock_format, Act.User user) { - var settings_backend = SettingsBackend.keyfile_settings_backend_new ( - "user", - "%s/.config/dconf/".printf (user.get_home_dir ()), - null - ); - - var clock_settings = new GLib.Settings.with_backend ("org.gnome.desktop.interface", settings_backend); - clock_settings.set_string ("clock-format", clock_format); - } } From ccaf1b4031b6a70c1694ea27a36a2e356dd821f1 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 27 Sep 2020 12:47:53 +0200 Subject: [PATCH 17/17] Chain async methods --- src/MainWindow.vala | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0a0a5d02..14cb6db7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -99,12 +99,8 @@ public class Installer.MainWindow : Hdy.Window { if (account_view.created != null) { account_view.created.set_language (Configuration.get_default ().lang); - set_timezone (); - - set_clock_format (); - - set_keyboard_layout.begin ((obj, res) => { - set_keyboard_layout.end (res); + set_settings.begin ((obj, res) => { + set_settings.end (res); destroy (); }); } else { @@ -113,9 +109,9 @@ public class Installer.MainWindow : Hdy.Window { } - private void set_timezone () { + private async void set_timezone () { try { - LocationHelper.DateTime1 datetime1 = Bus.get_proxy_sync (BusType.SYSTEM, "org.freedesktop.timedate1", "/org/freedesktop/timedate1"); + LocationHelper.DateTime1 datetime1 = yield Bus.get_proxy (BusType.SYSTEM, "org.freedesktop.timedate1", "/org/freedesktop/timedate1"); unowned Configuration configuration = Configuration.get_default (); datetime1.set_timezone (configuration.timezone, true); } catch (Error e) { @@ -123,16 +119,16 @@ public class Installer.MainWindow : Hdy.Window { } } - private void set_clock_format () { + private async void set_clock_format () { AccountsService accounts_service = null; try { - var act_service = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM, + var act_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM, "org.freedesktop.Accounts", "/org/freedesktop/Accounts"); var user_path = act_service.find_user_by_name (account_view.created.user_name); - accounts_service = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM, + accounts_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM, "org.freedesktop.Accounts", user_path, GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES); @@ -173,4 +169,10 @@ public class Installer.MainWindow : Hdy.Window { accounts_service.keyboard_layouts = { layout }; } } + + private async void set_settings () { + yield set_timezone (); + yield set_clock_format (); + yield set_keyboard_layout (); + } }