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 built in variables! and their default values! */
27 config_def_set(config_def_new("engine", Config_String));
28 config_def_set(config_def_new("theme", Config_String));
29 config_def_set(config_def_new("font", Config_String));
30 config_def_set(config_def_new("font.shadow.offset", Config_Integer));
31 config_def_set(config_def_new("font.shadow.tint", Config_Integer));
32 config_def_set(config_def_new("titlebar.layout", Config_String));
34 /*g_datalist_foreach(&config_def, print_config, NULL);*/
37 void config_shutdown()
39 g_datalist_clear(&config);
40 g_datalist_clear(&config_def);
47 gboolean load = FALSE;
49 /* load the user rc */
50 path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
51 if ((file = fopen(path, "r")) != NULL) {
52 cparse_go(path, file);
60 /* load the system wide rc */
61 path = g_build_filename(RCDIR, "rc3", NULL);
62 if ((file = fopen(path, "r")) != NULL) {
63 cparse_go(path, file);
69 gboolean config_set(char *name, ConfigValueType type, ConfigValue value)
74 name = g_ascii_strdown(name, -1);
75 g_message("Setting %s", name);
77 /*g_datalist_foreach(&config_def, print_config, NULL);*/
78 def = g_datalist_get_data(&config_def, name);
81 g_message("Invalid config option '%s'", name);
84 gboolean found = FALSE;
90 if (g_ascii_strcasecmp(it->data, value.string) == 0) {
94 } while ((it = it->next));
97 g_message("Invalid value '%s' for config option '%s'",
107 config_set_entry(name, type, value);
114 gboolean config_get(char *name, ConfigValueType type, ConfigValue *value)
117 gboolean ret = FALSE;
119 name = g_ascii_strdown(name, -1);
120 entry = g_datalist_get_data(&config, name);
121 if (entry != NULL && entry->type == type) {
122 *value = entry->value;
129 static void config_set_entry(char *name, ConfigValueType type,
132 ConfigEntry *entry = NULL;
134 entry = g_new(ConfigEntry, 1);
137 if (type == Config_String)
138 entry->value.string = g_strdup(value.string);
140 entry->value = value;
142 g_datalist_set_data_full(&config, name, entry,
143 (GDestroyNotify)config_free_entry);
146 static void config_free_entry(ConfigEntry *entry)
150 if(entry->type == Config_String) {
151 g_free(entry->value.string);
152 entry->value.string = NULL;
157 ConfigDefEntry *config_def_new(char *name, ConfigValueType type)
159 ConfigDefEntry *entry;
161 entry = g_new(ConfigDefEntry, 1);
162 entry->name = g_ascii_strdown(name, -1);
163 entry->hasList = FALSE;
165 entry->values = NULL;
169 static void config_def_free(ConfigDefEntry *entry)
174 if (entry->hasList) {
175 for (it = entry->values; it != NULL; it = it->next)
177 g_slist_free(entry->values);
182 gboolean config_def_add_value(ConfigDefEntry *entry, char *value)
184 if (entry->type != Config_String) {
185 g_warning("Tried adding value to non-string config definition");
189 entry->hasList = TRUE;
190 entry->values = g_slist_append(entry->values, g_ascii_strdown(value, -1));
194 gboolean config_def_set(ConfigDefEntry *entry)
196 gboolean ret = FALSE;
199 if ((def = g_datalist_get_data(&config_def, entry->name))) {
200 g_assert(def != entry); /* adding it twice!? */
201 g_warning("Definition already set for config option '%s'. ",
203 config_def_free(entry);
205 g_datalist_set_data_full(&config_def, entry->name, entry,
206 (GDestroyNotify)config_def_free);