text viewer: fix that the return value's type is wrong.
[kugel-rb.git] / apps / plugins / text_viewer / tv_menu.c
blob7c27a3d8c12a92fa6f24dcb920bc176ca66c6e46
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Gilles Roux
11 * 2003 Garrett Derner
12 * 2010 Yoshihisa Uchida
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.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
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"
29 /* settings helper functions */
31 static struct tv_preferences new_prefs;
33 /* */
34 /* horizontal scroll settings menu */
35 /* */
37 #ifdef HAVE_LCD_BITMAP
38 static bool tv_horizontal_scrollbar_setting(void)
40 static const struct opt_items names[] = {
41 {"No", -1},
42 {"Yes", -1},
45 return rb->set_option("Horizontal Scrollbar", &new_prefs.horizontal_scrollbar, INT,
46 names, 2, NULL);
48 #endif
50 static bool tv_horizontal_scroll_mode_setting(void)
52 static const struct opt_items names[] = {
53 {"Scroll by Screen", -1},
54 {"Scroll by Column", -1},
57 return rb->set_option("Scroll Mode", &new_prefs.horizontal_scroll_mode, INT,
58 names, 2, NULL);
61 #ifdef HAVE_LCD_BITMAP
62 MENUITEM_FUNCTION(horizontal_scrollbar_item, 0, "Scrollbar",
63 tv_horizontal_scrollbar_setting,
64 NULL, NULL, Icon_NOICON);
65 #endif
66 MENUITEM_FUNCTION(horizontal_scroll_mode_item, 0, "Scroll Mode",
67 tv_horizontal_scroll_mode_setting, NULL, NULL, Icon_NOICON);
69 MAKE_MENU(horizontal_scroll_menu, "Horizontal", NULL, Icon_NOICON,
70 #ifdef HAVE_LCD_BITMAP
71 &horizontal_scrollbar_item,
72 #endif
73 &horizontal_scroll_mode_item);
75 /* */
76 /* vertical scroll settings menu */
77 /* */
79 #ifdef HAVE_LCD_BITMAP
80 static bool tv_vertical_scrollbar_setting(void)
82 static const struct opt_items names[] = {
83 {"No", -1},
84 {"Yes", -1},
87 return rb->set_option("Vertical Scrollbar", &new_prefs.vertical_scrollbar, INT,
88 names, 2, NULL);
90 #endif
92 static bool tv_vertical_scroll_mode_setting(void)
94 static const struct opt_items names[] = {
95 {"Scroll by Page", -1},
96 {"Scroll by Line", -1},
99 return rb->set_option("Scroll Mode", &new_prefs.vertical_scroll_mode, INT,
100 names, 2, NULL);
103 static bool tv_page_mode_setting(void)
105 static const struct opt_items names[] = {
106 {"No", -1},
107 {"Yes", -1},
110 return rb->set_option("Overlap Pages", &new_prefs.page_mode, INT,
111 names, 2, NULL);
114 static bool tv_autoscroll_speed_setting(void)
116 return rb->set_int("Auto-scroll Speed", "", UNIT_INT,
117 &new_prefs.autoscroll_speed, NULL, 1, 1, 10, NULL);
120 static bool tv_narrow_mode_setting(void)
122 static const struct opt_items names[] = {
123 {"Previous/Next Page", -1},
124 {"Top/Bottom Page", -1},
127 return rb->set_option("Left/Right Key", &new_prefs.narrow_mode, INT,
128 names, 2, NULL);
131 #ifdef HAVE_LCD_BITMAP
132 MENUITEM_FUNCTION(vertical_scrollbar_item, 0, "Scrollbar",
133 tv_vertical_scrollbar_setting,
134 NULL, NULL, Icon_NOICON);
135 #endif
136 MENUITEM_FUNCTION(vertical_scroll_mode_item, 0, "Scroll Mode",
137 tv_vertical_scroll_mode_setting, NULL, NULL, Icon_NOICON);
138 MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", tv_page_mode_setting,
139 NULL, NULL, Icon_NOICON);
140 MENUITEM_FUNCTION(autoscroll_speed_item, 0, "Auto-Scroll Speed",
141 tv_autoscroll_speed_setting, NULL, NULL, Icon_NOICON);
142 MENUITEM_FUNCTION(narrow_mode_item, 0, "Left/Right Key (Narrow mode)",
143 tv_narrow_mode_setting, NULL, NULL, Icon_NOICON);
145 MAKE_MENU(vertical_scroll_menu, "Vertical", NULL, Icon_NOICON,
146 #ifdef HAVE_LCD_BITMAP
147 &vertical_scrollbar_item,
148 #endif
149 &vertical_scroll_mode_item, &page_mode_item, &autoscroll_speed_item,
150 &narrow_mode_item);
152 /* */
153 /* scroll settings menu */
154 /* */
156 MAKE_MENU(scroll_menu, "Scroll Settings", NULL, Icon_NOICON,
157 &horizontal_scroll_menu, &vertical_scroll_menu);
159 /* */
160 /* main menu */
161 /* */
163 static bool tv_encoding_setting(void)
165 static struct opt_items names[NUM_CODEPAGES];
166 int idx;
168 for (idx = 0; idx < NUM_CODEPAGES; idx++)
170 names[idx].string = rb->get_codepage_name(idx);
171 names[idx].voice_id = -1;
174 return rb->set_option("Encoding", &new_prefs.encoding, INT, names,
175 sizeof(names) / sizeof(names[0]), NULL);
178 static bool tv_word_wrap_setting(void)
180 static const struct opt_items names[] = {
181 {"On", -1},
182 {"Off (Chop Words)", -1},
185 return rb->set_option("Word Wrap", &new_prefs.word_mode, INT,
186 names, 2, NULL);
189 static bool tv_line_mode_setting(void)
191 static const struct opt_items names[] = {
192 {"Normal", -1},
193 {"Join Lines", -1},
194 {"Expand Lines", -1},
195 {"Reflow Lines", -1},
198 return rb->set_option("Line Mode", &new_prefs.line_mode, INT, names,
199 sizeof(names) / sizeof(names[0]), NULL);
202 static bool tv_windows_setting(void)
204 return rb->set_int("Screens Per Page", "", UNIT_INT,
205 &new_prefs.windows, NULL, 1, 1, 5, NULL);
208 static bool tv_alignment_setting(void)
210 static const struct opt_items names[] = {
211 {"Left", -1},
212 {"Right", -1},
215 return rb->set_option("Alignment", &new_prefs.alignment, INT,
216 names , 2, NULL);
219 #ifdef HAVE_LCD_BITMAP
220 static bool tv_header_setting(void)
222 int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
223 struct opt_items names[len];
225 names[0].string = "None";
226 names[0].voice_id = -1;
227 names[1].string = "File path";
228 names[1].voice_id = -1;
230 if (rb->global_settings->statusbar == STATUSBAR_TOP)
232 names[2].string = "Status bar";
233 names[2].voice_id = -1;
234 names[3].string = "Both";
235 names[3].voice_id = -1;
238 return rb->set_option("Show Header", &new_prefs.header_mode, INT,
239 names, len, NULL);
242 static bool tv_footer_setting(void)
244 int len = (rb->global_settings->statusbar == STATUSBAR_BOTTOM)? 4 : 2;
245 struct opt_items names[len];
247 names[0].string = "None";
248 names[0].voice_id = -1;
249 names[1].string = "Page Num";
250 names[1].voice_id = -1;
252 if (rb->global_settings->statusbar == STATUSBAR_BOTTOM)
254 names[2].string = "Status bar";
255 names[2].voice_id = -1;
256 names[3].string = "Both";
257 names[3].voice_id = -1;
260 return rb->set_option("Show Footer", &new_prefs.footer_mode, INT,
261 names, len, NULL);
264 static bool tv_font_setting(void)
266 int count = 0;
267 int i = 0;
268 int new_font = 0;
269 int old_font;
270 bool res;
271 unsigned char font_path[MAX_PATH];
273 struct tree_context *tree;
274 struct tree_context backup;
275 struct entry *dc;
276 int dirfilter = SHOW_FONT;
278 tree = rb->tree_get_context();
279 backup = *tree;
280 dc = tree->dircache;
281 rb->strlcat(backup.currdir, "/", MAX_PATH);
282 rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH);
283 tree->dirfilter = &dirfilter;
284 rb->snprintf(font_path, MAX_PATH, "%s/", FONT_DIR);
285 rb->set_current_file(font_path);
286 count = tree->filesindir;
288 struct opt_items names[count];
290 for (i = 0; i < count; i++)
292 char *p = rb->strrchr(dc[i].name, '.');
293 if (p) *p = 0;
294 if (!rb->strcmp(dc[i].name, new_prefs.font_name))
295 new_font = i;
297 names[i].string = dc[i].name;
298 names[i].voice_id = -1;
301 old_font = new_font;
303 res = rb->set_option("Select Font", &new_font, INT,
304 names, count, NULL);
306 if (new_font != old_font)
308 rb->memset(new_prefs.font_name, 0, MAX_PATH);
309 rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
312 *tree = backup;
313 rb->set_current_file(backup.currdir);
314 return res;
316 #endif
318 MENUITEM_FUNCTION(encoding_item, 0, "Encoding", tv_encoding_setting,
319 NULL, NULL, Icon_NOICON);
320 MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", tv_word_wrap_setting,
321 NULL, NULL, Icon_NOICON);
322 MENUITEM_FUNCTION(line_mode_item, 0, "Line Mode", tv_line_mode_setting,
323 NULL, NULL, Icon_NOICON);
324 MENUITEM_FUNCTION(windows_item, 0, "Screens Per Page", tv_windows_setting,
325 NULL, NULL, Icon_NOICON);
326 MENUITEM_FUNCTION(alignment_item, 0, "Alignment", tv_alignment_setting,
327 NULL, NULL, Icon_NOICON);
328 #ifdef HAVE_LCD_BITMAP
329 MENUITEM_FUNCTION(header_item, 0, "Show Header", tv_header_setting,
330 NULL, NULL, Icon_NOICON);
331 MENUITEM_FUNCTION(footer_item, 0, "Show Footer", tv_footer_setting,
332 NULL, NULL, Icon_NOICON);
333 MENUITEM_FUNCTION(font_item, 0, "Font", tv_font_setting,
334 NULL, NULL, Icon_NOICON);
335 #endif
337 MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
338 &encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
339 &alignment_item,
340 #ifdef HAVE_LCD_BITMAP
341 &header_item, &footer_item, &font_item,
342 #endif
343 &scroll_menu);
345 static enum tv_menu_result tv_options_menu(void)
347 enum tv_menu_result result = TV_MENU_RESULT_EXIT_MENU;
349 if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB)
350 result = TV_MENU_RESULT_ATTACHED_USB;
352 return result;
355 enum tv_menu_result tv_display_menu(void)
357 enum tv_menu_result result = TV_MENU_RESULT_EXIT_MENU;
359 MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL,
360 "Return", "Viewer Options",
361 "Show Playback Menu", "Select Bookmark",
362 "Global Settings", "Quit");
364 switch (rb->do_menu(&menu, NULL, NULL, false))
366 case 0: /* return */
367 break;
368 case 1: /* change settings */
369 tv_copy_preferences(&new_prefs);
370 result = tv_options_menu();
371 tv_set_preferences(&new_prefs);
372 break;
373 case 2: /* playback control */
374 playback_control(NULL);
375 break;
376 case 3: /* select bookmark */
377 tv_select_bookmark();
378 result = TV_MENU_RESULT_MOVE_PAGE;
379 break;
380 case 4: /* change global settings */
381 if (!tv_load_global_settings(&new_prefs))
382 tv_set_default_preferences(&new_prefs);
384 result = tv_options_menu();
385 tv_save_global_settings(&new_prefs);
386 break;
387 case 5: /* quit */
388 result = TV_MENU_RESULT_EXIT_PLUGIN;
389 break;
391 return result;