diff --git a/capplets/appearance/ChangeLog b/capplets/appearance/ChangeLog index 974a5b6c2..9562307c5 100644 --- a/capplets/appearance/ChangeLog +++ b/capplets/appearance/ChangeLog @@ -1,3 +1,12 @@ +2007-07-26 Jens Granseuer + + reviewed by: + + * appearance-style.c: (update_color_buttons_from_string): + * appearance-themes.c: (theme_load_from_gconf), (theme_is_equal): + * theme-util.c: (theme_find_in_model): + * theme-util.h: + 2007-07-26 Jens Granseuer * appearance-style.c: (update_color_buttons_from_settings), diff --git a/capplets/appearance/appearance-style.c b/capplets/appearance/appearance-style.c index 2c0c92579..be6cf6782 100644 --- a/capplets/appearance/appearance-style.c +++ b/capplets/appearance/appearance-style.c @@ -158,7 +158,7 @@ update_color_buttons_from_string (const gchar *color_scheme, AppearanceData *dat GdkColor color_scheme_colors[6]; GtkWidget *widget; - if (!theme_parse_color_scheme (color_scheme, color_scheme_colors)) + if (!gnome_theme_color_scheme_parse (color_scheme, color_scheme_colors)) return; /* now set all the buttons to the correct settings */ diff --git a/capplets/appearance/appearance-themes.c b/capplets/appearance/appearance-themes.c index a0439f12d..e63e2b2fb 100644 --- a/capplets/appearance/appearance-themes.c +++ b/capplets/appearance/appearance-themes.c @@ -120,15 +120,8 @@ theme_load_from_gconf (GConfClient *client, GnomeThemeMetaInfo *theme) scheme = gconf_client_get_string (client, COLOR_SCHEME_KEY, NULL); if (scheme == NULL || !strcmp (scheme, "")) { - /* try to find the color scheme from the gtkrc */ - gchar *gtkrc_file; - - gtkrc_file = gtkrc_find_named (theme->gtk_theme_name); - if (gtkrc_file) { - g_free (scheme); - scheme = gtkrc_get_color_scheme (gtkrc_file); - g_free (gtkrc_file); - } + g_free (scheme); + scheme = gtkrc_get_color_scheme_for_theme (theme->gtk_theme_name); } theme->gtk_color_scheme = scheme; @@ -233,7 +226,7 @@ theme_is_equal (const GnomeThemeMetaInfo *a, const GnomeThemeMetaInfo *b) 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))) + (a_set && !gnome_theme_color_scheme_equal (a->gtk_color_scheme, b->gtk_color_scheme))) return FALSE; return TRUE; diff --git a/capplets/appearance/theme-util.c b/capplets/appearance/theme-util.c index 89ffd74a4..c1c6b9cde 100644 --- a/capplets/appearance/theme-util.c +++ b/capplets/appearance/theme-util.c @@ -144,66 +144,3 @@ 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; -} diff --git a/capplets/appearance/theme-util.h b/capplets/appearance/theme-util.h index 977d82bf8..6af9b0810 100644 --- a/capplets/appearance/theme-util.h +++ b/capplets/appearance/theme-util.h @@ -46,5 +46,3 @@ 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); diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index ff67bed68..e8be9d2da 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,16 @@ +2007-07-26 Jens Granseuer + + * gnome-theme-info.c: (gnome_theme_read_meta_theme), + (gnome_theme_color_scheme_parse), (gnome_theme_color_scheme_equal): + * gnome-theme-info.h: + * gtkrc-utils.c: (str_nequal), (gtkrc_get_color_scheme), + (gtkrc_get_color_scheme_for_theme): + * gtkrc-utils.h: move some utility code here from appearance + + * gnome-theme-apply.c: (gnome_meta_theme_set): when applying a metatheme, + check whether to set/unset the color scheme gconf key (should fix bug + #421866) + 2007-07-25 Denis Washington * gnome-theme-apply.c: (gnome_meta_theme_set): diff --git a/capplets/common/gnome-theme-apply.c b/capplets/common/gnome-theme-apply.c index 0fa0029fa..b7d20340e 100644 --- a/capplets/common/gnome-theme-apply.c +++ b/capplets/common/gnome-theme-apply.c @@ -21,6 +21,7 @@ #include #include #include "gnome-theme-apply.h" +#include "gtkrc-utils.h" #define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme" #define COLOR_SCHEME_KEY "/desktop/gnome/interface/gtk_color_scheme" @@ -58,8 +59,22 @@ gnome_meta_theme_set (GnomeThemeMetaInfo *meta_theme_info) old_key = gconf_client_get_string (client, COLOR_SCHEME_KEY, NULL); if (compare (old_key, meta_theme_info->gtk_color_scheme)) { - gchar *new_value = (meta_theme_info->gtk_color_scheme) ? meta_theme_info->gtk_color_scheme : ""; - gconf_client_set_string (client, COLOR_SCHEME_KEY, new_value, NULL); + /* only save the color scheme if it differs from the default + scheme for the selected gtk theme */ + gchar *newval, *gtkcols; + + newval = meta_theme_info->gtk_color_scheme; + gtkcols = gtkrc_get_color_scheme_for_theme (meta_theme_info->gtk_theme_name); + + if (newval == NULL || !strcmp (newval, "") || + gnome_theme_color_scheme_equal (newval, gtkcols)) + { + gconf_client_unset (client, COLOR_SCHEME_KEY, NULL); + } + else + { + gconf_client_set_string (client, COLOR_SCHEME_KEY, newval, NULL); + } } g_free (old_key); diff --git a/capplets/common/gnome-theme-info.c b/capplets/common/gnome-theme-info.c index 4003e287a..2c10d743f 100644 --- a/capplets/common/gnome-theme-info.c +++ b/capplets/common/gnome-theme-info.c @@ -273,17 +273,7 @@ gnome_theme_read_meta_theme (GnomeVFSURI *meta_theme_uri) str = gnome_desktop_item_get_string (meta_theme_ditem, GTK_COLOR_SCHEME_KEY); if (str == NULL) - { - /* try to find the color scheme from the gtkrc */ - gchar *gtkrc_file = gtkrc_find_named (meta_theme_info->gtk_theme_name); - if (gtkrc_file) - { - scheme = gtkrc_get_color_scheme (gtkrc_file); - g_free (gtkrc_file); - } - else - scheme = NULL; - } + scheme = gtkrc_get_color_scheme_for_theme (meta_theme_info->gtk_theme_name); else scheme = g_strdup (str); @@ -1729,7 +1719,7 @@ read_current_cursor_font (void) } dir = opendir (dir_name); - + while ((file_dirent = readdir (dir)) != NULL) { struct stat st; gchar *link_name; @@ -1739,7 +1729,7 @@ read_current_cursor_font (void) g_free (link_name); continue; } - + if (S_ISLNK (st.st_mode)) { gint length; gchar target[256]; @@ -1753,7 +1743,7 @@ read_current_cursor_font (void) closedir (dir); return retval; } - + } g_free (link_name); } @@ -1821,6 +1811,69 @@ read_cursor_fonts (void) } #endif /* !HAVE_XCURSOR */ +gboolean +gnome_theme_color_scheme_parse (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 +gnome_theme_color_scheme_equal (const gchar *s1, const gchar *s2) +{ + GdkColor c1[6], c2[6]; + int i; + + if (!gnome_theme_color_scheme_parse (s1, c1) || + !gnome_theme_color_scheme_parse (s2, c2)) + return FALSE; + + for (i = 0; i < 6; ++i) { + if (!gdk_color_equal (&c1[i], &c2[i])) + return FALSE; + } + + return TRUE; +} + void gnome_theme_init (gboolean *monitor_not_added) { diff --git a/capplets/common/gnome-theme-info.h b/capplets/common/gnome-theme-info.h index 0dfaafdb5..8276b0fbf 100644 --- a/capplets/common/gnome-theme-info.h +++ b/capplets/common/gnome-theme-info.h @@ -156,4 +156,9 @@ void gnome_theme_info_register_theme_change (ThemeChangedCallback gboolean gnome_theme_is_writable (const gpointer theme, GnomeThemeType type); +gboolean gnome_theme_color_scheme_parse (const gchar *scheme, + GdkColor *colors); +gboolean gnome_theme_color_scheme_equal (const gchar *s1, + const gchar *s2); + #endif /* GNOME_THEME_INFO_H */ diff --git a/capplets/common/gtkrc-utils.c b/capplets/common/gtkrc-utils.c index ef4e072b8..9ddb49080 100644 --- a/capplets/common/gtkrc-utils.c +++ b/capplets/common/gtkrc-utils.c @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2007 The GNOME Foundation + * Written by Thomas Wood + * Jens Granseuer + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + #include #include #include @@ -8,7 +29,7 @@ #define COLOR_SCHEME_SYMBOL ((gpointer) 3) static gint -str_nequal (gchar *a, gchar *b) +str_nequal (const gchar *a, const gchar *b) { return !g_str_equal (a, b); } @@ -191,3 +212,19 @@ gtkrc_get_color_scheme (gchar *filename) g_scanner_destroy (scanner); return result; } + +gchar * +gtkrc_get_color_scheme_for_theme (const gchar *theme_name) +{ + /* try to find the color scheme from the gtkrc */ + gchar *gtkrc_file; + gchar *scheme = NULL; + + gtkrc_file = gtkrc_find_named (theme_name); + if (gtkrc_file) { + scheme = gtkrc_get_color_scheme (gtkrc_file); + g_free (gtkrc_file); + } + + return scheme; +} diff --git a/capplets/common/gtkrc-utils.h b/capplets/common/gtkrc-utils.h index ddfeec3ea..2e936c5cb 100644 --- a/capplets/common/gtkrc-utils.h +++ b/capplets/common/gtkrc-utils.h @@ -1,5 +1,25 @@ - +/* + * Copyright (C) 2007 The GNOME Foundation + * Written by Thomas Wood + * Jens Granseuer + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ void gtkrc_get_details (gchar *filename, GSList **engines, GSList **symbolic_colors); gchar * gtkrc_find_named (const gchar *name); gchar * gtkrc_get_color_scheme (gchar *filename); +gchar * gtkrc_get_color_scheme_for_theme (const gchar *theme_name);