[dconf-editor] Separate keys with and without schemas.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Separate keys with and without schemas.
- Date: Mon, 12 Oct 2015 04:30:49 +0000 (UTC)
commit 430f15c3de57d07fa9a260daeb632602cf487e78
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Oct 12 06:30:38 2015 +0200
Separate keys with and without schemas.
editor/dconf-model.vala | 93 ++++++++++++++++++++++++++++++++++------------
editor/dconf-view.vala | 61 ++++++++++++++++++------------
editor/dconf-window.vala | 29 +++++++-------
3 files changed, 119 insertions(+), 64 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index c7559de..9d27682 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -29,9 +29,9 @@ public struct SchemaKey
public class SettingObject : Object
{
- public Directory? parent; // TODO make protected or even remove
- public string name;
- public string full_name;
+ public Directory? parent { get; protected set; } // TODO make protected or even remove
+ public string name { get; protected set; }
+ public string full_name { get; protected set; }
}
public class Directory : SettingObject
@@ -52,11 +52,14 @@ public class Directory : SettingObject
}
}
-public class Key : SettingObject
+public abstract class Key : SettingObject
{
- private DConf.Client client;
+ public string path { get; protected set; }
+ public abstract bool has_schema { get; }
+ public string type_string { get; protected set; default = "*"; }
+ public abstract Variant value { get; set; }
- public string path;
+ public signal void value_changed ();
public static string cool_text_value_from_variant (Variant variant, string type) // called from
subclasses and from KeyListBoxRow
{
@@ -85,6 +88,7 @@ public class Key : SettingObject
}
return variant.print (false);
}
+
public static string cool_boolean_text_value (bool? nullable_boolean, bool capitalized = true)
{
if (capitalized)
@@ -105,19 +109,64 @@ public class Key : SettingObject
return _("nothing");
}
}
+}
- public SchemaKey? schema;
+public class DConfKey : Key
+{
+ private DConf.Client client;
- public bool has_schema { get; private set; }
- public string type_string { get; private set; default = "*"; }
+ public override bool has_schema { get { return false; } }
+
+ private Variant _value;
+ public override Variant value
+ {
+ get
+ {
+ _value = client.read (full_name);
+ return _value; // TODO cannot that error?
+ }
+ set
+ {
+ _value = value;
+ try
+ {
+ client.write_sync (full_name, value);
+ }
+ catch (Error e)
+ {
+ }
+ value_changed ();
+ }
+ }
+
+ public DConfKey (DConf.Client client, Directory parent, string name)
+ {
+ this.client = client;
+ this.parent = parent;
+
+ this.name = name;
+ path = parent.full_name;
+ full_name = path + name;
+
+ type_string = value.get_type_string ();
+ }
+}
+
+public class GSettingsKey : Key
+{
+ private DConf.Client client;
+
+ public SchemaKey schema;
+
+ public override bool has_schema { get { return true; } }
private Variant? _value = null;
- public Variant value
+ public override Variant value
{
get
{
update_value ();
- return _value ?? schema.default_value; // TODO cannot that error?
+ return _value ?? schema.default_value;
}
set
{
@@ -138,9 +187,7 @@ public class Key : SettingObject
get { update_value (); return _value == null; }
}
- public signal void value_changed ();
-
- public Key (DConf.Client client, Directory parent, string name, SchemaKey? schema)
+ public GSettingsKey (DConf.Client client, Directory parent, string name, SchemaKey schema)
{
this.client = client;
this.parent = parent;
@@ -150,16 +197,10 @@ public class Key : SettingObject
full_name = path + name;
this.schema = schema;
- has_schema = schema != null;
-
- if (schema != null)
- type_string = ((!) schema).type;
- else if (_value != null)
- type_string = value.get_type_string ();
+ type_string = schema.type;
}
public void set_to_default ()
- requires (has_schema)
{
_value = null;
try
@@ -296,13 +337,17 @@ public class SettingsModel : Object, Gtk.TreeModel
if (key != null)
return;
- Key new_key = new Key (client, view, name, schema_key);
+ Key new_key;
+ if (schema_key == null)
+ new_key = new DConfKey (client, view, name);
+ else
+ new_key = new GSettingsKey (client, view, name, (!) schema_key);
item_changed.connect ((key_name) => {
if ((key_name.has_suffix ("/") && new_key.full_name.has_prefix (key_name)) || key_name ==
new_key.full_name)
new_key.value_changed ();
});
- view.key_model.insert_sorted (new_key, (a, b) => { return strcmp (((SettingObject) a).name,
((SettingObject) b).name); });
- view.key_map.insert (name, new_key);
+ view.key_model.insert_sorted ((Key) new_key, (a, b) => { return strcmp (((SettingObject) a).name,
((SettingObject) b).name); });
+ view.key_map.insert (name, (Key) new_key);
}
/*\
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 588f3bf..85d8393 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -19,10 +19,11 @@ using Gtk;
private abstract class KeyEditorDialog : Dialog
{
- protected Key key;
protected bool custom_value_is_valid { get; set; default = true; }
protected KeyEditorChild key_editor_child;
+ protected string type_string { private get; protected set; }
+
public KeyEditorDialog ()
{
Object (use_header_bar: Gtk.Settings.get_default ().gtk_dialogs_use_header ? 1 : 0);
@@ -31,14 +32,9 @@ private abstract class KeyEditorDialog : Dialog
private void response_apply_cb () { on_response_apply (); this.destroy (); }
- protected virtual void on_response_apply ()
- {
- Variant variant = key_editor_child.get_variant ();
- if (key.value != variant)
- key.value = variant;
- }
+ protected abstract void on_response_apply ();
- protected void create_child (Grid custom_value_grid)
+ protected void create_child (Grid custom_value_grid, Key key)
{
switch (key.type_string)
{
@@ -111,7 +107,7 @@ private abstract class KeyEditorDialog : Dialog
protected string key_to_description ()
{
- switch (key.type_string)
+ switch (type_string)
{
case "b":
return _("Boolean");
@@ -145,18 +141,18 @@ private abstract class KeyEditorDialog : Dialog
get_min_and_max (out min, out max);
return _("Integer [%s..%s]").printf (min, max);
default:
- return key.type_string;
+ return type_string;
}
}
protected virtual void get_min_and_max (out string min, out string max)
{
- get_min_and_max_string (out min, out max, key.type_string);
+ get_min_and_max_string (out min, out max, type_string);
}
- private static void get_min_and_max_string (out string min, out string max, string type)
+ private static void get_min_and_max_string (out string min, out string max, string type_string)
{
- switch (type)
+ switch (type_string)
{
// TODO %I'xx everywhere! but would need support from the spinbutton…
case "y": min = "%hhu".printf (uint8.MIN); max = "%hhu".printf (uint8.MAX); return;
@@ -178,16 +174,25 @@ private class KeyEditorNoSchema : KeyEditorDialog // TODO add type informa
{
[GtkChild] private Grid custom_value_grid;
- public KeyEditorNoSchema (Key _key)
- requires (!_key.has_schema)
+ private DConfKey key;
+
+ public KeyEditorNoSchema (DConfKey _key)
{
- this.key = _key;
+ key = _key;
+ type_string = key.type_string;
this.title = key.name;
if (this.use_header_bar == 1) // TODO else..?
((HeaderBar) this.get_header_bar ()).subtitle = key.path; // TODO get_header_bar() is
[transfer none]
- create_child (custom_value_grid);
+ create_child (custom_value_grid, (Key) _key);
+ }
+
+ protected override void on_response_apply ()
+ {
+ Variant variant = key_editor_child.get_variant ();
+ if (key.value != variant)
+ key.value = variant;
}
}
@@ -205,16 +210,18 @@ private class KeyEditor : KeyEditorDialog
[GtkChild] private Switch custom_value_switch;
- public KeyEditor (Key _key)
- requires (_key.has_schema)
+ protected GSettingsKey key;
+
+ public KeyEditor (GSettingsKey _key)
{
- this.key = _key;
+ key = _key;
+ type_string = key.type_string;
this.title = key.name;
if (this.use_header_bar == 1) // TODO else..?
((HeaderBar) this.get_header_bar ()).subtitle = key.path; // TODO get_header_bar() is
[transfer none]
- create_child (custom_value_grid);
+ create_child (custom_value_grid, (Key) key);
// infos
@@ -248,7 +255,11 @@ private class KeyEditor : KeyEditorDialog
protected override void on_response_apply ()
{
if (!custom_value_switch.active)
- base.on_response_apply ();
+ {
+ Variant variant = key_editor_child.get_variant ();
+ if (key.value != variant)
+ key.value = variant;
+ }
else if (!key.is_default)
key.set_to_default ();
}
@@ -412,10 +423,10 @@ private class KeyEditorChildNumber : Grid, KeyEditorChild
this.attach (new_label_custom_value (), 0, 0, 1, 1);
double min, max;
- if (key.has_schema && key.schema.range_type == "range") // TODO test more; and what happen if
only min/max is in range?
+ if (key.has_schema && ((GSettingsKey) key).schema.range_type == "range") // TODO test more; and
what happen if only min/max is in range?
{
- min = get_variant_as_double (key.schema.range_content.get_child_value (0));
- max = get_variant_as_double (key.schema.range_content.get_child_value (1));
+ min = get_variant_as_double (((GSettingsKey) key).schema.range_content.get_child_value (0));
+ max = get_variant_as_double (((GSettingsKey) key).schema.range_content.get_child_value (1));
}
else
get_min_and_max_double (out min, out max, key.type_string);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 38b897d..fc7e318 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -128,13 +128,12 @@ class DConfWindow : ApplicationWindow
private Widget new_list_box_row (Object item)
{
- Key key = (Key) item;
- if (key.has_schema)
+ if (((Key) item).has_schema)
{
- KeyListBoxRowEditable key_list_box_row = new KeyListBoxRowEditable (key);
+ KeyListBoxRowEditable key_list_box_row = new KeyListBoxRowEditable ((GSettingsKey) item);
key_list_box_row.button_press_event.connect (on_button_pressed);
key_list_box_row.show_dialog.connect (() => {
- KeyEditor key_editor = new KeyEditor (key);
+ KeyEditor key_editor = new KeyEditor ((GSettingsKey) item);
key_editor.set_transient_for (this);
key_editor.run ();
});
@@ -142,10 +141,10 @@ class DConfWindow : ApplicationWindow
}
else
{
- KeyListBoxRowEditableNoSchema key_list_box_row = new KeyListBoxRowEditableNoSchema (key);
+ KeyListBoxRowEditableNoSchema key_list_box_row = new KeyListBoxRowEditableNoSchema ((DConfKey)
item);
key_list_box_row.button_press_event.connect (on_button_pressed);
key_list_box_row.show_dialog.connect (() => {
- KeyEditorNoSchema key_editor = new KeyEditorNoSchema (key);
+ KeyEditorNoSchema key_editor = new KeyEditorNoSchema ((DConfKey) item);
key_editor.set_transient_for (this);
key_editor.run ();
});
@@ -253,9 +252,9 @@ class DConfWindow : ApplicationWindow
/* Check key schema (description) */
if (key.has_schema)
{
- if (key.schema.summary != null && key.schema.summary.index_of (text) >= 0)
+ if (((GSettingsKey) key).schema.summary != null && ((GSettingsKey) key).schema.summary.index_of
(text) >= 0)
return true;
- if (key.schema.description != null && key.schema.description.index_of (text) >= 0)
+ if (((GSettingsKey) key).schema.description != null && ((GSettingsKey)
key).schema.description.index_of (text) >= 0)
return true;
}
@@ -419,9 +418,9 @@ private class KeyListBoxRow : EventBox
private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
{
- public Key key { get; private set; }
+ public DConfKey key { get; private set; }
- public KeyListBoxRowEditableNoSchema (Key _key)
+ public KeyListBoxRowEditableNoSchema (DConfKey _key)
{
this.key = _key;
@@ -462,11 +461,11 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
private class KeyListBoxRowEditable : KeyListBoxRow
{
- public Key key { get; private set; }
+ public GSettingsKey key { get; private set; }
private Pango.AttrList attr_list = new Pango.AttrList ();
- public KeyListBoxRowEditable (Key _key)
+ public KeyListBoxRowEditable (GSettingsKey _key)
{
this.key = _key;
@@ -562,7 +561,7 @@ private class ContextPopover : Popover
{
VariantType original_type = key.value.get_type ();
VariantType nullable_type = new VariantType.maybe (original_type);
- Variant variant = new Variant.maybe (original_type, key.is_default ? null : key.value);
+ Variant variant = new Variant.maybe (original_type, key.has_schema && ((GSettingsKey)
key).is_default ? null : key.value);
SimpleAction simple_action = new SimpleAction.stateful (ACTION_NAME, nullable_type, variant);
SimpleActionGroup group = new SimpleActionGroup ();
@@ -578,8 +577,8 @@ private class ContextPopover : Popover
add_model_button (Key.cool_boolean_text_value (true), new Variant.maybe
(VariantType.BOOLEAN, new Variant.boolean (true)));
add_model_button (Key.cool_boolean_text_value (false), new Variant.maybe
(VariantType.BOOLEAN, new Variant.boolean (false)));
break;
- case "<enum>":
- Variant range = key.schema.range_content;
+ case "<enum>": // defined by the schema
+ Variant range = ((GSettingsKey) key).schema.range_content;
uint size = (uint) range.n_children ();
if (size == 0) // TODO special case also 1?
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]