7 static void config_free_entry(ConfigEntry *entry);
8 static void config_set_entry(char *name, ConfigValueType type,
10 static void config_def_free(ConfigDefEntry *entry);
11 static void print_config(GQuark q, gpointer data, gpointer fonk){
12 ConfigDefEntry *e = (ConfigDefEntry *)data;
13 g_message("config: %s %d", e->name, e->hasList);
16 static GData *config = NULL;
17 static GData *config_def = NULL;
19 /* provided by cparse.l */
20 void cparse_go(char *filename, FILE *);
25 /* set up options exported by the kernel */
26 config_def_set(config_def_new("engine", Config_String,
28 "The name of the theming engine to be used "
29 "to decorate windows."));
30 config_def_set(config_def_new("theme", Config_String,
32 "The name of the theme to load with the "
34 config_def_set(config_def_new("font", Config_String,
36 "The fontstring specifying the font to "
37 "be used in window titlebars."));
38 config_def_set(config_def_new("font.shadow", Config_Bool,
39 "Titlebar Font Shadow",
40 "Whether or not the text in the window "
41 "titlebars gets a drop shadow."));
42 config_def_set(config_def_new("font.shadow.offset", Config_Integer,
43 "Titlebar Font Shadow Offset",
44 "The offset of the drop shadow for text "
45 "in the window titlebars."));
46 config_def_set(config_def_new("titlebar.layout", Config_String,
48 "The ordering of the elements in the "
49 "window titlebars."));
51 /*g_datalist_foreach(&config_def, print_config, NULL);*/
54 void config_shutdown()
56 g_datalist_clear(&config);
57 g_datalist_clear(&config_def);
64 gboolean load = FALSE;
66 /* load the user rc */
67 path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
68 if ((file = fopen(path, "r")) != NULL) {
69 cparse_go(path, file);
76 /* load the system wide rc */
77 path = g_build_filename(RCDIR, "rc3", NULL);
78 if ((file = fopen(path, "r")) != NULL) {
79 /*cparse_go(path, file);*/
86 gboolean config_set(char *name, ConfigValueType type, ConfigValue value)
91 name = g_ascii_strdown(name, -1);
93 /*g_datalist_foreach(&config_def, print_config, NULL);*/
94 def = g_datalist_get_data(&config_def, name);
97 g_warning("Invalid config option '%s'", name);
100 gboolean found = FALSE;
104 g_assert(it != NULL);
106 if (g_ascii_strcasecmp(it->data, value.string) == 0) {
110 } while ((it = it->next));
113 g_warning("Invalid value '%s' for config option '%s'",
117 } else if (type != def->type) {
118 g_warning("Incorrect type of value for config option '%s'", name);
125 config_set_entry(name, type, value);
132 gboolean config_get(char *name, ConfigValueType type, ConfigValue *value)
135 gboolean ret = FALSE;
137 name = g_ascii_strdown(name, -1);
138 entry = g_datalist_get_data(&config, name);
139 if (entry != NULL && entry->type == type) {
140 *value = entry->value;
147 static void config_set_entry(char *name, ConfigValueType type,
150 ConfigEntry *entry = NULL;
152 entry = g_new(ConfigEntry, 1);
155 if (type == Config_String)
156 entry->value.string = g_strdup(value.string);
158 entry->value = value;
160 g_datalist_set_data_full(&config, name, entry,
161 (GDestroyNotify)config_free_entry);
164 static void config_free_entry(ConfigEntry *entry)
168 if(entry->type == Config_String) {
169 g_free(entry->value.string);
170 entry->value.string = NULL;
175 ConfigDefEntry *config_def_new(char *name, ConfigValueType type,
176 char *descriptive_name, char *long_description)
178 ConfigDefEntry *entry;
180 entry = g_new(ConfigDefEntry, 1);
181 entry->name = g_ascii_strdown(name, -1);
182 entry->descriptive_name = g_strdup(descriptive_name);
183 entry->long_description = g_strdup(long_description);
184 entry->hasList = FALSE;
186 entry->values = NULL;
190 static void config_def_free(ConfigDefEntry *entry)
195 g_free(entry->descriptive_name);
196 g_free(entry->long_description);
197 if (entry->hasList) {
198 for (it = entry->values; it != NULL; it = it->next)
200 g_slist_free(entry->values);
205 gboolean config_def_add_value(ConfigDefEntry *entry, char *value)
207 if (entry->type != Config_String) {
208 g_warning("Tried adding value to non-string config definition");
212 entry->hasList = TRUE;
213 entry->values = g_slist_append(entry->values, g_ascii_strdown(value, -1));
217 gboolean config_def_set(ConfigDefEntry *entry)
219 gboolean ret = FALSE;
222 if ((def = g_datalist_get_data(&config_def, entry->name))) {
223 g_assert(def != entry); /* adding it twice!? */
224 g_warning("Definition already set for config option '%s'. ",
226 config_def_free(entry);
228 g_datalist_set_data_full(&config_def, entry->name, entry,
229 (GDestroyNotify)config_def_free);