Mercurial > pidgin.yaz
comparison pidgin/gtkblist-theme-loader.c @ 27284:9ad4b5200f24
Better error checking on the theme loaders.
Patch from Justin "ffdragon6" Rodriguez. Refs #8085.
committer: Paul Aurich <paul@darkrain42.org>
author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
---|---|
date | Sun, 28 Jun 2009 06:26:48 +0000 |
parents | 46b1d6eca6ef |
children | 7685f06c7801 |
comparison
equal
deleted
inserted
replaced
27283:702ebcb059fd | 27284:9ad4b5200f24 |
---|---|
22 | 22 |
23 #include <stdlib.h> | 23 #include <stdlib.h> |
24 #include <string.h> | 24 #include <string.h> |
25 | 25 |
26 #include "xmlnode.h" | 26 #include "xmlnode.h" |
27 #include "debug.h" | |
28 #include "util.h" | |
27 | 29 |
28 #include "gtkblist-theme-loader.h" | 30 #include "gtkblist-theme-loader.h" |
29 #include "gtkblist-theme.h" | 31 #include "gtkblist-theme.h" |
30 | 32 |
31 /****************************************************************************** | 33 /****************************************************************************** |
56 | 58 |
57 static PurpleTheme * | 59 static PurpleTheme * |
58 pidgin_blist_loader_build(const gchar *dir) | 60 pidgin_blist_loader_build(const gchar *dir) |
59 { | 61 { |
60 xmlnode *root_node = NULL, *sub_node, *sub_sub_node; | 62 xmlnode *root_node = NULL, *sub_node, *sub_sub_node; |
61 gchar *filename_full, *data; | 63 gchar *filename_full, *data = NULL; |
62 const gchar *temp; | 64 const gchar *temp, *name; |
63 gboolean success = TRUE; | 65 gboolean success = TRUE; |
64 GdkColor bgcolor, expanded_bgcolor, collapsed_bgcolor, contact_color; | 66 GdkColor bgcolor, expanded_bgcolor, collapsed_bgcolor, contact_color; |
65 PidginThemeFont *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status; | 67 PidginThemeFont *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status; |
66 PidginBlistLayout layout; | 68 PidginBlistLayout layout; |
67 PidginBlistTheme *theme; | 69 PidginBlistTheme *theme; |
98 | 100 |
99 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR)) | 101 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR)) |
100 root_node = xmlnode_from_file(dir, "theme.xml", "buddy list themes", "blist-loader"); | 102 root_node = xmlnode_from_file(dir, "theme.xml", "buddy list themes", "blist-loader"); |
101 | 103 |
102 g_free(filename_full); | 104 g_free(filename_full); |
103 g_return_val_if_fail(root_node != NULL, NULL); | 105 if (root_node == NULL) |
106 return NULL; | |
104 | 107 |
105 sub_node = xmlnode_get_child(root_node, "description"); | 108 sub_node = xmlnode_get_child(root_node, "description"); |
106 data = xmlnode_get_data(sub_node); | 109 data = xmlnode_get_data(sub_node); |
107 | 110 |
111 name = xmlnode_get_attrib(root_node, "name"); | |
112 | |
108 /* <blist> */ | 113 /* <blist> */ |
109 if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) { | 114 success = name && purple_strequal(xmlnode_get_attrib(root_node, "type"), "pidgin buddy list"); |
110 if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, &bgcolor)) | 115 |
111 gdk_colormap_alloc_color(gdk_colormap_get_system(), &bgcolor, FALSE, TRUE); | 116 if (!success) |
112 else | 117 purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n"); |
113 memset(&bgcolor, 0, sizeof(GdkColor)); | 118 |
119 if (success) { | |
120 if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) { | |
121 | |
122 if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, &bgcolor)) | |
123 gdk_colormap_alloc_color(gdk_colormap_get_system(), &bgcolor, FALSE, TRUE); | |
124 else | |
125 memset(&bgcolor, 0, sizeof(GdkColor)); | |
126 | |
127 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n"); | |
114 } | 128 } |
115 | 129 |
116 /* <groups> */ | 130 /* <groups> */ |
117 if ((success = (success && (sub_node = xmlnode_get_child(root_node, "groups")) != NULL | 131 if (success) { |
118 && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL))) | 132 if ((success = (sub_node = xmlnode_get_child(root_node, "groups")) != NULL |
119 { | 133 && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)) { |
120 expanded = pidgin_theme_font_parse(sub_sub_node); | 134 expanded = pidgin_theme_font_parse(sub_sub_node); |
121 | 135 |
122 if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &expanded_bgcolor)) | 136 if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &expanded_bgcolor)) |
123 gdk_colormap_alloc_color(gdk_colormap_get_system(), &expanded_bgcolor, FALSE, TRUE); | 137 gdk_colormap_alloc_color(gdk_colormap_get_system(), &expanded_bgcolor, FALSE, TRUE); |
124 else | 138 else |
125 memset(&expanded_bgcolor, 0, sizeof(GdkColor)); | 139 memset(&expanded_bgcolor, 0, sizeof(GdkColor)); |
126 } | 140 |
127 | 141 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n"); |
128 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL))) | 142 } |
129 { | 143 |
130 collapsed = pidgin_theme_font_parse(sub_sub_node); | 144 if (success) { |
131 | 145 if ((success = sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) { |
132 if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &collapsed_bgcolor)) | 146 |
133 gdk_colormap_alloc_color(gdk_colormap_get_system(), &collapsed_bgcolor, FALSE, TRUE); | 147 collapsed = pidgin_theme_font_parse(sub_sub_node); |
134 else | 148 |
135 memset(&collapsed_bgcolor, 0, sizeof(GdkColor)); | 149 if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &collapsed_bgcolor)) |
150 gdk_colormap_alloc_color(gdk_colormap_get_system(), &collapsed_bgcolor, FALSE, TRUE); | |
151 else | |
152 memset(&collapsed_bgcolor, 0, sizeof(GdkColor)); | |
153 | |
154 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n"); | |
136 } | 155 } |
137 | 156 |
138 /* <buddys> */ | 157 /* <buddys> */ |
139 if ((success = (success && (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL && | 158 if (success) { |
140 (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL))) | 159 if ((success = (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL && |
141 { | 160 (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)) { |
142 layout.status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0; | 161 |
143 layout.text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1; | 162 layout.status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0; |
144 layout.emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2; | 163 layout.text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1; |
145 layout.protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3; | 164 layout.emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2; |
146 layout.buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4; | 165 layout.protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3; |
147 layout.show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1; | 166 layout.buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4; |
148 } | 167 layout.show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1; |
149 | 168 |
150 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) { | 169 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <placement>.\n"); |
151 if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &contact_color)) | 170 } |
152 gdk_colormap_alloc_color(gdk_colormap_get_system(), &contact_color, FALSE, TRUE); | 171 |
153 else | 172 if (success) { |
154 memset(&contact_color, 0, sizeof(GdkColor)); | 173 if ((success = (sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) { |
174 if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &contact_color)) | |
175 gdk_colormap_alloc_color(gdk_colormap_get_system(), &contact_color, FALSE, TRUE); | |
176 else | |
177 memset(&contact_color, 0, sizeof(GdkColor)); | |
178 | |
179 } purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n"); | |
155 } | 180 } |
156 | 181 |
157 for (i = 0; success && lookups[i].tag; i++) { | 182 for (i = 0; success && lookups[i].tag; i++) { |
158 if ((success = (sub_node != NULL && | 183 if ((success = (sub_node != NULL && |
159 (sub_sub_node = xmlnode_get_child(sub_node, lookups[i].tag)) != NULL))) { | 184 (sub_sub_node = xmlnode_get_child(sub_node, lookups[i].tag)) != NULL))) { |
167 success = (success && xmlnode_get_attrib(root_node, "name") != NULL); | 192 success = (success && xmlnode_get_attrib(root_node, "name") != NULL); |
168 | 193 |
169 /* the new theme */ | 194 /* the new theme */ |
170 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME, | 195 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME, |
171 "type", "blist", | 196 "type", "blist", |
172 "name", xmlnode_get_attrib(root_node, "name"), | 197 "name", name, |
173 "author", xmlnode_get_attrib(root_node, "author"), | 198 "author", xmlnode_get_attrib(root_node, "author"), |
174 "image", xmlnode_get_attrib(root_node, "image"), | 199 "image", xmlnode_get_attrib(root_node, "image"), |
175 "directory", dir, | 200 "directory", dir, |
176 "description", data, | 201 "description", data, |
177 "background-color", &bgcolor, | 202 "background-color", &bgcolor, |