split out function themes_apply_theme() from themes_init(). Connect to

2003-11-12  Michael Natterer  <mitch@gimp.org>

	* app/gui/themes.[ch]: split out function themes_apply_theme()
	from themes_init(). Connect to "notify::theme" of gimp->config and
	change the theme in the callback. Added themes_list_themes().
	Added "const gchar *theme_name" parameter to
	themes_get_theme_dir().

	* app/gui/gui-vtable.c (gui_get_theme_dir): changed accordingly.

	* app/gui/preferences-dialog.c (prefs_dialog_create): enabled
	theme selection on the "Interface" page. Still has many issues
	(like using a conceptually wrong method of theme changing ;-)
	but it won't get fixed if we cannot change themes on the fly...
This commit is contained in:
Michael Natterer 2003-11-11 23:56:00 +00:00 committed by Michael Natterer
parent 614cc8272d
commit 0ce22bfc51
6 changed files with 321 additions and 46 deletions

View File

@ -1,3 +1,18 @@
2003-11-12 Michael Natterer <mitch@gimp.org>
* app/gui/themes.[ch]: split out function themes_apply_theme()
from themes_init(). Connect to "notify::theme" of gimp->config and
change the theme in the callback. Added themes_list_themes().
Added "const gchar *theme_name" parameter to
themes_get_theme_dir().
* app/gui/gui-vtable.c (gui_get_theme_dir): changed accordingly.
* app/gui/preferences-dialog.c (prefs_dialog_create): enabled
theme selection on the "Interface" page. Still has many issues
(like using a conceptually wrong method of theme changing ;-)
but it won't get fixed if we cannot change themes on the fly...
2003-11-12 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdataeditor.c (gimp_data_editor_save_dirty):

View File

@ -475,9 +475,13 @@ prefs_notebook_append_page (Gimp *gimp,
if (notebook_icon)
{
gchar *filename;
GimpGuiConfig *gui_config;
gchar *filename;
filename = g_build_filename (themes_get_theme_dir (gimp),
gui_config = GIMP_GUI_CONFIG (gimp->config);
filename = g_build_filename (themes_get_theme_dir (gimp,
gui_config->theme),
"images", "preferences", notebook_icon,
NULL);
@ -567,6 +571,23 @@ prefs_format_string_select_callback (GtkTreeSelection *sel,
}
}
static void
prefs_theme_select_callback (GtkTreeSelection *sel,
Gimp *gimp)
{
GtkTreeModel *model;
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (sel, &model, &iter))
{
GValue val = { 0, };
gtk_tree_model_get_value (model, &iter, 0, &val);
g_object_set (gimp->config, "theme", g_value_get_string (&val), NULL);
g_value_unset (&val);
}
}
static GtkWidget *
prefs_frame_new (const gchar *label,
GtkContainer *parent,
@ -1180,6 +1201,72 @@ prefs_dialog_new (Gimp *gimp,
_("Use Dynamic _Keyboard Shortcuts"),
GTK_BOX (vbox2));
/* Themes */
vbox2 = prefs_frame_new (_("Themes"), GTK_CONTAINER (vbox), FALSE);
{
GtkListStore *list_store;
GtkWidget *view;
GtkWidget *scrolled_win;
GtkCellRenderer *rend;
GtkTreeViewColumn *col;
GtkTreeIter iter;
GtkTreeSelection *sel;
gchar **themes;
gint n_themes;
gint i;
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (scrolled_win, -1, 80);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox2), scrolled_win, TRUE, TRUE, 0);
gtk_widget_show (scrolled_win);
list_store = gtk_list_store_new (1, G_TYPE_STRING);
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
gtk_container_add (GTK_CONTAINER (scrolled_win), view);
gtk_widget_show (view);
g_object_unref (list_store);
rend = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (NULL, rend,
"text", 0,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
themes = themes_list_themes (gimp, &n_themes);
for (i = 0; i < n_themes; i++)
{
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
0, themes[i],
-1);
if (GIMP_GUI_CONFIG (object)->theme &&
! strcmp (GIMP_GUI_CONFIG (object)->theme, themes[i]))
{
gtk_tree_selection_select_iter (sel, &iter);
}
}
if (themes)
g_strfreev (themes);
g_signal_connect (sel, "changed",
G_CALLBACK (prefs_theme_select_callback),
gimp);
}
/*****************************/
/* Interface / Help System */

View File

@ -24,6 +24,8 @@
#include "gui-types.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
@ -317,5 +319,5 @@ gui_get_display_name (Gimp *gimp,
static const gchar *
gui_get_theme_dir (Gimp *gimp)
{
return themes_get_theme_dir (gimp);
return themes_get_theme_dir (gimp, GIMP_GUI_CONFIG (gimp->config)->theme);
}

View File

@ -475,9 +475,13 @@ prefs_notebook_append_page (Gimp *gimp,
if (notebook_icon)
{
gchar *filename;
GimpGuiConfig *gui_config;
gchar *filename;
filename = g_build_filename (themes_get_theme_dir (gimp),
gui_config = GIMP_GUI_CONFIG (gimp->config);
filename = g_build_filename (themes_get_theme_dir (gimp,
gui_config->theme),
"images", "preferences", notebook_icon,
NULL);
@ -567,6 +571,23 @@ prefs_format_string_select_callback (GtkTreeSelection *sel,
}
}
static void
prefs_theme_select_callback (GtkTreeSelection *sel,
Gimp *gimp)
{
GtkTreeModel *model;
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (sel, &model, &iter))
{
GValue val = { 0, };
gtk_tree_model_get_value (model, &iter, 0, &val);
g_object_set (gimp->config, "theme", g_value_get_string (&val), NULL);
g_value_unset (&val);
}
}
static GtkWidget *
prefs_frame_new (const gchar *label,
GtkContainer *parent,
@ -1180,6 +1201,72 @@ prefs_dialog_new (Gimp *gimp,
_("Use Dynamic _Keyboard Shortcuts"),
GTK_BOX (vbox2));
/* Themes */
vbox2 = prefs_frame_new (_("Themes"), GTK_CONTAINER (vbox), FALSE);
{
GtkListStore *list_store;
GtkWidget *view;
GtkWidget *scrolled_win;
GtkCellRenderer *rend;
GtkTreeViewColumn *col;
GtkTreeIter iter;
GtkTreeSelection *sel;
gchar **themes;
gint n_themes;
gint i;
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (scrolled_win, -1, 80);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox2), scrolled_win, TRUE, TRUE, 0);
gtk_widget_show (scrolled_win);
list_store = gtk_list_store_new (1, G_TYPE_STRING);
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
gtk_container_add (GTK_CONTAINER (scrolled_win), view);
gtk_widget_show (view);
g_object_unref (list_store);
rend = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (NULL, rend,
"text", 0,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
themes = themes_list_themes (gimp, &n_themes);
for (i = 0; i < n_themes; i++)
{
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
0, themes[i],
-1);
if (GIMP_GUI_CONFIG (object)->theme &&
! strcmp (GIMP_GUI_CONFIG (object)->theme, themes[i]))
{
gtk_tree_selection_select_iter (sel, &iter);
}
}
if (themes)
g_strfreev (themes);
g_signal_connect (sel, "changed",
G_CALLBACK (prefs_theme_select_callback),
gimp);
}
/*****************************/
/* Interface / Help System */

View File

@ -36,8 +36,14 @@
/* local function prototypes */
static void gui_themes_dir_foreach_func (const GimpDatafileData *file_data,
gpointer user_data);
static void themes_directories_foreach (const GimpDatafileData *file_data,
gpointer user_data);
static void themes_list_themes_foreach (gpointer key,
gpointer value,
gpointer data);
static void themes_theme_change_notify (GimpGuiConfig *config,
GParamSpec *pspec,
Gimp *gimp);
/* private variables */
@ -51,8 +57,6 @@ void
themes_init (Gimp *gimp)
{
GimpGuiConfig *config;
const gchar *theme_dir;
gchar *gtkrc;
g_return_if_fail (GIMP_IS_GIMP (gimp));
@ -71,13 +75,84 @@ themes_init (Gimp *gimp)
gimp_datafiles_read_directories (path,
G_FILE_TEST_IS_DIR,
gui_themes_dir_foreach_func,
themes_directories_foreach,
gimp);
g_free (path);
}
theme_dir = themes_get_theme_dir (gimp);
themes_apply_theme (gimp, config->theme);
g_signal_connect (config, "notify::theme",
G_CALLBACK (themes_theme_change_notify),
gimp);
}
void
themes_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (themes_hash)
{
g_signal_handlers_disconnect_by_func (gimp->config,
themes_theme_change_notify,
gimp);
g_hash_table_destroy (themes_hash);
themes_hash = NULL;
}
}
gchar **
themes_list_themes (Gimp *gimp,
gint *n_themes)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (n_themes != NULL, NULL);
*n_themes = g_hash_table_size (themes_hash);
if (*n_themes > 0)
{
gchar **themes;
gchar **index;
themes = g_new0 (gchar *, *n_themes + 1);
index = themes;
g_hash_table_foreach (themes_hash, themes_list_themes_foreach, &index);
return themes;
}
return NULL;
}
const gchar *
themes_get_theme_dir (Gimp *gimp,
const gchar *theme_name)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (! theme_name)
theme_name = "Default";
return g_hash_table_lookup (themes_hash, theme_name);
}
void
themes_apply_theme (Gimp *gimp,
const gchar *theme_name)
{
const gchar *theme_dir;
gchar *gtkrc;
g_return_if_fail (GIMP_IS_GIMP (gimp));
theme_dir = themes_get_theme_dir (gimp, theme_name);
if (theme_dir)
{
@ -106,43 +181,14 @@ themes_init (Gimp *gimp)
g_free (gtkrc);
}
void
themes_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (themes_hash)
{
g_hash_table_destroy (themes_hash);
themes_hash = NULL;
}
}
const gchar *
themes_get_theme_dir (Gimp *gimp)
{
GimpGuiConfig *config;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
config = GIMP_GUI_CONFIG (gimp->config);
if (config->theme)
return g_hash_table_lookup (themes_hash, config->theme);
return g_hash_table_lookup (themes_hash, "Default");
}
/* private functions */
static void
gui_themes_dir_foreach_func (const GimpDatafileData *file_data,
gpointer user_data)
themes_directories_foreach (const GimpDatafileData *file_data,
gpointer user_data)
{
Gimp *gimp;
gimp = GIMP (user_data);
Gimp *gimp = GIMP (user_data);
if (gimp->be_verbose)
g_print (_("Adding theme '%s' (%s)\n"),
@ -152,3 +198,36 @@ gui_themes_dir_foreach_func (const GimpDatafileData *file_data,
g_strdup (file_data->basename),
g_strdup (file_data->filename));
}
static void
themes_list_themes_foreach (gpointer key,
gpointer value,
gpointer data)
{
gchar ***index = data;
**index = g_strdup ((gchar *) key);
*index = (*index)++;
}
static void
themes_theme_change_notify (GimpGuiConfig *config,
GParamSpec *pspec,
Gimp *gimp)
{
GList *list, *toplevels;
themes_apply_theme (gimp, config->theme);
toplevels = gtk_window_list_toplevels ();
g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
for (list = toplevels; list; list = list->next)
{
gtk_widget_reset_rc_styles (list->data);
g_object_unref (list->data);
}
g_list_free (toplevels);
}

View File

@ -20,10 +20,15 @@
#define __THEMES_H__
void themes_init (Gimp *gimp);
void themes_exit (Gimp *gimp);
void themes_init (Gimp *gimp);
void themes_exit (Gimp *gimp);
const gchar * themes_get_theme_dir (Gimp *gimp);
gchar ** themes_list_themes (Gimp *gimp,
gint *n_themes);
const gchar * themes_get_theme_dir (Gimp *gimp,
const gchar *theme_name);
void themes_apply_theme (Gimp *gimp,
const gchar *theme_name);
#endif /* __THEMES_H__ */