comparison src/gtkutil.c @ 90602:b5c13d1564a9

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 437-446) - Update from CVS - lisp/url/url-methods.el: Fix format error when http_proxy is empty string - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 137-140) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-111
author Miles Bader <miles@gnu.org>
date Wed, 20 Sep 2006 06:04:23 +0000
parents a1a25ac6c88a 13a9a628ff21
children bb0e318b7c53
comparison
equal deleted inserted replaced
90601:a1a25ac6c88a 90602:b5c13d1564a9
505 get_utf8_string (str) 505 get_utf8_string (str)
506 char *str; 506 char *str;
507 { 507 {
508 char *utf8_str = str; 508 char *utf8_str = str;
509 509
510 if (!str) return NULL;
511
510 /* If not UTF-8, try current locale. */ 512 /* If not UTF-8, try current locale. */
511 if (str && !g_utf8_validate (str, -1, NULL)) 513 if (!g_utf8_validate (str, -1, NULL))
512 utf8_str = g_locale_to_utf8 (str, -1, 0, 0, 0); 514 utf8_str = g_locale_to_utf8 (str, -1, 0, 0, 0);
513 515
516 if (!utf8_str)
517 {
518 /* Probably some control characters in str. Escape them. */
519 size_t nr_bad = 0;
520 gsize bytes_read;
521 gsize bytes_written;
522 unsigned char *p = (unsigned char *)str;
523 char *cp, *up;
524 GError *error = NULL;
525
526 while (! (cp = g_locale_to_utf8 (p, -1, &bytes_read,
527 &bytes_written, &error))
528 && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
529 {
530 ++nr_bad;
531 p += bytes_written+1;
532 g_error_free (error);
533 error = NULL;
534 }
535
536 if (error)
537 {
538 g_error_free (error);
539 error = NULL;
540 }
541 if (cp) g_free (cp);
542
543 up = utf8_str = xmalloc (strlen (str) + nr_bad * 4 + 1);
544 p = str;
545
546 while (! (cp = g_locale_to_utf8 (p, -1, &bytes_read,
547 &bytes_written, &error))
548 && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
549 {
550 strncpy (up, p, bytes_written);
551 sprintf (up + bytes_written, "\\%03o", p[bytes_written]);
552 up[bytes_written+4] = '\0';
553 up += bytes_written+4;
554 p += bytes_written+1;
555 g_error_free (error);
556 error = NULL;
557 }
558
559 if (cp)
560 {
561 strcat (utf8_str, cp);
562 g_free (cp);
563 }
564 if (error)
565 {
566 g_error_free (error);
567 error = NULL;
568 }
569 }
514 return utf8_str; 570 return utf8_str;
515 } 571 }
516 572
517 573
518 574
1154 1210
1155 int 1211 int
1156 xg_uses_old_file_dialog () 1212 xg_uses_old_file_dialog ()
1157 { 1213 {
1158 #ifdef HAVE_GTK_FILE_BOTH 1214 #ifdef HAVE_GTK_FILE_BOTH
1159 extern int x_use_old_gtk_file_dialog; 1215 extern int x_gtk_use_old_file_dialog;
1160 return x_use_old_gtk_file_dialog; 1216 return x_gtk_use_old_file_dialog;
1161 #else /* ! HAVE_GTK_FILE_BOTH */ 1217 #else /* ! HAVE_GTK_FILE_BOTH */
1162 1218
1163 #ifdef HAVE_GTK_FILE_SELECTION_NEW 1219 #ifdef HAVE_GTK_FILE_SELECTION_NEW
1164 return 1; 1220 return 1;
1165 #else 1221 #else
1292 GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)); 1348 GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f));
1293 GtkFileChooserAction action = (mustmatch_p ? 1349 GtkFileChooserAction action = (mustmatch_p ?
1294 GTK_FILE_CHOOSER_ACTION_OPEN : 1350 GTK_FILE_CHOOSER_ACTION_OPEN :
1295 GTK_FILE_CHOOSER_ACTION_SAVE); 1351 GTK_FILE_CHOOSER_ACTION_SAVE);
1296 extern int x_gtk_show_hidden_files; 1352 extern int x_gtk_show_hidden_files;
1353 extern int x_gtk_file_dialog_help_text;
1354
1297 1355
1298 if (only_dir_p) 1356 if (only_dir_p)
1299 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; 1357 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
1300 1358
1301 filewin = gtk_file_chooser_dialog_new (prompt, gwin, action, 1359 filewin = gtk_file_chooser_dialog_new (prompt, gwin, action,
1319 g_signal_connect (G_OBJECT (wtoggle), "clicked", 1377 g_signal_connect (G_OBJECT (wtoggle), "clicked",
1320 G_CALLBACK (xg_toggle_visibility_cb), filewin); 1378 G_CALLBACK (xg_toggle_visibility_cb), filewin);
1321 g_signal_connect (G_OBJECT (filewin), "notify", 1379 g_signal_connect (G_OBJECT (filewin), "notify",
1322 G_CALLBACK (xg_toggle_notify_cb), wtoggle); 1380 G_CALLBACK (xg_toggle_notify_cb), wtoggle);
1323 1381
1324 message[0] = '\0'; 1382 if (x_gtk_file_dialog_help_text)
1325 if (action != GTK_FILE_CHOOSER_ACTION_SAVE) 1383 {
1326 strcat (message, "\nType C-l to display a file name text entry box.\n"); 1384 message[0] = '\0';
1327 strcat (message, "\nIf you don't like this file selector, use the " 1385 if (action != GTK_FILE_CHOOSER_ACTION_SAVE)
1328 "corresponding\nkey binding or customize " 1386 strcat (message, "\nType C-l to display a file name text entry box.\n");
1329 "use-file-dialog to turn it off."); 1387 strcat (message, "\nIf you don't like this file selector, use the "
1388 "corresponding\nkey binding or customize "
1389 "use-file-dialog to turn it off.");
1330 1390
1331 wmessage = gtk_label_new (message); 1391 wmessage = gtk_label_new (message);
1332 gtk_widget_show (wmessage); 1392 gtk_widget_show (wmessage);
1393 }
1394
1333 gtk_box_pack_start (GTK_BOX (wbox), wtoggle, FALSE, FALSE, 0); 1395 gtk_box_pack_start (GTK_BOX (wbox), wtoggle, FALSE, FALSE, 0);
1334 gtk_box_pack_start (GTK_BOX (wbox), wmessage, FALSE, FALSE, 0); 1396 if (x_gtk_file_dialog_help_text)
1397 gtk_box_pack_start (GTK_BOX (wbox), wmessage, FALSE, FALSE, 0);
1335 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (filewin), wbox); 1398 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (filewin), wbox);
1336 1399
1337 if (default_filename) 1400 if (default_filename)
1338 { 1401 {
1339 Lisp_Object file; 1402 Lisp_Object file;