]>
Dogcows Code - chaz/openbox/blob - openbox/config.c
a6114b4768b571b08a93cd019c78e898c1a9e717
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);
92 g_message("Setting %s", name
);
94 /*g_datalist_foreach(&config_def, print_config, NULL);*/
95 def
= g_datalist_get_data(&config_def
, name
);
98 g_message("Invalid config option '%s'", name
);
101 gboolean found
= FALSE
;
105 g_assert(it
!= NULL
);
107 if (g_ascii_strcasecmp(it
->data
, value
.string
) == 0) {
111 } while ((it
= it
->next
));
114 g_message("Invalid value '%s' for config option '%s'",
124 config_set_entry(name
, type
, value
);
131 gboolean
config_get(char *name
, ConfigValueType type
, ConfigValue
*value
)
134 gboolean ret
= FALSE
;
136 name
= g_ascii_strdown(name
, -1);
137 entry
= g_datalist_get_data(&config
, name
);
138 if (entry
!= NULL
&& entry
->type
== type
) {
139 *value
= entry
->value
;
146 static void config_set_entry(char *name
, ConfigValueType type
,
149 ConfigEntry
*entry
= NULL
;
151 entry
= g_new(ConfigEntry
, 1);
154 if (type
== Config_String
)
155 entry
->value
.string
= g_strdup(value
.string
);
157 entry
->value
= value
;
159 g_datalist_set_data_full(&config
, name
, entry
,
160 (GDestroyNotify
)config_free_entry
);
163 static void config_free_entry(ConfigEntry
*entry
)
167 if(entry
->type
== Config_String
) {
168 g_free(entry
->value
.string
);
169 entry
->value
.string
= NULL
;
174 ConfigDefEntry
*config_def_new(char *name
, ConfigValueType type
,
175 char *descriptive_name
, char *long_description
)
177 ConfigDefEntry
*entry
;
179 entry
= g_new(ConfigDefEntry
, 1);
180 entry
->name
= g_ascii_strdown(name
, -1);
181 entry
->descriptive_name
= g_strdup(descriptive_name
);
182 entry
->long_description
= g_strdup(long_description
);
183 entry
->hasList
= FALSE
;
185 entry
->values
= NULL
;
189 static void config_def_free(ConfigDefEntry
*entry
)
194 g_free(entry
->descriptive_name
);
195 g_free(entry
->long_description
);
196 if (entry
->hasList
) {
197 for (it
= entry
->values
; it
!= NULL
; it
= it
->next
)
199 g_slist_free(entry
->values
);
204 gboolean
config_def_add_value(ConfigDefEntry
*entry
, char *value
)
206 if (entry
->type
!= Config_String
) {
207 g_warning("Tried adding value to non-string config definition");
211 entry
->hasList
= TRUE
;
212 entry
->values
= g_slist_append(entry
->values
, g_ascii_strdown(value
, -1));
216 gboolean
config_def_set(ConfigDefEntry
*entry
)
218 gboolean ret
= FALSE
;
221 if ((def
= g_datalist_get_data(&config_def
, entry
->name
))) {
222 g_assert(def
!= entry
); /* adding it twice!? */
223 g_warning("Definition already set for config option '%s'. ",
225 config_def_free(entry
);
227 g_datalist_set_data_full(&config_def
, entry
->name
, entry
,
228 (GDestroyNotify
)config_def_free
);
This page took 0.047276 seconds and 4 git commands to generate.