-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expose clock format as granite setting #528
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
base: master
Are you sure you want to change the base?
Changes from 13 commits
7cb1d33
68a4c1e
e3b27f2
2583b9a
074d6d0
12bec72
637f95f
88b11a2
ee3266e
3ae15a2
e8be31e
1705dfd
88dfec1
1522581
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,10 @@ namespace Granite { | |||||
| * Granite.Settings provides a way to share Pantheon desktop settings with applications. | ||||||
| */ | ||||||
| public class Settings : Object { | ||||||
|
|
||||||
| private const string GNOME_DESKTOP_INTERFACE = "org.gnome.desktop.interface"; | ||||||
| private const string CLOCK_FORMAT_KEY = "clock-format"; | ||||||
|
|
||||||
| /** | ||||||
| * Possible color scheme preferences expressed by the user | ||||||
| */ | ||||||
|
|
@@ -69,6 +73,36 @@ namespace Granite { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Possible clock format preferences expressed by the user | ||||||
| */ | ||||||
| public enum ClockFormat { | ||||||
| /** | ||||||
| * The user prefers a 12 hour clock | ||||||
| */ | ||||||
| 12H, | ||||||
| /** | ||||||
| * The user prefers a 24 hour clock | ||||||
| */ | ||||||
| 24H | ||||||
| } | ||||||
|
|
||||||
| private ClockFormat? _clock_format = null; | ||||||
| /** | ||||||
| * Whether the user would prefer a 12 hour or 24 hour clock | ||||||
| */ | ||||||
| public ClockFormat clock_format { | ||||||
| get { | ||||||
| if (_clock_format == null) { | ||||||
| setup_clock_format (); | ||||||
| } | ||||||
| return _clock_format; | ||||||
|
Member
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.
Suggested change
_clock_format might be null, so we need to explicitly do/ |
||||||
| } | ||||||
| private set { | ||||||
| _clock_format = value; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private static GLib.Once<Granite.Settings> instance; | ||||||
| public static unowned Granite.Settings get_default () { | ||||||
| return instance.once (() => { | ||||||
|
|
@@ -96,9 +130,15 @@ namespace Granite { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void setup_portal () { | ||||||
| if (portal == null) { | ||||||
| portal = Portal.Settings.get (); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void setup_prefers_color_scheme () { | ||||||
| try { | ||||||
| portal = Portal.Settings.get (); | ||||||
| setup_portal (); | ||||||
|
|
||||||
| prefers_color_scheme = (ColorScheme) portal.read ( | ||||||
| "org.freedesktop.appearance", | ||||||
|
|
@@ -139,5 +179,47 @@ namespace Granite { | |||||
| // Set a default in case we can't get from system | ||||||
| prefers_color_scheme = ColorScheme.NO_PREFERENCE; | ||||||
| } | ||||||
|
|
||||||
| private void setup_clock_format () { | ||||||
| try { | ||||||
| setup_portal (); | ||||||
|
|
||||||
| var clock_format_variant = portal.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); | ||||||
| var format = clock_format_variant.get_string (); | ||||||
|
Member
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.
Suggested change
|
||||||
|
|
||||||
| set_clock_format_from_nick (format); | ||||||
|
|
||||||
| portal.setting_changed.connect ((@namespace, key, @value) => { | ||||||
| if (@namespace == GNOME_DESKTOP_INTERFACE && key == CLOCK_FORMAT_KEY) { | ||||||
| var updated_format = @value.get_string (); | ||||||
|
Member
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.
Suggested change
|
||||||
| set_clock_format_from_nick (updated_format); | ||||||
| } | ||||||
| }); | ||||||
| } catch (Error e) { | ||||||
| debug ("Unable to connect to desktop portal (%s), using GSettings", e.message); | ||||||
|
|
||||||
| var interface_settings = new GLib.Settings (GNOME_DESKTOP_INTERFACE); | ||||||
| var format = interface_settings.get_string (CLOCK_FORMAT_KEY); | ||||||
| set_clock_format_from_nick (format); | ||||||
|
|
||||||
| interface_settings.changed.connect ((key) => { | ||||||
| if (key == CLOCK_FORMAT_KEY) { | ||||||
| var updated_format = interface_settings.get_string (CLOCK_FORMAT_KEY); | ||||||
| set_clock_format_from_nick (updated_format); | ||||||
| } | ||||||
| }); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void set_clock_format_from_nick (string format) { | ||||||
| EnumClass clock_format_enum_class = (EnumClass) typeof (ClockFormat).class_ref (); | ||||||
| unowned EnumValue? eval = clock_format_enum_class.get_value_by_nick (format); | ||||||
|
|
||||||
| if (eval == null) { | ||||||
| _clock_format = null; | ||||||
| } else { | ||||||
| clock_format = (ClockFormat) eval.value; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.