[Window] Add the ability to set the initial number of TildaTerminals
[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, "initial-terminals", "1");
46         g_hash_table_insert (config_defaults, "tab-position", "top");
47         g_hash_table_insert (config_defaults, "animation-orientation", "top");
48         g_hash_table_insert (config_defaults, "animation-delay", "15000");
49         g_hash_table_insert (config_defaults, "keep-above", "true");
50         g_hash_table_insert (config_defaults, "skip-taskbar-hint", "true");
51         g_hash_table_insert (config_defaults, "stick", "true");
52         g_hash_table_insert (config_defaults, "hidden-at-start", "false");
53         g_hash_table_insert (config_defaults, "centered-horizontally", "false");
54         g_hash_table_insert (config_defaults, "centered-vertically", "false");
55
56         /* Terminal Properties */
57         g_hash_table_insert (config_defaults, "background-image", NULL);
58         g_hash_table_insert (config_defaults, "shell", NULL);
59         g_hash_table_insert (config_defaults, "font", "Bitstream Vera Sans Mono 12");
60         g_hash_table_insert (config_defaults, "title", "Tilda");
61         g_hash_table_insert (config_defaults, "working-directory", NULL);
62         g_hash_table_insert (config_defaults, "web-browser", "firefox");
63         g_hash_table_insert (config_defaults, "scrollback-lines", "1000");
64         g_hash_table_insert (config_defaults, "transparency-percent", "0");
65         g_hash_table_insert (config_defaults, "backspace-binding", "vte-erase-auto");
66         g_hash_table_insert (config_defaults, "delete-binding", "vte-erase-auto");
67         g_hash_table_insert (config_defaults, "dynamic-title", "after-initial");
68         g_hash_table_insert (config_defaults, "exit-action", "exit");
69         g_hash_table_insert (config_defaults, "scrollbar-position", "right");
70 #if 0
71         /* These don't have properties yet! */
72         g_hash_table_insert (config_defaults, "background-color", "0;0;0");
73         g_hash_table_insert (config_defaults, "foreground-color", "255;255;255");
74 #endif
75         g_hash_table_insert (config_defaults, "scroll-background", "false");
76         g_hash_table_insert (config_defaults, "scroll-on-output", "false");
77         g_hash_table_insert (config_defaults, "scroll-on-keystroke", "true");
78         g_hash_table_insert (config_defaults, "antialiased", "true");
79         g_hash_table_insert (config_defaults, "allow-bold-text", "true");
80         g_hash_table_insert (config_defaults, "cursor-blinks", "true");
81         g_hash_table_insert (config_defaults, "audible-bell", "false");
82         g_hash_table_insert (config_defaults, "visible-bell", "true");
83         g_hash_table_insert (config_defaults, "double-buffered", "true");
84         g_hash_table_insert (config_defaults, "mouse-autohide", "true");
85 }
86
87 gboolean
88 tilda_config_init (const gchar *filename)
89 {
90         /* Create the hashtable */
91         config_defaults = g_hash_table_new (g_str_hash, g_str_equal);
92
93         /* Fill it with the default values */
94         tilda_config_setup_defaults ();
95
96         /* If we have no file to read from, then we are just using the defaults,
97          * and are done. */
98         if (filename == NULL)
99         {
100                 config_userprefs = NULL;
101                 return TRUE;
102         }
103
104         /* Create the key file */
105         config_userprefs = g_key_file_new ();
106
107         /* TODO: load from a file! */
108         return TRUE;
109 }
110
111 /**
112  * Since we DO NOT allow writing to the configuration file from a Tilda
113  * process (only from the wizard), this does nothing more than free the
114  * defaults hashtable, and free the opened keyfile.
115  */
116 gboolean
117 tilda_config_free ()
118 {
119         g_hash_table_destroy (config_defaults);
120         g_key_file_free (config_userprefs);
121
122         config_defaults = NULL;
123         config_userprefs = NULL;
124
125         return TRUE;
126 }
127
128 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */