| 34 |
34 |
| 35 #if GLIB_CHECK_VERSION(2,6,0) |
35 #if GLIB_CHECK_VERSION(2,6,0) |
| 36 static GKeyFile *gkfile; |
36 static GKeyFile *gkfile; |
| 37 #endif |
37 #endif |
| 38 |
38 |
| 39 static GHashTable *unknowns; |
|
| 40 static char * str_styles[GNT_STYLES]; |
39 static char * str_styles[GNT_STYLES]; |
| 41 static int int_styles[GNT_STYLES]; |
40 static int int_styles[GNT_STYLES]; |
| 42 static int bool_styles[GNT_STYLES]; |
41 static int bool_styles[GNT_STYLES]; |
| 43 |
42 |
| 44 const char *gnt_style_get(GntStyle style) |
43 const char *gnt_style_get(GntStyle style) |
| 45 { |
44 { |
| 46 return str_styles[style]; |
45 return str_styles[style]; |
| 47 } |
46 } |
| 48 |
47 |
| 49 const char *gnt_style_get_from_name(const char *name) |
48 const char *gnt_style_get_from_name(const char *group, const char *key) |
| 50 { |
49 { |
| 51 return g_hash_table_lookup(unknowns, name); |
50 #if GLIB_CHECK_VERSION(2,6,0) |
| |
51 return g_key_file_get_value(gkfile, group, key, NULL); |
| |
52 #endif |
| 52 } |
53 } |
| 53 |
54 |
| 54 gboolean gnt_style_get_bool(GntStyle style, gboolean def) |
55 gboolean gnt_style_get_bool(GntStyle style, gboolean def) |
| 55 { |
56 { |
| 56 int i; |
57 int i; |
| 291 for (i = 0; styles[i].style; i++) |
292 for (i = 0; styles[i].style; i++) |
| 292 { |
293 { |
| 293 str_styles[styles[i].en] = |
294 str_styles[styles[i].en] = |
| 294 g_key_file_get_string(kfile, "general", styles[i].style, NULL); |
295 g_key_file_get_string(kfile, "general", styles[i].style, NULL); |
| 295 } |
296 } |
| 296 |
|
| 297 for (i = 0; i < nkeys; i++) |
|
| 298 g_hash_table_replace(unknowns, g_strdup(keys[i]), |
|
| 299 g_strdup(g_key_file_get_string(kfile, "general", keys[i], NULL))); |
|
| 300 } |
297 } |
| 301 g_strfreev(keys); |
298 g_strfreev(keys); |
| 302 } |
299 } |
| 303 #endif |
300 #endif |
| 304 |
301 |
| 305 void gnt_style_read_configure_file(const char *filename) |
302 void gnt_style_read_configure_file(const char *filename) |
| 306 { |
303 { |
| 307 #if GLIB_CHECK_VERSION(2,6,0) |
304 #if GLIB_CHECK_VERSION(2,6,0) |
| 308 GError *error = NULL; |
305 GError *error = NULL; |
| 309 gkfile = g_key_file_new(); |
306 gkfile = g_key_file_new(); |
| 310 unknowns = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
307 |
| 311 |
308 if (!g_key_file_load_from_file(gkfile, filename, |
| 312 if (!g_key_file_load_from_file(gkfile, filename, G_KEY_FILE_NONE, &error)) |
309 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) |
| 313 { |
310 { |
| 314 g_printerr("GntStyle: %s\n", error->message); |
311 g_printerr("GntStyle: %s\n", error->message); |
| 315 g_error_free(error); |
312 g_error_free(error); |
| 316 return; |
313 return; |
| 317 } |
314 } |
| 335 { |
332 { |
| 336 int i; |
333 int i; |
| 337 for (i = 0; i < GNT_STYLES; i++) |
334 for (i = 0; i < GNT_STYLES; i++) |
| 338 g_free(str_styles[i]); |
335 g_free(str_styles[i]); |
| 339 |
336 |
| 340 g_hash_table_destroy(unknowns); |
|
| 341 #if GLIB_CHECK_VERSION(2,6,0) |
337 #if GLIB_CHECK_VERSION(2,6,0) |
| 342 g_key_file_free(gkfile); |
338 g_key_file_free(gkfile); |
| 343 #endif |
339 #endif |
| 344 } |
340 } |
| 345 |
341 |