[Config] Add initial implementation of the configuration subsystem
authorIra W. Snyder <devel@irasnyder.com>
Sat, 26 Jan 2008 06:02:31 +0000 (22:02 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sat, 26 Jan 2008 06:07:12 +0000 (22:07 -0800)
This is my initial attempt at a configuration subsystem. I used what
I believe to be sensible defaults for now. They will probably have to
be changed later.

This version of the config system is missing the ability to actually
load a GKeyFile. It just ignores it for now.

This version of the config system is missing versioning and migration
capabilities. They will be added later.

Makefile
tilda-config.c [new file with mode: 0644]
tilda-config.h [new file with mode: 0644]

index b8f8cc9..7ce6909 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,12 +15,15 @@ ALL_LIBS=`pkg-config --libs gtk+-2.0 vte dbus-glib-1`
 
 all: tilda
 
-tilda: tilda.o tilda-controller.o tilda-window.o tilda-terminal.o tomboykeybinder.o eggaccelerators.o
+tilda: tilda.o tilda-config.o tilda-controller.o tilda-window.o tilda-terminal.o tomboykeybinder.o eggaccelerators.o
        $(GCC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(ALL_LIBS)
 
 tilda.o: tilda.c tilda.h
        $(GCC) $(CFLAGS) -c -o $@ $< $(ALL_CFLAGS)
 
+tilda-config.o: tilda-config.c tilda-config.h
+       $(GCC) $(CFLAGS) -c -o $@ $< $(ALL_CFLAGS)
+
 tilda-controller.o: tilda-controller.c tilda-controller.h tilda-controller.xml
        dbus-binding-tool --mode=glib-server --prefix=tilda_controller tilda-controller.xml > tilda-controller-dbus-glue.h
        $(GCC) $(CFLAGS) -c -o $@ $< $(ALL_CFLAGS)
diff --git a/tilda-config.c b/tilda-config.c
new file mode 100644 (file)
index 0000000..cc33fb1
--- /dev/null
@@ -0,0 +1,127 @@
+#include "debug.h"
+#include "tilda-config.h"
+
+GHashTable *config_defaults;
+GKeyFile   *config_userprefs;
+
+/*
+ * TODO:
+ *
+ * Add some capability to version the config file. Maybe a [meta] section.
+ *
+ * Make it possible to get the version number without firing up the config system
+ * as a whole. Or maybe just add the migration here, in this file, upon startup.
+ *
+ * The whole idea of this is that each of the objects that accesses the config
+ * system implements their own lookup engine.
+ */
+
+/*
+ * The main idea behind this configuration system is that each of the objects
+ * that accesses the config system implements their own lookup scheme. Since
+ * both TildaWindow and TildaTerminal need to lookup things different ways,
+ * I thought this would be the most logical solution.
+ */
+
+/**
+ * This function adds all of the defaults to the defaults hashtable.
+ * It just uses their names, since there are currently no conflicts
+ * in the properties of TildaWindow and TildaTerminal. If conflicts
+ * become a problem in the future, prefix them with "w-" and "t-",
+ * for example. Then fix up all callers. :) */
+static void
+tilda_config_setup_defaults ()
+{
+       /* NOTE: All properties must be specified as strings. This sucks, but it really
+        * is easiest to keep it this way. We can then implement custom functions to
+        * change the values as we need them. */
+
+       /* Window properties */
+       g_hash_table_insert (config_defaults, "key", NULL);
+       g_hash_table_insert (config_defaults, "height", "300");
+       g_hash_table_insert (config_defaults, "width", "600");
+       g_hash_table_insert (config_defaults, "x-position", "0");
+       g_hash_table_insert (config_defaults, "y-position", "0");
+       g_hash_table_insert (config_defaults, "tab-position", "top");
+       g_hash_table_insert (config_defaults, "animation-orientation", "top");
+       g_hash_table_insert (config_defaults, "animation-delay", "15000");
+       g_hash_table_insert (config_defaults, "keep-above", "true");
+       g_hash_table_insert (config_defaults, "skip-taskbar-hint", "true");
+       g_hash_table_insert (config_defaults, "stick", "true");
+       g_hash_table_insert (config_defaults, "hidden-at-start", "false");
+       g_hash_table_insert (config_defaults, "centered-horizontally", "false");
+       g_hash_table_insert (config_defaults, "centered-vertically", "false");
+
+       /* Terminal Properties */
+       g_hash_table_insert (config_defaults, "background-image", NULL);
+       g_hash_table_insert (config_defaults, "shell", NULL);
+       g_hash_table_insert (config_defaults, "font", "Bitstream Vera Sans Mono 12");
+       g_hash_table_insert (config_defaults, "title", "Tilda");
+       g_hash_table_insert (config_defaults, "working-directory", NULL);
+       g_hash_table_insert (config_defaults, "web-browser", "firefox");
+       g_hash_table_insert (config_defaults, "scrollback-lines", "1000");
+       g_hash_table_insert (config_defaults, "transparency-percent", "0");
+       g_hash_table_insert (config_defaults, "backspace-binding", "vte-erase-auto");
+       g_hash_table_insert (config_defaults, "delete-binding", "vte-erase-auto");
+       g_hash_table_insert (config_defaults, "dynamic-title", "after-initial");
+       g_hash_table_insert (config_defaults, "exit-action", "exit");
+       g_hash_table_insert (config_defaults, "scrollbar-position", "right");
+#if 0
+       /* These don't have properties yet! */
+       g_hash_table_insert (config_defaults, "background-color", "0;0;0");
+       g_hash_table_insert (config_defaults, "foreground-color", "255;255;255");
+#endif
+       g_hash_table_insert (config_defaults, "scroll-background", "false");
+       g_hash_table_insert (config_defaults, "scroll-on-output", "false");
+       g_hash_table_insert (config_defaults, "scroll-on-keystroke", "true");
+       g_hash_table_insert (config_defaults, "antialiased", "true");
+       g_hash_table_insert (config_defaults, "allow-bold-text", "true");
+       g_hash_table_insert (config_defaults, "cursor-blinks", "true");
+       g_hash_table_insert (config_defaults, "audible-bell", "false");
+       g_hash_table_insert (config_defaults, "visible-bell", "true");
+       g_hash_table_insert (config_defaults, "double-buffered", "true");
+       g_hash_table_insert (config_defaults, "mouse-autohide", "true");
+}
+
+gboolean
+tilda_config_init (const gchar *filename)
+{
+       /* Create the hashtable */
+       config_defaults = g_hash_table_new (g_str_hash, g_str_equal);
+
+       /* Fill it with the default values */
+       tilda_config_setup_defaults ();
+
+       /* If we have no file to read from, then we are just using the defaults,
+        * and are done. */
+       if (filename == NULL)
+       {
+               config_userprefs = NULL;
+               return TRUE;
+       }
+
+       /* Create the key file */
+       config_userprefs = g_key_file_new ();
+
+       /* TODO: load from a file! */
+       return TRUE;
+}
+
+/**
+ * Since we DO NOT allow writing to the configuration file from a Tilda
+ * process (only from the wizard), this does nothing more than free the
+ * defaults hashtable, and free the opened keyfile.
+ */
+gboolean
+tilda_config_free ()
+{
+       g_hash_table_destroy (config_defaults);
+       g_key_file_free (config_userprefs);
+
+       config_defaults = NULL;
+       config_userprefs = NULL;
+
+       return TRUE;
+}
+
+/* vim: set ts=4 sts=4 sw=4 noet tw=112: */
diff --git a/tilda-config.h b/tilda-config.h
new file mode 100644 (file)
index 0000000..e18b870
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef TILDA_CONFIG_H
+#define TILDA_CONFIG_H
+
+#include <glib.h>
+
+/* Global configuration-holding structures */
+extern GHashTable *config_defaults;
+extern GKeyFile   *config_userprefs;
+
+/* Set-up and tear-down functions */
+gboolean tilda_config_init (const gchar *filename);
+gboolean tilda_config_free ();
+
+#endif /* TILDA_CONFIG_H */
+
+/* vim: set ts=4 sts=4 sw=4 noet tw=112: */