Mercurial > pidgin
changeset 14329:479164e18f1a
[gaim-migrate @ 17024]
If you loaded this plugin and activated one of the color preference check
boxes but never actually set a color choice you could cause gtk to crash when
it failed to understand a color setting of "". This is really a gtk+ bug since
they shouldn't crash on that but this workaround was easy and sensible.
I just added some minimal sanity checking to the values returned from
gaim_prefs_get_string (non-NULL and non-empty), it isn't perfect but it solves
the simple case.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Thu, 24 Aug 2006 20:25:57 +0000 |
parents | 2ce396e60cea |
children | 9d3ff97e8105 |
files | gtk/plugins/gaimrc.c |
diffstat | 1 files changed, 73 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/gtk/plugins/gaimrc.c Thu Aug 24 20:24:47 2006 +0000 +++ b/gtk/plugins/gaimrc.c Thu Aug 24 20:25:57 2006 +0000 @@ -104,22 +104,31 @@ if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) { const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); - g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref); } if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) { const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name"); - g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref); } g_string_append(style_string, "style \"gaimrc_style\" {\n"); for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) { if (gaim_prefs_get_bool(color_prefs_set[i])) { + const char *pref; + prefbase = g_path_get_basename(color_prefs[i]); - g_string_append_printf(style_string, - "%s = \"%s\"\n", prefbase, - gaim_prefs_get_string(color_prefs[i])); + pref = gaim_prefs_get_string(color_prefs[i]); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, + "%s = \"%s\"\n", + prefbase, pref); g_free(prefbase); } } @@ -149,14 +158,19 @@ for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) { if (gaim_prefs_get_bool(font_prefs_set[i])) { + const char *pref; + prefbase = g_path_get_basename(font_prefs[i]); - g_string_append_printf(style_string, - "style \"%s_style\"\n" - "{font_name = \"%s\"}\n" - "widget \"%s\"" - "style \"%s_style\"\n", prefbase, - gaim_prefs_get_string(font_prefs[i]), - prefbase, prefbase); + pref = gaim_prefs_get_string(font_prefs[i]); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, + "style \"%s_style\"\n" + "{font_name = \"%s\"}\n" + "widget \"%s\"" + "style \"%s_style\"\n", + prefbase, pref, + prefbase, prefbase); g_free(prefbase); } } @@ -179,22 +193,35 @@ if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) { const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); - g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, + "gtk-font-name = \"%s\"\n", + pref); } if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) { const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name"); - g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, + "gtk-key-theme-name = \"%s\"\n", + pref); } g_string_append(style_string, "style \"gaimrc_style\" {\n"); for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) { if (gaim_prefs_get_bool(color_prefs_set[i])) { + const char *pref; + prefbase = g_path_get_basename(color_prefs[i]); - g_string_append_printf(style_string, - "%s = \"%s\"\n", prefbase, - gaim_prefs_get_string(color_prefs[i])); + pref = gaim_prefs_get_string(color_prefs[i]); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, + "%s = \"%s\"\n", + prefbase, pref); g_free(prefbase); } } @@ -224,14 +251,19 @@ for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) { if (gaim_prefs_get_bool(font_prefs_set[i])) { + const char *pref; + prefbase = g_path_get_basename(font_prefs[i]); - g_string_append_printf(style_string, - "style \"%s_style\"\n" - "{font_name = \"%s\"}\n" - "widget \"%s\"" - "style \"%s_style\"\n", prefbase, - gaim_prefs_get_string(font_prefs[i]), - prefbase, prefbase); + pref = gaim_prefs_get_string(font_prefs[i]); + + if (pref != NULL && strcmp(pref, "")) + g_string_append_printf(style_string, + "style \"%s_style\"\n" + "{font_name = \"%s\"}\n" + "widget \"%s\"" + "style \"%s_style\"\n", + prefbase, pref, + prefbase, prefbase); g_free(prefbase); } } @@ -282,6 +314,7 @@ GtkWidget *color_dialog = NULL; GdkColor color; char title[128]; + const char *pref = NULL; int subscript = GPOINTER_TO_INT(data); g_snprintf(title, sizeof(title), _("Select Color for %s"), @@ -290,9 +323,12 @@ g_signal_connect(G_OBJECT(color_dialog), "response", G_CALLBACK(gaimrc_color_response), data); - if (gdk_color_parse(gaim_prefs_get_string(color_prefs[subscript]), - &color)) { - gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color); + pref = gaim_prefs_get_string(color_prefs[subscript]); + + if (pref != NULL && strcmp(pref, "")) { + if (gdk_color_parse(pref, &color)) { + gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color); + } } gtk_window_present(GTK_WINDOW(color_dialog)); @@ -319,6 +355,7 @@ { GtkWidget *font_dialog = NULL; char title[128]; + const char *pref = NULL; int subscript = GPOINTER_TO_INT(data); g_snprintf(title, sizeof(title), _("Select Font for %s"), @@ -327,12 +364,11 @@ g_signal_connect(G_OBJECT(font_dialog), "response", G_CALLBACK(gaimrc_font_response), data); - /* TODO Figure out a way to test for the presence of a value in the - * actual pref - if (gaim_prefs_get_bool(font_prefs[subscript])) { - gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), gaim_prefs_get_string(font_prefs[subscript])); + pref = gaim_prefs_get_string(font_prefs[subscript]); + + if (pref != NULL && strcmp(pref, "")) { + gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), pref); } - */ gtk_window_present(GTK_WINDOW(font_dialog)); } @@ -357,25 +393,17 @@ gaimrc_set_font_special(GtkWidget *widget, gpointer data) { GtkWidget *font_dialog = NULL; -#if 0 - const char *font = NULL; -#endif + const char *pref = NULL; font_dialog = gtk_font_selection_dialog_new(_("Select Interface Font")); g_signal_connect(G_OBJECT(font_dialog), "response", G_CALLBACK(gaimrc_font_response_special), NULL); -#if 0 - /* - * TODO Figure out a way to test for the presence of a value in the - * actual pref - */ - font = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); - printf("font - %s.\n", font); - if (font != NULL && font != "") { - gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name")); + pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); + + if (pref != NULL && strcmp(pref, "")) { + gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), pref); } -#endif gtk_window_present(GTK_WINDOW(font_dialog)); }