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

Use Portal For clock-format #527

Closed
Closed
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
25 changes: 23 additions & 2 deletions lib/DateTime.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
* getting the default translated format for either date and time.
*/
namespace Granite.DateTime {

[DBus (name = "org.freedesktop.portal.Settings")]
private interface FDO.Portal.Settings : Object {
public abstract Variant read (string @namespace, string key);
}

/**
* Gets a default translated time format.
* The function constructs a new string interpreting the //is_12h// and //with_second// parameters
Expand Down Expand Up @@ -96,8 +102,23 @@ namespace Granite.DateTime {
* @return true if the clock format is 12h based, false otherwise.
*/
private static bool is_clock_format_12h () {
var h24_settings = new GLib.Settings ("org.gnome.desktop.interface");
var format = h24_settings.get_string ("clock-format");
string format;
try {
var settings_bus = GLib.Bus.get_proxy_sync<FDO.Portal.Settings> (
GLib.BusType.SESSION,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop"
);

var clock_format_variant = settings_bus.read ("org.gnome.desktop.interface", "clock-format").get_variant ();
format = clock_format_variant.get_string ();
} catch (GLib.Error e) {
debug ("Unable to connect to desktop portal (%s), using GSettings", e.message);
var h24_settings = new GLib.Settings ("org.gnome.desktop.interface");
format = h24_settings.get_string ("clock-format");
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Lint

Suggested change

return (format.contains ("12h"));
}

Expand Down