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 1 commit
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
61 changes: 45 additions & 16 deletions src/LanguagesFormat.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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).


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 DateFormat () {
return _("%B %e, %Y");
Expand All @@ -26,22 +70,7 @@ namespace Maya.Settings {
}

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

// 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);
}

}
Expand Down