pidgin/gtkblist-theme-loader.c

branch
soc.2013.gobjectification
changeset 34935
686fa55b0deb
parent 33170
ce4447562d64
child 35060
195dbb3b6432
equal deleted inserted replaced
34934:d50c4b767a5e 34935:686fa55b0deb
41 /***************************************************************************** 41 /*****************************************************************************
42 * Buddy List Theme Builder 42 * Buddy List Theme Builder
43 *****************************************************************************/ 43 *****************************************************************************/
44 44
45 static PidginThemeFont * 45 static PidginThemeFont *
46 pidgin_theme_font_parse(xmlnode *node) 46 pidgin_theme_font_parse(PurpleXmlNode *node)
47 { 47 {
48 const char *font; 48 const char *font;
49 const char *colordesc; 49 const char *colordesc;
50 GdkColor color; 50 GdkColor color;
51 51
52 font = xmlnode_get_attrib(node, "font"); 52 font = purple_xmlnode_get_attrib(node, "font");
53 53
54 if ((colordesc = xmlnode_get_attrib(node, "color")) == NULL || 54 if ((colordesc = purple_xmlnode_get_attrib(node, "color")) == NULL ||
55 !gdk_color_parse(colordesc, &color)) 55 !gdk_color_parse(colordesc, &color))
56 gdk_color_parse(DEFAULT_TEXT_COLOR, &color); 56 gdk_color_parse(DEFAULT_TEXT_COLOR, &color);
57 57
58 return pidgin_theme_font_new(font, &color); 58 return pidgin_theme_font_new(font, &color);
59 } 59 }
60 60
61 static GdkColor * 61 static GdkColor *
62 parse_color(xmlnode *node, const char *tag) 62 parse_color(PurpleXmlNode *node, const char *tag)
63 { 63 {
64 const char *temp = xmlnode_get_attrib(node, tag); 64 const char *temp = purple_xmlnode_get_attrib(node, tag);
65 GdkColor color; 65 GdkColor color;
66 66
67 if (temp && gdk_color_parse(temp, &color)) { 67 if (temp && gdk_color_parse(temp, &color)) {
68 #if !GTK_CHECK_VERSION(3,0,0) 68 #if !GTK_CHECK_VERSION(3,0,0)
69 gdk_colormap_alloc_color(gdk_colormap_get_system(), &color, FALSE, TRUE); 69 gdk_colormap_alloc_color(gdk_colormap_get_system(), &color, FALSE, TRUE);
75 } 75 }
76 76
77 static PurpleTheme * 77 static PurpleTheme *
78 pidgin_blist_loader_build(const gchar *theme_dir) 78 pidgin_blist_loader_build(const gchar *theme_dir)
79 { 79 {
80 xmlnode *root_node = NULL, *sub_node, *sub_sub_node; 80 PurpleXmlNode *root_node = NULL, *sub_node, *sub_sub_node;
81 gchar *dir, *filename_full, *data = NULL; 81 gchar *dir, *filename_full, *data = NULL;
82 const gchar *temp, *name; 82 const gchar *temp, *name;
83 gboolean success = TRUE; 83 gboolean success = TRUE;
84 GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *contact_color; 84 GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *contact_color;
85 PidginThemeFont *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status; 85 PidginThemeFont *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status;
117 g_return_val_if_fail(theme_dir != NULL, NULL); 117 g_return_val_if_fail(theme_dir != NULL, NULL);
118 dir = g_build_filename(theme_dir, "purple", "blist", NULL); 118 dir = g_build_filename(theme_dir, "purple", "blist", NULL);
119 filename_full = g_build_filename(dir, "theme.xml", NULL); 119 filename_full = g_build_filename(dir, "theme.xml", NULL);
120 120
121 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR)) 121 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR))
122 root_node = xmlnode_from_file(dir, "theme.xml", "buddy list themes", "blist-loader"); 122 root_node = purple_xmlnode_from_file(dir, "theme.xml", "buddy list themes", "blist-loader");
123 123
124 g_free(filename_full); 124 g_free(filename_full);
125 if (root_node == NULL) { 125 if (root_node == NULL) {
126 g_free(dir); 126 g_free(dir);
127 return NULL; 127 return NULL;
128 } 128 }
129 129
130 sub_node = xmlnode_get_child(root_node, "description"); 130 sub_node = purple_xmlnode_get_child(root_node, "description");
131 data = xmlnode_get_data(sub_node); 131 data = purple_xmlnode_get_data(sub_node);
132 132
133 name = xmlnode_get_attrib(root_node, "name"); 133 name = purple_xmlnode_get_attrib(root_node, "name");
134 134
135 /* <blist> */ 135 /* <blist> */
136 success = name && purple_strequal(xmlnode_get_attrib(root_node, "type"), "pidgin buddy list"); 136 success = name && purple_strequal(purple_xmlnode_get_attrib(root_node, "type"), "pidgin buddy list");
137 137
138 if (!success) 138 if (!success)
139 purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n"); 139 purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n");
140 140
141 if (success) { 141 if (success) {
142 if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) 142 if ((success = (sub_node = purple_xmlnode_get_child(root_node, "blist")) != NULL))
143 bgcolor = parse_color(sub_node, "color"); 143 bgcolor = parse_color(sub_node, "color");
144 else 144 else
145 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n"); 145 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n");
146 } 146 }
147 147
148 /* <groups> */ 148 /* <groups> */
149 if (success) { 149 if (success) {
150 if ((success = (sub_node = xmlnode_get_child(root_node, "groups")) != NULL 150 if ((success = (sub_node = purple_xmlnode_get_child(root_node, "groups")) != NULL
151 && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)) { 151 && (sub_sub_node = purple_xmlnode_get_child(sub_node, "expanded")) != NULL)) {
152 expanded = pidgin_theme_font_parse(sub_sub_node); 152 expanded = pidgin_theme_font_parse(sub_sub_node);
153 expanded_bgcolor = parse_color(sub_sub_node, "background"); 153 expanded_bgcolor = parse_color(sub_sub_node, "background");
154 } else 154 } else
155 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n"); 155 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n");
156 } 156 }
157 157
158 if (success) { 158 if (success) {
159 if ((success = sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) { 159 if ((success = sub_node != NULL && (sub_sub_node = purple_xmlnode_get_child(sub_node, "collapsed")) != NULL)) {
160 collapsed = pidgin_theme_font_parse(sub_sub_node); 160 collapsed = pidgin_theme_font_parse(sub_sub_node);
161 collapsed_bgcolor = parse_color(sub_sub_node, "background"); 161 collapsed_bgcolor = parse_color(sub_sub_node, "background");
162 } else 162 } else
163 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n"); 163 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n");
164 } 164 }
165 165
166 /* <buddys> */ 166 /* <buddys> */
167 if (success) { 167 if (success) {
168 if ((success = (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL && 168 if ((success = (sub_node = purple_xmlnode_get_child(root_node, "buddys")) != NULL &&
169 (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)) { 169 (sub_sub_node = purple_xmlnode_get_child(sub_node, "placement")) != NULL)) {
170 170
171 layout.status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0; 171 layout.status_icon = (temp = purple_xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0;
172 layout.text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1; 172 layout.text = (temp = purple_xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1;
173 layout.emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2; 173 layout.emblem = (temp = purple_xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2;
174 layout.protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3; 174 layout.protocol_icon = (temp = purple_xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3;
175 layout.buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4; 175 layout.buddy_icon = (temp = purple_xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4;
176 layout.show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1; 176 layout.show_status = (temp = purple_xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1;
177 177
178 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <placement>.\n"); 178 } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <placement>.\n");
179 } 179 }
180 180
181 if (success) { 181 if (success) {
182 if ((success = (sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) 182 if ((success = (sub_node != NULL && (sub_sub_node = purple_xmlnode_get_child(sub_node, "background")) != NULL)))
183 contact_color = parse_color(sub_sub_node, "color"); 183 contact_color = parse_color(sub_sub_node, "color");
184 else 184 else
185 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n"); 185 purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n");
186 } 186 }
187 187
188 for (i = 0; success && lookups[i].tag; i++) { 188 for (i = 0; success && lookups[i].tag; i++) {
189 if ((success = (sub_node != NULL && 189 if ((success = (sub_node != NULL &&
190 (sub_sub_node = xmlnode_get_child(sub_node, lookups[i].tag)) != NULL))) { 190 (sub_sub_node = purple_xmlnode_get_child(sub_node, lookups[i].tag)) != NULL))) {
191 *(lookups[i].font) = pidgin_theme_font_parse(sub_sub_node); 191 *(lookups[i].font) = pidgin_theme_font_parse(sub_sub_node);
192 } else { 192 } else {
193 *(lookups[i].font) = NULL; 193 *(lookups[i].font) = NULL;
194 } 194 }
195 } 195 }
196 196
197 /* name is required for theme manager */ 197 /* name is required for theme manager */
198 success = (success && xmlnode_get_attrib(root_node, "name") != NULL); 198 success = (success && purple_xmlnode_get_attrib(root_node, "name") != NULL);
199 199
200 /* the new theme */ 200 /* the new theme */
201 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME, 201 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME,
202 "type", "blist", 202 "type", "blist",
203 "name", name, 203 "name", name,
204 "author", xmlnode_get_attrib(root_node, "author"), 204 "author", purple_xmlnode_get_attrib(root_node, "author"),
205 "image", xmlnode_get_attrib(root_node, "image"), 205 "image", purple_xmlnode_get_attrib(root_node, "image"),
206 "directory", dir, 206 "directory", dir,
207 "description", data, 207 "description", data,
208 "background-color", bgcolor, 208 "background-color", bgcolor,
209 "layout", &layout, 209 "layout", &layout,
210 "expanded-color", expanded_bgcolor, 210 "expanded-color", expanded_bgcolor,
228 } 228 }
229 229
230 pidgin_theme_font_free(expanded); 230 pidgin_theme_font_free(expanded);
231 pidgin_theme_font_free(collapsed); 231 pidgin_theme_font_free(collapsed);
232 232
233 xmlnode_free(root_node); 233 purple_xmlnode_free(root_node);
234 g_free(data); 234 g_free(data);
235 g_free(dir); 235 g_free(dir);
236 236
237 /* malformed xml file - also frees all partial data*/ 237 /* malformed xml file - also frees all partial data*/
238 if (!success) { 238 if (!success) {

mercurial