Enable a message when the current theme does not support colour schemes

2007-01-07  Thomas Wood  <thos@gnome.org>

	* Makefile.am:
	* gnome-theme-details.c: (gtk_theme_update_remove_button),
	(remove_theme), (color_select), (toggle_color_scheme_key),
	(gnome_theme_details_init):
	* gnome-theme-manager.c: (main):
	* gtkrc-utils.c:
	* gtkrc-utils.h:
	* theme-properties.glade:

	Enable a message when the current theme does not support colour schemes

svn path=/trunk/; revision=7092
This commit is contained in:
Thomas Wood 2007-01-07 22:08:02 +00:00 committed by Thomas Wood
parent 869a405a9c
commit f4ddd4914a
7 changed files with 267 additions and 6 deletions

View file

@ -1,3 +1,16 @@
2007-01-07 Thomas Wood <thos@gnome.org>
* Makefile.am:
* gnome-theme-details.c: (gtk_theme_update_remove_button),
(remove_theme), (color_select), (toggle_color_scheme_key),
(gnome_theme_details_init):
* gnome-theme-manager.c: (main):
* gtkrc-utils.c:
* gtkrc-utils.h:
* theme-properties.glade:
Enable a message when the current theme does not support colour schemes
2007-01-07 Thomas Wood <thos@gnome.org>
Based on patch by: Gabor Kelemen <kelemeng@gnome.hu>

View file

@ -18,7 +18,9 @@ gnome_theme_manager_SOURCES = \
gnome-theme-details.c \
gnome-theme-details.h \
gnome-theme-installer.c \
gnome-theme-installer.h
gnome-theme-installer.h \
gtkrc-utils.c \
gtkrc-utils.h
gnome_theme_manager_LDFLAGS = -export-dynamic

View file

@ -15,6 +15,7 @@
#include "gnome-theme-details.h"
#include "gnome-theme-installer.h"
#include "gnome-theme-info.h"
#include "gtkrc-utils.h"
#define MAX_ELEMENTS_BEFORE_SCROLLING 12
@ -200,14 +201,50 @@ gtk_theme_update_remove_button (GtkTreeSelection *selection,
g_free (theme_selected);
}
static void
update_color_scheme_tab ()
{
GSList *symbolic_colors = NULL;
GSList *engines = NULL;
gboolean fg, bg, base, text, fg_s, bg_s, enable_colors;
gchar *filename, *theme_name;
GtkSettings *settings;
GladeXML *dialog;
dialog = gnome_theme_manager_get_theme_dialog ();
settings = gtk_settings_get_default ();
g_object_get (G_OBJECT (settings), "gtk-theme-name", &theme_name, NULL);
filename = gtkrc_find_named (theme_name);
gtkrc_get_details (filename, &engines, &symbolic_colors);
fg = (g_slist_find_custom (symbolic_colors, "fg_color", g_str_equal) != NULL);
bg = (g_slist_find_custom (symbolic_colors, "bg_color", g_str_equal) != NULL);
base = (g_slist_find_custom (symbolic_colors, "base_color", g_str_equal) != NULL);
text = (g_slist_find_custom (symbolic_colors, "text_color", g_str_equal) != NULL);
fg_s = (g_slist_find_custom (symbolic_colors, "selected_fg_color", g_str_equal) != NULL);
bg_s = (g_slist_find_custom (symbolic_colors, "selected_bg_color", g_str_equal) != NULL);
enable_colors = (fg && bg && base && text && fg_s && bg_s);
gtk_widget_set_sensitive (WID ("enable_custom_colors_checkbutton"), enable_colors);
gtk_widget_set_sensitive (WID ("color_scheme_table"), enable_colors);
if (enable_colors)
gtk_widget_hide (WID ("color_scheme_message_hbox"));
else
gtk_widget_show (WID ("color_scheme_message_hbox"));
g_free (filename);
g_free (theme_name);
}
static void
gtk_theme_selection_changed (GtkTreeSelection *selection,
gpointer data)
{
GladeXML *dialog;
dialog = gnome_theme_manager_get_theme_dialog ();
update_gconf_key_from_selection (selection, GTK_THEME_KEY);
gtk_theme_update_remove_button(selection, WID("control_remove_button"), THEME_GTK);
}
@ -460,7 +497,7 @@ remove_theme(GtkWidget *button, gpointer data)
}
void
color_select (GtkWidget *colorbutton, gpointer dialog)
color_select (GtkWidget *colorbutton, GladeXML *dialog)
{
GConfClient *client = NULL;
gchar *new_scheme;
@ -533,6 +570,12 @@ toggle_color_scheme_key (GtkWidget *checkbutton, gpointer *data)
}
}
void
theme_notebook_changed_page (GtkWidget *widget, GladeXML *dialog)
{
update_color_scheme_tab ();
}
void
gnome_theme_details_init (void)
{
@ -592,10 +635,12 @@ gnome_theme_details_init (void)
widget = WID ("enable_custom_colors_checkbutton");
g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (toggle_color_scheme_key), parent);
g_signal_connect (G_OBJECT (WID ("theme_notebook")), "switch-page", G_CALLBACK (theme_notebook_changed_page), dialog);
g_object_get (G_OBJECT (gtk_settings_get_default()), "gtk-color-scheme", &color_scheme, NULL);
update_color_buttons_from_string (color_scheme);
/* general signals */
g_signal_connect (G_OBJECT (parent), "response", G_CALLBACK (cb_dialog_response), NULL);
g_signal_connect (G_OBJECT (parent), "delete-event", G_CALLBACK (gtk_true), NULL);

View file

@ -1618,6 +1618,9 @@ main (int argc, char *argv[])
};
GOptionContext *option_context;
if (!g_thread_supported ())
g_thread_init (NULL);
/* We need to do this before we initialize anything else */
theme_thumbnail_factory_init (argc, argv);

View file

@ -0,0 +1,138 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <fcntl.h>
#include <gtk/gtk.h>
#define INCLUDE_SYMBOL ((gpointer) 1)
#define ENGINE_SYMBOL ((gpointer) 2)
#define SYMBOLIC_COLOR_SYMBOL ((gpointer) 3)
static gint
str_nequal (gchar *a, gchar *b)
{
return !g_str_equal (a, b);
}
gchar *
gtkrc_find_named (gchar *name)
{
/* find the gtkrc of the named theme
* taken from gtkrc.c (gtk_rc_parse_named)
*/
gchar *path = NULL;
const gchar *home_dir;
gchar *subpath;
subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
/* First look in the users home directory
*/
home_dir = g_get_home_dir ();
if (home_dir)
{
path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
if (!g_file_test (path, G_FILE_TEST_EXISTS))
{
g_free (path);
path = NULL;
}
}
if (!path)
{
gchar *theme_dir = gtk_rc_get_theme_dir ();
path = g_build_filename (theme_dir, name, subpath, NULL);
g_free (theme_dir);
if (!g_file_test (path, G_FILE_TEST_EXISTS))
{
g_free (path);
path = NULL;
}
}
return path;
}
void
gtkrc_get_details (gchar *filename, GSList **engines, GSList **symbolic_colors)
{
gint file = -1;
GSList *files = NULL;
GSList *read_files = NULL;
GTokenType token;
GScanner *scanner = g_scanner_new (NULL);
g_scanner_scope_add_symbol (scanner, 0, "include", INCLUDE_SYMBOL);
g_scanner_scope_add_symbol (scanner, 0, "engine", ENGINE_SYMBOL);
files = g_slist_prepend (files, g_strdup (filename));
while (files != NULL)
{
filename = files->data;
files = g_slist_delete_link (files, files);
if (g_slist_find_custom (read_files, filename, (GCompareFunc) str_nequal))
{
g_warning ("Recursion in the gtkrc detected!");
continue; /* skip this file since we've done it before... */
}
read_files = g_slist_prepend (read_files, filename);
file = g_open (filename, O_RDONLY);
if (file == -1)
{
g_warning ("Could not open file \"%s\"", filename);
}
else
{
g_scanner_input_file (scanner, file);
while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF)
{
GTokenType string_token;
if (token == '@')
{
token = g_scanner_get_next_token (scanner);
if (token != G_TOKEN_IDENTIFIER)
continue;
if (!g_slist_find_custom (*symbolic_colors, scanner->value.v_identifier, (GCompareFunc) str_nequal))
*symbolic_colors = g_slist_append (*symbolic_colors, g_strdup (scanner->value.v_identifier));
continue;
}
if (token != G_TOKEN_SYMBOL)
continue;
if (scanner->value.v_symbol == INCLUDE_SYMBOL)
{
string_token = g_scanner_get_next_token (scanner);
if (string_token != G_TOKEN_STRING)
continue;
if (g_path_is_absolute (scanner->value.v_string))
{
files = g_slist_prepend (files, g_strdup (scanner->value.v_string));
}
else
{
gchar *basedir = g_path_get_dirname (filename);
files = g_slist_prepend (files, g_build_path (G_DIR_SEPARATOR_S, basedir, scanner->value.v_string, NULL));
g_free (basedir);
}
}
else if (scanner->value.v_symbol == ENGINE_SYMBOL)
{
string_token = g_scanner_get_next_token (scanner);
if (string_token != G_TOKEN_STRING)
continue;
if (!g_slist_find_custom (*engines, scanner->value.v_string, (GCompareFunc) str_nequal))
*engines = g_slist_append (*engines, g_strdup (scanner->value.v_string));
}
}
}
}
}

View file

@ -0,0 +1,5 @@
void gtkrc_get_details (gchar *filename, GSList *engines, GSList *symbolic_colors);
gchar * gtkrc_find_named (gchar *name);

View file

@ -1126,12 +1126,67 @@
</child>
<child>
<widget class="GtkVBox" id="vbox14">
<widget class="GtkVBox" id="colors_vbox">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="color_scheme_message_hbox">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<widget class="GtkImage" id="image24">
<property name="visible">True</property>
<property name="stock">gtk-dialog-info</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label70">
<property name="visible">True</property>
<property name="label" translatable="yes">The current controls theme does not support color schemes</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="enable_custom_colors_checkbutton">
<property name="visible">True</property>