diff --git a/src/LanguagesFormat.vala b/src/LanguagesFormat.vala index f330ec674..67ed9abf1 100644 --- a/src/LanguagesFormat.vala +++ b/src/LanguagesFormat.vala @@ -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; - 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 (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); + 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 () { + return Granite.DateTime.get_default_time_format (TimeFormatHolder.get_instance ().is_12h); + } + }