move some utility code here from appearance
2007-07-26 Jens Granseuer <jensgr@gmx.net> * 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) svn path=/trunk/; revision=7897
This commit is contained in:
parent
7eefc853d1
commit
abd1b52762
11 changed files with 174 additions and 94 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2007-07-26 Jens Granseuer <jensgr@gmx.net>
|
||||||
|
|
||||||
|
reviewed by: <delete if not using a buddy>
|
||||||
|
|
||||||
|
* 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 <jensgr@gmx.net>
|
2007-07-26 Jens Granseuer <jensgr@gmx.net>
|
||||||
|
|
||||||
* appearance-style.c: (update_color_buttons_from_settings),
|
* appearance-style.c: (update_color_buttons_from_settings),
|
||||||
|
|
|
@ -158,7 +158,7 @@ update_color_buttons_from_string (const gchar *color_scheme, AppearanceData *dat
|
||||||
GdkColor color_scheme_colors[6];
|
GdkColor color_scheme_colors[6];
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
|
||||||
if (!theme_parse_color_scheme (color_scheme, color_scheme_colors))
|
if (!gnome_theme_color_scheme_parse (color_scheme, color_scheme_colors))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* now set all the buttons to the correct settings */
|
/* now set all the buttons to the correct settings */
|
||||||
|
|
|
@ -120,15 +120,8 @@ theme_load_from_gconf (GConfClient *client, GnomeThemeMetaInfo *theme)
|
||||||
scheme = gconf_client_get_string (client, COLOR_SCHEME_KEY, NULL);
|
scheme = gconf_client_get_string (client, COLOR_SCHEME_KEY, NULL);
|
||||||
|
|
||||||
if (scheme == NULL || !strcmp (scheme, "")) {
|
if (scheme == NULL || !strcmp (scheme, "")) {
|
||||||
/* try to find the color scheme from the gtkrc */
|
g_free (scheme);
|
||||||
gchar *gtkrc_file;
|
scheme = gtkrc_get_color_scheme_for_theme (theme->gtk_theme_name);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
theme->gtk_color_scheme = scheme;
|
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, "");
|
a_set = a->gtk_color_scheme && strcmp (a->gtk_color_scheme, "");
|
||||||
b_set = b->gtk_color_scheme && strcmp (b->gtk_color_scheme, "");
|
b_set = b->gtk_color_scheme && strcmp (b->gtk_color_scheme, "");
|
||||||
if ((a_set != b_set) ||
|
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 FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -144,66 +144,3 @@ theme_find_in_model (GtkTreeModel *model, const gchar *name, GtkTreeIter *iter)
|
||||||
|
|
||||||
return FALSE;
|
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,5 +46,3 @@ typedef enum {
|
||||||
gboolean theme_delete (const gchar *name, ThemeType type);
|
gboolean theme_delete (const gchar *name, ThemeType type);
|
||||||
gboolean theme_model_iter_last (GtkTreeModel *model, GtkTreeIter *iter);
|
gboolean theme_model_iter_last (GtkTreeModel *model, GtkTreeIter *iter);
|
||||||
gboolean theme_find_in_model (GtkTreeModel *model, const gchar *name, 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);
|
|
||||||
|
|
|
@ -1,3 +1,16 @@
|
||||||
|
2007-07-26 Jens Granseuer <jensgr@gmx.net>
|
||||||
|
|
||||||
|
* 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 <denisw@svn.gnome.org>
|
2007-07-25 Denis Washington <denisw@svn.gnome.org>
|
||||||
|
|
||||||
* gnome-theme-apply.c: (gnome_meta_theme_set):
|
* gnome-theme-apply.c: (gnome_meta_theme_set):
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <gconf/gconf-client.h>
|
#include <gconf/gconf-client.h>
|
||||||
#include <gnome-wm-manager.h>
|
#include <gnome-wm-manager.h>
|
||||||
#include "gnome-theme-apply.h"
|
#include "gnome-theme-apply.h"
|
||||||
|
#include "gtkrc-utils.h"
|
||||||
|
|
||||||
#define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
|
#define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
|
||||||
#define COLOR_SCHEME_KEY "/desktop/gnome/interface/gtk_color_scheme"
|
#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);
|
old_key = gconf_client_get_string (client, COLOR_SCHEME_KEY, NULL);
|
||||||
if (compare (old_key, meta_theme_info->gtk_color_scheme))
|
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 : "";
|
/* only save the color scheme if it differs from the default
|
||||||
gconf_client_set_string (client, COLOR_SCHEME_KEY, new_value, NULL);
|
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);
|
g_free (old_key);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
str = gnome_desktop_item_get_string (meta_theme_ditem, GTK_COLOR_SCHEME_KEY);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
{
|
scheme = gtkrc_get_color_scheme_for_theme (meta_theme_info->gtk_theme_name);
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
scheme = g_strdup (str);
|
scheme = g_strdup (str);
|
||||||
|
|
||||||
|
@ -1821,6 +1811,69 @@ read_cursor_fonts (void)
|
||||||
}
|
}
|
||||||
#endif /* !HAVE_XCURSOR */
|
#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
|
void
|
||||||
gnome_theme_init (gboolean *monitor_not_added)
|
gnome_theme_init (gboolean *monitor_not_added)
|
||||||
{
|
{
|
||||||
|
|
|
@ -156,4 +156,9 @@ void gnome_theme_info_register_theme_change (ThemeChangedCallback
|
||||||
gboolean gnome_theme_is_writable (const gpointer theme,
|
gboolean gnome_theme_is_writable (const gpointer theme,
|
||||||
GnomeThemeType type);
|
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 */
|
#endif /* GNOME_THEME_INFO_H */
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The GNOME Foundation
|
||||||
|
* Written by Thomas Wood <thos@gnome.org>
|
||||||
|
* Jens Granseuer <jensgr@gmx.net>
|
||||||
|
* 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 <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -8,7 +29,7 @@
|
||||||
#define COLOR_SCHEME_SYMBOL ((gpointer) 3)
|
#define COLOR_SCHEME_SYMBOL ((gpointer) 3)
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
str_nequal (gchar *a, gchar *b)
|
str_nequal (const gchar *a, const gchar *b)
|
||||||
{
|
{
|
||||||
return !g_str_equal (a, b);
|
return !g_str_equal (a, b);
|
||||||
}
|
}
|
||||||
|
@ -191,3 +212,19 @@ gtkrc_get_color_scheme (gchar *filename)
|
||||||
g_scanner_destroy (scanner);
|
g_scanner_destroy (scanner);
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The GNOME Foundation
|
||||||
|
* Written by Thomas Wood <thos@gnome.org>
|
||||||
|
* Jens Granseuer <jensgr@gmx.net>
|
||||||
|
* 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);
|
void gtkrc_get_details (gchar *filename, GSList **engines, GSList **symbolic_colors);
|
||||||
gchar * gtkrc_find_named (const gchar *name);
|
gchar * gtkrc_find_named (const gchar *name);
|
||||||
gchar * gtkrc_get_color_scheme (gchar *filename);
|
gchar * gtkrc_get_color_scheme (gchar *filename);
|
||||||
|
gchar * gtkrc_get_color_scheme_for_theme (const gchar *theme_name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue