summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2011-01-14 18:37:54 -0600
committerRobert Ancell <robert.ancell@canonical.com>2011-01-14 18:37:54 -0600
commitd13f094f673ee8544ba05e683bffb7350dc4419d (patch)
treea39e10b4bbf78ea23bf6fd7739a0823c67860f22
parent09b93207fd02189e43926e168a852d170c8c0a66 (diff)
downloaddconf-d13f094f673ee8544ba05e683bffb7350dc4419d.tar.gz
Use implicit types for variables, print warnings for unknown things in schemas
-rw-r--r--editor/dconf-editor.vala12
-rw-r--r--editor/dconf-model.vala8
-rw-r--r--editor/dconf-schema.vala96
-rw-r--r--editor/dconf-view.vala6
4 files changed, 81 insertions, 41 deletions
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index e9bd871..6b1f967 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -16,13 +16,13 @@ public class EditorWindow : Gtk.Window
set_default_size(600, 300);
set_border_width(6);
- Gtk.HBox hbox = new Gtk.HBox(false, 6);
+ var hbox = new Gtk.HBox(false, 6);
hbox.show();
add(hbox);
model = new SettingsModel();
- Gtk.ScrolledWindow scroll = new Gtk.ScrolledWindow(null, null);
+ var scroll = new Gtk.ScrolledWindow(null, null);
scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
scroll.show();
hbox.pack_start(scroll, false, false, 0);
@@ -33,7 +33,7 @@ public class EditorWindow : Gtk.Window
dir_tree_view.show();
scroll.add(dir_tree_view);
- Gtk.VBox vbox = new Gtk.VBox(false, 6);
+ var vbox = new Gtk.VBox(false, 6);
vbox.show();
hbox.pack_start(vbox, true, true, 0);
@@ -47,7 +47,7 @@ public class EditorWindow : Gtk.Window
key_tree_view.get_selection().changed.connect(key_selected_cb);
scroll.add(key_tree_view);
- Gtk.Table schema_table = new Gtk.Table(0, 2, false);
+ var schema_table = new Gtk.Table(0, 2, false);
schema_table.set_row_spacings(6);
schema_table.set_col_spacings(6);
schema_table.show();
@@ -107,7 +107,7 @@ public class EditorWindow : Gtk.Window
Gtk.TreeModel model;
if (key_tree_view.get_selection().get_selected(out model, out iter))
{
- KeyModel key_model = (KeyModel) model;
+ var key_model = (KeyModel) model;
return key_model.get_key(iter);
}
else
@@ -133,7 +133,7 @@ public class EditorWindow : Gtk.Window
private void key_selected_cb()
{
- Key? key = get_selected_key();
+ var key = get_selected_key();
string schema_name = "", summary = "", description = "", type = "", default_value = "";
if (key != null)
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 28b2c23..bd30c78 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -173,7 +173,7 @@ public class Directory : GLib.Object
if (have_children)
return;
have_children = true;
-
+
string[] items = model.client.list(full_name);
for (int i = 0; i < items.length; i++)
{
@@ -242,7 +242,7 @@ public class KeyModel: GLib.Object, Gtk.TreeModel/*, Gtk.TreeSortable*/
public Gtk.TreePath get_path(Gtk.TreeIter iter)
{
- Gtk.TreePath path = new Gtk.TreePath();
+ var path = new Gtk.TreePath();
path.append_index(get_key(iter).index);
return path;
}
@@ -378,7 +378,7 @@ public class EnumModel: GLib.Object, Gtk.TreeModel
public Gtk.TreePath get_path(Gtk.TreeIter iter)
{
- Gtk.TreePath path = new Gtk.TreePath();
+ var path = new Gtk.TreePath();
path.append_index((int)get_enum_value(iter).index);
return path;
}
@@ -524,7 +524,7 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
public Gtk.TreePath get_path(Gtk.TreeIter iter)
{
- Gtk.TreePath path = new Gtk.TreePath();
+ var path = new Gtk.TreePath();
path.append_index((int)get_directory(iter).index);
return path;
}
diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala
index e1dc11f..561df63 100644
--- a/editor/dconf-schema.vala
+++ b/editor/dconf-schema.vala
@@ -4,6 +4,7 @@ public class SchemaKey
public string name;
public string type;
public Variant default_value;
+ public SchemaValueRange? range;
public string? enum_name;
public string? summary;
public string? description;
@@ -14,7 +15,7 @@ public class SchemaKey
this.schema = schema;
this.gettext_domain = gettext_domain;
- for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next)
+ for (var prop = node->properties; prop != null; prop = prop->next)
{
if (prop->name == "name")
name = prop->children->content;
@@ -25,14 +26,14 @@ public class SchemaKey
type = "s";
enum_name = prop->children->content;
}
- //else
- // ?
+ else
+ warning ("Unknown property on <key>, %s", prop->name);
}
//if (name == null || type == null)
// ?
- for (Xml.Node* child = node->children; child != null; child = child->next)
+ for (var child = node->children; child != null; child = child->next)
{
if (child->name == "default")
{
@@ -49,10 +50,12 @@ public class SchemaKey
summary = child->children->content;
else if (child->name == "description")
description = child->children->content;
- //else
- // ?
+ else if (child->name == "range")
+ range = new SchemaValueRange (type, child);
+ else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
+ warning ("Unknown child tag in <key>, <%s>", child->name);
}
-
+
//if (default_value == null)
// ?
}
@@ -74,6 +77,43 @@ public class SchemaEnumValue : GLib.Object
}
}
+public class SchemaValueRange
+{
+ public Variant min;
+ public Variant max;
+
+ public SchemaValueRange(string type, Xml.Node* node)
+ {
+ for (var prop = node->properties; prop != null; prop = prop->next)
+ {
+ if (prop->name == "min")
+ {
+ try
+ {
+ min = Variant.parse(new VariantType(type), prop->children->content);
+ }
+ catch (VariantParseError e)
+ {
+ // ...
+ }
+ }
+ else if (prop->name == "max")
+ {
+ try
+ {
+ max = Variant.parse(new VariantType(type), prop->children->content);
+ }
+ catch (VariantParseError e)
+ {
+ // ...
+ }
+ }
+ else
+ warning ("Unknown property in <range>, %s", prop->name);
+ }
+ }
+}
+
public class SchemaEnum
{
public SchemaList list;
@@ -84,32 +124,32 @@ public class SchemaEnum
{
this.list = list;
- for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next)
+ for (var prop = node->properties; prop != null; prop = prop->next)
{
if (prop->name == "id")
id = prop->children->content;
- //else
- // ?
+ else
+ warning ("Unknown property in <enum>, %s", prop->name);
}
//if (id = null)
// ?
- for (Xml.Node* child = node->children; child != null; child = child->next)
+ for (var child = node->children; child != null; child = child->next)
{
if (child->name == "value")
{
string? nick = null;
int value = -1;
- for (Xml.Attr* prop = child->properties; prop != null; prop = prop->next)
+ for (var prop = child->properties; prop != null; prop = prop->next)
{
if (prop->name == "value")
value = prop->children->content.to_int();
else if (prop->name == "nick")
nick = prop->children->content;
- //else
- // ?
+ else
+ warning ("Unknown property in enum <value>, %s", prop->name);
}
//if (value < 0 || nick == null)
@@ -118,8 +158,8 @@ public class SchemaEnum
SchemaEnumValue schema_value = new SchemaEnumValue(this, values.length(), nick, value);
values.append(schema_value);
}
- //else
- // ?
+ else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
+ warning ("Unknown tag in <enum>, <%s>", child->name);
}
//if (default_value == null)
@@ -138,7 +178,7 @@ public class Schema
{
this.list = list;
- for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next)
+ for (var prop = node->properties; prop != null; prop = prop->next)
{
if (prop->name == "id")
id = prop->children->content;
@@ -146,18 +186,18 @@ public class Schema
path = prop->children->content; // FIXME: Does the path have to end with '/'?
else if (prop->name == "gettext-domain")
gettext_domain = prop->children->content;
- //else
- // ?
+ else
+ warning ("Unknown property on <schema>, %s", prop->name);
}
//if (id == null)
- // ?
+ //?
- for (Xml.Node* child = node->children; child != null; child = child->next)
+ for (var child = node->children; child != null; child = child->next)
{
if (child->name != "key")
continue;
- SchemaKey key = new SchemaKey(child, this, gettext_domain);
+ var key = new SchemaKey(child, this, gettext_domain);
keys.insert(key.name, key);
}
}
@@ -171,24 +211,24 @@ public class SchemaList
public void parse_file(string path)
{
- Xml.Doc* doc = Xml.Parser.parse_file(path);
+ var doc = Xml.Parser.parse_file(path);
if (doc == null)
return;
- Xml.Node* root = doc->get_root_element();
+ var root = doc->get_root_element();
if (root == null)
return;
if (root->name != "schemalist")
return;
string? gettext_domain = null;
- for (Xml.Attr* prop = root->properties; prop != null; prop = prop->next)
+ for (var prop = root->properties; prop != null; prop = prop->next)
{
if (prop->name == "gettext-domain")
gettext_domain = prop->children->content;
}
- for (Xml.Node* node = root->children; node != null; node = node->next)
+ for (var node = root->children; node != null; node = node->next)
{
if (node->name == "schema")
{
@@ -211,8 +251,8 @@ public class SchemaList
SchemaEnum enum = new SchemaEnum(this, node);
enums.insert(enum.id, enum);
}
- //else
- // ?
+ else if (node->type != Xml.ElementType.TEXT_NODE)
+ warning ("Unknown tag <%s>", node->name);
}
delete doc;
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 42da5b6..063dd63 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -18,7 +18,7 @@ private class KeyValueRenderer: Gtk.CellRenderer
text_renderer.text = key.value.get_string();
}
else if (key.type_string == "<enum>")
- {
+ {
combo_renderer.text = key.value.get_string();
combo_renderer.model = new EnumModel(key.schema.schema.list.enums.lookup(key.schema.enum_name));
mode = Gtk.CellRendererMode.EDITABLE;
@@ -228,13 +228,13 @@ private class KeyValueRenderer: Gtk.CellRenderer
private void toggle_cb(Gtk.CellRendererToggle renderer, string path)
{
- Key key = get_key_from_path(path);
+ var key = get_key_from_path(path);
key.value = new Variant.boolean(!key.value.get_boolean());
}
private void text_edited_cb(Gtk.CellRendererText renderer, string path, string text)
{
- Key key = get_key_from_path(path);
+ var key = get_key_from_path(path);
key.value = new Variant.string(text);
}