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

Get the time format from the new key and make it more efficient #401

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
55 changes: 42 additions & 13 deletions src/LanguagesFormat.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,54 @@
//

namespace Maya.Settings {
[DBus (name = "io.elementary.greeter.AccountsService")]
interface Greeter.AccountsService : Object {
public abstract string time_format { owned get; set; }
}

public string TimeFormat () {
// If AM/PM doesn't exist, use 24h.
if (Posix.nl_langinfo (Posix.NLItem.AM_STR) == null || Posix.nl_langinfo (Posix.NLItem.AM_STR) == "") {
return Granite.DateTime.get_default_time_format (false);
[DBus (name = "org.freedesktop.Accounts")]
interface FDO.Accounts : Object {
public abstract string find_user_by_name (string username) throws GLib.Error;
}

public class TimeFormatHolder : Object {
private static TimeFormatHolder instance;
public static unowned TimeFormatHolder get_instance () {
if (instance == null) {
instance = new TimeFormatHolder ();
}

return instance;
}

// If AM/PM exists, assume it is the default time format and check for format override.
var setting = new GLib.Settings ("org.gnome.desktop.interface");
var clockformat = setting.get_user_value ("clock-format");
if (clockformat == null)
return Granite.DateTime.get_default_time_format (true);
public bool is_12h { get; private set; default = false; }
private Greeter.AccountsService? greeter_act = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor point: I would call this greeter_acc or greeter_acnt` - as "act" is not generally used as an abbreviation for "account" (and is a word in its own right).


if (clockformat.get_string ().contains ("12h")) {
return Granite.DateTime.get_default_time_format (true);
} else {
return Granite.DateTime.get_default_time_format (false);
construct {
try {
var accounts_service = GLib.Bus.get_proxy_sync<FDO.Accounts> (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts");
var user_path = accounts_service.find_user_by_name (GLib.Environment.get_user_name ());
greeter_act = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
is_12h = greeter_act.time_format == "12h" ? true : false;
} catch (Error e) {
critical (e.message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another minor point: Could add an indication that we are falling back to org.gnome.desktop.interface setting to the error message.

var setting = new GLib.Settings ("org.gnome.desktop.interface");
GLib.Variant? clockformat = setting.get_user_value ("clock-format");
if (clockformat != null) {
is_12h = clockformat.get_string ().contains ("12h");
}
}
}
}

public string TimeFormat () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to change this function name to time_format () in order to resolve the conflict with master

return Granite.DateTime.get_default_time_format (TimeFormatHolder.get_instance ().is_12h);
}

}