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
|
@ -1,3 +1,12 @@
|
|||
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
|
||||
|
||||
2007-07-26 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* gnome-wp-item.c: (gnome_wp_item_update_description): add a comment
|
||||
|
|
|
@ -136,7 +136,7 @@ cursor_theme_sort_func (GtkTreeModel *model,
|
|||
gpointer user_data)
|
||||
{
|
||||
const gchar *a_label = NULL;
|
||||
const gchar *b_label = NULL;
|
||||
const gchar *b_label = NULL;
|
||||
const gchar *default_label;
|
||||
|
||||
gtk_tree_model_get (model, a, COL_LABEL, &a_label, -1);
|
||||
|
@ -156,46 +156,10 @@ static void
|
|||
update_color_buttons_from_string (const gchar *color_scheme, AppearanceData *data)
|
||||
{
|
||||
GdkColor color_scheme_colors[6];
|
||||
gchar **color_scheme_strings, **color_scheme_pair, *current_string;
|
||||
gint i;
|
||||
GtkWidget *widget;
|
||||
|
||||
if (!color_scheme || !strcmp (color_scheme, "")) return;
|
||||
|
||||
/* 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 (color_scheme, "\n", 0);
|
||||
|
||||
/* loop through the name:color pairs, and save the colour 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], &color_scheme_colors[0]);
|
||||
else if (!strcmp ("bg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &color_scheme_colors[1]);
|
||||
else if (!strcmp ("text_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &color_scheme_colors[2]);
|
||||
else if (!strcmp ("base_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &color_scheme_colors[3]);
|
||||
else if (!strcmp ("selected_fg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &color_scheme_colors[4]);
|
||||
else if (!strcmp ("selected_bg_color", color_scheme_pair[0]))
|
||||
gdk_color_parse (color_scheme_pair[1], &color_scheme_colors[5]);
|
||||
}
|
||||
|
||||
g_strfreev (color_scheme_pair);
|
||||
}
|
||||
|
||||
g_strfreev (color_scheme_strings);
|
||||
if (!theme_parse_color_scheme (color_scheme, color_scheme_colors))
|
||||
return;
|
||||
|
||||
/* now set all the buttons to the correct settings */
|
||||
widget = glade_xml_get_widget (data->xml, "fg_colorbutton");
|
||||
|
@ -221,7 +185,8 @@ update_color_buttons_from_settings (GtkSettings *settings,
|
|||
scheme = gconf_client_get_string (data->client, COLOR_SCHEME_KEY, NULL);
|
||||
g_object_get (G_OBJECT (settings), "gtk-color-scheme", &setting, NULL);
|
||||
|
||||
if (scheme == NULL || strcmp (scheme, "") == 0 || strcmp (scheme, setting) == 0)
|
||||
if (scheme == NULL || strcmp (scheme, "") == 0 ||
|
||||
theme_color_scheme_equal (scheme, setting))
|
||||
{
|
||||
gtk_widget_set_sensitive (glade_xml_get_widget (data->xml, "color_scheme_defaults_button"), FALSE);
|
||||
}
|
||||
|
|
|
@ -218,12 +218,6 @@ theme_is_equal (const GnomeThemeMetaInfo *a, const GnomeThemeMetaInfo *b)
|
|||
strcmp (a->gtk_theme_name, b->gtk_theme_name))
|
||||
return FALSE;
|
||||
|
||||
a_set = a->gtk_color_scheme && strcmp (a->gtk_color_scheme, "");
|
||||
b_set = b->gtk_color_scheme && strcmp (b->gtk_color_scheme, "");
|
||||
if ((a_set != b_set) ||
|
||||
(a_set && strcmp (a->gtk_color_scheme, b->gtk_color_scheme)))
|
||||
return FALSE;
|
||||
|
||||
if (!(a->icon_theme_name && b->icon_theme_name) ||
|
||||
strcmp (a->icon_theme_name, b->icon_theme_name))
|
||||
return FALSE;
|
||||
|
@ -236,6 +230,12 @@ theme_is_equal (const GnomeThemeMetaInfo *a, const GnomeThemeMetaInfo *b)
|
|||
strcmp (a->cursor_theme_name, b->cursor_theme_name))
|
||||
return FALSE;
|
||||
|
||||
a_set = a->gtk_color_scheme && strcmp (a->gtk_color_scheme, "");
|
||||
b_set = b->gtk_color_scheme && strcmp (b->gtk_color_scheme, "");
|
||||
if ((a_set != b_set) ||
|
||||
(a_set && !theme_color_scheme_equal (a->gtk_color_scheme, b->gtk_color_scheme)))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -46,3 +46,5 @@ typedef enum {
|
|||
gboolean theme_delete (const gchar *name, ThemeType type);
|
||||
gboolean theme_model_iter_last (GtkTreeModel *model, GtkTreeIter *iter);
|
||||
gboolean theme_find_in_model (GtkTreeModel *model, const gchar *name, GtkTreeIter *iter);
|
||||
gboolean theme_parse_color_scheme (const gchar *scheme, GdkColor *colors);
|
||||
gboolean theme_color_scheme_equal (const gchar *s1, const gchar *s2);
|
||||
|
|
Loading…
Add table
Reference in a new issue