[dconf-editor] Share Key properties by a GVariant.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Share Key properties by a GVariant.
- Date: Thu, 12 May 2016 14:30:41 +0000 (UTC)
commit cda83d790646ad061ea99eda5e2fe06053bd9428
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu May 12 16:30:30 2016 +0200
Share Key properties by a GVariant.
editor/dconf-model.vala | 75 +++++++++++++++++++++++++++++----
editor/dconf-view.vala | 108 +++++++++++++++++++++--------------------------
2 files changed, 115 insertions(+), 68 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 9b619c4..0fa2fa7 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -174,11 +174,13 @@ public abstract class Key : SettingObject
public abstract bool has_schema { get; }
public string type_string { get; protected set; default = "*"; }
+ public Variant properties { owned get; protected set; }
+
public abstract Variant value { owned get; set; }
public signal void value_changed ();
- public static string key_to_description (string type)
+ protected static string key_to_description (string type)
{
switch (type)
{
@@ -216,7 +218,7 @@ public abstract class Key : SettingObject
}
}
- public static void get_min_and_max_string (out string min, out string max, string type_string)
+ protected static void get_min_and_max_string (out string min, out string max, string type_string)
{
switch (type_string)
{
@@ -309,6 +311,11 @@ public abstract class Key : SettingObject
return _("nothing");
}
}
+
+ protected static bool show_min_and_max (string type)
+ {
+ return (type == "d" || type == "y" || type == "n" || type == "q" || type == "i" || type == "u" ||
type == "x" || type == "t");
+ }
}
public class DConfKey : Key
@@ -345,6 +352,21 @@ public class DConfKey : Key
this.client = client;
this.type_string = value.get_type_string ();
+
+ if (show_min_and_max (type_string))
+ {
+ string min, max;
+ get_min_and_max_string (out min, out max, type_string);
+ properties = new Variant.parsed ("(false, [{'type-name', %s},
+ {'minimum', %s},
+ {'maximum', %s}])",
+ key_to_description (type_string),
+ min,
+ max);
+ }
+ else
+ properties = new Variant.parsed ("(false, [{'type-name', %s}])",
+ key_to_description (type_string));
}
}
@@ -352,12 +374,12 @@ public class GSettingsKey : Key
{
public override bool has_schema { get { return true; } }
- public string schema_id { get; construct; }
- public string summary { get; construct; }
- public string description { get; construct; }
- public Variant default_value { get; construct; }
- public string range_type { get; construct; }
- public Variant range_content { get; construct; }
+ public string schema_id { get; construct; }
+ public string summary { get; construct; }
+ public string description { private get; construct; }
+ public Variant default_value { private get; construct; }
+ public string range_type { get; construct; }
+ public Variant range_content { get; construct; }
private GLib.Settings settings;
@@ -393,6 +415,43 @@ public class GSettingsKey : Key
settings.changed [name].connect (() => { value_changed (); });
this.type_string = type_string;
+ if (show_min_and_max (type_string))
+ {
+ string min, max;
+ if (range_type == "range") // TODO test more; and what happen if only min/max is in range?
+ {
+ min = cool_text_value_from_variant (range_content.get_child_value (0), type_string);
+ max = cool_text_value_from_variant (range_content.get_child_value (1), type_string);
+ }
+ else
+ get_min_and_max_string (out min, out max, type_string);
+
+ properties = new Variant.parsed ("(true, [{'type-name', %s},
+ {'schema-id', %s},
+ {'summary', %s},
+ {'description', %s},
+ {'default-value', %s},
+ {'minimum', %s},
+ {'maximum', %s}])",
+ key_to_description (type_string),
+ schema_id,
+ summary,
+ description,
+ cool_text_value_from_variant (default_value, type_string),
+ min,
+ max);
+ }
+ else
+ properties = new Variant.parsed ("(true, [{'type-name', %s},
+ {'schema-id', %s},
+ {'summary', %s},
+ {'description', %s},
+ {'default-value', %s}])",
+ key_to_description (type_string),
+ schema_id,
+ summary,
+ description,
+ cool_text_value_from_variant (default_value, type_string));
}
public bool search_for (string text)
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index aca429b..1ae8b85 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -88,21 +88,19 @@ private abstract class KeyEditorDialog : Dialog
{
[GtkChild] protected Button button_apply;
[GtkChild] protected InfoBar no_schema_warning;
- [GtkChild] protected PropertyRow schema_row;
- [GtkChild] protected PropertyRow summary_row;
- [GtkChild] protected PropertyRow description_row;
- [GtkChild] protected PropertyRow type_row;
- [GtkChild] protected PropertyRow minimum_row;
- [GtkChild] protected PropertyRow maximum_row;
- [GtkChild] protected PropertyRow default_row;
+ [GtkChild] private PropertyRow schema_row;
+ [GtkChild] private PropertyRow summary_row;
+ [GtkChild] private PropertyRow description_row;
+ [GtkChild] private PropertyRow type_row;
+ [GtkChild] private PropertyRow minimum_row;
+ [GtkChild] private PropertyRow maximum_row;
+ [GtkChild] private PropertyRow default_row;
[GtkChild] protected PropertyRow custom_value_row;
[GtkChild] protected PropertyRow value_row;
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);
@@ -113,6 +111,36 @@ private abstract class KeyEditorDialog : Dialog
protected abstract void on_response_apply ();
+ protected void setup_rows (bool has_schema, Variant dict)
+ {
+ if (has_schema)
+ {
+ no_schema_warning.destroy ();
+ }
+ else
+ {
+ custom_value_row.destroy ();
+ no_schema_warning.show ();
+ }
+
+ // TODO use VariantDict
+ string tmp_string;
+ if (dict.lookup ("schema-id", "s", out tmp_string)) schema_row.set_text (tmp_string);
+ else schema_row.destroy ();
+ if (dict.lookup ("summary", "s", out tmp_string)) summary_row.set_text (tmp_string);
+ else summary_row.destroy ();
+ if (dict.lookup ("description", "s", out tmp_string)) description_row.set_text (tmp_string);
+ else description_row.destroy ();
+ if (dict.lookup ("type-name", "s", out tmp_string)) type_row.set_text (tmp_string);
+ else assert_not_reached ();
+ if (dict.lookup ("minimum", "s", out tmp_string)) minimum_row.set_text (tmp_string);
+ else minimum_row.destroy ();
+ if (dict.lookup ("maximum", "s", out tmp_string)) maximum_row.set_text (tmp_string);
+ else maximum_row.destroy ();
+ if (dict.lookup ("default-value", "s", out tmp_string)) default_row.set_text (tmp_string);
+ else default_row.destroy ();
+ }
+
protected Widget create_child (Key key)
{
switch (key.type_string)
@@ -194,8 +222,6 @@ private class KeyEditorNoSchema : KeyEditorDialog // TODO add type informa
public KeyEditorNoSchema (DConfKey _key)
{
key = _key;
- type_string = key.type_string;
- string _type_string = key.type_string;
this.title = key.name;
if (this.use_header_bar == 1) // TODO else..?
@@ -203,28 +229,12 @@ private class KeyEditorNoSchema : KeyEditorDialog // TODO add type informa
value_row.set_widget (create_child ((Key) _key), add_warning ((Key) _key));
- type_row.set_text (Key.key_to_description (_type_string));
- if (_type_string == "d" || _type_string == "y" || _type_string == "n" || _type_string == "q" ||
_type_string == "i" || _type_string == "u" || _type_string == "x" || _type_string == "t") // TODO "h"? 1/2
- {
- string min, max;
- Key.get_min_and_max_string (out min, out max, _type_string);
- minimum_row.set_text (min);
- maximum_row.set_text (max);
- }
- else
- {
- minimum_row.destroy ();
- maximum_row.destroy ();
- }
+ bool has_schema;
+ unowned Variant [] dict_container;
+ key.properties.get ("(ba{ss})", out has_schema, out dict_container);
+ setup_rows (has_schema, dict_container [0]);
notify ["custom-value-is-valid"].connect (() => { button_apply.set_sensitive
(custom_value_is_valid); });
-
- no_schema_warning.show ();
- schema_row.destroy ();
- summary_row.destroy ();
- description_row.destroy ();
- default_row.destroy ();
- custom_value_row.destroy ();
}
protected override void on_response_apply ()
@@ -244,13 +254,18 @@ private class KeyEditor : KeyEditorDialog
public KeyEditor (GSettingsKey _key)
{
key = _key;
- type_string = key.type_string;
- string _type_string = key.type_string;
this.title = key.name;
if (this.use_header_bar == 1) // TODO else..?
((HeaderBar) this.get_header_bar ()).subtitle = ((!) key.parent).full_name; // TODO
get_header_bar() is [transfer none]
+ // infos
+
+ bool has_schema;
+ unowned Variant [] dict_container;
+ key.properties.get ("(ba{ss})", out has_schema, out dict_container);
+ setup_rows (has_schema, dict_container [0]);
+
// actions
Widget _key_editor_child = create_child ((Key) key);
@@ -259,33 +274,6 @@ private class KeyEditor : KeyEditorDialog
custom_value_switch = custom_value_row.set_switch ();
custom_value_switch.bind_property ("active", _key_editor_child, "sensitive",
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
- // infos
-
- no_schema_warning.destroy ();
- schema_row.set_text (key.schema_id);
- summary_row.set_text (key.summary);
- description_row.set_text (key.description);
- type_row.set_text (Key.key_to_description (_type_string));
- if (_type_string == "d" || _type_string == "y" || _type_string == "n" || _type_string == "q" ||
_type_string == "i" || _type_string == "u" || _type_string == "x" || _type_string == "t") // TODO "h"? 2/2
- {
- string min, max;
- if (key.range_type == "range") // TODO test more; and what happen if only min/max is in
range?
- {
- min = Key.cool_text_value_from_variant (key.range_content.get_child_value (0), _type_string);
- max = Key.cool_text_value_from_variant (key.range_content.get_child_value (1), _type_string);
- }
- else
- Key.get_min_and_max_string (out min, out max, _type_string);
- minimum_row.set_text (min);
- maximum_row.set_text (max);
- }
- else
- {
- minimum_row.destroy ();
- maximum_row.destroy ();
- }
- default_row.set_text (Key.cool_text_value_from_variant (key.default_value, key.type_string));
-
// switch
custom_value_switch.set_active (key.is_default);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]