Codepage messages related translated & other stuff...
[midnight-commander.git] / src / selcodepage.c
blobef4fdc313706e28bfc97ee0fc69d4f63a54fc991
1 #include <config.h>
3 #ifdef HAVE_CHARSET
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include "i18n.h"
7 #include "dlg.h"
8 #include "dialog.h"
9 #include "widget.h"
10 #include "wtools.h"
11 #include "charsets.h"
12 #include "main.h"
14 #define ENTRY_LEN 35
16 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
17 int source_codepage = -1;
18 int display_codepage = -1;
20 unsigned char get_hotkey( int n )
22 return (n <= 9) ? '0' + n : 'a' + n - 10;
25 int select_charset( int current_charset, int seldisplay )
27 int i, menu_lines = n_codepages + 1;
29 /* Create listbox */
30 Listbox* listbox =
31 create_listbox_window ( ENTRY_LEN + 2, menu_lines,
32 _(" Choose input codepage "),
33 "[Codepages Translation]");
35 if (!seldisplay)
36 LISTBOX_APPEND_TEXT( listbox, '-', _("- < No translation >"), NULL );
38 /* insert all the items found */
39 for (i = 0; i < n_codepages; i++) {
40 struct codepage_desc cpdesc = codepages[i];
41 char buffer[255];
42 sprintf( buffer, "%c %s", get_hotkey(i), cpdesc.name );
43 LISTBOX_APPEND_TEXT( listbox, get_hotkey(i), buffer, NULL );
45 if (seldisplay) {
46 char buffer[255];
47 sprintf( buffer, "%c %s", get_hotkey(n_codepages), _("Other 8 bit"));
48 LISTBOX_APPEND_TEXT( listbox, get_hotkey(n_codepages), buffer, NULL );
51 /* Select the default entry */
52 i = (seldisplay)
54 ( (current_charset < 0) ? n_codepages : current_charset )
56 ( current_charset + 1 );
58 listbox_select_by_number( listbox->list, i );
60 i = run_listbox( listbox );
62 return (seldisplay) ? ( (i >= n_codepages) ? -1 : i )
63 : ( i - 1 );
66 /* Helper functions for codepages support */
69 int do_select_codepage()
71 #ifndef HAVE_ICONV
73 message( 1, _(" Warning "),
74 _("Midnight Commander was compiled without iconv support,\n"
75 "so charsets recoding feature is not available!" ));
76 return -1;
78 #else
80 char *errmsg;
82 if (display_codepage > 0) {
83 source_codepage = select_charset( source_codepage, 0 );
84 errmsg = init_translation_table( source_codepage, display_codepage );
85 if (errmsg) {
86 message( 1, MSG_ERROR, "%s", errmsg );
87 return -1;
89 } else {
90 message( 1, _(" Warning "),
91 _("To use this feature select your codepage in\n"
92 "Setup / Display Bits dialog!\n"
93 "Do not forget to save options." ));
94 return -1;
96 return 0;
99 #endif /* HAVE_ICONV */
101 #endif /* HAVE_CHARSET */