From 66af802143f65ee8a15606d160fca90c42894cac Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 25 May 2007 18:42:26 +0000 Subject: [PATCH] less code duplication --- src/handlers.c | 145 +++++++++---------------------------------------- 1 file changed, 27 insertions(+), 118 deletions(-) diff --git a/src/handlers.c b/src/handlers.c index a6f856f..23634c2 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -490,9 +490,9 @@ void setup_window_border(GtkWidget *w) mapping = FALSE; } -void setup_font_active(GtkWidget *w) +static void setup_font(GtkWidget *w, const gchar *place) { - gchar *fontstring; + gchar *fontstring, *node; gchar *name, **names; gchar *size; gchar *weight; @@ -500,10 +500,21 @@ void setup_font_active(GtkWidget *w) mapping = TRUE; - name = tree_get_string("theme/font:place=ActiveWindow/name", "Sans"); - size = tree_get_string("theme/font:place=ActiveWindow/size", "8"); - weight = tree_get_string("theme/font:place=ActiveWindow/weight", ""); - slant = tree_get_string("theme/font:place=ActiveWindow/slant", ""); + node = g_strdup_printf("theme/font:place=%s/name", place); + name = tree_get_string(node, "Sans"); + g_free(node); + + node = g_strdup_printf("theme/font:place=%s/size", place); + size = tree_get_string(node, "8"); + g_free(node); + + node = g_strdup_printf("theme/font:place=%s/weight", place); + weight = tree_get_string(node, ""); + g_free(node); + + node = g_strdup_printf("theme/font:place=%s/slant", place); + slant = tree_get_string(node, ""); + g_free(node); /* get only the first font in the string */ names = g_strsplit(name, ",", 0); @@ -530,134 +541,32 @@ void setup_font_active(GtkWidget *w) mapping = FALSE; } -void setup_font_inactive(GtkWidget *w) +void setup_font_active(GtkWidget *w) { - gchar *fontstring; - gchar *name, **names; - gchar *size; - gchar *weight; - gchar *slant; - - mapping = TRUE; - - name = tree_get_string("theme/font:place=InactiveWindow/name", "Sans"); - size = tree_get_string("theme/font:place=InactiveWindow/size", "8"); - weight = tree_get_string("theme/font:place=InactiveWindow/weight", ""); - slant = tree_get_string("theme/font:place=InactiveWindow/slant", ""); - - /* get only the first font in the string */ - names = g_strsplit(name, ",", 0); - g_free(name); - name = g_strdup(names[0]); - g_strfreev(names); - - fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontstring); - g_free(fontstring); - g_free(slant); - g_free(weight); - g_free(size); - g_free(name); + setup_font(w, "ActiveWindow"); +} - mapping = FALSE; +void setup_font_inactive(GtkWidget *w) +{ + setup_font(w, "InactiveWindow"); } void setup_font_menu_header(GtkWidget *w) { - gchar *fontstring; - gchar *name, **names; - gchar *size; - gchar *weight; - gchar *slant; - - mapping = TRUE; - - name = tree_get_string("theme/font:place=MenuHeader/name", "Sans"); - size = tree_get_string("theme/font:place=MenuHeader/size", "8"); - weight = tree_get_string("theme/font:place=MenuHeader/weight", ""); - slant = tree_get_string("theme/font:place=MenuHeader/slant", ""); - - /* get only the first font in the string */ - names = g_strsplit(name, ",", 0); - g_free(name); - name = g_strdup(names[0]); - g_strfreev(names); - - fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontstring); - g_free(fontstring); - g_free(slant); - g_free(weight); - g_free(size); - g_free(name); - - mapping = FALSE; + setup_font(w, "MenuHeader"); } void setup_font_menu_item(GtkWidget *w) { - gchar *fontstring; - gchar *name, **names; - gchar *size; - gchar *weight; - gchar *slant; - - mapping = TRUE; - - name = tree_get_string("theme/font:place=MenuItem/name", "Sans"); - size = tree_get_string("theme/font:place=MenuItem/size", "8"); - weight = tree_get_string("theme/font:place=MenuItem/weight", ""); - slant = tree_get_string("theme/font:place=MenuItem/slant", ""); - - /* get only the first font in the string */ - names = g_strsplit(name, ",", 0); - g_free(name); - name = g_strdup(names[0]); - g_strfreev(names); - - fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontstring); - g_free(fontstring); - g_free(slant); - g_free(weight); - g_free(size); - g_free(name); - - mapping = FALSE; + setup_font(w, "MenuItem"); } void setup_font_display(GtkWidget *w) { - gchar *fontstring; - gchar *name, **names; - gchar *size; - gchar *weight; - gchar *slant; - - mapping = TRUE; - - name = tree_get_string("theme/font:place=OnScreenDisplay/name", "Sans"); - size = tree_get_string("theme/font:place=OnScreenDisplay/size", "8"); - weight = tree_get_string("theme/font:place=OnScreenDisplay/weight", ""); - slant = tree_get_string("theme/font:place=OnScreenDisplay/slant", ""); - - /* get only the first font in the string */ - names = g_strsplit(name, ",", 0); - g_free(name); - name = g_strdup(names[0]); - g_strfreev(names); - - fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontstring); - g_free(fontstring); - g_free(slant); - g_free(weight); - g_free(size); - g_free(name); - - mapping = FALSE; + setup_font(w, "OnScreenDisplay"); } + static void reset_desktop_names() { GtkTreeIter it; -- 2.39.2