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
60
61 static unsigned char
62 get_hotkey (int n)
63 {
64 return (n <= 9) ? '0' + n : 'a' + n - 10;
65 }
66
67
68
69
70
71
72
73
74
75
76
77 int
78 select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay)
79 {
80 Listbox *listbox;
81 size_t i;
82 int listbox_result;
83 char buffer[255];
84
85
86 listbox =
87 listbox_window_centered_new (center_y, center_x, codepages->len + 1, ENTRY_LEN + 2,
88 _("Choose codepage"), "[Codepages Translation]");
89
90 if (!seldisplay)
91 LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL, FALSE);
92
93
94 for (i = 0; i < codepages->len; i++)
95 {
96 const char *name;
97
98 name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
99 g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name);
100 LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL, FALSE);
101 }
102
103 if (seldisplay)
104 {
105 unsigned char hotkey;
106
107 hotkey = get_hotkey (codepages->len);
108 g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
109 LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL, FALSE);
110 }
111
112
113 i = seldisplay
114 ? ((current_charset < 0) ? codepages->len : (size_t) current_charset)
115 : ((size_t) current_charset + 1);
116
117 listbox_set_current (listbox->list, i);
118
119 listbox_result = listbox_run (listbox);
120
121 if (listbox_result < 0)
122
123 return SELECT_CHARSET_CANCEL;
124
125
126 if (seldisplay)
127
128 return (listbox_result >=
129 (int) codepages->len) ? SELECT_CHARSET_OTHER_8BIT : listbox_result;
130
131
132 return (listbox_result - 1);
133 }
134
135
136
137
138 gboolean
139 do_set_codepage (int codepage)
140 {
141 char *errmsg;
142 gboolean ret;
143
144 mc_global.source_codepage = codepage;
145 errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
146 mc_global.display_codepage : mc_global.source_codepage,
147 mc_global.display_codepage);
148 ret = errmsg == NULL;
149
150 if (!ret)
151 {
152 message (D_ERROR, MSG_ERROR, "%s", errmsg);
153 g_free (errmsg);
154 }
155
156 return ret;
157 }
158
159
160
161
162 gboolean
163 do_select_codepage (void)
164 {
165 int r;
166
167 r = select_charset (-1, -1, default_source_codepage, FALSE);
168 if (r == SELECT_CHARSET_CANCEL)
169 return FALSE;
170
171 default_source_codepage = r;
172 return do_set_codepage (default_source_codepage);
173 }
174
175