Mercurial > pidgin.yaz
comparison gtk/plugins/gaimrc.c @ 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 | 009db0b357b5 |
children |
comparison
equal
deleted
inserted
replaced
14328:2ce396e60cea | 14329:479164e18f1a |
---|---|
102 #endif | 102 #endif |
103 GString *style_string = g_string_new(""); | 103 GString *style_string = g_string_new(""); |
104 | 104 |
105 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) { | 105 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) { |
106 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); | 106 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); |
107 g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref); | 107 |
108 if (pref != NULL && strcmp(pref, "")) | |
109 g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref); | |
108 } | 110 } |
109 | 111 |
110 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) { | 112 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) { |
111 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name"); | 113 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name"); |
112 g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref); | 114 |
115 if (pref != NULL && strcmp(pref, "")) | |
116 g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref); | |
113 } | 117 } |
114 | 118 |
115 g_string_append(style_string, "style \"gaimrc_style\" {\n"); | 119 g_string_append(style_string, "style \"gaimrc_style\" {\n"); |
116 | 120 |
117 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) { | 121 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) { |
118 if (gaim_prefs_get_bool(color_prefs_set[i])) { | 122 if (gaim_prefs_get_bool(color_prefs_set[i])) { |
123 const char *pref; | |
124 | |
119 prefbase = g_path_get_basename(color_prefs[i]); | 125 prefbase = g_path_get_basename(color_prefs[i]); |
120 g_string_append_printf(style_string, | 126 pref = gaim_prefs_get_string(color_prefs[i]); |
121 "%s = \"%s\"\n", prefbase, | 127 |
122 gaim_prefs_get_string(color_prefs[i])); | 128 if (pref != NULL && strcmp(pref, "")) |
129 g_string_append_printf(style_string, | |
130 "%s = \"%s\"\n", | |
131 prefbase, pref); | |
123 g_free(prefbase); | 132 g_free(prefbase); |
124 } | 133 } |
125 } | 134 } |
126 | 135 |
127 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) { | 136 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) { |
147 g_string_append(style_string, "}"); | 156 g_string_append(style_string, "}"); |
148 g_string_append(style_string, "widget_class \"*\" style \"gaimrc_style\"\n"); | 157 g_string_append(style_string, "widget_class \"*\" style \"gaimrc_style\"\n"); |
149 | 158 |
150 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) { | 159 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) { |
151 if (gaim_prefs_get_bool(font_prefs_set[i])) { | 160 if (gaim_prefs_get_bool(font_prefs_set[i])) { |
161 const char *pref; | |
162 | |
152 prefbase = g_path_get_basename(font_prefs[i]); | 163 prefbase = g_path_get_basename(font_prefs[i]); |
153 g_string_append_printf(style_string, | 164 pref = gaim_prefs_get_string(font_prefs[i]); |
154 "style \"%s_style\"\n" | 165 |
155 "{font_name = \"%s\"}\n" | 166 if (pref != NULL && strcmp(pref, "")) |
156 "widget \"%s\"" | 167 g_string_append_printf(style_string, |
157 "style \"%s_style\"\n", prefbase, | 168 "style \"%s_style\"\n" |
158 gaim_prefs_get_string(font_prefs[i]), | 169 "{font_name = \"%s\"}\n" |
159 prefbase, prefbase); | 170 "widget \"%s\"" |
171 "style \"%s_style\"\n", | |
172 prefbase, pref, | |
173 prefbase, prefbase); | |
160 g_free(prefbase); | 174 g_free(prefbase); |
161 } | 175 } |
162 } | 176 } |
163 | 177 |
164 gtk_rc_parse_string(style_string->str); | 178 gtk_rc_parse_string(style_string->str); |
177 GString *style_string = g_string_new(""); | 191 GString *style_string = g_string_new(""); |
178 char *prefbase = NULL; | 192 char *prefbase = NULL; |
179 | 193 |
180 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) { | 194 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) { |
181 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); | 195 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); |
182 g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref); | 196 |
197 if (pref != NULL && strcmp(pref, "")) | |
198 g_string_append_printf(style_string, | |
199 "gtk-font-name = \"%s\"\n", | |
200 pref); | |
183 } | 201 } |
184 | 202 |
185 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) { | 203 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) { |
186 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name"); | 204 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name"); |
187 g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref); | 205 |
206 if (pref != NULL && strcmp(pref, "")) | |
207 g_string_append_printf(style_string, | |
208 "gtk-key-theme-name = \"%s\"\n", | |
209 pref); | |
188 } | 210 } |
189 | 211 |
190 g_string_append(style_string, "style \"gaimrc_style\" {\n"); | 212 g_string_append(style_string, "style \"gaimrc_style\" {\n"); |
191 | 213 |
192 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) { | 214 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) { |
193 if (gaim_prefs_get_bool(color_prefs_set[i])) { | 215 if (gaim_prefs_get_bool(color_prefs_set[i])) { |
216 const char *pref; | |
217 | |
194 prefbase = g_path_get_basename(color_prefs[i]); | 218 prefbase = g_path_get_basename(color_prefs[i]); |
195 g_string_append_printf(style_string, | 219 pref = gaim_prefs_get_string(color_prefs[i]); |
196 "%s = \"%s\"\n", prefbase, | 220 |
197 gaim_prefs_get_string(color_prefs[i])); | 221 if (pref != NULL && strcmp(pref, "")) |
222 g_string_append_printf(style_string, | |
223 "%s = \"%s\"\n", | |
224 prefbase, pref); | |
198 g_free(prefbase); | 225 g_free(prefbase); |
199 } | 226 } |
200 } | 227 } |
201 | 228 |
202 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) { | 229 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) { |
222 g_string_append(style_string, "}"); | 249 g_string_append(style_string, "}"); |
223 g_string_append(style_string, "widget_class \"*\" style \"gaimrc_style\"\n"); | 250 g_string_append(style_string, "widget_class \"*\" style \"gaimrc_style\"\n"); |
224 | 251 |
225 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) { | 252 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) { |
226 if (gaim_prefs_get_bool(font_prefs_set[i])) { | 253 if (gaim_prefs_get_bool(font_prefs_set[i])) { |
254 const char *pref; | |
255 | |
227 prefbase = g_path_get_basename(font_prefs[i]); | 256 prefbase = g_path_get_basename(font_prefs[i]); |
228 g_string_append_printf(style_string, | 257 pref = gaim_prefs_get_string(font_prefs[i]); |
229 "style \"%s_style\"\n" | 258 |
230 "{font_name = \"%s\"}\n" | 259 if (pref != NULL && strcmp(pref, "")) |
231 "widget \"%s\"" | 260 g_string_append_printf(style_string, |
232 "style \"%s_style\"\n", prefbase, | 261 "style \"%s_style\"\n" |
233 gaim_prefs_get_string(font_prefs[i]), | 262 "{font_name = \"%s\"}\n" |
234 prefbase, prefbase); | 263 "widget \"%s\"" |
264 "style \"%s_style\"\n", | |
265 prefbase, pref, | |
266 prefbase, prefbase); | |
235 g_free(prefbase); | 267 g_free(prefbase); |
236 } | 268 } |
237 } | 269 } |
238 | 270 |
239 gaim_util_write_data_to_file("gtkrc-2.0", style_string->str, -1); | 271 gaim_util_write_data_to_file("gtkrc-2.0", style_string->str, -1); |
280 gaimrc_set_color(GtkWidget *widget, gpointer data) | 312 gaimrc_set_color(GtkWidget *widget, gpointer data) |
281 { | 313 { |
282 GtkWidget *color_dialog = NULL; | 314 GtkWidget *color_dialog = NULL; |
283 GdkColor color; | 315 GdkColor color; |
284 char title[128]; | 316 char title[128]; |
317 const char *pref = NULL; | |
285 int subscript = GPOINTER_TO_INT(data); | 318 int subscript = GPOINTER_TO_INT(data); |
286 | 319 |
287 g_snprintf(title, sizeof(title), _("Select Color for %s"), | 320 g_snprintf(title, sizeof(title), _("Select Color for %s"), |
288 _(color_names[GPOINTER_TO_INT(data)])); | 321 _(color_names[GPOINTER_TO_INT(data)])); |
289 color_dialog = gtk_color_selection_dialog_new(_("Select Color")); | 322 color_dialog = gtk_color_selection_dialog_new(_("Select Color")); |
290 g_signal_connect(G_OBJECT(color_dialog), "response", | 323 g_signal_connect(G_OBJECT(color_dialog), "response", |
291 G_CALLBACK(gaimrc_color_response), data); | 324 G_CALLBACK(gaimrc_color_response), data); |
292 | 325 |
293 if (gdk_color_parse(gaim_prefs_get_string(color_prefs[subscript]), | 326 pref = gaim_prefs_get_string(color_prefs[subscript]); |
294 &color)) { | 327 |
295 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color); | 328 if (pref != NULL && strcmp(pref, "")) { |
329 if (gdk_color_parse(pref, &color)) { | |
330 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color); | |
331 } | |
296 } | 332 } |
297 | 333 |
298 gtk_window_present(GTK_WINDOW(color_dialog)); | 334 gtk_window_present(GTK_WINDOW(color_dialog)); |
299 } | 335 } |
300 | 336 |
317 static void | 353 static void |
318 gaimrc_set_font(GtkWidget *widget, gpointer data) | 354 gaimrc_set_font(GtkWidget *widget, gpointer data) |
319 { | 355 { |
320 GtkWidget *font_dialog = NULL; | 356 GtkWidget *font_dialog = NULL; |
321 char title[128]; | 357 char title[128]; |
358 const char *pref = NULL; | |
322 int subscript = GPOINTER_TO_INT(data); | 359 int subscript = GPOINTER_TO_INT(data); |
323 | 360 |
324 g_snprintf(title, sizeof(title), _("Select Font for %s"), | 361 g_snprintf(title, sizeof(title), _("Select Font for %s"), |
325 _(font_names[subscript])); | 362 _(font_names[subscript])); |
326 font_dialog = gtk_font_selection_dialog_new(title); | 363 font_dialog = gtk_font_selection_dialog_new(title); |
327 g_signal_connect(G_OBJECT(font_dialog), "response", | 364 g_signal_connect(G_OBJECT(font_dialog), "response", |
328 G_CALLBACK(gaimrc_font_response), data); | 365 G_CALLBACK(gaimrc_font_response), data); |
329 | 366 |
330 /* TODO Figure out a way to test for the presence of a value in the | 367 pref = gaim_prefs_get_string(font_prefs[subscript]); |
331 * actual pref | 368 |
332 if (gaim_prefs_get_bool(font_prefs[subscript])) { | 369 if (pref != NULL && strcmp(pref, "")) { |
333 gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), gaim_prefs_get_string(font_prefs[subscript])); | 370 gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), pref); |
334 } | 371 } |
335 */ | |
336 | 372 |
337 gtk_window_present(GTK_WINDOW(font_dialog)); | 373 gtk_window_present(GTK_WINDOW(font_dialog)); |
338 } | 374 } |
339 | 375 |
340 static void | 376 static void |
355 | 391 |
356 static void | 392 static void |
357 gaimrc_set_font_special(GtkWidget *widget, gpointer data) | 393 gaimrc_set_font_special(GtkWidget *widget, gpointer data) |
358 { | 394 { |
359 GtkWidget *font_dialog = NULL; | 395 GtkWidget *font_dialog = NULL; |
360 #if 0 | 396 const char *pref = NULL; |
361 const char *font = NULL; | |
362 #endif | |
363 | 397 |
364 font_dialog = gtk_font_selection_dialog_new(_("Select Interface Font")); | 398 font_dialog = gtk_font_selection_dialog_new(_("Select Interface Font")); |
365 g_signal_connect(G_OBJECT(font_dialog), "response", | 399 g_signal_connect(G_OBJECT(font_dialog), "response", |
366 G_CALLBACK(gaimrc_font_response_special), NULL); | 400 G_CALLBACK(gaimrc_font_response_special), NULL); |
367 | 401 |
368 #if 0 | 402 pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); |
369 /* | 403 |
370 * TODO Figure out a way to test for the presence of a value in the | 404 if (pref != NULL && strcmp(pref, "")) { |
371 * actual pref | 405 gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), pref); |
372 */ | 406 } |
373 font = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"); | |
374 printf("font - %s.\n", font); | |
375 if (font != NULL && font != "") { | |
376 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")); | |
377 } | |
378 #endif | |
379 | 407 |
380 gtk_window_present(GTK_WINDOW(font_dialog)); | 408 gtk_window_present(GTK_WINDOW(font_dialog)); |
381 } | 409 } |
382 | 410 |
383 static gboolean | 411 static gboolean |