Commit FS#11799 by Alexander Meshcheryakov. Improves the text viewer plugin to write...
[kugel-rb.git] / apps / plugins / text_viewer / tv_menu.c
blob9be8312732bbcf158076393f6dcfe952cad0f598
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 return rb->set_bool("Horizontal Scrollbar", &new_prefs.horizontal_scrollbar);
42 #endif
44 static bool tv_horizontal_scroll_mode_setting(void)
46 static const struct opt_items names[] = {
47 {"Scroll by Screen", -1},
48 {"Scroll by Column", -1},
51 return rb->set_option("Scroll Mode", &new_prefs.horizontal_scroll_mode, INT,
52 names, 2, NULL);
55 #ifdef HAVE_LCD_BITMAP
56 MENUITEM_FUNCTION(horizontal_scrollbar_item, 0, "Scrollbar",
57 tv_horizontal_scrollbar_setting,
58 NULL, NULL, Icon_NOICON);
59 #endif
60 MENUITEM_FUNCTION(horizontal_scroll_mode_item, 0, "Scroll Mode",
61 tv_horizontal_scroll_mode_setting, NULL, NULL, Icon_NOICON);
63 MAKE_MENU(horizontal_scroll_menu, "Horizontal", NULL, Icon_NOICON,
64 #ifdef HAVE_LCD_BITMAP
65 &horizontal_scrollbar_item,
66 #endif
67 &horizontal_scroll_mode_item);
69 /* */
70 /* vertical scroll settings menu */
71 /* */
73 #ifdef HAVE_LCD_BITMAP
74 static bool tv_vertical_scrollbar_setting(void)
76 return rb->set_bool("Vertical Scrollbar", &new_prefs.vertical_scrollbar);
78 #endif
80 static bool tv_vertical_scroll_mode_setting(void)
82 static const struct opt_items names[] = {
83 {"Scroll by Page", -1},
84 {"Scroll by Line", -1},
87 return rb->set_option("Scroll Mode", &new_prefs.vertical_scroll_mode, INT,
88 names, 2, NULL);
91 static bool tv_overlap_page_mode_setting(void)
93 return rb->set_bool("Overlap Pages", &new_prefs.overlap_page_mode);
96 static bool tv_autoscroll_speed_setting(void)
98 return rb->set_int("Auto-scroll Speed", "", UNIT_INT,
99 &new_prefs.autoscroll_speed, NULL, 1, 1, 10, NULL);
102 static bool tv_narrow_mode_setting(void)
104 static const struct opt_items names[] = {
105 {"Previous/Next Page", -1},
106 {"Top/Bottom Page", -1},
109 return rb->set_option("Left/Right Key", &new_prefs.narrow_mode, INT,
110 names, 2, NULL);
113 #ifdef HAVE_LCD_BITMAP
114 MENUITEM_FUNCTION(vertical_scrollbar_item, 0, "Scrollbar",
115 tv_vertical_scrollbar_setting,
116 NULL, NULL, Icon_NOICON);
117 #endif
118 MENUITEM_FUNCTION(vertical_scroll_mode_item, 0, "Scroll Mode",
119 tv_vertical_scroll_mode_setting, NULL, NULL, Icon_NOICON);
120 MENUITEM_FUNCTION(overlap_page_mode_item, 0, "Overlap Pages", tv_overlap_page_mode_setting,
121 NULL, NULL, Icon_NOICON);
122 MENUITEM_FUNCTION(autoscroll_speed_item, 0, "Auto-Scroll Speed",
123 tv_autoscroll_speed_setting, NULL, NULL, Icon_NOICON);
124 MENUITEM_FUNCTION(narrow_mode_item, 0, "Left/Right Key (Narrow mode)",
125 tv_narrow_mode_setting, NULL, NULL, Icon_NOICON);
127 MAKE_MENU(vertical_scroll_menu, "Vertical", NULL, Icon_NOICON,
128 #ifdef HAVE_LCD_BITMAP
129 &vertical_scrollbar_item,
130 #endif
131 &vertical_scroll_mode_item, &overlap_page_mode_item, &autoscroll_speed_item,
132 &narrow_mode_item);
134 /* */
135 /* scroll settings menu */
136 /* */
138 MAKE_MENU(scroll_menu, "Scroll Settings", NULL, Icon_NOICON,
139 &horizontal_scroll_menu, &vertical_scroll_menu);
141 /* */
142 /* main menu */
143 /* */
145 static bool tv_encoding_setting(void)
147 static struct opt_items names[NUM_CODEPAGES];
148 int idx;
150 for (idx = 0; idx < NUM_CODEPAGES; idx++)
152 names[idx].string = rb->get_codepage_name(idx);
153 names[idx].voice_id = -1;
156 return rb->set_option("Encoding", &new_prefs.encoding, INT, names,
157 sizeof(names) / sizeof(names[0]), NULL);
160 static bool tv_word_wrap_setting(void)
162 static const struct opt_items names[] = {
163 {"On", -1},
164 {"Off (Chop Words)", -1},
167 return rb->set_option("Word Wrap", &new_prefs.word_mode, INT,
168 names, 2, NULL);
171 static bool tv_line_mode_setting(void)
173 static const struct opt_items names[] = {
174 {"Normal", -1},
175 {"Join Lines", -1},
176 {"Expand Lines", -1},
177 {"Reflow Lines", -1},
180 return rb->set_option("Line Mode", &new_prefs.line_mode, INT, names,
181 sizeof(names) / sizeof(names[0]), NULL);
184 static bool tv_windows_setting(void)
186 return rb->set_int("Screens Per Page", "", UNIT_INT,
187 &new_prefs.windows, NULL, 1, 1, 5, NULL);
190 static bool tv_alignment_setting(void)
192 static const struct opt_items names[] = {
193 {"Left", -1},
194 {"Right", -1},
197 return rb->set_option("Alignment", &new_prefs.alignment, INT,
198 names , 2, NULL);
201 #ifdef HAVE_LCD_BITMAP
202 static bool tv_header_setting(void)
204 return rb->set_bool("Show Header", &new_prefs.header_mode);
207 static bool tv_footer_setting(void)
209 return rb->set_bool("Show Footer", &new_prefs.footer_mode);
212 static bool tv_statusbar_setting(void)
214 return rb->set_bool("Show Statusbar", &new_prefs.statusbar);
217 static bool tv_font_setting(void)
219 int count = 0;
220 int i = 0;
221 int new_font = 0;
222 int old_font;
223 bool res;
224 unsigned char font_path[MAX_PATH];
226 struct tree_context *tree;
227 struct tree_context backup;
228 struct entry *dc;
229 int dirfilter = SHOW_FONT;
231 tree = rb->tree_get_context();
232 backup = *tree;
233 dc = tree->dircache;
234 rb->strlcat(backup.currdir, "/", MAX_PATH);
235 rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH);
236 tree->dirfilter = &dirfilter;
237 tree->browse = NULL;
238 rb->snprintf(font_path, MAX_PATH, "%s/", FONT_DIR);
239 rb->set_current_file(font_path);
240 count = tree->filesindir;
242 struct opt_items names[count];
244 for (i = 0; i < count; i++)
246 char *p = rb->strrchr(dc[i].name, '.');
247 if (p) *p = 0;
248 if (!rb->strcmp(dc[i].name, new_prefs.font_name))
249 new_font = i;
251 names[i].string = dc[i].name;
252 names[i].voice_id = -1;
255 old_font = new_font;
257 res = rb->set_option("Select Font", &new_font, INT,
258 names, count, NULL);
260 if (new_font != old_font)
261 rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
263 *tree = backup;
264 rb->set_current_file(backup.currdir);
265 return res;
267 #endif
269 static bool tv_indent_spaces_setting(void)
271 return rb->set_int("Indent Spaces", "", UNIT_INT,
272 &new_prefs.indent_spaces, NULL, 1, 0, 5, NULL);
275 MENUITEM_FUNCTION(encoding_item, 0, "Encoding", tv_encoding_setting,
276 NULL, NULL, Icon_NOICON);
277 MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", tv_word_wrap_setting,
278 NULL, NULL, Icon_NOICON);
279 MENUITEM_FUNCTION(line_mode_item, 0, "Line Mode", tv_line_mode_setting,
280 NULL, NULL, Icon_NOICON);
281 MENUITEM_FUNCTION(windows_item, 0, "Screens Per Page", tv_windows_setting,
282 NULL, NULL, Icon_NOICON);
283 MENUITEM_FUNCTION(alignment_item, 0, "Alignment", tv_alignment_setting,
284 NULL, NULL, Icon_NOICON);
285 #ifdef HAVE_LCD_BITMAP
286 MENUITEM_FUNCTION(header_item, 0, "Show Header", tv_header_setting,
287 NULL, NULL, Icon_NOICON);
288 MENUITEM_FUNCTION(footer_item, 0, "Show Footer", tv_footer_setting,
289 NULL, NULL, Icon_NOICON);
290 MENUITEM_FUNCTION(statusbar_item, 0, "Show Statusbar", tv_statusbar_setting,
291 NULL, NULL, Icon_NOICON);
292 MENUITEM_FUNCTION(font_item, 0, "Font", tv_font_setting,
293 NULL, NULL, Icon_NOICON);
294 #endif
295 MENUITEM_FUNCTION(indent_spaces_item, 0, "Indent Spaces", tv_indent_spaces_setting,
296 NULL, NULL, Icon_NOICON);
298 MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
299 &encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
300 &alignment_item,
301 #ifdef HAVE_LCD_BITMAP
302 &header_item, &footer_item, &font_item, &statusbar_item,
303 #endif
304 &scroll_menu, &indent_spaces_item);
306 static unsigned tv_options_menu(void)
308 unsigned result = TV_MENU_RESULT_EXIT_MENU;
310 if (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB)
311 result = TV_MENU_RESULT_ATTACHED_USB;
313 return result;
316 unsigned tv_display_menu(void)
318 unsigned result = TV_MENU_RESULT_EXIT_MENU;
320 MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL,
321 "Return", "Viewer Options",
322 "Show Playback Menu", "Select Bookmark",
323 "Global Settings", "Quit");
325 switch (rb->do_menu(&menu, NULL, NULL, false))
327 case 0: /* return */
328 break;
329 case 1: /* change settings */
330 tv_copy_preferences(&new_prefs);
331 result = tv_options_menu();
332 if (tv_compare_preferences(&new_prefs))
333 preferences_changed = true;
334 if (!tv_set_preferences(&new_prefs))
335 result = TV_MENU_RESULT_ERROR;
336 break;
337 case 2: /* playback control */
338 playback_control(NULL);
339 break;
340 case 3: /* select bookmark */
341 tv_select_bookmark();
342 result = TV_MENU_RESULT_MOVE_PAGE;
343 break;
344 case 4: /* change global settings */
345 if (!tv_load_global_settings(&new_prefs))
346 tv_set_default_preferences(&new_prefs);
348 result = tv_options_menu();
349 tv_save_global_settings(&new_prefs);
350 break;
351 case 5: /* quit */
352 result = TV_MENU_RESULT_EXIT_PLUGIN;
353 break;
355 return result;