2 * GTKBlistThemeLoader for Pidgin
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
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.
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.
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
32 #include "gtkblist-theme-loader.h"
33 #include "gtkblist-theme.h"
35 /******************************************************************************
37 *****************************************************************************/
39 #define DEFAULT_TEXT_COLOR "black"
41 /*****************************************************************************
42 * Buddy List Theme Builder
43 *****************************************************************************/
45 static PidginThemeFont
*
46 pidgin_theme_font_parse(PurpleXmlNode
*node
)
49 const char *colordesc
;
52 font
= purple_xmlnode_get_attrib(node
, "font");
54 if ((colordesc
= purple_xmlnode_get_attrib(node
, "color")) == NULL
||
55 !gdk_rgba_parse(&color
, colordesc
))
56 gdk_rgba_parse(&color
, DEFAULT_TEXT_COLOR
);
58 return pidgin_theme_font_new(font
, &color
);
62 parse_color(PurpleXmlNode
*node
, const char *tag
)
64 const char *temp
= purple_xmlnode_get_attrib(node
, tag
);
67 if (temp
&& gdk_rgba_parse(&color
, temp
)) {
68 return gdk_rgba_copy(&color
);
75 pidgin_blist_loader_build(const gchar
*theme_dir
)
77 PurpleXmlNode
*root_node
= NULL
, *sub_node
, *sub_sub_node
;
78 gchar
*dir
, *filename_full
, *data
= NULL
;
79 const gchar
*temp
, *name
;
80 gboolean success
= TRUE
;
81 GdkRGBA
*bgcolor
, *expanded_bgcolor
, *collapsed_bgcolor
, *contact_color
;
82 PidginThemeFont
*expanded
, *collapsed
, *contact
, *online
, *away
, *offline
, *idle
, *message
, *message_nick_said
, *status
;
83 PidginBlistLayout layout
;
84 PidginBlistTheme
*theme
;
88 PidginThemeFont
**font
;
90 {"contact_text", &contact
},
91 {"online_text", &online
},
93 {"offline_text", &offline
},
95 {"message_text", &message
},
96 {"message_nick_said_text", &message_nick_said
},
97 {"status_text", &status
},
101 bgcolor
= expanded_bgcolor
= collapsed_bgcolor
= contact_color
= NULL
;
110 message_nick_said
= NULL
;
113 /* Find the theme file */
114 g_return_val_if_fail(theme_dir
!= NULL
, NULL
);
115 dir
= g_build_filename(theme_dir
, "purple", "blist", NULL
);
116 filename_full
= g_build_filename(dir
, "theme.xml", NULL
);
118 if (g_file_test(filename_full
, G_FILE_TEST_IS_REGULAR
))
119 root_node
= purple_xmlnode_from_file(dir
, "theme.xml", "buddy list themes", "blist-loader");
121 g_free(filename_full
);
122 if (root_node
== NULL
) {
127 sub_node
= purple_xmlnode_get_child(root_node
, "description");
128 data
= purple_xmlnode_get_data(sub_node
);
130 name
= purple_xmlnode_get_attrib(root_node
, "name");
133 success
= name
&& purple_strequal(purple_xmlnode_get_attrib(root_node
, "type"), "pidgin buddy list");
136 purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n");
139 if ((success
= (sub_node
= purple_xmlnode_get_child(root_node
, "blist")) != NULL
))
140 bgcolor
= parse_color(sub_node
, "color");
142 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n");
147 if ((success
= (sub_node
= purple_xmlnode_get_child(root_node
, "groups")) != NULL
148 && (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "expanded")) != NULL
)) {
149 expanded
= pidgin_theme_font_parse(sub_sub_node
);
150 expanded_bgcolor
= parse_color(sub_sub_node
, "background");
152 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n");
156 if ((success
= sub_node
!= NULL
&& (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "collapsed")) != NULL
)) {
157 collapsed
= pidgin_theme_font_parse(sub_sub_node
);
158 collapsed_bgcolor
= parse_color(sub_sub_node
, "background");
160 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n");
165 if ((success
= (sub_node
= purple_xmlnode_get_child(root_node
, "buddys")) != NULL
&&
166 (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "placement")) != NULL
)) {
168 layout
.status_icon
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "status_icon")) != NULL
? atoi(temp
) : 0;
169 layout
.text
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "name")) != NULL
? atoi(temp
) : 1;
170 layout
.emblem
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "emblem")) != NULL
? atoi(temp
) : 2;
171 layout
.protocol_icon
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "protocol_icon")) != NULL
? atoi(temp
) : 3;
172 layout
.buddy_icon
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "buddy_icon")) != NULL
? atoi(temp
) : 4;
173 layout
.show_status
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "status_icon")) != NULL
? atoi(temp
) != 0 : 1;
175 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <placement>.\n");
179 if ((success
= (sub_node
!= NULL
&& (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "background")) != NULL
)))
180 contact_color
= parse_color(sub_sub_node
, "color");
182 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n");
185 for (i
= 0; success
&& lookups
[i
].tag
; i
++) {
186 if ((success
= (sub_node
!= NULL
&&
187 (sub_sub_node
= purple_xmlnode_get_child(sub_node
, lookups
[i
].tag
)) != NULL
))) {
188 *(lookups
[i
].font
) = pidgin_theme_font_parse(sub_sub_node
);
190 *(lookups
[i
].font
) = NULL
;
194 /* name is required for theme manager */
195 success
= (success
&& purple_xmlnode_get_attrib(root_node
, "name") != NULL
);
198 theme
= g_object_new(PIDGIN_TYPE_BLIST_THEME
,
201 "author", purple_xmlnode_get_attrib(root_node
, "author"),
202 "image", purple_xmlnode_get_attrib(root_node
, "image"),
205 "background-color", bgcolor
,
207 "expanded-color", expanded_bgcolor
,
208 "expanded-text", expanded
,
209 "collapsed-color", collapsed_bgcolor
,
210 "collapsed-text", collapsed
,
211 "contact-color", contact_color
,
218 "message-nick-said", message_nick_said
,
219 "status", status
, NULL
);
221 for (i
= 0; lookups
[i
].tag
; i
++) {
222 if (*lookups
[i
].font
) {
223 pidgin_theme_font_free(*lookups
[i
].font
);
227 pidgin_theme_font_free(expanded
);
228 pidgin_theme_font_free(collapsed
);
230 purple_xmlnode_free(root_node
);
234 /* malformed xml file - also frees all partial data*/
236 g_object_unref(theme
);
241 gdk_rgba_free(bgcolor
);
242 if (expanded_bgcolor
)
243 gdk_rgba_free(expanded_bgcolor
);
244 if (collapsed_bgcolor
)
245 gdk_rgba_free(collapsed_bgcolor
);
247 gdk_rgba_free(contact_color
);
249 return PURPLE_THEME(theme
);
252 /******************************************************************************
254 *****************************************************************************/
257 pidgin_blist_theme_loader_class_init(PidginBlistThemeLoaderClass
*klass
)
259 PurpleThemeLoaderClass
*loader_klass
= PURPLE_THEME_LOADER_CLASS(klass
);
261 loader_klass
->purple_theme_loader_build
= pidgin_blist_loader_build
;
265 pidgin_blist_theme_loader_get_type(void)
267 static GType type
= 0;
269 static const GTypeInfo info
= {
270 sizeof(PidginBlistThemeLoaderClass
),
271 NULL
, /* base_init */
272 NULL
, /* base_finalize */
273 (GClassInitFunc
)pidgin_blist_theme_loader_class_init
, /* class_init */
274 NULL
, /* class_finalize */
275 NULL
, /* class_data */
276 sizeof(PidginBlistThemeLoader
),
278 NULL
, /* instance_init */
279 NULL
, /* value table */
281 type
= g_type_register_static(PURPLE_TYPE_THEME_LOADER
,
282 "PidginBlistThemeLoader", &info
, 0);