[dconf-editor] Remove planned_* from Key



commit ff5509b13e8d664e97f0df4d27a8565d1b338e91
Author: Davi da Silva Böger <dsboger gmail com>
Date:   Mon Dec 4 16:21:50 2017 -0200

    Remove planned_* from Key

 editor/dconf-model.vala           |    4 --
 editor/modifications-handler.vala |   76 ++++++++++++++++++------------------
 2 files changed, 38 insertions(+), 42 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 54eee4f..8126dff 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -194,9 +194,6 @@ public abstract class Key : SettingObject
     public string type_string { get; protected set; default = "*"; }
     public Variant properties { owned get; protected set; }
 
-    public bool planned_change { get; set; default = false; }
-    public Variant? planned_value { get; set; default = null; }
-
     public abstract Variant value { owned get; set; }
 
     public signal void value_changed ();
@@ -415,7 +412,6 @@ public class DConfKey : Key
             warning (error.message);
         }
         is_ghost = true;
-        planned_change = false;
         value_changed ();
     }
 
diff --git a/editor/modifications-handler.vala b/editor/modifications-handler.vala
index 6a9f18e..a53a6ff 100644
--- a/editor/modifications-handler.vala
+++ b/editor/modifications-handler.vala
@@ -21,14 +21,24 @@ public enum ModificationsMode {
     DELAYED
 }
 
+public uint key_hash (Key key)
+{
+    return str_hash (key.descriptor);
+}
+
+public bool key_equal (Key key1, Key key2)
+{
+    return str_equal (key1.descriptor, key2.descriptor);
+}
+
 class ModificationsHandler : Object
 {
     public ModificationsMode mode { get; set; default=ModificationsMode.NONE; }
 
     private DConf.Client dconf_client = new DConf.Client ();
 
-    private HashTable<string, DConfKey>         dconf_keys_awaiting_hashtable = new HashTable<string, 
DConfKey>     (str_hash, str_equal);
-    private HashTable<string, GSettingsKey> gsettings_keys_awaiting_hashtable = new HashTable<string, 
GSettingsKey> (str_hash, str_equal);
+    private HashTable<DConfKey, Variant?>         dconf_keys_awaiting_hashtable = new HashTable<DConfKey, 
Variant?>     (key_hash, key_equal);
+    private HashTable<GSettingsKey, Variant?> gsettings_keys_awaiting_hashtable = new 
HashTable<GSettingsKey, Variant?> (key_hash, key_equal);
     public uint dconf_changes_count     { get { return dconf_keys_awaiting_hashtable.length; } }
     public uint gsettings_changes_count { get { return gsettings_keys_awaiting_hashtable.length; } }
 
@@ -66,13 +76,10 @@ class ModificationsHandler : Object
 
     public void add_delayed_setting (Key key, Variant? new_value)
     {
-        key.planned_change = true;
-        key.planned_value = new_value;
-
         if (key is GSettingsKey)
-            gsettings_keys_awaiting_hashtable.insert (key.descriptor, (GSettingsKey) key);
+            gsettings_keys_awaiting_hashtable.insert ((GSettingsKey) key, new_value);
         else
-            dconf_keys_awaiting_hashtable.insert (key.descriptor, (DConfKey) key);
+            dconf_keys_awaiting_hashtable.insert ((DConfKey) key, new_value);
 
         mode = get_current_delay_mode () ? ModificationsMode.DELAYED : ModificationsMode.TEMPORARY;
 
@@ -84,13 +91,10 @@ class ModificationsHandler : Object
         if (mode == ModificationsMode.NONE)
             mode = behaviour == Behaviour.ALWAYS_DELAY ? ModificationsMode.DELAYED : 
ModificationsMode.TEMPORARY;
 
-        key.planned_change = false;
-        key.planned_value = null;
-
         if (key is GSettingsKey)
-            gsettings_keys_awaiting_hashtable.remove (key.descriptor);
+            gsettings_keys_awaiting_hashtable.remove ((GSettingsKey) key);
         else
-            dconf_keys_awaiting_hashtable.remove (key.descriptor);
+            dconf_keys_awaiting_hashtable.remove ((DConfKey) key);
 
         delayed_changes_changed ();
     }
@@ -114,8 +118,9 @@ class ModificationsHandler : Object
         /* GSettings stuff */
 
         HashTable<string, GLib.Settings> delayed_settings_hashtable = new HashTable<string, GLib.Settings> 
(str_hash, str_equal);
-        gsettings_keys_awaiting_hashtable.foreach_remove ((descriptor, key) => {
-                string settings_descriptor = descriptor [0:descriptor.last_index_of_char (' ')]; // strip 
the key name
+        gsettings_keys_awaiting_hashtable.foreach_remove ((key, planned_value) => {
+                string key_descriptor = key.descriptor;
+                string settings_descriptor = key_descriptor [0:key_descriptor.last_index_of_char (' ')]; // 
strip the key name
                 GLib.Settings? settings = delayed_settings_hashtable.lookup (settings_descriptor);
                 if (settings == null)
                 {
@@ -124,7 +129,7 @@ class ModificationsHandler : Object
                     delayed_settings_hashtable.insert (settings_descriptor, (!) settings);
                 }
 
-                if (key.planned_value == null)
+                if (planned_value == null)
                 {
                     ((!) settings).reset (key.name);
                     if (((!) settings).backend.get_type ().name () == "GDelayedSettingsBackend") // 
Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=791290
@@ -132,8 +137,7 @@ class ModificationsHandler : Object
                     // Alternative workaround: key.value_changed ();
                 }
                 else
-                    ((!) settings).set_value (key.name, (!) key.planned_value);
-                key.planned_change = false;
+                    ((!) settings).set_value (key.name, (!) planned_value);
 
                 return true;
             });
@@ -143,12 +147,11 @@ class ModificationsHandler : Object
         /* DConf stuff */
 
         DConf.Changeset dconf_changeset = new DConf.Changeset ();
-        dconf_keys_awaiting_hashtable.foreach_remove ((descriptor, key) => {
-                dconf_changeset.set (key.full_name, key.planned_value);
+        dconf_keys_awaiting_hashtable.foreach_remove ((key, planned_value) => {
+                dconf_changeset.set (key.full_name, planned_value);
 
-                if (key.planned_value == null)
+                if (planned_value == null)
                     key.is_ghost = true;
-                key.planned_change = false;
 
                 return true;
             });
@@ -169,19 +172,8 @@ class ModificationsHandler : Object
     {
         mode = ModificationsMode.NONE;
 
-        /* GSettings stuff */
-
-        gsettings_keys_awaiting_hashtable.foreach_remove ((descriptor, key) => {
-                key.planned_change = false;
-                return true;
-            });
-
-        /* DConf stuff */
-
-        dconf_keys_awaiting_hashtable.foreach_remove ((descriptor, key) => {
-                key.planned_change = false;
-                return true;
-            });
+        gsettings_keys_awaiting_hashtable.remove_all ();
+        dconf_keys_awaiting_hashtable.remove_all ();
 
         /* reload notably key_editor_child */
 
@@ -191,12 +183,16 @@ class ModificationsHandler : Object
 
     public Variant get_key_custom_value (Key key)
     {
-        return key.planned_change && (key.planned_value != null) ? (!) key.planned_value : key.value;
+        bool planned_change = key_has_planned_change (key);
+        Variant? planned_value = get_key_planned_value (key);
+        return planned_change && (planned_value != null) ? (!) planned_value : key.value;
     }
 
     public bool key_value_is_default (GSettingsKey key) // doesn't make sense for DConfKey?
     {
-        return key.planned_change ? key.planned_value == null : key.is_default;
+        bool planned_change = key_has_planned_change (key);
+        Variant? planned_value = get_key_planned_value (key);
+        return planned_change ? planned_value == null : key.is_default;
     }
 
     public void set_key_value (Key key, Variant? new_value)
@@ -218,12 +214,16 @@ class ModificationsHandler : Object
 
     public bool key_has_planned_change (Key key)
     {
-        return key.planned_change;
+        if (key is GSettingsKey)
+            return gsettings_keys_awaiting_hashtable.contains ((GSettingsKey) key);
+        return dconf_keys_awaiting_hashtable.contains ((DConfKey) key);
     }
 
     public Variant? get_key_planned_value (Key key)
     {
-        return key.planned_value;
+        if (key is GSettingsKey)
+            return gsettings_keys_awaiting_hashtable.lookup ((GSettingsKey) key);
+        return dconf_keys_awaiting_hashtable.lookup ((DConfKey) key);
     }
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]