[dconf] Bring dconf-editor in-tree



commit e3fc1eede1089647a86253b88c17a0ac447c66f4
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Jun 11 14:07:36 2010 -0400

    Bring dconf-editor in-tree

 Makefile.am              |    2 +-
 configure.ac             |    3 +
 editor/.gitignore        |    3 +
 editor/Makefile.am       |    6 ++
 editor/dconf-editor.vala |  158 ++++++++++++++++++++++++++++++++++++++++++++++
 editor/dconf.vapi        |   43 +++++++++++++
 6 files changed, 214 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 541464c..1677ded 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,3 @@
-SUBDIRS = gvdb service gsettings tests client bin engine common docs
+SUBDIRS = gvdb service gsettings tests client bin engine common docs editor
 
 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
diff --git a/configure.ac b/configure.ac
index d12bd44..8916c31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,10 +3,12 @@ AM_INIT_AUTOMAKE
 AM_SILENT_RULES(yes)
 GOBJECT_INTROSPECTION_CHECK([0.6.7])
 AC_PROG_LIBTOOL
+AM_PROG_VALAC
 GTK_DOC_CHECK
 AC_PROG_CC
 
 PKG_CHECK_MODULES(gio, gio-2.0 >= 2.25.7)
+PKG_CHECK_MODULES(gtk, gtk+-2.0)
 
 AC_ARG_WITH(gio_modules_dir, [  --with-gio-modules-dir=PATH choose directory for the GIO module, [default=LIBDIR/gio/modules]], giomodulesdir="$withval", giomodulesdir=${libdir}/gio/modules)
 AC_SUBST(giomodulesdir)
@@ -30,6 +32,7 @@ AC_OUTPUT([
   client/Makefile
   service/Makefile
   bin/Makefile
+  editor/Makefile
   tests/Makefile
   docs/Makefile
   Makefile
diff --git a/editor/.gitignore b/editor/.gitignore
new file mode 100644
index 0000000..292b5b8
--- /dev/null
+++ b/editor/.gitignore
@@ -0,0 +1,3 @@
+*.c
+*.stamp
+dconf-editor
diff --git a/editor/Makefile.am b/editor/Makefile.am
new file mode 100644
index 0000000..2d6a486
--- /dev/null
+++ b/editor/Makefile.am
@@ -0,0 +1,6 @@
+bin_PROGRAMS = dconf-editor
+
+AM_CFLAGS = $(gtk_CFLAGS) -I$(top_srcdir)/common -I$(top_srcdir)/client
+AM_VALAFLAGS = --pkg gtk+-2.0
+dconf_editor_LDADD = ../client/libdconf.la $(gtk_LIBS)
+dconf_editor_SOURCES = dconf-editor.vala dconf.vapi
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
new file mode 100644
index 0000000..127881a
--- /dev/null
+++ b/editor/dconf-editor.vala
@@ -0,0 +1,158 @@
+public class ConfModel : Gtk.TreeStore
+{
+    public ConfModel()
+    {
+        set_column_types({typeof(string), typeof(string)});
+    }
+    
+    private Gtk.TreeIter? get_iter(string[] split_key, int length)
+    {
+        if (length == 1) // NOTE: Assumes key started with /
+            return null;
+
+        Gtk.TreeIter? parent = get_iter(split_key, length - 1);
+        string key = split_key[length - 1];
+
+        Gtk.TreeIter iter;
+        bool have_iter = iter_children(out iter, parent);
+        while (have_iter)
+        {
+            string name;
+            get(iter, 0, out name, -1);
+            if (name == key)
+                return iter;
+            if (name > key)
+            {
+                insert_before(out iter, parent, iter);
+                break;
+            }
+            have_iter = iter_next(ref iter);
+        }
+        if (!have_iter)
+            append(out iter, parent);
+
+        set(iter, 0, key, -1);
+
+        return iter;
+    }
+
+    public void add_key(string key)
+    {
+        string[] tokens = key.split("/", -1);    
+        Gtk.TreeIter? iter = get_iter(tokens, tokens.length);
+        set(iter, 1, key, -1);
+    }
+}
+
+public class EditorWindow : Gtk.Window
+{
+    public ConfModel model;
+
+    private DConf.Client client;
+    private Gtk.TreeView tree_view;
+    private Gtk.Label name_label;
+    private Gtk.Label value_label;
+
+    public EditorWindow(DConf.Client client)
+    {
+        this.client = client;
+        set_title("Configuration Editor");
+        set_default_size(600, 300);
+        set_border_width(6);
+        
+        Gtk.HBox hbox = new Gtk.HBox(false, 6);
+        hbox.show();
+        add(hbox);
+
+        model = new ConfModel();
+
+        tree_view = new Gtk.TreeView();
+        tree_view.set_headers_visible(false);
+        tree_view.set_model(model);
+        tree_view.insert_column_with_attributes(-1, "Key", new Gtk.CellRendererText(), "text", 0, null);
+        tree_view.get_selection().changed.connect(key_selected_cb);
+        tree_view.show();
+        hbox.pack_start(tree_view, false, false, 0);
+
+        Gtk.VBox vbox = new Gtk.VBox(false, 6);
+        vbox.show();
+        hbox.pack_start(vbox, true, true, 0);
+
+        name_label = new Gtk.Label("");
+        name_label.set_alignment(0.0f, 0.5f);
+        name_label.show();
+        vbox.pack_start(name_label, false, true, 0);
+
+        value_label = new Gtk.Label("");
+        value_label.set_alignment(0.0f, 0.5f);
+        value_label.show();
+        vbox.pack_start(value_label, false, true, 0);
+    }
+    
+    private string? get_selected_key()
+    {
+        Gtk.TreeIter iter;
+        if (!tree_view.get_selection().get_selected(null, out iter))
+            return null;
+
+        string key;
+        model.get(iter, 1, out key, -1);
+        return key;
+    }
+    
+    private void key_selected_cb()
+    {
+        string? key = get_selected_key();
+        if (key == null)
+        {
+            name_label.set_text("");
+            value_label.set_text("");
+        }
+        else
+        {
+            GLib.Variant value = client.read(key);
+            name_label.set_text(key);
+            value_label.set_text(value == null ? "(unset)" : value.print(false));
+        }
+    }
+}
+
+class ConfigurationEditor
+{
+    private DConf.Client client;
+    private EditorWindow window;
+    
+    public ConfigurationEditor()
+    {
+        client = new DConf.Client("", true, null, null);
+        window = new EditorWindow(client);
+        window.destroy.connect(Gtk.main_quit);
+        
+        read_keys("/");
+
+        window.show();
+    }
+
+    private void read_keys(string parent)
+    {
+        string[] keys = client.list(parent);
+        for (int i = 0; i < keys.length; i++)
+        {
+            if (DConf.is_rel_dir(keys[i]))
+                read_keys(parent + keys[i]);
+            else
+                window.model.add_key(parent + keys[i]);
+        }
+    }
+
+    public static int main(string[] args)
+    {
+        Gtk.init(ref args);
+
+        new ConfigurationEditor();
+
+        Gtk.main();
+
+        return 0;
+    }
+}
diff --git a/editor/dconf.vapi b/editor/dconf.vapi
new file mode 100644
index 0000000..1a1f15b
--- /dev/null
+++ b/editor/dconf.vapi
@@ -0,0 +1,43 @@
+/* dconf.vapi generated by vapigen, do not modify. */
+
+[CCode (cprefix = "DConf", lower_case_cprefix = "dconf_")]
+namespace DConf {
+	[CCode (cheader_filename = "dconf.h")]
+	public class Client : GLib.Object {
+		[CCode (has_construct_function = false)]
+		public Client (string context, bool can_write, DConf.WatchFunc? watch_func, GLib.DestroyNotify? notify);
+		public bool is_writable (string prefix) throws GLib.Error;
+		[CCode (array_length_type = "gsize")]
+		public string[] list (string prefix);
+		public GLib.Variant read (string key);
+		public bool set_locked (string path, bool locked, GLib.Cancellable cancellable) throws GLib.Error;
+		public async bool set_locked_async (string path, bool locked, GLib.Cancellable cancellable) throws GLib.Error;
+		public bool set_locked_finish (GLib.AsyncResult _result) throws GLib.Error;
+		public bool unwatch (string name) throws GLib.Error;
+		public async bool unwatch_async (string name);
+		public bool unwatch_finish (GLib.AsyncResult _result);
+		public bool watch (string name) throws GLib.Error;
+		public async bool watch_async (string name);
+		public bool watch_finish (GLib.AsyncResult _result);
+		public bool write (string key, GLib.Variant value, uint64 sequence, GLib.Cancellable cancellable) throws GLib.Error;
+		public async bool write_async (string key, GLib.Variant value, GLib.Cancellable cancellable) throws GLib.Error;
+		public bool write_finish (GLib.AsyncResult _result, uint64 sequence) throws GLib.Error;
+		public bool write_many (string prefix, string keys, out unowned GLib.Variant values, uint64 sequence, GLib.Cancellable cancellable) throws GLib.Error;
+		public async bool write_many_async (string prefix, string keys, out unowned GLib.Variant values, GLib.Cancellable cancellable) throws GLib.Error;
+		public bool write_many_finish (GLib.AsyncResult _result, uint64 sequence) throws GLib.Error;
+	}
+	[CCode (cheader_filename = "dconf.h")]
+	public delegate void WatchFunc (DConf.Client client, string path, string items);
+	[CCode (cheader_filename = "dconf.h")]
+	public static bool is_dir (string str);
+	[CCode (cheader_filename = "dconf.h")]
+	public static bool is_key (string str);
+	[CCode (cheader_filename = "dconf.h")]
+	public static bool is_path (string str);
+	[CCode (cheader_filename = "dconf.h")]
+	public static bool is_rel (string str);
+	[CCode (cheader_filename = "dconf.h")]
+	public static bool is_rel_dir (string str);
+	[CCode (cheader_filename = "dconf.h")]
+	public static bool is_rel_key (string str);
+}



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