Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Select First Day of Week for Locale #127

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c996352
OK, Let's roll.
Nov 12, 2020
dde3770
Satisfy linter.
Nov 12, 2020
6f193a7
* - fix setting First Day
Nov 13, 2020
12a4730
* - make it use an int instead for easier use
Nov 13, 2020
ccf2383
* - fixed things
Nov 14, 2020
2372ceb
* - review points
Nov 17, 2020
ff79d31
* - further review points
Nov 17, 2020
a15753f
* - use enum for easier futureproof
Nov 17, 2020
54a0dd9
Merge branch 'master' into first-day-of-week
Nov 18, 2020
7436c20
* - reduce options to real world usage options
Nov 18, 2020
3f29bd1
Merge branch 'first-day-of-week' of https://github.com/lainsce/switch…
Nov 18, 2020
82aa07b
* - forgot to update gschema enum
Nov 18, 2020
b5de7f1
* - update first day store to store index as well
Nov 19, 2020
7c86cf5
* - fix an oops
Nov 19, 2020
767d4a9
*
Nov 19, 2020
427bddf
* - small thing
Nov 19, 2020
bb3f4ec
Simplify combobox
Nov 20, 2020
151226b
Merge pull request #1 from elementary/jeremypw/first-day-of-week
lainsce Nov 20, 2020
aeaef74
Update src/Widgets/LocaleSetting.vala
lainsce Nov 24, 2020
219bd6c
Update src/Widgets/LocaleSetting.vala
lainsce Nov 24, 2020
3f05479
* - adjust enum to futureproof it
Nov 24, 2020
9e3137c
Update data/io.elementary.switchboard.locale.gschema.xml
lainsce Dec 9, 2020
91b8c5e
Update src/Widgets/LocaleSetting.vala
lainsce Dec 9, 2020
b2e8ccb
Update src/LocaleManager.vala
lainsce Dec 9, 2020
3f99160
Merge branch 'master' into first-day-of-week
lainsce Feb 6, 2021
f000bb3
Merge branch 'master' into first-day-of-week
lainsce Apr 14, 2021
c9077e8
Merge branch 'master' into first-day-of-week
Jun 22, 2021
8614671
Merge branch 'master' into first-day-of-week
lainsce Jan 11, 2022
fe783cd
*
lainsce Jan 12, 2022
56f7259
Merge branch 'master' into first-day-of-week
lainsce Apr 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion data/io.elementary.switchboard.locale.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<enum id='first-day'>
<value nick='Sunday' value='0'/>
<value nick='Monday' value='1'/>
<value nick='Friday' value='2'/>
<value nick='Saturday' value='3'/>
</enum>
<schema path="/io/elementary/switchboard/locale/" id="io.elementary.switchboard.locale">
<key name="input-selections" type="a(ss)">
<default>[]</default>
<summary>Saves selected input sources per language.</summary>
<description>Saves selected input sources per language.</description>
</key>

<key name='week-start-day-name' enum='first-day'>
<default>'Sunday'</default>
<summary>Saves the First Day of the Week for use in locale settings such as a calendar display.</summary>
<description>Saves the First Day of the Week for use in locale settings such as a calendar display.</description>
</key>
</schema>
</schemalist>
9 changes: 9 additions & 0 deletions src/LocaleManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface AccountProxy : GLib.Object {
public abstract void set_formats_locale (string formats_locale) throws GLib.Error;
public abstract void set_language (string language) throws GLib.Error;
public abstract string formats_locale { owned get; }
public abstract string first_day { owned get; }
public abstract string language { owned get; }
}

Expand Down Expand Up @@ -127,6 +128,14 @@ namespace SwitchboardPlugLocale {
return account_proxy.formats_locale;
}

public void set_user_first_day (int first_day) {
settings.set_enum ("week-start-day-name", first_day.clamp (0, 6));
lainsce marked this conversation as resolved.
Show resolved Hide resolved
}

public int get_user_first_day () {
return settings.get_enum ("week-start-day-name");
}

private void localectl_set_locale (string locale, string? format = null) throws GLib.Error {
debug ("setting system-wide locale via localectl");
if (Utils.get_permission ().allowed) {
Expand Down
57 changes: 54 additions & 3 deletions src/Widgets/LocaleSetting.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ namespace SwitchboardPlugLocale.Widgets {
private Gtk.Button set_button;
private Gtk.ComboBox format_combobox;
private Gtk.ComboBox region_combobox;
private Gtk.ComboBox first_day_combobox;
private Gtk.ListStore format_store;
private Gtk.ListStore region_store;
private Gtk.ListStore first_day_store;

private LocaleManager lm;
private Preview preview;
private string language;
private string selected_language = "";
private string selected_format = "";
private int selected_first_day;
private bool has_region;
private EndLabel region_endlabel;
private EndLabel first_day_endlabel;

private static GLib.Settings? temperature_settings = null;

Expand Down Expand Up @@ -62,26 +66,40 @@ namespace SwitchboardPlugLocale.Widgets {
format_combobox.changed.connect (compare);
format_combobox.active = 0;

first_day_store = new Gtk.ListStore (2, typeof (string), typeof (int));

first_day_combobox = new Gtk.ComboBox.with_model (first_day_store);
first_day_combobox.pack_start (renderer, true);
first_day_combobox.add_attribute (renderer, "text", 0);
first_day_combobox.active = lm.get_user_first_day ();
first_day_combobox.changed.connect (() => {
lm.set_user_first_day (first_day_combobox.active);
compare ();
});
lainsce marked this conversation as resolved.
Show resolved Hide resolved

preview = new Preview ();
preview.margin_bottom = 12;
preview.margin_top = 12;

region_endlabel = new EndLabel (_("Region: "));
first_day_endlabel = new EndLabel (_("First Day of Week:"));

content_area.halign = Gtk.Align.CENTER;
content_area.attach (region_endlabel, 0, 2, 1, 1);
content_area.attach (region_combobox, 1, 2, 1, 1);
content_area.attach (new EndLabel (_("Formats: ")), 0, 3, 1, 1);
content_area.attach (format_combobox, 1, 3, 1, 1);
content_area.attach (preview, 0, 5, 2, 1);
content_area.attach (first_day_endlabel, 0, 4, 1, 1);
content_area.attach (first_day_combobox, 1, 4, 1, 1);
content_area.attach (preview, 0, 6, 2, 1);
lainsce marked this conversation as resolved.
Show resolved Hide resolved

if (temperature_settings != null) {
var temperature = new Granite.Widgets.ModeButton ();
temperature.append_text (_("Celsius"));
temperature.append_text (_("Fahrenheit"));

content_area.attach (new EndLabel (_("Temperature:")), 0, 4, 1, 1);
content_area.attach (temperature, 1, 4, 1, 1);
content_area.attach (new EndLabel (_("Temperature:")), 0, 5, 1, 1);
content_area.attach (temperature, 1, 5, 1, 1);
lainsce marked this conversation as resolved.
Show resolved Hide resolved

var temp_setting = temperature_settings.get_string ("temperature-unit");

Expand Down Expand Up @@ -311,6 +329,39 @@ namespace SwitchboardPlugLocale.Widgets {
compare ();
}

public void reload_first_day () {
Gee.ArrayList<string>? first_days = new Gee.ArrayList<string> ();
// As per real world data, First Day option in many countries boils down to these 4 options.
first_days.add (_("Sunday"));
first_days.add (_("Monday"));
first_days.add (_("Friday"));
first_days.add (_("Saturday"));
first_day_store.clear ();
lainsce marked this conversation as resolved.
Show resolved Hide resolved
var user_first_day = lm.get_user_first_day ();
int first_day_id = 0;

int i = 0;
foreach (var first_day in first_days) {
var iter = Gtk.TreeIter ();
first_day_store.append (out iter);
first_day_store.set (iter, 0, first_day, 1, first_days.index_of (first_day));

if (first_days.index_of (first_day) == user_first_day) {
first_day_id = i;
}

i++;
}
first_day_combobox.sensitive = i != 1; // set to unsensitive if only have one item
first_day_combobox.active = user_first_day;

if (selected_first_day == 0) {
selected_first_day = user_first_day;
}

compare ();
}

public void reload_labels (string language) {
title = Utils.translate (language, null);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Widgets/LocaleView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ namespace SwitchboardPlugLocale.Widgets {
var regions = Utils.get_regions (selected_language_code);

debug ("reloading Settings widget for language '%s'".printf (selected_language_code));
locale_setting.reload_regions (selected_language_code, regions);
locale_setting.reload_regions.begin (selected_language_code, regions);
locale_setting.reload_first_day ();
locale_setting.reload_labels (selected_language_code);

if (selected_language_code == locale_manager.get_user_language ().slice (0, 2)) {
Expand Down