| 1 #include "gntstyle.h" |
1 #include "gntstyle.h" |
| 2 #include "gntcolors.h" |
2 #include "gntcolors.h" |
| |
3 |
| |
4 #include <string.h> |
| |
5 |
| |
6 static char * str_styles[GNT_STYLES]; |
| |
7 static int int_styles[GNT_STYLES]; |
| |
8 static int bool_styles[GNT_STYLES]; |
| |
9 |
| |
10 const char *gnt_style_get(GntStyle style) |
| |
11 { |
| |
12 return str_styles[style]; |
| |
13 } |
| |
14 |
| |
15 gboolean gnt_style_get_bool(GntStyle style, gboolean def) |
| |
16 { |
| |
17 int i; |
| |
18 const char * str; |
| |
19 |
| |
20 if (bool_styles[style] != -1) |
| |
21 return bool_styles[style]; |
| |
22 |
| |
23 str = gnt_style_get(style); |
| |
24 |
| |
25 if (str) |
| |
26 { |
| |
27 if (strcmp(str, "false") == 0) |
| |
28 def = FALSE; |
| |
29 else if (strcmp(str, "true") == 0) |
| |
30 def = TRUE; |
| |
31 else if (sscanf(str, "%d", &i) == 1) |
| |
32 { |
| |
33 if (i) |
| |
34 def = TRUE; |
| |
35 else |
| |
36 def = FALSE; |
| |
37 } |
| |
38 } |
| |
39 |
| |
40 bool_styles[style] = def; |
| |
41 return bool_styles[style]; |
| |
42 } |
| |
43 |
| |
44 static void |
| |
45 read_general_style(GKeyFile *kfile) |
| |
46 { |
| |
47 GError *error = NULL; |
| |
48 gsize nkeys; |
| |
49 char **keys = g_key_file_get_keys(kfile, "general", &nkeys, &error); |
| |
50 int i; |
| |
51 struct |
| |
52 { |
| |
53 const char *style; |
| |
54 GntStyle en; |
| |
55 } styles[] = {{"shadow", GNT_STYLE_SHADOW}, |
| |
56 {NULL, 0}}; |
| |
57 |
| |
58 if (error) |
| |
59 { |
| |
60 /* XXX: some error happened. */ |
| |
61 g_error_free(error); |
| |
62 } |
| |
63 else |
| |
64 { |
| |
65 for (i = 0; styles[i].style; i++) |
| |
66 { |
| |
67 error = NULL; |
| |
68 str_styles[styles[i].en] = |
| |
69 g_key_file_get_string(kfile, "general", styles[i].style, &error); |
| |
70 } |
| |
71 } |
| |
72 } |
| 3 |
73 |
| 4 void gnt_style_read_configure_file(const char *filename) |
74 void gnt_style_read_configure_file(const char *filename) |
| 5 { |
75 { |
| 6 #if GLIB_CHECK_VERSION(2,6,0) |
76 #if GLIB_CHECK_VERSION(2,6,0) |
| 7 GKeyFile *kfile = g_key_file_new(); |
77 GKeyFile *kfile = g_key_file_new(); |
| 12 /* XXX: Print the error or something */ |
82 /* XXX: Print the error or something */ |
| 13 g_error_free(error); |
83 g_error_free(error); |
| 14 return; |
84 return; |
| 15 } |
85 } |
| 16 gnt_colors_parse(kfile); |
86 gnt_colors_parse(kfile); |
| |
87 read_general_style(kfile); |
| 17 |
88 |
| 18 g_key_file_free(kfile); |
89 g_key_file_free(kfile); |
| 19 #endif |
90 #endif |
| 20 } |
91 } |
| 21 |
92 |
| |
93 void gnt_init_styles() |
| |
94 { |
| |
95 int i; |
| |
96 for (i = 0; i < GNT_STYLES; i++) |
| |
97 { |
| |
98 str_styles[i] = NULL; |
| |
99 int_styles[i] = -1; |
| |
100 bool_styles[i] = -1; |
| |
101 } |
| |
102 } |
| |
103 |
| |
104 void gnt_uninit_styles() |
| |
105 { |
| |
106 int i; |
| |
107 for (i = 0; i < GNT_STYLES; i++) |
| |
108 g_free(str_styles[i]); |
| |
109 } |
| |
110 |