[geary/wip/730682-refine-convo-list: 5/15] Bind some Configuration props so they can be listened to using notify.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/730682-refine-convo-list: 5/15] Bind some Configuration props so they can be listened to using notify.
- Date: Tue, 17 Oct 2017 07:51:21 +0000 (UTC)
commit 74dfc1b0774149ac94c4305b39781985971a2319
Author: Michael James Gratton <mike vee net>
Date: Sat Oct 14 09:33:11 2017 +1100
Bind some Configuration props so they can be listened to using notify.
src/client/application/geary-config.vala | 62 +++++++++++++++++++-----------
1 files changed, 39 insertions(+), 23 deletions(-)
---
diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala
index a678240..ef97d71 100644
--- a/src/client/application/geary-config.vala
+++ b/src/client/application/geary-config.vala
@@ -1,4 +1,6 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
+/*
+ * Copyright 2017 Michael Gratton <mike vee net>
+ * Copyright 2016 Software Freedom Conservancy Inc.
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
@@ -6,8 +8,9 @@
/**
* Provides convenience properties to current Geary GSettings values.
+
*/
-public class Configuration {
+public class Configuration : Geary.BaseObject {
public const string ATTACHMENTS_DIR_KEY = "attachments-directory";
public const string PRINT_DIR_KEY = "print-directory";
@@ -20,7 +23,6 @@ public class Configuration {
public const string FOLDER_LIST_PANE_HORIZONTAL_KEY = "folder-list-pane-horizontal";
public const string MESSAGES_PANE_POSITION_KEY = "messages-pane-position";
public const string AUTOSELECT_KEY = "autoselect";
- public const string DISPLAY_PREVIEW_KEY = "display-preview";
public const string PLAY_SOUNDS_KEY = "play-sounds";
public const string SHOW_NOTIFICATIONS_KEY = "show-notifications";
public const string STARTUP_NOTIFICATIONS_KEY = "startup-notifications";
@@ -31,6 +33,10 @@ public class Configuration {
public const string SEARCH_STRATEGY_KEY = "search-strategy";
public const string CONVERSATION_VIEWER_ZOOM_KEY = "conversation-viewer-zoom";
+ // Properties converted to be bind to the settings
+ private const string CLOCK_FORMAT_KEY = "clock-format";
+ public const string DISPLAY_PREVIEW_KEY = "display-preview";
+
public enum DesktopEnvironment {
UNKNOWN = 0,
@@ -111,10 +117,8 @@ public class Configuration {
public bool autoselect {
get { return settings.get_boolean(AUTOSELECT_KEY); }
}
-
- public bool display_preview {
- get { return settings.get_boolean(DISPLAY_PREVIEW_KEY); }
- }
+
+ public bool display_preview { get; set; }
public string[] spell_check_languages {
owned get {
@@ -146,17 +150,9 @@ public class Configuration {
get { return settings.get_boolean(STARTUP_NOTIFICATIONS_KEY); }
set { set_boolean(STARTUP_NOTIFICATIONS_KEY, value); }
}
-
- private const string CLOCK_FORMAT_KEY = "clock-format";
- public Date.ClockFormat clock_format {
- get {
- if (gnome_interface.get_string(CLOCK_FORMAT_KEY) == "12h")
- return Date.ClockFormat.TWELVE_HOURS;
- else
- return Date.ClockFormat.TWENTY_FOUR_HOURS;
- }
- }
-
+
+ public Date.ClockFormat clock_format { get; set; }
+
public bool ask_open_attachment {
get { return settings.get_boolean(ASK_OPEN_ATTACHMENT_KEY); }
set { set_boolean(ASK_OPEN_ATTACHMENT_KEY, value); }
@@ -173,11 +169,26 @@ public class Configuration {
}
- // Creates a configuration object.
public Configuration(string schema_id) {
- // Start GSettings.
- settings = new Settings(schema_id);
- gnome_interface = new Settings("org.gnome.desktop.interface");
+ this.settings = new Settings(schema_id);
+ this.gnome_interface = new Settings("org.gnome.desktop.interface");
+
+ bind_this(DISPLAY_PREVIEW_KEY);
+
+ this.gnome_interface.bind_with_mapping(
+ CLOCK_FORMAT_KEY, this, CLOCK_FORMAT_KEY,
+ GLib.SettingsBindFlags.DEFAULT,
+ (value, variant) => {
+ if (variant.get_string() == "12h")
+ value.set_enum(Date.ClockFormat.TWELVE_HOURS);
+ else
+ value.set_enum(Date.ClockFormat.TWENTY_FOUR_HOURS);
+ return true;
+ },
+ // we don't support setting
+ (value, expected_type) => { return false; },
+ null, null
+ );
Migrate.old_app_config(settings);
}
@@ -229,5 +240,10 @@ public class Configuration {
break;
}
}
-}
+
+ private inline void bind_this(string property) {
+ this.settings.bind(property, this, property, GLib.SettingsBindFlags.DEFAULT);
+ }
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]