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