Use GConfPropertyEditor for theme combo boxes
2007-05-07 Thomas Wood <thos@gnome.org> * appearance-style.c: (prepare_combo): Use GConfPropertyEditor for theme combo boxes svn path=/trunk/; revision=7571
This commit is contained in:
parent
88c4cb5314
commit
679410b323
2 changed files with 55 additions and 13 deletions
|
@ -1,3 +1,8 @@
|
|||
2007-05-07 Thomas Wood <thos@gnome.org>
|
||||
|
||||
* appearance-style.c: (prepare_combo): Use GConfPropertyEditor for theme
|
||||
combo boxes
|
||||
|
||||
2007-05-07 Thomas Wood <thos@gnome.org>
|
||||
|
||||
* Makefile.am:
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "gnome-theme-info.h"
|
||||
#include "appearance.h"
|
||||
#include "gconf-property-editor.h"
|
||||
|
||||
enum ThemeType {
|
||||
GTK_THEMES,
|
||||
|
@ -37,23 +38,57 @@ static gchar *gconf_keys[] = {
|
|||
"/desktop/gnome/peripherals/mouse/cursor_theme"
|
||||
};
|
||||
|
||||
static void
|
||||
theme_changed (GtkComboBox *combo, AppearanceData *data)
|
||||
static GConfValue *
|
||||
conv_to_widget_cb (GConfPropertyEditor *peditor, GConfValue *value)
|
||||
{
|
||||
enum ThemeType type;
|
||||
gchar *value;
|
||||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
gboolean valid;
|
||||
gchar *test = NULL;
|
||||
GtkWidget *combo;
|
||||
GConfValue *new_value;
|
||||
gint index = -1;
|
||||
|
||||
/* find value in model */
|
||||
combo = GTK_WIDGET (gconf_property_editor_get_ui_control (peditor));
|
||||
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo)));
|
||||
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
|
||||
while (valid)
|
||||
{
|
||||
index++;
|
||||
g_free (test);
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, 0, &test, -1);
|
||||
if (test && !strcmp (test, gconf_value_get_string (value)))
|
||||
break;
|
||||
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
|
||||
}
|
||||
g_free (test);
|
||||
|
||||
new_value = gconf_value_new (GCONF_VALUE_INT);
|
||||
gconf_value_set_int (new_value, index);
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
static GConfValue *
|
||||
conv_from_widget_cb (GConfPropertyEditor *peditor, GConfValue *value)
|
||||
{
|
||||
GConfValue *new_value;
|
||||
gchar *combo_value = NULL;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
GtkWidget *combo;
|
||||
|
||||
combo = GTK_WIDGET (gconf_property_editor_get_ui_control (peditor));
|
||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
||||
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
|
||||
gtk_tree_model_get (model, &iter, 0, &value, -1);
|
||||
type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "theme_type"));
|
||||
gtk_tree_model_get (model, &iter, 0, &combo_value, -1);
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
new_value = gconf_value_new (GCONF_VALUE_STRING);
|
||||
gconf_value_set_string (new_value, combo_value);
|
||||
g_free (combo_value);
|
||||
|
||||
gconf_client_set_string (data->client, gconf_keys[type], value, NULL);
|
||||
return new_value;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -95,7 +130,7 @@ prepare_combo (AppearanceData *data, GtkWidget *combo, enum ThemeType type)
|
|||
|
||||
if (type < ICON_THEMES)
|
||||
name = ((GnomeThemeInfo*) l->data)->name;
|
||||
else
|
||||
else if (type == ICON_THEMES)
|
||||
name = ((GnomeThemeIconInfo*) l->data)->name;
|
||||
|
||||
if (!name)
|
||||
|
@ -111,12 +146,14 @@ prepare_combo (AppearanceData *data, GtkWidget *combo, enum ThemeType type)
|
|||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 0);
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &active_row);
|
||||
g_object_set_data (G_OBJECT (combo), "theme_type", GINT_TO_POINTER (type));
|
||||
|
||||
g_signal_connect (G_OBJECT (combo), "changed", (GCallback) theme_changed, data);
|
||||
gconf_peditor_new_combo_box (NULL, gconf_keys[type], combo,
|
||||
"conv-to-widget-cb", conv_to_widget_cb,
|
||||
"conv-from-widget-cb", conv_from_widget_cb,
|
||||
NULL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
style_init (AppearanceData *data)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue