diff options
Diffstat (limited to 'apps/plugins/textviewer/tv_menu.c')
-rw-r--r-- | apps/plugins/textviewer/tv_menu.c | 384 |
1 files changed, 0 insertions, 384 deletions
diff --git a/apps/plugins/textviewer/tv_menu.c b/apps/plugins/textviewer/tv_menu.c deleted file mode 100644 index aa1b8d615e..0000000000 --- a/apps/plugins/textviewer/tv_menu.c +++ /dev/null | |||
@@ -1,384 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Gilles Roux | ||
11 | * 2003 Garrett Derner | ||
12 | * 2010 Yoshihisa Uchida | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | #include "plugin.h" | ||
24 | #include "lib/playback_control.h" | ||
25 | |||
26 | |||
27 | /* settings helper functions */ | ||
28 | |||
29 | static bool encoding_setting(void) | ||
30 | { | ||
31 | static struct opt_items names[NUM_CODEPAGES]; | ||
32 | int idx; | ||
33 | bool res; | ||
34 | enum codepages oldenc = prefs.encoding; | ||
35 | |||
36 | for (idx = 0; idx < NUM_CODEPAGES; idx++) | ||
37 | { | ||
38 | names[idx].string = rb->get_codepage_name(idx); | ||
39 | names[idx].voice_id = -1; | ||
40 | } | ||
41 | |||
42 | res = rb->set_option("Encoding", &prefs.encoding, INT, names, | ||
43 | sizeof(names) / sizeof(names[0]), NULL); | ||
44 | |||
45 | /* When prefs.encoding changes into UTF-8 or changes from UTF-8, | ||
46 | * filesize (file_size) might change. | ||
47 | * In addition, if prefs.encoding is UTF-8, then BOM does not read. | ||
48 | */ | ||
49 | if (oldenc != prefs.encoding && (oldenc == UTF_8 || prefs.encoding == UTF_8)) | ||
50 | { | ||
51 | check_bom(); | ||
52 | get_filesize(); | ||
53 | fill_buffer(file_pos, buffer, buffer_size); | ||
54 | } | ||
55 | |||
56 | return res; | ||
57 | } | ||
58 | |||
59 | static bool word_wrap_setting(void) | ||
60 | { | ||
61 | static const struct opt_items names[] = { | ||
62 | {"On", -1}, | ||
63 | {"Off (Chop Words)", -1}, | ||
64 | }; | ||
65 | |||
66 | return rb->set_option("Word Wrap", &prefs.word_mode, INT, | ||
67 | names, 2, NULL); | ||
68 | } | ||
69 | |||
70 | static bool line_mode_setting(void) | ||
71 | { | ||
72 | static const struct opt_items names[] = { | ||
73 | {"Normal", -1}, | ||
74 | {"Join Lines", -1}, | ||
75 | {"Expand Lines", -1}, | ||
76 | #ifdef HAVE_LCD_BITMAP | ||
77 | {"Reflow Lines", -1}, | ||
78 | #endif | ||
79 | }; | ||
80 | |||
81 | return rb->set_option("Line Mode", &prefs.line_mode, INT, names, | ||
82 | sizeof(names) / sizeof(names[0]), NULL); | ||
83 | } | ||
84 | |||
85 | static bool view_mode_setting(void) | ||
86 | { | ||
87 | static const struct opt_items names[] = { | ||
88 | {"No (Narrow)", -1}, | ||
89 | {"Yes", -1}, | ||
90 | }; | ||
91 | bool ret; | ||
92 | ret = rb->set_option("Wide View", &prefs.view_mode, INT, | ||
93 | names , 2, NULL); | ||
94 | if (prefs.view_mode == NARROW) | ||
95 | col = 0; | ||
96 | calc_max_width(); | ||
97 | return ret; | ||
98 | } | ||
99 | |||
100 | static bool scroll_mode_setting(void) | ||
101 | { | ||
102 | static const struct opt_items names[] = { | ||
103 | {"Scroll by Page", -1}, | ||
104 | {"Scroll by Line", -1}, | ||
105 | }; | ||
106 | |||
107 | return rb->set_option("Scroll Mode", &prefs.scroll_mode, INT, | ||
108 | names, 2, NULL); | ||
109 | } | ||
110 | |||
111 | #ifdef HAVE_LCD_BITMAP | ||
112 | static bool page_mode_setting(void) | ||
113 | { | ||
114 | static const struct opt_items names[] = { | ||
115 | {"No", -1}, | ||
116 | {"Yes", -1}, | ||
117 | }; | ||
118 | |||
119 | return rb->set_option("Overlap Pages", &prefs.page_mode, INT, | ||
120 | names, 2, NULL); | ||
121 | } | ||
122 | |||
123 | static bool scrollbar_setting(void) | ||
124 | { | ||
125 | static const struct opt_items names[] = { | ||
126 | {"Off", -1}, | ||
127 | {"On", -1} | ||
128 | }; | ||
129 | |||
130 | return rb->set_option("Show Scrollbar", &prefs.scrollbar_mode, INT, | ||
131 | names, 2, NULL); | ||
132 | } | ||
133 | |||
134 | static bool header_setting(void) | ||
135 | { | ||
136 | int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2; | ||
137 | struct opt_items names[len]; | ||
138 | |||
139 | names[0].string = "None"; | ||
140 | names[0].voice_id = -1; | ||
141 | names[1].string = "File path"; | ||
142 | names[1].voice_id = -1; | ||
143 | |||
144 | if (rb->global_settings->statusbar == STATUSBAR_TOP) | ||
145 | { | ||
146 | names[2].string = "Status bar"; | ||
147 | names[2].voice_id = -1; | ||
148 | names[3].string = "Both"; | ||
149 | names[3].voice_id = -1; | ||
150 | } | ||
151 | |||
152 | return rb->set_option("Show Header", &prefs.header_mode, INT, | ||
153 | names, len, NULL); | ||
154 | } | ||
155 | |||
156 | static bool footer_setting(void) | ||
157 | { | ||
158 | int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2; | ||
159 | struct opt_items names[len]; | ||
160 | |||
161 | names[0].string = "None"; | ||
162 | names[0].voice_id = -1; | ||
163 | names[1].string = "Page Num"; | ||
164 | names[1].voice_id = -1; | ||
165 | |||
166 | if (rb->global_settings->statusbar == STATUSBAR_BOTTOM) | ||
167 | { | ||
168 | names[2].string = "Status bar"; | ||
169 | names[2].voice_id = -1; | ||
170 | names[3].string = "Both"; | ||
171 | names[3].voice_id = -1; | ||
172 | } | ||
173 | |||
174 | return rb->set_option("Show Footer", &prefs.footer_mode, INT, | ||
175 | names, len, NULL); | ||
176 | } | ||
177 | |||
178 | static int font_comp(const void *a, const void *b) | ||
179 | { | ||
180 | struct opt_items *pa; | ||
181 | struct opt_items *pb; | ||
182 | |||
183 | pa = (struct opt_items *)a; | ||
184 | pb = (struct opt_items *)b; | ||
185 | |||
186 | return rb->strcmp(pa->string, pb->string); | ||
187 | } | ||
188 | |||
189 | static bool font_setting(void) | ||
190 | { | ||
191 | int count = 0; | ||
192 | DIR *dir; | ||
193 | struct dirent *entry; | ||
194 | int i = 0; | ||
195 | int len; | ||
196 | int new_font = 0; | ||
197 | int old_font; | ||
198 | bool res; | ||
199 | int size = 0; | ||
200 | |||
201 | dir = rb->opendir(FONT_DIR); | ||
202 | if (!dir) | ||
203 | { | ||
204 | rb->splash(HZ/2, "font dir does not access."); | ||
205 | return false; | ||
206 | } | ||
207 | |||
208 | while (1) | ||
209 | { | ||
210 | entry = rb->readdir(dir); | ||
211 | |||
212 | if (entry == NULL) | ||
213 | break; | ||
214 | |||
215 | len = rb->strlen(entry->d_name); | ||
216 | if (len < 4 || rb->strcmp(entry->d_name + len-4, ".fnt")) | ||
217 | continue; | ||
218 | size += len-3; | ||
219 | count++; | ||
220 | } | ||
221 | rb->closedir(dir); | ||
222 | |||
223 | struct opt_items names[count]; | ||
224 | unsigned char font_names[size]; | ||
225 | unsigned char *p = font_names; | ||
226 | |||
227 | dir = rb->opendir(FONT_DIR); | ||
228 | if (!dir) | ||
229 | { | ||
230 | rb->splash(HZ/2, "font dir does not access."); | ||
231 | return false; | ||
232 | } | ||
233 | |||
234 | while (1) | ||
235 | { | ||
236 | entry = rb->readdir(dir); | ||
237 | |||
238 | if (entry == NULL) | ||
239 | break; | ||
240 | |||
241 | len = rb->strlen(entry->d_name); | ||
242 | if (len < 4 || rb->strcmp(entry->d_name + len-4, ".fnt")) | ||
243 | continue; | ||
244 | |||
245 | rb->snprintf(p, len-3, "%s", entry->d_name); | ||
246 | names[i].string = p; | ||
247 | names[i].voice_id = -1; | ||
248 | p += len-3; | ||
249 | i++; | ||
250 | if (i >= count) | ||
251 | break; | ||
252 | } | ||
253 | rb->closedir(dir); | ||
254 | |||
255 | rb->qsort(names, count, sizeof(struct opt_items), font_comp); | ||
256 | |||
257 | for (i = 0; i < count; i++) | ||
258 | { | ||
259 | if (!rb->strcmp(names[i].string, prefs.font)) | ||
260 | { | ||
261 | new_font = i; | ||
262 | break; | ||
263 | } | ||
264 | } | ||
265 | old_font = new_font; | ||
266 | |||
267 | res = rb->set_option("Select Font", &new_font, INT, | ||
268 | names, count, NULL); | ||
269 | |||
270 | if (new_font != old_font) | ||
271 | { | ||
272 | rb->memset(prefs.font, 0, MAX_PATH); | ||
273 | rb->snprintf(prefs.font, MAX_PATH, "%s", names[new_font].string); | ||
274 | change_font(prefs.font); | ||
275 | } | ||
276 | |||
277 | return res; | ||
278 | } | ||
279 | #endif | ||
280 | |||
281 | static bool autoscroll_speed_setting(void) | ||
282 | { | ||
283 | return rb->set_int("Auto-scroll Speed", "", UNIT_INT, | ||
284 | &prefs.autoscroll_speed, NULL, 1, 1, 10, NULL); | ||
285 | } | ||
286 | |||
287 | MENUITEM_FUNCTION(encoding_item, 0, "Encoding", encoding_setting, | ||
288 | NULL, NULL, Icon_NOICON); | ||
289 | MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", word_wrap_setting, | ||
290 | NULL, NULL, Icon_NOICON); | ||
291 | MENUITEM_FUNCTION(line_mode_item, 0, "Line Mode", line_mode_setting, | ||
292 | NULL, NULL, Icon_NOICON); | ||
293 | MENUITEM_FUNCTION(view_mode_item, 0, "Wide View", view_mode_setting, | ||
294 | NULL, NULL, Icon_NOICON); | ||
295 | #ifdef HAVE_LCD_BITMAP | ||
296 | MENUITEM_FUNCTION(scrollbar_item, 0, "Show Scrollbar", scrollbar_setting, | ||
297 | NULL, NULL, Icon_NOICON); | ||
298 | MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", page_mode_setting, | ||
299 | NULL, NULL, Icon_NOICON); | ||
300 | MENUITEM_FUNCTION(header_item, 0, "Show Header", header_setting, | ||
301 | NULL, NULL, Icon_NOICON); | ||
302 | MENUITEM_FUNCTION(footer_item, 0, "Show Footer", footer_setting, | ||
303 | NULL, NULL, Icon_NOICON); | ||
304 | MENUITEM_FUNCTION(font_item, 0, "Font", font_setting, | ||
305 | NULL, NULL, Icon_NOICON); | ||
306 | #endif | ||
307 | MENUITEM_FUNCTION(scroll_mode_item, 0, "Scroll Mode", scroll_mode_setting, | ||
308 | NULL, NULL, Icon_NOICON); | ||
309 | MENUITEM_FUNCTION(autoscroll_speed_item, 0, "Auto-Scroll Speed", | ||
310 | autoscroll_speed_setting, NULL, NULL, Icon_NOICON); | ||
311 | MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON, | ||
312 | &encoding_item, &word_wrap_item, &line_mode_item, &view_mode_item, | ||
313 | #ifdef HAVE_LCD_BITMAP | ||
314 | &scrollbar_item, &page_mode_item, &header_item, &footer_item, &font_item, | ||
315 | #endif | ||
316 | &scroll_mode_item, &autoscroll_speed_item); | ||
317 | |||
318 | static bool viewer_options_menu(bool is_global) | ||
319 | { | ||
320 | bool result; | ||
321 | struct preferences tmp_prefs; | ||
322 | |||
323 | rb->memcpy(&tmp_prefs, &prefs, sizeof(struct preferences)); | ||
324 | |||
325 | result = (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB); | ||
326 | |||
327 | if (!is_global && rb->memcmp(&tmp_prefs, &prefs, sizeof(struct preferences))) | ||
328 | { | ||
329 | /* Show-scrollbar mode for current view-width mode */ | ||
330 | #ifdef HAVE_LCD_BITMAP | ||
331 | init_need_scrollbar(); | ||
332 | init_header_and_footer(); | ||
333 | #endif | ||
334 | calc_page(); | ||
335 | } | ||
336 | return result; | ||
337 | } | ||
338 | |||
339 | void viewer_menu(void) | ||
340 | { | ||
341 | int result; | ||
342 | |||
343 | MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL, | ||
344 | "Return", "Viewer Options", | ||
345 | "Show Playback Menu", "Select Bookmark", | ||
346 | "Global Settings", "Quit"); | ||
347 | |||
348 | result = rb->do_menu(&menu, NULL, NULL, false); | ||
349 | switch (result) | ||
350 | { | ||
351 | case 0: /* return */ | ||
352 | break; | ||
353 | case 1: /* change settings */ | ||
354 | done = viewer_options_menu(false); | ||
355 | break; | ||
356 | case 2: /* playback control */ | ||
357 | playback_control(NULL); | ||
358 | break; | ||
359 | case 3: /* select bookmark */ | ||
360 | viewer_select_bookmark(viewer_add_last_read_bookmark()); | ||
361 | viewer_remove_last_read_bookmark(); | ||
362 | fill_buffer(file_pos, buffer, buffer_size); | ||
363 | if (prefs.scroll_mode == PAGE && cline > 1) | ||
364 | viewer_scroll_to_top_line(); | ||
365 | break; | ||
366 | case 4: /* change global settings */ | ||
367 | { | ||
368 | struct preferences orig_prefs; | ||
369 | |||
370 | rb->memcpy(&orig_prefs, &prefs, sizeof(struct preferences)); | ||
371 | if (!viewer_load_global_settings()) | ||
372 | viewer_default_preferences(); | ||
373 | done = viewer_options_menu(true); | ||
374 | viewer_save_global_settings(); | ||
375 | rb->memcpy(&prefs, &orig_prefs, sizeof(struct preferences)); | ||
376 | } | ||
377 | break; | ||
378 | case 5: /* quit */ | ||
379 | viewer_exit(NULL); | ||
380 | done = true; | ||
381 | break; | ||
382 | } | ||
383 | viewer_draw(col); | ||
384 | } | ||