summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_menu.c')
-rw-r--r--apps/plugins/text_viewer/tv_menu.c349
1 files changed, 349 insertions, 0 deletions
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c
new file mode 100644
index 0000000000..f40afb8848
--- /dev/null
+++ b/apps/plugins/text_viewer/tv_menu.c
@@ -0,0 +1,349 @@
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#include "tv_bookmark.h"
26#include "tv_menu.h"
27#include "tv_settings.h"
28
29/* settings helper functions */
30
31static struct tv_preferences new_prefs;
32
33static bool tv_encoding_setting(void)
34{
35 static struct opt_items names[NUM_CODEPAGES];
36 int idx;
37
38 for (idx = 0; idx < NUM_CODEPAGES; idx++)
39 {
40 names[idx].string = rb->get_codepage_name(idx);
41 names[idx].voice_id = -1;
42 }
43
44 return rb->set_option("Encoding", &new_prefs.encoding, INT, names,
45 sizeof(names) / sizeof(names[0]), NULL);
46}
47
48static bool tv_word_wrap_setting(void)
49{
50 static const struct opt_items names[] = {
51 {"On", -1},
52 {"Off (Chop Words)", -1},
53 };
54
55 return rb->set_option("Word Wrap", &new_prefs.word_mode, INT,
56 names, 2, NULL);
57}
58
59static bool tv_line_mode_setting(void)
60{
61 static const struct opt_items names[] = {
62 {"Normal", -1},
63 {"Join Lines", -1},
64 {"Expand Lines", -1},
65 {"Reflow Lines", -1},
66 };
67
68 return rb->set_option("Line Mode", &new_prefs.line_mode, INT, names,
69 sizeof(names) / sizeof(names[0]), NULL);
70}
71
72static bool tv_view_mode_setting(void)
73{
74 static const struct opt_items names[] = {
75 {"No (Narrow)", -1},
76 {"Yes", -1},
77 };
78
79 return rb->set_option("Wide View", &new_prefs.view_mode, INT,
80 names , 2, NULL);
81}
82
83static bool tv_scroll_mode_setting(void)
84{
85 static const struct opt_items names[] = {
86 {"Scroll by Page", -1},
87 {"Scroll by Line", -1},
88 };
89
90 return rb->set_option("Scroll Mode", &new_prefs.scroll_mode, INT,
91 names, 2, NULL);
92}
93
94static bool tv_alignment_setting(void)
95{
96 static const struct opt_items names[] = {
97 {"Left", -1},
98 {"Right", -1},
99 };
100
101 return rb->set_option("Alignment", &new_prefs.alignment, INT,
102 names , 2, NULL);
103}
104
105#ifdef HAVE_LCD_BITMAP
106static bool tv_page_mode_setting(void)
107{
108 static const struct opt_items names[] = {
109 {"No", -1},
110 {"Yes", -1},
111 };
112
113 return rb->set_option("Overlap Pages", &new_prefs.page_mode, INT,
114 names, 2, NULL);
115}
116
117static bool tv_scrollbar_setting(void)
118{
119 static const struct opt_items names[] = {
120 {"Off", -1},
121 {"On", -1}
122 };
123
124 return rb->set_option("Show Scrollbar", &new_prefs.scrollbar_mode, INT,
125 names, 2, NULL);
126}
127
128static bool tv_header_setting(void)
129{
130 int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
131 struct opt_items names[len];
132
133 names[0].string = "None";
134 names[0].voice_id = -1;
135 names[1].string = "File path";
136 names[1].voice_id = -1;
137
138 if (rb->global_settings->statusbar == STATUSBAR_TOP)
139 {
140 names[2].string = "Status bar";
141 names[2].voice_id = -1;
142 names[3].string = "Both";
143 names[3].voice_id = -1;
144 }
145
146 return rb->set_option("Show Header", &new_prefs.header_mode, INT,
147 names, len, NULL);
148}
149
150static bool tv_footer_setting(void)
151{
152 int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2;
153 struct opt_items names[len];
154
155 names[0].string = "None";
156 names[0].voice_id = -1;
157 names[1].string = "Page Num";
158 names[1].voice_id = -1;
159
160 if (rb->global_settings->statusbar == STATUSBAR_BOTTOM)
161 {
162 names[2].string = "Status bar";
163 names[2].voice_id = -1;
164 names[3].string = "Both";
165 names[3].voice_id = -1;
166 }
167
168 return rb->set_option("Show Footer", &new_prefs.footer_mode, INT,
169 names, len, NULL);
170}
171
172static int tv_font_comp(const void *a, const void *b)
173{
174 struct opt_items *pa;
175 struct opt_items *pb;
176
177 pa = (struct opt_items *)a;
178 pb = (struct opt_items *)b;
179
180 return rb->strcmp(pa->string, pb->string);
181}
182
183static bool tv_font_setting(void)
184{
185 int count = 0;
186 DIR *dir;
187 struct dirent *entry;
188 int i = 0;
189 int len;
190 int new_font = 0;
191 int old_font;
192 bool res;
193 int size = 0;
194
195 dir = rb->opendir(FONT_DIR);
196 if (!dir)
197 {
198 rb->splash(HZ/2, "font dir does not access");
199 return false;
200 }
201
202 while ((entry = rb->readdir(dir)) != NULL)
203 {
204 len = rb->strlen(entry->d_name);
205 if (len < 4 || rb->strcmp(entry->d_name + len - 4, ".fnt"))
206 continue;
207 size += len - 3;
208 count++;
209 }
210 rb->closedir(dir);
211
212 struct opt_items names[count];
213 unsigned char font_names[size];
214 unsigned char *p = font_names;
215
216 dir = rb->opendir(FONT_DIR);
217 if (!dir)
218 {
219 rb->splash(HZ/2, "font dir does not access");
220 return false;
221 }
222
223 while ((entry = rb->readdir(dir)) != NULL)
224 {
225 len = rb->strlen(entry->d_name);
226 if (len < 4 || rb->strcmp(entry->d_name + len - 4, ".fnt"))
227 continue;
228
229 rb->strlcpy(p, entry->d_name, len - 3);
230 names[i].string = p;
231 names[i].voice_id = -1;
232 p += len - 3;
233 if (++i >= count)
234 break;
235 }
236 rb->closedir(dir);
237
238 rb->qsort(names, count, sizeof(struct opt_items), tv_font_comp);
239
240 for (i = 0; i < count; i++)
241 {
242 if (!rb->strcmp(names[i].string, new_prefs.font_name))
243 {
244 new_font = i;
245 break;
246 }
247 }
248 old_font = new_font;
249
250 res = rb->set_option("Select Font", &new_font, INT,
251 names, count, NULL);
252
253 if (new_font != old_font)
254 {
255 rb->memset(new_prefs.font_name, 0, MAX_PATH);
256 rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
257 }
258
259 return res;
260}
261#endif
262
263static bool tv_autoscroll_speed_setting(void)
264{
265 return rb->set_int("Auto-scroll Speed", "", UNIT_INT,
266 &new_prefs.autoscroll_speed, NULL, 1, 1, 10, NULL);
267}
268
269MENUITEM_FUNCTION(encoding_item, 0, "Encoding", tv_encoding_setting,
270 NULL, NULL, Icon_NOICON);
271MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", tv_word_wrap_setting,
272 NULL, NULL, Icon_NOICON);
273MENUITEM_FUNCTION(line_mode_item, 0, "Line Mode", tv_line_mode_setting,
274 NULL, NULL, Icon_NOICON);
275MENUITEM_FUNCTION(view_mode_item, 0, "Wide View", tv_view_mode_setting,
276 NULL, NULL, Icon_NOICON);
277MENUITEM_FUNCTION(alignment_item, 0, "Alignment", tv_alignment_setting,
278 NULL, NULL, Icon_NOICON);
279#ifdef HAVE_LCD_BITMAP
280MENUITEM_FUNCTION(scrollbar_item, 0, "Show Scrollbar", tv_scrollbar_setting,
281 NULL, NULL, Icon_NOICON);
282MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", tv_page_mode_setting,
283 NULL, NULL, Icon_NOICON);
284MENUITEM_FUNCTION(header_item, 0, "Show Header", tv_header_setting,
285 NULL, NULL, Icon_NOICON);
286MENUITEM_FUNCTION(footer_item, 0, "Show Footer", tv_footer_setting,
287 NULL, NULL, Icon_NOICON);
288MENUITEM_FUNCTION(font_item, 0, "Font", tv_font_setting,
289 NULL, NULL, Icon_NOICON);
290#endif
291MENUITEM_FUNCTION(scroll_mode_item, 0, "Scroll Mode", tv_scroll_mode_setting,
292 NULL, NULL, Icon_NOICON);
293MENUITEM_FUNCTION(autoscroll_speed_item, 0, "Auto-Scroll Speed",
294 tv_autoscroll_speed_setting, NULL, NULL, Icon_NOICON);
295MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
296 &encoding_item, &word_wrap_item, &line_mode_item, &view_mode_item,
297 &alignment_item,
298#ifdef HAVE_LCD_BITMAP
299 &scrollbar_item, &page_mode_item, &header_item, &footer_item, &font_item,
300#endif
301 &scroll_mode_item, &autoscroll_speed_item);
302
303static enum tv_menu_result tv_options_menu(void)
304{
305 bool result = TV_MENU_RESULT_EXIT_MENU;
306
307 if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB)
308 result = TV_MENU_RESULT_ATTACHED_USB;
309
310 return result;
311}
312
313enum tv_menu_result tv_display_menu(void)
314{
315 int result = TV_MENU_RESULT_EXIT_MENU;
316
317 MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL,
318 "Return", "Viewer Options",
319 "Show Playback Menu", "Select Bookmark",
320 "Global Settings", "Quit");
321
322 switch (rb->do_menu(&menu, NULL, NULL, false))
323 {
324 case 0: /* return */
325 break;
326 case 1: /* change settings */
327 tv_copy_preferences(&new_prefs);
328 result = tv_options_menu();
329 tv_set_preferences(&new_prefs);
330 break;
331 case 2: /* playback control */
332 playback_control(NULL);
333 break;
334 case 3: /* select bookmark */
335 tv_select_bookmark();
336 break;
337 case 4: /* change global settings */
338 if (!tv_load_global_settings(&new_prefs))
339 tv_set_default_preferences(&new_prefs);
340
341 result = tv_options_menu();
342 tv_save_global_settings(&new_prefs);
343 break;
344 case 5: /* quit */
345 result = TV_MENU_RESULT_EXIT_PLUGIN;
346 break;
347 }
348 return result;
349}