Mercurial > pidgin.yaz
changeset 29362:1956b27ed87c
blist theme: Do not treat missing colors as black.
Fixes #10938.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Thu, 04 Feb 2010 22:31:46 +0000 |
parents | eb024bcff0c9 |
children | d73ec122554d |
files | pidgin/gtkblist-theme-loader.c pidgin/gtkblist-theme.c |
diffstat | 2 files changed, 47 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkblist-theme-loader.c Thu Feb 04 18:27:58 2010 +0000 +++ b/pidgin/gtkblist-theme-loader.c Thu Feb 04 22:31:46 2010 +0000 @@ -58,6 +58,20 @@ return pidgin_theme_font_new(font, &color); } +static GdkColor * +parse_color(xmlnode *node, const char *tag) +{ + const char *temp = xmlnode_get_attrib(node, tag); + GdkColor color; + + if (temp && gdk_color_parse(temp, &color)) { + gdk_colormap_alloc_color(gdk_colormap_get_system(), &color, FALSE, TRUE); + return gdk_color_copy(&color); + } else { + return NULL; + } +} + static PurpleTheme * pidgin_blist_loader_build(const gchar *dir) { @@ -65,7 +79,7 @@ gchar *filename_full, *data = NULL; const gchar *temp, *name; gboolean success = TRUE; - GdkColor bgcolor, expanded_bgcolor, collapsed_bgcolor, contact_color; + GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *contact_color; PidginThemeFont *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status; PidginBlistLayout layout; PidginBlistTheme *theme; @@ -119,14 +133,10 @@ purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n"); if (success) { - if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) { - - if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, &bgcolor)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), &bgcolor, FALSE, TRUE); - else - memset(&bgcolor, 0, sizeof(GdkColor)); - - } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n"); + if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) + bgcolor = parse_color(sub_node, "color"); + else + purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n"); } /* <groups> */ @@ -134,26 +144,17 @@ if ((success = (sub_node = xmlnode_get_child(root_node, "groups")) != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)) { expanded = pidgin_theme_font_parse(sub_sub_node); - - if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &expanded_bgcolor)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), &expanded_bgcolor, FALSE, TRUE); - else - memset(&expanded_bgcolor, 0, sizeof(GdkColor)); - - } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n"); + expanded_bgcolor = parse_color(sub_sub_node, "background"); + } else + purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n"); } if (success) { if ((success = sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) { - collapsed = pidgin_theme_font_parse(sub_sub_node); - - if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &collapsed_bgcolor)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), &collapsed_bgcolor, FALSE, TRUE); - else - memset(&collapsed_bgcolor, 0, sizeof(GdkColor)); - - } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n"); + collapsed_bgcolor = parse_color(sub_sub_node, "background"); + } else + purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n"); } /* <buddys> */ @@ -172,13 +173,10 @@ } if (success) { - if ((success = (sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) { - if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &contact_color)) - gdk_colormap_alloc_color(gdk_colormap_get_system(), &contact_color, FALSE, TRUE); - else - memset(&contact_color, 0, sizeof(GdkColor)); - - } else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n"); + if ((success = (sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) + contact_color = parse_color(sub_sub_node, "color"); + else + purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n"); } for (i = 0; success && lookups[i].tag; i++) { @@ -201,13 +199,13 @@ "image", xmlnode_get_attrib(root_node, "image"), "directory", dir, "description", data, - "background-color", &bgcolor, + "background-color", bgcolor, "layout", &layout, - "expanded-color", &expanded_bgcolor, + "expanded-color", expanded_bgcolor, "expanded-text", expanded, - "collapsed-color", &collapsed_bgcolor, + "collapsed-color", collapsed_bgcolor, "collapsed-text", collapsed, - "contact-color", &contact_color, + "contact-color", contact_color, "contact", contact, "online", online, "away", away, @@ -235,6 +233,15 @@ theme = NULL; } + if (bgcolor) + gdk_color_free(bgcolor); + if (expanded_bgcolor) + gdk_color_free(expanded_bgcolor); + if (collapsed_bgcolor) + gdk_color_free(collapsed_bgcolor); + if (contact_color) + gdk_color_free(contact_color); + return PURPLE_THEME(theme); }
--- a/pidgin/gtkblist-theme.c Thu Feb 04 18:27:58 2010 +0000 +++ b/pidgin/gtkblist-theme.c Thu Feb 04 22:31:46 2010 +0000 @@ -133,7 +133,7 @@ copy->font = g_strdup(pair->font); strncpy(copy->color, pair->color, sizeof(copy->color) - 1); if (pair->gdkcolor) - copy->gdkcolor = gdk_color_copy(pair->gdkcolor); + copy->gdkcolor = pair->gdkcolor ? gdk_color_copy(pair->gdkcolor) : NULL; return copy; } @@ -704,7 +704,7 @@ if (priv->bgcolor) gdk_color_free(priv->bgcolor); - priv->bgcolor = gdk_color_copy(color); + priv->bgcolor = color ? gdk_color_copy(color) : NULL; } void @@ -743,7 +743,7 @@ if (priv->expanded_color) gdk_color_free(priv->expanded_color); - priv->expanded_color = gdk_color_copy(color); + priv->expanded_color = color ? gdk_color_copy(color) : NULL; } void @@ -770,7 +770,7 @@ if (priv->collapsed_color) gdk_color_free(priv->collapsed_color); - priv->collapsed_color = gdk_color_copy(color); + priv->collapsed_color = color ? gdk_color_copy(color) : NULL; } void @@ -797,7 +797,7 @@ if (priv->contact_color) gdk_color_free(priv->contact_color); - priv->contact_color = gdk_color_copy(color); + priv->contact_color = color ? gdk_color_copy(color) : NULL; } void