Mercurial > pidgin.yaz
comparison console/libgnt/gntcolors.c @ 14004:06f75fb84a78
[gaim-migrate @ 16589]
Add a configure file (~/.gntrc) for gnt to configure its looks. This
is available only for GLib 2.6 and above. Currently, it only allows
changing the colors (r;g;b -- each in [0, 1000]) and color-groups. I
have added gntrc.sample as an example.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 28 Jul 2006 04:47:19 +0000 |
parents | 0a0d2a1fd2bc |
children | bb38f32ab6aa |
comparison
equal
deleted
inserted
replaced
14003:44c5c6d80239 | 14004:06f75fb84a78 |
---|---|
1 #include <ncursesw/ncurses.h> | 1 #include <ncursesw/ncurses.h> |
2 #include "gntcolors.h" | 2 #include "gntcolors.h" |
3 | |
4 #include <glib.h> | |
5 | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
3 | 8 |
4 static struct | 9 static struct |
5 { | 10 { |
6 short r, g, b; | 11 short r, g, b; |
7 } colors[GNT_TOTAL_COLORS]; | 12 } colors[GNT_TOTAL_COLORS]; |
73 gnt_uninit_colors() | 78 gnt_uninit_colors() |
74 { | 79 { |
75 restore_colors(); | 80 restore_colors(); |
76 } | 81 } |
77 | 82 |
83 static int | |
84 get_color(char *key) | |
85 { | |
86 int color; | |
87 | |
88 key = g_strstrip(key); | |
89 | |
90 if (strcmp(key, "black") == 0) | |
91 color = GNT_COLOR_BLACK; | |
92 else if (strcmp(key, "red") == 0) | |
93 color = GNT_COLOR_RED; | |
94 else if (strcmp(key, "green") == 0) | |
95 color = GNT_COLOR_GREEN; | |
96 else if (strcmp(key, "blue") == 0) | |
97 color = GNT_COLOR_BLUE; | |
98 else if (strcmp(key, "white") == 0) | |
99 color = GNT_COLOR_WHITE; | |
100 else if (strcmp(key, "gray") == 0) | |
101 color = GNT_COLOR_GRAY; | |
102 else if (strcmp(key, "darkgray") == 0) | |
103 color = GNT_COLOR_DARK_GRAY; | |
104 else | |
105 color = -1; | |
106 return color; | |
107 } | |
108 | |
109 void gnt_colors_parse(GKeyFile *kfile) | |
110 { | |
111 GError *error = NULL; | |
112 gsize nkeys; | |
113 char **keys = g_key_file_get_keys(kfile, "colors", &nkeys, &error); | |
114 | |
115 if (error) | |
116 { | |
117 /* XXX: some error happened. */ | |
118 g_error_free(error); | |
119 } | |
120 else | |
121 { | |
122 while (nkeys--) | |
123 { | |
124 gsize len; | |
125 char *key = keys[nkeys]; | |
126 char **list = g_key_file_get_string_list(kfile, "colors", key, &len, NULL); | |
127 if (len == 3) | |
128 { | |
129 int r = atoi(list[0]); | |
130 int g = atoi(list[1]); | |
131 int b = atoi(list[2]); | |
132 int color = -1; | |
133 | |
134 g_ascii_strdown(key, -1); | |
135 color = get_color(key); | |
136 if (color == -1) | |
137 continue; | |
138 | |
139 init_color(color, r, g, b); | |
140 } | |
141 g_strfreev(list); | |
142 } | |
143 | |
144 g_strfreev(keys); | |
145 } | |
146 | |
147 gnt_color_pairs_parse(kfile); | |
148 } | |
149 | |
150 void gnt_color_pairs_parse(GKeyFile *kfile) | |
151 { | |
152 GError *error = NULL; | |
153 gsize nkeys; | |
154 char **keys = g_key_file_get_keys(kfile, "colorpairs", &nkeys, &error); | |
155 | |
156 if (error) | |
157 { | |
158 /* XXX: some error happened. */ | |
159 g_error_free(error); | |
160 return; | |
161 } | |
162 | |
163 while (nkeys--) | |
164 { | |
165 gsize len; | |
166 char *key = keys[nkeys]; | |
167 char **list = g_key_file_get_string_list(kfile, "colorpairs", key, &len, NULL); | |
168 if (len == 2) | |
169 { | |
170 GntColorType type = 0; | |
171 int fg = get_color(g_ascii_strdown(list[0], -1)); | |
172 int bg = get_color(g_ascii_strdown(list[1], -1)); | |
173 if (fg == -1 || bg == -1) | |
174 continue; | |
175 | |
176 g_ascii_strdown(key, -1); | |
177 | |
178 if (strcmp(key, "normal") == 0) | |
179 type = GNT_COLOR_NORMAL; | |
180 else if (strcmp(key, "highlight") == 0) | |
181 type = GNT_COLOR_HIGHLIGHT; | |
182 else if (strcmp(key, "highlightd") == 0) | |
183 type = GNT_COLOR_HIGHLIGHT_D; | |
184 else if (strcmp(key, "shadow") == 0) | |
185 type = GNT_COLOR_SHADOW; | |
186 else if (strcmp(key, "title") == 0) | |
187 type = GNT_COLOR_TITLE; | |
188 else if (strcmp(key, "titled") == 0) | |
189 type = GNT_COLOR_TITLE_D; | |
190 else if (strcmp(key, "text") == 0) | |
191 type = GNT_COLOR_TEXT_NORMAL; | |
192 else if (strcmp(key, "disabled") == 0) | |
193 type = GNT_COLOR_DISABLED; | |
194 else | |
195 continue; | |
196 | |
197 init_pair(type, fg, bg); | |
198 } | |
199 g_strfreev(list); | |
200 } | |
201 | |
202 g_strfreev(keys); | |
203 } | |
204 |