Add the config system to main()
[tilda-gobject.git] / tilda-config.c
1 #include "debug.h"
2 #include "tilda-config.h"
3
4 GHashTable *config_defaults;
5 GKeyFile   *config_userprefs;
6
7 /*
8  * TODO:
9  *
10  * Add some capability to version the config file. Maybe a [meta] section.
11  *
12  * Make it possible to get the version number without firing up the config system
13  * as a whole. Or maybe just add the migration here, in this file, upon startup.
14  *
15  * The whole idea of this is that each of the objects that accesses the config
16  * system implements their own lookup engine.
17  */
18
19 /*
20  * The main idea behind this configuration system is that each of the objects
21  * that accesses the config system implements their own lookup scheme. Since
22  * both TildaWindow and TildaTerminal need to lookup things different ways,
23  * I thought this would be the most logical solution.
24  */
25
26 /**
27  * This function adds all of the defaults to the defaults hashtable.
28  * It just uses their names, since there are currently no conflicts
29  * in the properties of TildaWindow and TildaTerminal. If conflicts
30  * become a problem in the future, prefix them with "w-" and "t-",
31  * for example. Then fix up all callers. :) */
32 static void
33 tilda_config_setup_defaults ()
34 {
35         /* NOTE: All properties must be specified as strings. This sucks, but it really
36          * is easiest to keep it this way. We can then implement custom functions to
37          * change the values as we need them. */
38
39         /* Window properties */
40         g_hash_table_insert (config_defaults, "key", NULL);
41         g_hash_table_insert (config_defaults, "height", "300");
42         g_hash_table_insert (config_defaults, "width", "600");
43         g_hash_table_insert (config_defaults, "x-position", "0");
44         g_hash_table_insert (config_defaults, "y-position", "0");
45         g_hash_table_insert (config_defaults, "tab-position", "top");
46         g_hash_table_insert (config_defaults, "animation-orientation", "top");
47         g_hash_table_insert (config_defaults, "animation-delay", "15000");
48         g_hash_table_insert (config_defaults, "keep-above", "true");
49         g_hash_table_insert (config_defaults, "skip-taskbar-hint", "true");
50         g_hash_table_insert (config_defaults, "stick", "true");
51         g_hash_table_insert (config_defaults, "hidden-at-start", "false");
52         g_hash_table_insert (config_defaults, "centered-horizontally", "false");
53         g_hash_table_insert (config_defaults, "centered-vertically", "false");
54
55         /* Terminal Properties */
56         g_hash_table_insert (config_defaults, "background-image", NULL);
57         g_hash_table_insert (config_defaults, "shell", NULL);
58         g_hash_table_insert (config_defaults, "font", "Bitstream Vera Sans Mono 12");
59         g_hash_table_insert (config_defaults, "title", "Tilda");
60         g_hash_table_insert (config_defaults, "working-directory", NULL);
61         g_hash_table_insert (config_defaults, "web-browser", "firefox");
62         g_hash_table_insert (config_defaults, "scrollback-lines", "1000");
63         g_hash_table_insert (config_defaults, "transparency-percent", "0");
64         g_hash_table_insert (config_defaults, "backspace-binding", "vte-erase-auto");
65         g_hash_table_insert (config_defaults, "delete-binding", "vte-erase-auto");
66         g_hash_table_insert (config_defaults, "dynamic-title", "after-initial");
67         g_hash_table_insert (config_defaults, "exit-action", "exit");
68         g_hash_table_insert (config_defaults, "scrollbar-position", "right");
69 #if 0
70         /* These don't have properties yet! */
71         g_hash_table_insert (config_defaults, "background-color", "0;0;0");
72         g_hash_table_insert (config_defaults, "foreground-color", "255;255;255");
73 #endif
74         g_hash_table_insert (config_defaults, "scroll-background", "false");
75         g_hash_table_insert (config_defaults, "scroll-on-output", "false");
76         g_hash_table_insert (config_defaults, "scroll-on-keystroke", "true");
77         g_hash_table_insert (config_defaults, "antialiased", "true");
78         g_hash_table_insert (config_defaults, "allow-bold-text", "true");
79         g_hash_table_insert (config_defaults, "cursor-blinks", "true");
80         g_hash_table_insert (config_defaults, "audible-bell", "false");
81         g_hash_table_insert (config_defaults, "visible-bell", "true");
82         g_hash_table_insert (config_defaults, "double-buffered", "true");
83         g_hash_table_insert (config_defaults, "mouse-autohide", "true");
84 }
85
86 gboolean
87 tilda_config_init (const gchar *filename)
88 {
89         /* Create the hashtable */
90         config_defaults = g_hash_table_new (g_str_hash, g_str_equal);
91
92         /* Fill it with the default values */
93         tilda_config_setup_defaults ();
94
95         /* If we have no file to read from, then we are just using the defaults,
96          * and are done. */
97         if (filename == NULL)
98         {
99                 config_userprefs = NULL;
100                 return TRUE;
101         }
102
103         /* Create the key file */
104         config_userprefs = g_key_file_new ();
105
106         /* TODO: load from a file! */
107         return TRUE;
108 }
109
110 /**
111  * Since we DO NOT allow writing to the configuration file from a Tilda
112  * process (only from the wizard), this does nothing more than free the
113  * defaults hashtable, and free the opened keyfile.
114  */
115 gboolean
116 tilda_config_free ()
117 {
118         g_hash_table_destroy (config_defaults);
119         g_key_file_free (config_userprefs);
120
121         config_defaults = NULL;
122         config_userprefs = NULL;
123
124         return TRUE;
125 }
126
127 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */