From e794639a0c8c5ad95039fc1f3dd3e619993ab105 Mon Sep 17 00:00:00 2001 From: Jens Granseuer Date: Tue, 1 May 2007 13:02:29 +0000 Subject: [PATCH] fill the Preferences tab with life 2007-05-01 Jens Granseuer * appearance-main.c: (main): * appearance-ui.c: * appearance-ui.h: * appearance.h: * appearance.glade: fill the Preferences tab with life svn path=/trunk/; revision=7530 --- capplets/appearance/ChangeLog | 10 + capplets/appearance/appearance-main.c | 3 + capplets/appearance/appearance-ui.c | 252 ++++++++++++++++++++++++++ capplets/appearance/appearance-ui.h | 22 +++ capplets/appearance/appearance.glade | 124 ++++++------- capplets/appearance/appearance.h | 3 + 6 files changed, 345 insertions(+), 69 deletions(-) create mode 100644 capplets/appearance/appearance-ui.c create mode 100644 capplets/appearance/appearance-ui.h diff --git a/capplets/appearance/ChangeLog b/capplets/appearance/ChangeLog index 7e5d008c2..c50149996 100644 --- a/capplets/appearance/ChangeLog +++ b/capplets/appearance/ChangeLog @@ -1,3 +1,13 @@ +2007-05-01 Jens Granseuer + + * appearance-main.c: (main): + * appearance-ui.c: + * appearance-ui.h: + * appearance.h: + * appearance.glade: + + fill the Preferences tab with life + 2007-05-01 Jens Granseuer * appearance-main.c: (init_appearance_data), (main): diff --git a/capplets/appearance/appearance-main.c b/capplets/appearance/appearance-main.c index 5becbcf7c..e3507d21b 100644 --- a/capplets/appearance/appearance-main.c +++ b/capplets/appearance/appearance-main.c @@ -20,6 +20,7 @@ #include "appearance.h" #include "appearance-themes.h" +#include "appearance-ui.h" #include "theme-thumbnail.h" #include "activate-settings-daemon.h" @@ -80,6 +81,7 @@ main (int argc, char **argv) /* init tabs */ themes_init (data); + ui_init (data); /* * fonts_init (data); * desktop_init (data); @@ -95,6 +97,7 @@ main (int argc, char **argv) gtk_main (); /* free stuff */ + ui_shutdown (data); g_object_unref (data->client); g_object_unref (data->xml); g_free (data); diff --git a/capplets/appearance/appearance-ui.c b/capplets/appearance/appearance-ui.c new file mode 100644 index 000000000..b4899fd02 --- /dev/null +++ b/capplets/appearance/appearance-ui.c @@ -0,0 +1,252 @@ +/* + * Copyright (C) 2007 The GNOME Foundation + * Written by Jonathan Blandford + * 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 "appearance.h" + +#include "gconf-property-editor.h" + +static GConfEnumStringPair toolbar_style_enums[] = { + { 0, "both" }, + { 1, "both-horiz" }, + { 2, "icons" }, + { 3, "text" }, + { -1, NULL } +}; + + +static void +show_handlebar (AppearanceData *data, gboolean show) +{ + GtkWidget *handlebox = WID ("toolbar_handlebox"); + GtkWidget *toolbar = WID ("toolbar_toolbar"); + GtkWidget *align = WID ("toolbar_align"); + + g_object_ref (handlebox); + g_object_ref (toolbar); + + if (GTK_BIN (align)->child) + gtk_container_remove (GTK_CONTAINER (align), GTK_BIN (align)->child); + + if (GTK_BIN (handlebox)->child) + gtk_container_remove (GTK_CONTAINER (handlebox), GTK_BIN (handlebox)->child); + + if (show) { + gtk_container_add (GTK_CONTAINER (align), handlebox); + gtk_container_add (GTK_CONTAINER (handlebox), toolbar); + g_object_unref (handlebox); + } else { + gtk_container_add (GTK_CONTAINER (align), toolbar); + } + + g_object_unref (toolbar); +} + +static void +set_toolbar_style (AppearanceData *data, const char *value) +{ + static const GtkToolbarStyle gtk_toolbar_styles[] = + { GTK_TOOLBAR_BOTH, GTK_TOOLBAR_BOTH_HORIZ, GTK_TOOLBAR_ICONS, GTK_TOOLBAR_TEXT }; + + int enum_val; + + if (!gconf_string_to_enum (toolbar_style_enums, value, &enum_val)) + enum_val = 0; + + gtk_toolbar_set_style (GTK_TOOLBAR (WID("toolbar_toolbar")), + gtk_toolbar_styles[enum_val]); +} + +static void +set_have_icons (AppearanceData *data, gboolean value) +{ + static const char *menu_item_names[] = { + "menu_item_1", + "menu_item_2", + "menu_item_3", + "menu_item_4", + "menu_item_5", + "cut", + "copy", + "paste", + NULL + }; + + const char **name; + + for (name = menu_item_names; *name != NULL; name++) { + GtkImageMenuItem *item = GTK_IMAGE_MENU_ITEM (WID (*name)); + GtkWidget *image; + + if (value) { + image = g_object_get_data (G_OBJECT (item), "image"); + if (image) { + gtk_image_menu_item_set_image (item, image); + g_object_unref (image); + } + } else { + image = gtk_image_menu_item_get_image (item); + g_object_set_data (G_OBJECT (item), "image", image); + g_object_ref (image); + gtk_image_menu_item_set_image (item, NULL); + } + } +} + +/** GConf Callbacks and Conversions **/ + +static GConfValue * +toolbar_from_widget (GConfPropertyEditor *peditor, GConfValue *value) +{ + GConfValue *new_value; + + new_value = gconf_value_new (GCONF_VALUE_STRING); + gconf_value_set_string (new_value, + gconf_enum_to_string (toolbar_style_enums, + gconf_value_get_int (value))); + + return new_value; +} + +static GConfValue * +toolbar_to_widget (GConfPropertyEditor *peditor, GConfValue *value) +{ + GConfValue *new_value; + const gchar *str; + gint val; + + str = (value && (value->type == GCONF_VALUE_STRING)) ? + gconf_value_get_string (value) : NULL; + + if (!gconf_string_to_enum (toolbar_style_enums, str, &val)) + val = 0; + + new_value = gconf_value_new (GCONF_VALUE_INT); + gconf_value_set_int (new_value, val); + return new_value; +} + +static void +toolbar_style_cb (GConfPropertyEditor *peditor, + gchar *key, + GConfValue *value, + AppearanceData *data) +{ + set_toolbar_style (data, gconf_value_get_string (value)); +} + +static void +menus_have_icons_cb (GConfPropertyEditor *peditor, + gchar *key, + GConfValue *value, + AppearanceData *data) +{ + set_have_icons (data, gconf_value_get_bool (value)); +} + +static void +toolbar_detachable_cb (GConfClient *client, + const gchar *key, + GConfValue *value, + AppearanceData *data) +{ + if (key != NULL && + strcmp (key, "/desktop/gnome/interface/toolbar_detachable") == 0) + show_handlebar (data, gconf_value_get_bool (value)); +} + +/** GUI Callbacks **/ + +static gint +button_press_block_cb (GtkWidget *toolbar, + GdkEvent *event, + gpointer data) +{ + return TRUE; +} + +/** Public Functions **/ + +void +ui_init (AppearanceData *data) +{ + GSList *peds = NULL; + GObject *peditor; + char *toolbar_style; + + gconf_client_add_dir (data->client, "/desktop/gnome/interface", + GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + + peditor = gconf_peditor_new_boolean + (NULL, "/desktop/gnome/interface/can_change_accels", + WID ("menu_accel_toggle"), NULL); + g_slist_append (peds, peditor); + + peditor = gconf_peditor_new_boolean + (NULL, "/desktop/gnome/interface/menus_have_icons", + WID ("menu_icons_toggle"), NULL); + g_signal_connect (peditor, "value_changed", + G_CALLBACK (menus_have_icons_cb), data); + g_slist_append (peds, peditor); + + set_have_icons (data, + gconf_client_get_bool (data->client, + "/desktop/gnome/interface/menus_have_icons", + NULL)); + + peditor = gconf_peditor_new_select_menu + (NULL, "/desktop/gnome/interface/toolbar_style", + WID ("toolbar_style_omenu"), + "conv-to-widget-cb", toolbar_to_widget, + "conv-from-widget-cb", toolbar_from_widget, + NULL); + g_signal_connect (peditor, "value_changed", + G_CALLBACK (toolbar_style_cb), data); + g_slist_append (peds, peditor); + + g_signal_connect (G_OBJECT (WID ("toolbar_handlebox")), + "button_press_event", + G_CALLBACK (button_press_block_cb), NULL); + + show_handlebar (data, + gconf_client_get_bool (data->client, + "/desktop/gnome/interface/toolbar_detachable", + NULL)); + + toolbar_style = gconf_client_get_string + (data->client, + "/desktop/gnome/interface/toolbar_style", + NULL); + set_toolbar_style (data, toolbar_style); + g_free (toolbar_style); + + /* no ui for detachable toolbars */ + g_signal_connect (G_OBJECT (data->client), "value_changed", + G_CALLBACK (toolbar_detachable_cb), data); + + data->peditors = peds; +} + +void +ui_shutdown (AppearanceData *data) +{ + g_slist_foreach (data->peditors, (GFunc) g_object_unref, NULL); + g_slist_free (data->peditors); +} diff --git a/capplets/appearance/appearance-ui.h b/capplets/appearance/appearance-ui.h new file mode 100644 index 000000000..747a2ba02 --- /dev/null +++ b/capplets/appearance/appearance-ui.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2007 The GNOME Foundation + * Written by 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 ui_init (AppearanceData *data); +void ui_shutdown (AppearanceData *data); diff --git a/capplets/appearance/appearance.glade b/capplets/appearance/appearance.glade index 2eac41354..a00bdebcc 100644 --- a/capplets/appearance/appearance.glade +++ b/capplets/appearance/appearance.glade @@ -1193,7 +1193,7 @@ True 6 - + True True Show _icons in menus @@ -1207,22 +1207,7 @@ - - True - True - Show icons in buttons - True - True - True - - - False - False - 1 - - - - + True True _Editable menu shortcut keys @@ -1235,42 +1220,6 @@ 2 - - - True - 12 - - - 150 - True - Toolbar Icon Size: - True - GTK_JUSTIFY_CENTER - - - False - False - - - - - True - True - Small - - - False - False - 1 - - - - - False - False - 3 - - True @@ -1289,10 +1238,47 @@ - + True True - Icons and Text + + + + True + + + + True + Text below icons + True + + + + + + True + Text beside icons + True + + + + + + True + Icons only + True + + + + + + True + Text only + True + + + + False @@ -1362,14 +1348,14 @@ True - + True _File True - + - + True _New True @@ -1383,7 +1369,7 @@ - + True _Open True @@ -1397,7 +1383,7 @@ - + True _Save True @@ -1416,7 +1402,7 @@ - + True _Print True @@ -1435,7 +1421,7 @@ - + True _Quit True @@ -1460,7 +1446,7 @@ - + True C_ut True @@ -1474,7 +1460,7 @@ - + True _Copy True @@ -1488,7 +1474,7 @@ - + True _Paste True @@ -1512,14 +1498,14 @@ - + True - + True GTK_SHADOW_OUT - + True GTK_TOOLBAR_BOTH @@ -1544,7 +1530,7 @@ - + True Save File gtk-save diff --git a/capplets/appearance/appearance.h b/capplets/appearance/appearance.h index 204212fb7..c380eb919 100644 --- a/capplets/appearance/appearance.h +++ b/capplets/appearance/appearance.h @@ -32,4 +32,7 @@ typedef struct { int argc; char **argv; GladeXML *xml; + + /* ui */ + GSList *peditors; } AppearanceData;