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"
36 * PidginBlistThemeLoader:
38 * A pidgin buddy list theme loader. extends PurpleThemeLoader (theme-loader.h)
39 * This is a class designed to build sound themes
41 struct _PidginBlistThemeLoader
43 PurpleThemeLoader parent
;
46 /******************************************************************************
48 *****************************************************************************/
50 #define DEFAULT_TEXT_COLOR "black"
52 /*****************************************************************************
53 * Buddy List Theme Builder
54 *****************************************************************************/
56 static PidginThemeFont
*
57 pidgin_theme_font_parse(PurpleXmlNode
*node
)
60 const char *colordesc
;
63 font
= purple_xmlnode_get_attrib(node
, "font");
65 if ((colordesc
= purple_xmlnode_get_attrib(node
, "color")) == NULL
||
66 !gdk_rgba_parse(&color
, colordesc
))
67 gdk_rgba_parse(&color
, DEFAULT_TEXT_COLOR
);
69 return pidgin_theme_font_new(font
, &color
);
73 parse_color(PurpleXmlNode
*node
, const char *tag
)
75 const char *temp
= purple_xmlnode_get_attrib(node
, tag
);
78 if (temp
&& gdk_rgba_parse(&color
, temp
)) {
79 return gdk_rgba_copy(&color
);
86 pidgin_blist_loader_build(const gchar
*theme_dir
)
88 PurpleXmlNode
*root_node
= NULL
, *sub_node
, *sub_sub_node
;
89 gchar
*dir
, *filename_full
, *data
= NULL
;
90 const gchar
*temp
, *name
;
91 gboolean success
= TRUE
;
92 GdkRGBA
*bgcolor
, *expanded_bgcolor
, *collapsed_bgcolor
, *contact_color
;
93 PidginThemeFont
*expanded
, *collapsed
, *contact
, *online
, *away
, *offline
, *idle
, *message
, *message_nick_said
, *status
;
94 PidginBlistLayout layout
;
95 PidginBlistTheme
*theme
;
99 PidginThemeFont
**font
;
101 {"contact_text", &contact
},
102 {"online_text", &online
},
103 {"away_text", &away
},
104 {"offline_text", &offline
},
105 {"idle_text", &idle
},
106 {"message_text", &message
},
107 {"message_nick_said_text", &message_nick_said
},
108 {"status_text", &status
},
112 bgcolor
= expanded_bgcolor
= collapsed_bgcolor
= contact_color
= NULL
;
121 message_nick_said
= NULL
;
124 /* Find the theme file */
125 g_return_val_if_fail(theme_dir
!= NULL
, NULL
);
126 dir
= g_build_filename(theme_dir
, "purple", "blist", NULL
);
127 filename_full
= g_build_filename(dir
, "theme.xml", NULL
);
129 if (g_file_test(filename_full
, G_FILE_TEST_IS_REGULAR
))
130 root_node
= purple_xmlnode_from_file(dir
, "theme.xml", "buddy list themes", "blist-loader");
132 g_free(filename_full
);
133 if (root_node
== NULL
) {
138 sub_node
= purple_xmlnode_get_child(root_node
, "description");
139 data
= purple_xmlnode_get_data(sub_node
);
141 name
= purple_xmlnode_get_attrib(root_node
, "name");
144 success
= name
&& purple_strequal(purple_xmlnode_get_attrib(root_node
, "type"), "pidgin buddy list");
147 purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n");
150 if ((success
= (sub_node
= purple_xmlnode_get_child(root_node
, "blist")) != NULL
))
151 bgcolor
= parse_color(sub_node
, "color");
153 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n");
158 if ((success
= (sub_node
= purple_xmlnode_get_child(root_node
, "groups")) != NULL
159 && (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "expanded")) != NULL
)) {
160 expanded
= pidgin_theme_font_parse(sub_sub_node
);
161 expanded_bgcolor
= parse_color(sub_sub_node
, "background");
163 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n");
167 if ((success
= sub_node
!= NULL
&& (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "collapsed")) != NULL
)) {
168 collapsed
= pidgin_theme_font_parse(sub_sub_node
);
169 collapsed_bgcolor
= parse_color(sub_sub_node
, "background");
171 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n");
176 if ((success
= (sub_node
= purple_xmlnode_get_child(root_node
, "buddys")) != NULL
&&
177 (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "placement")) != NULL
)) {
179 layout
.status_icon
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "status_icon")) != NULL
? atoi(temp
) : 0;
180 layout
.text
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "name")) != NULL
? atoi(temp
) : 1;
181 layout
.emblem
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "emblem")) != NULL
? atoi(temp
) : 2;
182 layout
.protocol_icon
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "protocol_icon")) != NULL
? atoi(temp
) : 3;
183 layout
.buddy_icon
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "buddy_icon")) != NULL
? atoi(temp
) : 4;
184 layout
.show_status
= (temp
= purple_xmlnode_get_attrib(sub_sub_node
, "status_icon")) != NULL
? atoi(temp
) != 0 : 1;
186 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <placement>.\n");
190 if ((success
= (sub_node
!= NULL
&& (sub_sub_node
= purple_xmlnode_get_child(sub_node
, "background")) != NULL
)))
191 contact_color
= parse_color(sub_sub_node
, "color");
193 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n");
196 for (i
= 0; success
&& lookups
[i
].tag
; i
++) {
197 if ((success
= (sub_node
!= NULL
&&
198 (sub_sub_node
= purple_xmlnode_get_child(sub_node
, lookups
[i
].tag
)) != NULL
))) {
199 *(lookups
[i
].font
) = pidgin_theme_font_parse(sub_sub_node
);
201 *(lookups
[i
].font
) = NULL
;
205 /* name is required for theme manager */
206 success
= (success
&& purple_xmlnode_get_attrib(root_node
, "name") != NULL
);
209 theme
= g_object_new(PIDGIN_TYPE_BLIST_THEME
,
212 "author", purple_xmlnode_get_attrib(root_node
, "author"),
213 "image", purple_xmlnode_get_attrib(root_node
, "image"),
216 "background-color", bgcolor
,
218 "expanded-color", expanded_bgcolor
,
219 "expanded-text", expanded
,
220 "collapsed-color", collapsed_bgcolor
,
221 "collapsed-text", collapsed
,
222 "contact-color", contact_color
,
229 "message-nick-said", message_nick_said
,
230 "status", status
, NULL
);
232 for (i
= 0; lookups
[i
].tag
; i
++) {
233 if (*lookups
[i
].font
) {
234 pidgin_theme_font_free(*lookups
[i
].font
);
238 pidgin_theme_font_free(expanded
);
239 pidgin_theme_font_free(collapsed
);
241 purple_xmlnode_free(root_node
);
245 /* malformed xml file - also frees all partial data*/
247 g_object_unref(theme
);
252 gdk_rgba_free(bgcolor
);
253 if (expanded_bgcolor
)
254 gdk_rgba_free(expanded_bgcolor
);
255 if (collapsed_bgcolor
)
256 gdk_rgba_free(collapsed_bgcolor
);
258 gdk_rgba_free(contact_color
);
260 return PURPLE_THEME(theme
);
263 /******************************************************************************
265 *****************************************************************************/
268 pidgin_blist_theme_loader_class_init(PidginBlistThemeLoaderClass
*klass
)
270 PurpleThemeLoaderClass
*loader_klass
= PURPLE_THEME_LOADER_CLASS(klass
);
272 loader_klass
->purple_theme_loader_build
= pidgin_blist_loader_build
;
276 pidgin_blist_theme_loader_get_type(void)
278 static GType type
= 0;
280 static const GTypeInfo info
= {
281 sizeof(PidginBlistThemeLoaderClass
),
282 NULL
, /* base_init */
283 NULL
, /* base_finalize */
284 (GClassInitFunc
)pidgin_blist_theme_loader_class_init
, /* class_init */
285 NULL
, /* class_finalize */
286 NULL
, /* class_data */
287 sizeof(PidginBlistThemeLoader
),
289 NULL
, /* instance_init */
290 NULL
, /* value table */
292 type
= g_type_register_static(PURPLE_TYPE_THEME_LOADER
,
293 "PidginBlistThemeLoader", &info
, 0);