make color scheme comparisons work much more reliably
2007-07-26 Jens Granseuer <jensgr@gmx.net> * appearance-style.c: (update_color_buttons_from_string), (update_color_buttons_from_settings): * appearance-themes.c: (theme_is_equal): * theme-util.c: (theme_parse_color_scheme), (theme_color_scheme_equal): * theme-util.h: make color scheme comparisons work much more reliably svn path=/trunk/; revision=7893
This commit is contained in:
parent
0b3d3935dd
commit
e91260a58b
5 changed files with 85 additions and 46 deletions
|
@ -144,3 +144,66 @@ theme_find_in_model (GtkTreeModel *model, const gchar *name, GtkTreeIter *iter)
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
theme_parse_color_scheme (const gchar *scheme, GdkColor *colors)
|
||||
{
|
||||
gchar **color_scheme_strings, **color_scheme_pair, *current_string;
|
||||
gint i;
|
||||
|
||||
if (!scheme || !strcmp (scheme, ""))
|
||||
return FALSE;
|
||||
|
||||
/* The color scheme string consists of name:color pairs, seperated by
|
||||
* newlines, so first we split the string up by new line */
|
||||
|
||||
color_scheme_strings = g_strsplit (scheme, "\n", 0);
|
||||
|
||||
/* loop through the name:color pairs, and save the color if we recognise the name */
|
||||
i = 0;
|
||||
while ((current_string = color_scheme_strings[i++])) {
|
||||
color_scheme_pair = g_strsplit (current_string, ":", 0);
|
||||
|
||||
if (color_scheme_pair[0] != NULL && color_scheme_pair[1] != NULL) {
|
||||
g_strstrip (color_scheme_pair[0]);
|
||||
g_strstrip (color_scheme_pair[1]);
|
||||
|
||||
if (!strcmp ("fg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &colors[0]);
|
||||
else if (!strcmp ("bg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &colors[1]);
|
||||
else if (!strcmp ("text_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &colors[2]);
|
||||
else if (!strcmp ("base_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &colors[3]);
|
||||
else if (!strcmp ("selected_fg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &colors[4]);
|
||||
else if (!strcmp ("selected_bg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &colors[5]);
|
||||
}
|
||||
|
||||
g_strfreev (color_scheme_pair);
|
||||
}
|
||||
|
||||
g_strfreev (color_scheme_strings);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
theme_color_scheme_equal (const gchar *s1, const gchar *s2)
|
||||
{
|
||||
GdkColor c1[6], c2[6];
|
||||
int i;
|
||||
|
||||
if (!theme_parse_color_scheme (s1, c1) ||
|
||||
!theme_parse_color_scheme (s2, c2))
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < 6; ++i) {
|
||||
if (!gdk_color_equal (&c1[i], &c2[i]))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue