-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
634f391
cb50809
be02c8c
13c9e62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,50 @@ | |
// | ||
|
||
namespace Maya.Settings { | ||
[DBus (name = "io.elementary.greeter.AccountsService")] | ||
interface Greeter.AccountsService : Object { | ||
public abstract string time_format { owned get; set; } | ||
} | ||
|
||
[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; | ||
} | ||
|
||
public bool is_12h { get; private set; default = false; } | ||
private Greeter.AccountsService? greeter_act = null; | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 DateFormat () { | ||
return _("%B %e, %Y"); | ||
|
@@ -26,22 +70,7 @@ namespace Maya.Settings { | |
} | ||
|
||
public string TimeFormat () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
// 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); | ||
} | ||
|
||
// 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); | ||
|
||
if (clockformat.get_string ().contains ("12h")) { | ||
return Granite.DateTime.get_default_time_format (true); | ||
} else { | ||
return Granite.DateTime.get_default_time_format (false); | ||
} | ||
return Granite.DateTime.get_default_time_format (TimeFormatHolder.get_instance ().is_12h); | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
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).