This source file includes following definitions.
- get_hotkey
- select_charset
- do_set_codepage
- do_select_codepage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 #include <config.h>
33
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #include "lib/global.h"
38 #include "lib/widget.h"
39 #include "lib/charsets.h"
40
41 #include "setup.h"
42
43 #include "selcodepage.h"
44
45
46
47
48
49 #define ENTRY_LEN 30
50
51
52
53
54
55
56
57
58
59 static unsigned char
60 get_hotkey (int n)
61 {
62 return (n <= 9) ? '0' + n : 'a' + n - 10;
63 }
64
65
66
67
68
69
70
71
72
73
74
75 int
76 select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay)
77 {
78 size_t i;
79 int listbox_result;
80 char buffer[255];
81
82
83 Listbox *listbox = create_listbox_window_centered (center_y, center_x,
84 codepages->len + 1, ENTRY_LEN + 2,
85 _("Choose codepage"),
86 "[Codepages Translation]");
87
88 if (!seldisplay)
89 LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL, FALSE);
90
91
92 for (i = 0; i < codepages->len; i++)
93 {
94 const char *name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
95 g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name);
96 LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL, FALSE);
97 }
98 if (seldisplay)
99 {
100 unsigned char hotkey = get_hotkey (codepages->len);
101 g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
102 LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL, FALSE);
103 }
104
105
106 i = (seldisplay)
107 ? ((current_charset < 0) ? codepages->len : (size_t) current_charset)
108 : ((size_t) current_charset + 1);
109
110 listbox_select_entry (listbox->list, i);
111
112 listbox_result = run_listbox (listbox);
113
114 if (listbox_result < 0)
115 {
116
117 return SELECT_CHARSET_CANCEL;
118 }
119 else
120 {
121
122 if (seldisplay)
123 {
124
125 return (listbox_result >= (int) codepages->len)
126 ? SELECT_CHARSET_OTHER_8BIT : listbox_result;
127 }
128 else
129 {
130
131 return (listbox_result - 1);
132 }
133 }
134 }
135
136
137
138
139 gboolean
140 do_set_codepage (int codepage)
141 {
142 char *errmsg;
143 gboolean ret;
144
145 mc_global.source_codepage = codepage;
146 errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
147 mc_global.display_codepage : mc_global.source_codepage,
148 mc_global.display_codepage);
149 ret = errmsg == NULL;
150
151 if (!ret)
152 {
153 message (D_ERROR, MSG_ERROR, "%s", errmsg);
154 g_free (errmsg);
155 }
156
157 return ret;
158 }
159
160
161
162
163 gboolean
164 do_select_codepage (void)
165 {
166 int r;
167
168 r = select_charset (-1, -1, default_source_codepage, FALSE);
169 if (r == SELECT_CHARSET_CANCEL)
170 return FALSE;
171
172 default_source_codepage = r;
173 return do_set_codepage (default_source_codepage);
174 }
175
176