Mercurial > pidgin.yaz
comparison pidgin/gtkblist-theme-loader.c @ 25268:7ddaa405936e
renamed gtkblist-loader.[ch] to gtblist-theme-loader.[ch]
renmaed gtkicon-loader.[ch] to gtkicon-theme-loader.[ch]
other updates as necessary due to the renames
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Thu, 28 Aug 2008 13:13:39 +0000 |
parents | |
children | dc2584ebaa1a |
comparison
equal
deleted
inserted
replaced
25267:e0a596a0a020 | 25268:7ddaa405936e |
---|---|
1 /* | |
2 * GTKBlistThemeLoader for Pidgin | |
3 * | |
4 * Pidgin is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
21 * | |
22 */ | |
23 | |
24 #include <stdlib.h> | |
25 | |
26 #include "xmlnode.h" | |
27 | |
28 #include "gtkblist-theme-loader.h" | |
29 #include "gtkblist-theme.h" | |
30 | |
31 /****************************************************************************** | |
32 * Globals | |
33 *****************************************************************************/ | |
34 #define DEFAULT_TEXT_COLOR "black" | |
35 /***************************************************************************** | |
36 * Buddy List Theme Builder | |
37 *****************************************************************************/ | |
38 | |
39 static PurpleTheme * | |
40 pidgin_blist_loader_build(const gchar *dir) | |
41 { | |
42 xmlnode *root_node = NULL, *sub_node, *sub_sub_node; | |
43 gchar *filename_full, *data; | |
44 const gchar *temp; | |
45 gboolean sucess = TRUE; | |
46 GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *contact_color; | |
47 GdkColor color; | |
48 FontColorPair *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *status; | |
49 PidginBlistLayout *layout; | |
50 PidginBlistTheme *theme; | |
51 | |
52 /* Find the theme file */ | |
53 g_return_val_if_fail(dir != NULL, NULL); | |
54 filename_full = g_build_filename(dir, "theme.xml", NULL); | |
55 | |
56 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR)) | |
57 root_node = xmlnode_from_file(dir, "theme.xml", "buddy list themes", "blist-loader"); | |
58 | |
59 g_free(filename_full); | |
60 g_return_val_if_fail(root_node != NULL, NULL); | |
61 | |
62 sub_node = xmlnode_get_child(root_node, "description"); | |
63 data = xmlnode_get_data(sub_node); | |
64 | |
65 /* init all structs and colors */ | |
66 bgcolor = g_new0(GdkColor, 1); | |
67 expanded_bgcolor = g_new0(GdkColor, 1); | |
68 collapsed_bgcolor = g_new0(GdkColor, 1); | |
69 | |
70 layout = g_new0(PidginBlistLayout, 1); | |
71 | |
72 contact_color = g_new0(GdkColor, 1); | |
73 | |
74 expanded = g_new0(FontColorPair, 1); | |
75 collapsed = g_new0(FontColorPair, 1); | |
76 contact = g_new0(FontColorPair, 1); | |
77 online = g_new0(FontColorPair, 1); | |
78 away = g_new0(FontColorPair, 1); | |
79 offline = g_new0(FontColorPair, 1); | |
80 idle = g_new0(FontColorPair, 1); | |
81 message = g_new0(FontColorPair, 1); | |
82 status = g_new0(FontColorPair, 1); | |
83 | |
84 /* <blist> */ | |
85 if ((sucess = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) { | |
86 if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, bgcolor)) | |
87 gdk_colormap_alloc_color(gdk_colormap_get_system(), bgcolor, FALSE, TRUE); | |
88 else { | |
89 g_free(bgcolor); | |
90 bgcolor = NULL; | |
91 } | |
92 } | |
93 | |
94 /* <groups> */ | |
95 if ((sucess = sucess && (sub_node = xmlnode_get_child(root_node, "groups")) != NULL | |
96 && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)) { | |
97 | |
98 expanded->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
99 | |
100 if ((temp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(temp, &color)) | |
101 expanded->color = g_strdup(temp); | |
102 else expanded->color = g_strdup(DEFAULT_TEXT_COLOR); | |
103 | |
104 | |
105 if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, expanded_bgcolor)) | |
106 gdk_colormap_alloc_color(gdk_colormap_get_system(), expanded_bgcolor, FALSE, TRUE); | |
107 else { | |
108 g_free(expanded_bgcolor); | |
109 expanded_bgcolor = NULL; | |
110 } | |
111 } | |
112 | |
113 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) { | |
114 | |
115 collapsed->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
116 | |
117 if((temp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(temp, &color)) | |
118 collapsed->color = g_strdup(temp); | |
119 else collapsed->color = g_strdup(DEFAULT_TEXT_COLOR); | |
120 | |
121 if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, collapsed_bgcolor)) | |
122 gdk_colormap_alloc_color(gdk_colormap_get_system(), collapsed_bgcolor, FALSE, TRUE); | |
123 else { | |
124 g_free(collapsed_bgcolor); | |
125 collapsed_bgcolor = NULL; | |
126 } | |
127 } | |
128 | |
129 /* <buddys> */ | |
130 if ((sucess = sucess && (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL && | |
131 (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)) { | |
132 | |
133 layout->status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0; | |
134 layout->text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1; | |
135 layout->emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2; | |
136 layout->protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3; | |
137 layout->buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4; | |
138 layout->show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1; | |
139 } | |
140 | |
141 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL)) { | |
142 if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), contact_color)) | |
143 gdk_colormap_alloc_color(gdk_colormap_get_system(), contact_color, FALSE, TRUE); | |
144 else { | |
145 g_free(contact_color); | |
146 contact_color = NULL; | |
147 } | |
148 } | |
149 | |
150 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "contact_text")) != NULL)) { | |
151 contact->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
152 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
153 contact->color = g_strdup(temp); | |
154 else contact->color = g_strdup(DEFAULT_TEXT_COLOR); | |
155 } | |
156 | |
157 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "online_text")) != NULL)) { | |
158 online->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
159 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
160 online->color = g_strdup(temp); | |
161 else online->color = g_strdup(DEFAULT_TEXT_COLOR); | |
162 } | |
163 | |
164 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "away_text")) != NULL)) { | |
165 away->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
166 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
167 away->color = g_strdup(temp); | |
168 else away->color = g_strdup(DEFAULT_TEXT_COLOR); | |
169 } | |
170 | |
171 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "offline_text")) != NULL)) { | |
172 offline->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
173 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
174 online->color = g_strdup(temp); | |
175 else online->color = g_strdup(DEFAULT_TEXT_COLOR); | |
176 } | |
177 | |
178 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "idle_text")) != NULL)) { | |
179 idle->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
180 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
181 idle->color = g_strdup(temp); | |
182 else online->color = g_strdup(DEFAULT_TEXT_COLOR); | |
183 } | |
184 | |
185 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "message_text")) != NULL)) { | |
186 message->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
187 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
188 message->color = g_strdup(temp); | |
189 else message->color = g_strdup(DEFAULT_TEXT_COLOR); | |
190 } | |
191 | |
192 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "status_text")) != NULL)) { | |
193 status->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); | |
194 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) | |
195 status->color = g_strdup(temp); | |
196 else status->color = g_strdup(DEFAULT_TEXT_COLOR); | |
197 } | |
198 | |
199 /* name is required for theme manager */ | |
200 sucess = sucess && xmlnode_get_attrib(root_node, "name") != NULL; | |
201 | |
202 /* the new theme */ | |
203 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME, | |
204 "type", "blist", | |
205 "name", xmlnode_get_attrib(root_node, "name"), | |
206 "author", xmlnode_get_attrib(root_node, "author"), | |
207 "image", xmlnode_get_attrib(root_node, "image"), | |
208 "directory", dir, | |
209 "description", data, | |
210 "background-color", bgcolor, | |
211 "layout", layout, | |
212 "expanded-color", expanded_bgcolor, | |
213 "expanded-text", expanded, | |
214 "collapsed-color", collapsed_bgcolor, | |
215 "collapsed-text", collapsed, | |
216 "contact-color", contact_color, | |
217 "contact", contact, | |
218 "online", online, | |
219 "away", away, | |
220 "offline", offline, | |
221 "idle", idle, | |
222 "message", message, | |
223 "status", status, NULL); | |
224 | |
225 xmlnode_free(root_node); | |
226 g_free(data); | |
227 | |
228 /* malformed xml file - also frees all partial data*/ | |
229 if (!sucess) { | |
230 g_object_unref(theme); | |
231 theme = NULL; | |
232 } | |
233 | |
234 return PURPLE_THEME(theme); | |
235 } | |
236 | |
237 /****************************************************************************** | |
238 * GObject Stuff | |
239 *****************************************************************************/ | |
240 | |
241 static void | |
242 pidgin_blist_theme_loader_class_init(PidginBlistThemeLoaderClass *klass) | |
243 { | |
244 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass); | |
245 | |
246 loader_klass->purple_theme_loader_build = pidgin_blist_loader_build; | |
247 } | |
248 | |
249 | |
250 GType | |
251 pidgin_blist_theme_loader_get_type(void) | |
252 { | |
253 static GType type = 0; | |
254 if (type == 0) { | |
255 static const GTypeInfo info = { | |
256 sizeof (PidginBlistThemeLoaderClass), | |
257 NULL, /* base_init */ | |
258 NULL, /* base_finalize */ | |
259 (GClassInitFunc)pidgin_blist_theme_loader_class_init, /* class_init */ | |
260 NULL, /* class_finalize */ | |
261 NULL, /* class_data */ | |
262 sizeof (PidginBlistThemeLoader), | |
263 0, /* n_preallocs */ | |
264 NULL, /* instance_init */ | |
265 NULL, /* value table */ | |
266 }; | |
267 type = g_type_register_static(PURPLE_TYPE_THEME_LOADER, | |
268 "PidginBlistThemeLoader", | |
269 &info, 0); | |
270 } | |
271 return type; | |
272 } | |
273 | |
274 |