Added ID3 database support. Still very early.
[kugel-rb.git] / apps / settings_menu.c
blobcf87564c9de130ebaa86641bce3261ff7cfeae5b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Robert Hak
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include <string.h>
26 #include "lcd.h"
27 #include "menu.h"
28 #include "mpeg.h"
29 #include "button.h"
30 #include "kernel.h"
31 #include "thread.h"
32 #include "sprintf.h"
33 #include "settings.h"
34 #include "settings_menu.h"
35 #include "backlight.h"
36 #include "playlist.h" /* for playlist_shuffle */
37 #include "fat.h" /* For dotfile settings */
38 #include "sleeptimer.h"
39 #include "powermgmt.h"
40 #include "rtc.h"
41 #include "ata.h"
42 #include "tree.h"
43 #include "screens.h"
44 #include "talk.h"
45 #include "timefuncs.h"
46 #include "misc.h"
47 #ifdef HAVE_LCD_BITMAP
48 #include "peakmeter.h"
49 #endif
50 #include "lang.h"
51 #if CONFIG_HWCODEC == MAS3507D
52 void dac_line_in(bool enable);
53 #endif
54 #ifdef HAVE_ALARM_MOD
55 #include "alarm_menu.h"
56 #endif
58 /* This flag is set by dirbrowse() if a new language is loaded */
59 bool language_changed;
61 #ifdef HAVE_CHARGING
62 static bool car_adapter_mode(void)
64 return set_bool_options( str(LANG_CAR_ADAPTER_MODE),
65 &global_settings.car_adapter_mode,
66 STR(LANG_SET_BOOL_YES),
67 STR(LANG_SET_BOOL_NO),
68 set_car_adapter_mode);
70 #endif
72 static bool contrast(void)
74 return set_int( str(LANG_CONTRAST), "", UNIT_INT,
75 &global_settings.contrast,
76 lcd_set_contrast, 1, MIN_CONTRAST_SETTING,
77 MAX_CONTRAST_SETTING );
80 #ifdef CONFIG_BACKLIGHT
81 static bool caption_backlight(void)
83 bool rc = set_bool( str(LANG_CAPTION_BACKLIGHT),
84 &global_settings.caption_backlight);
86 return rc;
88 #endif
90 /**
91 * Menu to set icon visibility
93 static bool show_icons(void)
95 return set_bool( str(LANG_SHOW_ICONS), &global_settings.show_icons );
98 #ifdef HAVE_LCD_BITMAP
101 * Menu to set LCD Mode (normal/inverse)
103 static bool invert(void)
105 bool rc = set_bool_options(str(LANG_INVERT),
106 &global_settings.invert,
107 STR(LANG_INVERT_LCD_INVERSE),
108 STR(LANG_INVERT_LCD_NORMAL),
109 lcd_set_invert_display);
110 return rc;
114 * Menu to set Line Selector Type (Pointer/Bar)
116 static bool invert_cursor(void)
118 return set_bool_options(str(LANG_INVERT_CURSOR),
119 &global_settings.invert_cursor,
120 STR(LANG_INVERT_CURSOR_BAR),
121 STR(LANG_INVERT_CURSOR_POINTER),
122 NULL);
126 * Menu to turn the display+buttons by 180 degrees
128 static bool flip_display(void)
130 bool rc = set_bool( str(LANG_FLIP_DISPLAY),
131 &global_settings.flip_display);
133 button_set_flip(global_settings.flip_display);
134 lcd_set_flip(global_settings.flip_display);
136 return rc;
140 * Menu to configure the battery display on status bar
142 static bool battery_type(void)
144 static const struct opt_items names[] = {
145 { STR(LANG_DISPLAY_GRAPHIC) },
146 { STR(LANG_DISPLAY_NUMERIC) }
148 return set_option( str(LANG_BATTERY_DISPLAY),
149 &global_settings.battery_type, INT, names, 2, NULL);
153 * Menu to configure the volume display on status bar
155 static bool volume_type(void)
157 static const struct opt_items names[] = {
158 { STR(LANG_DISPLAY_GRAPHIC) },
159 { STR(LANG_DISPLAY_NUMERIC) }
161 return set_option( str(LANG_VOLUME_DISPLAY), &global_settings.volume_type,
162 INT, names, 2, NULL);
165 #ifdef PM_DEBUG
166 static bool peak_meter_fps_menu(void) {
167 bool retval = false;
168 retval = set_int( "Refresh rate", "/s", UNIT_PER_SEC,
169 &peak_meter_fps,
170 NULL, 1, 5, 40);
171 return retval;
173 #endif /* PM_DEBUG */
176 * Menu to set the hold time of normal peaks.
178 static bool peak_meter_hold(void) {
179 bool retval = false;
180 static const struct opt_items names[] = {
181 { STR(LANG_OFF) },
182 { "200 ms " , TALK_ID(200, UNIT_MS) },
183 { "300 ms " , TALK_ID(300, UNIT_MS) },
184 { "500 ms " , TALK_ID(500, UNIT_MS) },
185 { "1 s" , TALK_ID(1, UNIT_SEC) },
186 { "2 s" , TALK_ID(2, UNIT_SEC) },
187 { "3 s" , TALK_ID(3, UNIT_SEC) },
188 { "4 s" , TALK_ID(4, UNIT_SEC) },
189 { "5 s" , TALK_ID(5, UNIT_SEC) },
190 { "6 s" , TALK_ID(6, UNIT_SEC) },
191 { "7 s" , TALK_ID(7, UNIT_SEC) },
192 { "8 s" , TALK_ID(8, UNIT_SEC) },
193 { "9 s" , TALK_ID(9, UNIT_SEC) },
194 { "10 s" , TALK_ID(10, UNIT_SEC) },
195 { "15 s" , TALK_ID(15, UNIT_SEC) },
196 { "20 s" , TALK_ID(20, UNIT_SEC) },
197 { "30 s" , TALK_ID(30, UNIT_SEC) },
198 { "1 min" , TALK_ID(1, UNIT_MIN) }
200 retval = set_option( str(LANG_PM_PEAK_HOLD),
201 &global_settings.peak_meter_hold, INT, names,
202 18, NULL);
204 peak_meter_init_times(global_settings.peak_meter_release,
205 global_settings.peak_meter_hold,
206 global_settings.peak_meter_clip_hold);
208 return retval;
212 * Menu to set the hold time of clips.
214 static bool peak_meter_clip_hold(void) {
215 bool retval = false;
217 static const struct opt_items names[] = {
218 { STR(LANG_PM_ETERNAL) },
219 { "1s " , TALK_ID(1, UNIT_SEC) },
220 { "2s " , TALK_ID(2, UNIT_SEC) },
221 { "3s " , TALK_ID(3, UNIT_SEC) },
222 { "4s " , TALK_ID(4, UNIT_SEC) },
223 { "5s " , TALK_ID(5, UNIT_SEC) },
224 { "6s " , TALK_ID(6, UNIT_SEC) },
225 { "7s " , TALK_ID(7, UNIT_SEC) },
226 { "8s " , TALK_ID(8, UNIT_SEC) },
227 { "9s " , TALK_ID(9, UNIT_SEC) },
228 { "10s" , TALK_ID(10, UNIT_SEC) },
229 { "15s" , TALK_ID(15, UNIT_SEC) },
230 { "20s" , TALK_ID(20, UNIT_SEC) },
231 { "25s" , TALK_ID(25, UNIT_SEC) },
232 { "30s" , TALK_ID(30, UNIT_SEC) },
233 { "45s" , TALK_ID(45, UNIT_SEC) },
234 { "60s" , TALK_ID(60, UNIT_SEC) },
235 { "90s" , TALK_ID(90, UNIT_SEC) },
236 { "2min" , TALK_ID(2, UNIT_MIN) },
237 { "3min" , TALK_ID(3, UNIT_MIN) },
238 { "5min" , TALK_ID(5, UNIT_MIN) },
239 { "10min" , TALK_ID(10, UNIT_MIN) },
240 { "20min" , TALK_ID(20, UNIT_MIN) },
241 { "45min" , TALK_ID(45, UNIT_MIN) },
242 { "90min" , TALK_ID(90, UNIT_MIN) }
244 retval = set_option( str(LANG_PM_CLIP_HOLD),
245 &global_settings.peak_meter_clip_hold, INT, names,
246 25, peak_meter_set_clip_hold);
248 peak_meter_init_times(global_settings.peak_meter_release,
249 global_settings.peak_meter_hold,
250 global_settings.peak_meter_clip_hold);
252 return retval;
256 * Menu to set the release time of the peak meter.
258 static bool peak_meter_release(void) {
259 bool retval = false;
261 /* The range of peak_meter_release is restricted so that it
262 fits into a 7 bit number. The 8th bit is used for storing
263 something else in the rtc ram.
264 Also, the max value is 0x7e, since the RTC value 0xff is reserved */
265 retval = set_int( str(LANG_PM_RELEASE), str(LANG_PM_UNITS_PER_READ),
266 LANG_PM_UNITS_PER_READ,
267 &global_settings.peak_meter_release,
268 NULL, 1, 1, 0x7e);
270 peak_meter_init_times(global_settings.peak_meter_release,
271 global_settings.peak_meter_hold,
272 global_settings.peak_meter_clip_hold);
274 return retval;
278 * Menu to select wether the scale of the meter
279 * displays dBfs of linear values.
281 static bool peak_meter_scale(void) {
282 bool retval = false;
283 bool use_dbfs = global_settings.peak_meter_dbfs;
284 retval = set_bool_options(str(LANG_PM_SCALE),
285 &use_dbfs,
286 STR(LANG_PM_DBFS), STR(LANG_PM_LINEAR),
287 NULL);
289 /* has the user really changed the scale? */
290 if (use_dbfs != global_settings.peak_meter_dbfs) {
292 /* store the change */
293 global_settings.peak_meter_dbfs = use_dbfs;
294 peak_meter_set_use_dbfs(use_dbfs);
296 /* If the user changed the scale mode the meaning of
297 peak_meter_min (peak_meter_max) has changed. Thus we have
298 to convert the values stored in global_settings. */
299 if (use_dbfs) {
301 /* we only store -dBfs */
302 global_settings.peak_meter_min = -peak_meter_get_min() / 100;
303 global_settings.peak_meter_max = -peak_meter_get_max() / 100;
304 } else {
305 int max;
307 /* linear percent */
308 global_settings.peak_meter_min = peak_meter_get_min();
310 /* converting dBfs -> percent results in a precision loss.
311 I assume that the user doesn't bother that conversion
312 dBfs <-> percent isn't symmetrical for odd values but that
313 he wants 0 dBfs == 100%. Thus I 'correct' the percent value
314 resulting from dBfs -> percent manually here */
315 max = peak_meter_get_max();
316 global_settings.peak_meter_max = max < 99 ? max : 100;
318 settings_apply_pm_range();
320 return retval;
324 * Adjust the min value of the value range that
325 * the peak meter shall visualize.
327 static bool peak_meter_min(void) {
328 bool retval = false;
329 if (global_settings.peak_meter_dbfs) {
331 /* for dBfs scale */
332 int range_max = -global_settings.peak_meter_max;
333 int min = -global_settings.peak_meter_min;
335 retval = set_int(str(LANG_PM_MIN), str(LANG_PM_DBFS), UNIT_DB,
336 &min, NULL, 1, -89, range_max);
338 global_settings.peak_meter_min = - min;
341 /* for linear scale */
342 else {
343 int min = global_settings.peak_meter_min;
345 retval = set_int(str(LANG_PM_MIN), "%", UNIT_PERCENT,
346 &min, NULL,
347 1, 0, global_settings.peak_meter_max - 1);
349 global_settings.peak_meter_min = (unsigned char)min;
352 settings_apply_pm_range();
353 return retval;
358 * Adjust the max value of the value range that
359 * the peak meter shall visualize.
361 static bool peak_meter_max(void) {
362 bool retval = false;
363 if (global_settings.peak_meter_dbfs) {
365 /* for dBfs scale */
366 int range_min = -global_settings.peak_meter_min;
367 int max = -global_settings.peak_meter_max;;
369 retval = set_int(str(LANG_PM_MAX), str(LANG_PM_DBFS), UNIT_DB,
370 &max, NULL, 1, range_min, 0);
372 global_settings.peak_meter_max = - max;
376 /* for linear scale */
377 else {
378 int max = global_settings.peak_meter_max;
380 retval = set_int(str(LANG_PM_MAX), "%", UNIT_PERCENT,
381 &max, NULL,
382 1, global_settings.peak_meter_min + 1, 100);
384 global_settings.peak_meter_max = (unsigned char)max;
387 settings_apply_pm_range();
388 return retval;
392 * Menu to select wether the meter is in
393 * precision or in energy saver mode
395 static bool peak_meter_performance(void) {
396 bool retval = false;
397 retval = set_bool_options(str(LANG_PM_PERFORMANCE),
398 &global_settings.peak_meter_performance,
399 STR(LANG_PM_HIGH_PERFORMANCE), STR(LANG_PM_ENERGY_SAVER),
400 NULL);
402 if (global_settings.peak_meter_performance) {
403 peak_meter_fps = 25;
404 } else {
405 peak_meter_fps = 20;
407 return retval;
411 * Menu to configure the peak meter
413 static bool peak_meter_menu(void)
415 int m;
416 bool result;
418 static const struct menu_item items[] = {
419 { ID2P(LANG_PM_RELEASE) , peak_meter_release },
420 { ID2P(LANG_PM_PEAK_HOLD), peak_meter_hold },
421 { ID2P(LANG_PM_CLIP_HOLD), peak_meter_clip_hold },
422 { ID2P(LANG_PM_PERFORMANCE), peak_meter_performance },
423 #ifdef PM_DEBUG
424 { "Refresh rate" , -1 , peak_meter_fps_menu },
425 #endif
426 { ID2P(LANG_PM_SCALE) , peak_meter_scale },
427 { ID2P(LANG_PM_MIN) , peak_meter_min },
428 { ID2P(LANG_PM_MAX) , peak_meter_max },
431 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
432 NULL, NULL, NULL );
433 result = menu_run(m);
434 menu_exit(m);
435 return result;
437 #endif /* HAVE_LCD_BITMAP */
439 static bool shuffle(void)
441 return set_bool( str(LANG_SHUFFLE), &global_settings.playlist_shuffle );
444 static bool repeat_mode(void)
446 bool result;
447 static const struct opt_items names[] = {
448 { STR(LANG_OFF) },
449 { STR(LANG_REPEAT_ALL) },
450 { STR(LANG_REPEAT_ONE) }
452 int old_repeat = global_settings.repeat_mode;
454 result = set_option( str(LANG_REPEAT), &global_settings.repeat_mode,
455 INT, names, 3, NULL );
457 if (old_repeat != global_settings.repeat_mode)
458 mpeg_flush_and_reload_tracks();
460 return result;
463 static bool play_selected(void)
465 return set_bool( str(LANG_PLAY_SELECTED), &global_settings.play_selected );
468 static bool dir_filter(void)
470 static const struct opt_items names[] = {
471 { STR(LANG_FILTER_ALL) },
472 { STR(LANG_FILTER_SUPPORTED) },
473 { STR(LANG_FILTER_MUSIC) },
474 { STR(LANG_FILTER_PLAYLIST) },
475 { STR(LANG_FILTER_ID3DB) }
477 return set_option( str(LANG_FILTER), &global_settings.dirfilter, INT,
478 names, 5, NULL );
481 static bool sort_case(void)
483 return set_bool( str(LANG_SORT_CASE), &global_settings.sort_case );
486 static bool sort_file(void)
488 int oldval = global_settings.sort_file;
489 bool ret;
490 static const struct opt_items names[] = {
491 { STR(LANG_SORT_ALPHA) },
492 { STR(LANG_SORT_DATE) },
493 { STR(LANG_SORT_DATE_REVERSE) },
494 { STR(LANG_SORT_TYPE) }
496 ret = set_option( str(LANG_SORT_FILE), &global_settings.sort_file, INT,
497 names, 4, NULL );
498 if (global_settings.sort_file != oldval)
499 reload_directory(); /* force reload if this has changed */
500 return ret;
503 static bool sort_dir(void)
505 int oldval = global_settings.sort_dir;
506 bool ret;
507 static const struct opt_items names[] = {
508 { STR(LANG_SORT_ALPHA) },
509 { STR(LANG_SORT_DATE) },
510 { STR(LANG_SORT_DATE_REVERSE) }
512 ret = set_option( str(LANG_SORT_DIR), &global_settings.sort_dir, INT,
513 names, 3, NULL );
514 if (global_settings.sort_dir != oldval)
515 reload_directory(); /* force reload if this has changed */
516 return ret;
519 static bool resume(void)
521 static const struct opt_items names[] = {
522 { STR(LANG_SET_BOOL_NO) },
523 { STR(LANG_RESUME_SETTING_ASK) },
524 { STR(LANG_RESUME_SETTING_ASK_ONCE) },
525 { STR(LANG_SET_BOOL_YES) }
527 return set_option( str(LANG_RESUME), &global_settings.resume, INT,
528 names, 4, NULL );
531 static bool autocreatebookmark(void)
533 bool retval = false;
534 static const struct opt_items names[] = {
535 { STR(LANG_SET_BOOL_NO) },
536 { STR(LANG_SET_BOOL_YES) },
537 { STR(LANG_RESUME_SETTING_ASK) },
538 { STR(LANG_BOOKMARK_SETTINGS_RECENT_ONLY_YES) },
539 { STR(LANG_BOOKMARK_SETTINGS_RECENT_ONLY_ASK) }
542 retval = set_option( str(LANG_BOOKMARK_SETTINGS_AUTOCREATE),
543 &global_settings.autocreatebookmark, INT,
544 names, 5, NULL );
545 if(global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_YES ||
546 global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK)
548 if(global_settings.usemrb == BOOKMARK_NO)
549 global_settings.usemrb = BOOKMARK_YES;
552 return retval;
555 static bool autoloadbookmark(void)
557 static const struct opt_items names[] = {
558 { STR(LANG_SET_BOOL_NO) },
559 { STR(LANG_SET_BOOL_YES) },
560 { STR(LANG_RESUME_SETTING_ASK) }
562 return set_option( str(LANG_BOOKMARK_SETTINGS_AUTOLOAD),
563 &global_settings.autoloadbookmark, INT,
564 names, 3, NULL );
567 static bool useMRB(void)
569 static const struct opt_items names[] = {
570 { STR(LANG_SET_BOOL_NO) },
571 { STR(LANG_SET_BOOL_YES) },
572 { STR(LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY) }
574 return set_option( str(LANG_BOOKMARK_SETTINGS_MAINTAIN_RECENT_BOOKMARKS),
575 &global_settings.usemrb, INT,
576 names, 3, NULL );
579 #ifdef CONFIG_BACKLIGHT
580 #ifdef HAVE_CHARGING
581 static bool backlight_on_when_charging(void)
583 bool result = set_bool(str(LANG_BACKLIGHT_ON_WHEN_CHARGING),
584 &global_settings.backlight_on_when_charging);
585 backlight_set_on_when_charging(global_settings.backlight_on_when_charging);
586 return result;
588 #endif
590 static bool backlight_timer(void)
592 static const struct opt_items names[] = {
593 { STR(LANG_OFF) },
594 { STR(LANG_ON) },
595 { "1s ", TALK_ID(1, UNIT_SEC) },
596 { "2s ", TALK_ID(2, UNIT_SEC) },
597 { "3s ", TALK_ID(3, UNIT_SEC) },
598 { "4s ", TALK_ID(4, UNIT_SEC) },
599 { "5s ", TALK_ID(5, UNIT_SEC) },
600 { "6s ", TALK_ID(6, UNIT_SEC) },
601 { "7s ", TALK_ID(7, UNIT_SEC) },
602 { "8s ", TALK_ID(8, UNIT_SEC) },
603 { "9s ", TALK_ID(9, UNIT_SEC) },
604 { "10s", TALK_ID(10, UNIT_SEC) },
605 { "15s", TALK_ID(15, UNIT_SEC) },
606 { "20s", TALK_ID(20, UNIT_SEC) },
607 { "25s", TALK_ID(25, UNIT_SEC) },
608 { "30s", TALK_ID(30, UNIT_SEC) },
609 { "45s", TALK_ID(45, UNIT_SEC) },
610 { "60s", TALK_ID(60, UNIT_SEC) },
611 { "90s", TALK_ID(90, UNIT_SEC) }
613 return set_option(str(LANG_BACKLIGHT), &global_settings.backlight_timeout,
614 INT, names, 19, backlight_set_timeout );
616 #endif /* CONFIG_BACKLIGHT */
618 static bool poweroff_idle_timer(void)
620 static const struct opt_items names[] = {
621 { STR(LANG_OFF) },
622 { "1m ", TALK_ID(1, UNIT_MIN) },
623 { "2m ", TALK_ID(2, UNIT_MIN) },
624 { "3m ", TALK_ID(3, UNIT_MIN) },
625 { "4m ", TALK_ID(4, UNIT_MIN) },
626 { "5m ", TALK_ID(5, UNIT_MIN) },
627 { "6m ", TALK_ID(6, UNIT_MIN) },
628 { "7m ", TALK_ID(7, UNIT_MIN) },
629 { "8m ", TALK_ID(8, UNIT_MIN) },
630 { "9m ", TALK_ID(9, UNIT_MIN) },
631 { "10m", TALK_ID(10, UNIT_MIN) },
632 { "15m", TALK_ID(15, UNIT_MIN) },
633 { "30m", TALK_ID(30, UNIT_MIN) },
634 { "45m", TALK_ID(45, UNIT_MIN) },
635 { "60m", TALK_ID(60, UNIT_MIN) }
637 return set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff,
638 INT, names, 15, set_poweroff_timeout);
641 static bool scroll_speed(void)
643 return set_int(str(LANG_SCROLL), "", UNIT_INT,
644 &global_settings.scroll_speed,
645 &lcd_scroll_speed, 1, 0, 15 );
649 static bool scroll_delay(void)
651 int dummy = global_settings.scroll_delay * (HZ/10);
652 int rc = set_int(str(LANG_SCROLL_DELAY), "ms", UNIT_MS,
653 &dummy,
654 &lcd_scroll_delay, 100, 0, 2500 );
655 global_settings.scroll_delay = dummy / (HZ/10);
656 return rc;
659 #ifdef HAVE_LCD_BITMAP
660 static bool scroll_step(void)
662 return set_int(str(LANG_SCROLL_STEP_EXAMPLE), "pixels", UNIT_PIXEL,
663 &global_settings.scroll_step,
664 &lcd_scroll_step, 1, 1, LCD_WIDTH );
666 #endif
668 static bool bidir_limit(void)
670 return set_int(str(LANG_BIDIR_SCROLL), "%", UNIT_PERCENT,
671 &global_settings.bidir_limit,
672 &lcd_bidir_scroll, 25, 0, 200 );
675 #ifdef HAVE_LCD_CHARCELLS
676 static bool jump_scroll(void)
678 static const struct opt_items names[] = {
679 { STR(LANG_OFF) },
680 { STR(LANG_ONE_TIME) },
681 { "2", TALK_ID(2, UNIT_INT) },
682 { "3", TALK_ID(3, UNIT_INT) },
683 { "4", TALK_ID(4, UNIT_INT) },
684 { STR(LANG_ALWAYS) }
686 bool ret;
687 ret=set_option(str(LANG_JUMP_SCROLL), &global_settings.jump_scroll,
688 INT, names, 6, lcd_jump_scroll);
689 return ret;
691 static bool jump_scroll_delay(void)
693 int dummy = global_settings.jump_scroll_delay * (HZ/10);
694 int rc = set_int(str(LANG_JUMP_SCROLL_DELAY), "ms", UNIT_MS,
695 &dummy,
696 &lcd_jump_scroll_delay, 100, 0, 2500 );
697 global_settings.jump_scroll_delay = dummy / (HZ/10);
698 return rc;
700 #endif
702 #ifndef SIMULATOR
704 * Menu to set the battery capacity
706 static bool battery_capacity(void)
708 return set_int(str(LANG_BATTERY_CAPACITY), "mAh", UNIT_MAH,
709 &global_settings.battery_capacity,
710 &set_battery_capacity, 50, BATTERY_CAPACITY_MIN,
711 BATTERY_CAPACITY_MAX );
713 #endif
715 #ifdef HAVE_CHARGE_CTRL
716 static bool deep_discharge(void)
718 bool result;
719 result = set_bool( str(LANG_DISCHARGE), &global_settings.discharge );
720 charge_restart_level = global_settings.discharge ?
721 CHARGE_RESTART_LO : CHARGE_RESTART_HI;
722 return result;
724 static bool trickle_charge(void)
726 bool result;
727 result = set_bool( str(LANG_TRICKLE_CHARGE), &global_settings.trickle_charge );
728 enable_trickle_charge(global_settings.trickle_charge);
729 return result;
731 #endif
733 #ifdef HAVE_RTC
734 static bool timedate_set(void)
736 struct tm tm;
737 int timedate[8];
738 bool result;
740 timedate[0] = rtc_read(0x03); /* hour */
741 timedate[1] = rtc_read(0x02); /* minute */
742 timedate[2] = rtc_read(0x01); /* second */
743 timedate[3] = rtc_read(0x07); /* year */
744 timedate[4] = rtc_read(0x06); /* month */
745 timedate[5] = rtc_read(0x05); /* day */
747 /* Make a local copy of the time struct */
748 memcpy(&tm, get_time(), sizeof(struct tm));
750 /* do some range checks */
751 /* This prevents problems with time/date setting after a power loss */
752 if (!valid_time(&tm))
754 /* hour */
755 tm.tm_hour = 0;
756 tm.tm_min = 0;
757 tm.tm_sec = 0;
758 tm.tm_mday = 1;
759 tm.tm_mon = 0;
760 tm.tm_wday = 1;
761 tm.tm_year = 100;
764 result = set_time_screen(str(LANG_TIME), &tm);
766 if(tm.tm_year != -1) {
767 set_time(&tm);
769 return result;
772 static bool timeformat_set(void)
774 static const struct opt_items names[] = {
775 { STR(LANG_24_HOUR_CLOCK) },
776 { STR(LANG_12_HOUR_CLOCK) }
778 return set_option(str(LANG_TIMEFORMAT), &global_settings.timeformat,
779 INT, names, 2, NULL);
781 #endif
783 #ifndef HAVE_MMC
784 static bool spindown(void)
786 return set_int(str(LANG_SPINDOWN), "s", UNIT_SEC,
787 &global_settings.disk_spindown,
788 ata_spindown, 1, 3, 254 );
791 #ifdef HAVE_ATA_POWER_OFF
792 static bool poweroff(void)
794 bool rc = set_bool(str(LANG_POWEROFF), &global_settings.disk_poweroff);
795 ata_poweroff(global_settings.disk_poweroff);
796 return rc;
798 #endif /* HAVE_ATA_POWEROFF */
799 #endif /* !HAVE_MMC */
801 #if CONFIG_HWCODEC == MAS3507D
802 static bool line_in(void)
804 bool rc = set_bool(str(LANG_LINE_IN), &global_settings.line_in);
805 dac_line_in(global_settings.line_in);
806 return rc;
808 #endif
810 static bool max_files_in_dir(void)
812 return set_int(str(LANG_MAX_FILES_IN_DIR), "", UNIT_INT,
813 &global_settings.max_files_in_dir,
814 NULL, 50, 50, 10000 );
817 static bool max_files_in_playlist(void)
819 return set_int(str(LANG_MAX_FILES_IN_PLAYLIST), "", UNIT_INT,
820 &global_settings.max_files_in_playlist,
821 NULL, 1000, 1000, 20000 );
824 static bool buffer_margin(void)
826 return set_int(str(LANG_MP3BUFFER_MARGIN), "s", UNIT_SEC,
827 &global_settings.buffer_margin,
828 mpeg_set_buffer_margin, 1, 0, 7 );
831 static bool ff_rewind_min_step(void)
833 static const struct opt_items names[] = {
834 { "1s", TALK_ID(1, UNIT_SEC) },
835 { "2s", TALK_ID(2, UNIT_SEC) },
836 { "3s", TALK_ID(3, UNIT_SEC) },
837 { "4s", TALK_ID(4, UNIT_SEC) },
838 { "5s", TALK_ID(5, UNIT_SEC) },
839 { "6s", TALK_ID(6, UNIT_SEC) },
840 { "8s", TALK_ID(8, UNIT_SEC) },
841 { "10s", TALK_ID(10, UNIT_SEC) },
842 { "15s", TALK_ID(15, UNIT_SEC) },
843 { "20s", TALK_ID(20, UNIT_SEC) },
844 { "25s", TALK_ID(25, UNIT_SEC) },
845 { "30s", TALK_ID(30, UNIT_SEC) },
846 { "45s", TALK_ID(45, UNIT_SEC) },
847 { "60s", TALK_ID(60, UNIT_SEC) }
849 return set_option(str(LANG_FFRW_STEP), &global_settings.ff_rewind_min_step,
850 INT, names, 14, NULL );
853 static bool set_fade_on_stop(void)
855 return set_bool( str(LANG_FADE_ON_STOP), &global_settings.fade_on_stop );
859 static bool ff_rewind_accel(void)
861 static const struct opt_items names[] = {
862 { STR(LANG_OFF) },
863 { "2x/1s", TALK_ID(1, UNIT_SEC) },
864 { "2x/2s", TALK_ID(2, UNIT_SEC) },
865 { "2x/3s", TALK_ID(3, UNIT_SEC) },
866 { "2x/4s", TALK_ID(4, UNIT_SEC) },
867 { "2x/5s", TALK_ID(5, UNIT_SEC) },
868 { "2x/6s", TALK_ID(6, UNIT_SEC) },
869 { "2x/7s", TALK_ID(7, UNIT_SEC) },
870 { "2x/8s", TALK_ID(8, UNIT_SEC) },
871 { "2x/9s", TALK_ID(9, UNIT_SEC) },
872 { "2x/10s", TALK_ID(10, UNIT_SEC) },
873 { "2x/11s", TALK_ID(11, UNIT_SEC) },
874 { "2x/12s", TALK_ID(12, UNIT_SEC) },
875 { "2x/13s", TALK_ID(13, UNIT_SEC) },
876 { "2x/14s", TALK_ID(14, UNIT_SEC) },
877 { "2x/15s", TALK_ID(15, UNIT_SEC) }
879 return set_option(str(LANG_FFRW_ACCEL), &global_settings.ff_rewind_accel,
880 INT, names, 16, NULL );
883 static bool browse_current(void)
885 return set_bool( str(LANG_FOLLOW), &global_settings.browse_current );
888 static bool custom_wps_browse(void)
890 return rockbox_browse(ROCKBOX_DIR, SHOW_WPS);
893 static bool custom_cfg_browse(void)
895 return rockbox_browse(ROCKBOX_DIR, SHOW_CFG);
898 static bool language_browse(void)
900 language_changed = false;
901 rockbox_browse(ROCKBOX_DIR LANG_DIR, SHOW_LNG);
902 return language_changed;
905 static bool voice_menus(void)
907 bool ret;
908 bool temp = global_settings.talk_menu;
909 /* work on a temp variable first, avoid "life" disabling */
910 ret = set_bool( str(LANG_VOICE_MENU), &temp );
911 global_settings.talk_menu = temp;
912 return ret;
915 /* this is used 2 times below, so it saves memory to put it in global scope */
916 static const struct opt_items voice_names[] = {
917 { STR(LANG_OFF) },
918 { STR(LANG_VOICE_NUMBER) },
919 { STR(LANG_VOICE_SPELL) },
920 { STR(LANG_VOICE_DIR_HOVER) }
923 static bool voice_dirs(void)
925 return set_option( str(LANG_VOICE_DIR),
926 &global_settings.talk_dir, INT, voice_names, 4, NULL);
929 static bool voice_files(void)
931 int oldval = global_settings.talk_file;
932 bool ret;
933 ret = set_option( str(LANG_VOICE_FILE),
934 &global_settings.talk_file, INT, voice_names, 4, NULL);
935 if (oldval != 3 && global_settings.talk_file == 3)
936 { /* force reload if newly talking thumbnails,
937 because the clip presence is cached only if enabled */
938 reload_directory();
940 return ret;
943 static bool voice_menu(void)
945 int m;
946 bool result;
948 static const struct menu_item items[] = {
949 { ID2P(LANG_VOICE_MENU), voice_menus },
950 { ID2P(LANG_VOICE_DIR), voice_dirs },
951 { ID2P(LANG_VOICE_FILE), voice_files }
954 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
955 NULL, NULL, NULL);
956 result = menu_run(m);
957 menu_exit(m);
958 return result;
961 #ifdef HAVE_LCD_BITMAP
962 static bool font_browse(void)
964 return rockbox_browse(ROCKBOX_DIR FONT_DIR, SHOW_FONT);
967 static bool scroll_bar(void)
969 return set_bool( str(LANG_SCROLL_BAR), &global_settings.scrollbar );
972 static bool status_bar(void)
974 return set_bool( str(LANG_STATUS_BAR), &global_settings.statusbar );
977 #if CONFIG_KEYPAD == RECORDER_PAD
978 static bool button_bar(void)
980 return set_bool( str(LANG_BUTTON_BAR), &global_settings.buttonbar );
982 #endif /* CONFIG_KEYPAD == RECORDER_PAD */
983 #endif /* HAVE_LCD_BITMAP */
985 static bool ff_rewind_settings_menu(void)
987 int m;
988 bool result;
990 static const struct menu_item items[] = {
991 { ID2P(LANG_FFRW_STEP), ff_rewind_min_step },
992 { ID2P(LANG_FFRW_ACCEL), ff_rewind_accel },
995 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
996 NULL, NULL, NULL);
997 result = menu_run(m);
998 menu_exit(m);
1000 return result;
1003 static bool id3_order(void)
1005 return set_bool_options( str(LANG_ID3_ORDER),
1006 &global_settings.id3_v1_first,
1007 STR(LANG_ID3_V1_FIRST),
1008 STR(LANG_ID3_V2_FIRST),
1009 mpeg_id3_options);
1012 static bool playback_settings_menu(void)
1014 int m;
1015 bool result;
1017 static const struct menu_item items[] = {
1018 { ID2P(LANG_SHUFFLE), shuffle },
1019 { ID2P(LANG_REPEAT), repeat_mode },
1020 { ID2P(LANG_PLAY_SELECTED), play_selected },
1021 { ID2P(LANG_RESUME), resume },
1022 { ID2P(LANG_WIND_MENU), ff_rewind_settings_menu },
1023 { ID2P(LANG_MP3BUFFER_MARGIN), buffer_margin },
1024 { ID2P(LANG_FADE_ON_STOP), set_fade_on_stop },
1025 { ID2P(LANG_ID3_ORDER), id3_order },
1028 bool old_shuffle = global_settings.playlist_shuffle;
1030 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1031 NULL, NULL, NULL);
1032 result = menu_run(m);
1033 menu_exit(m);
1035 if (old_shuffle != global_settings.playlist_shuffle)
1037 if (global_settings.playlist_shuffle)
1039 playlist_randomise(NULL, current_tick, true);
1041 else
1043 playlist_sort(NULL, true);
1046 return result;
1049 static bool bookmark_settings_menu(void)
1051 int m;
1052 bool result;
1054 static const struct menu_item items[] = {
1055 { ID2P(LANG_BOOKMARK_SETTINGS_AUTOCREATE), autocreatebookmark},
1056 { ID2P(LANG_BOOKMARK_SETTINGS_AUTOLOAD), autoloadbookmark},
1057 { ID2P(LANG_BOOKMARK_SETTINGS_MAINTAIN_RECENT_BOOKMARKS), useMRB},
1060 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1061 NULL, NULL, NULL);
1062 result = menu_run(m);
1063 menu_exit(m);
1065 return result;
1067 static bool reset_settings(void)
1069 bool done=false;
1070 int line;
1071 int button;
1073 lcd_clear_display();
1075 #ifdef HAVE_LCD_CHARCELLS
1076 line = 0;
1077 #else
1078 line = 1;
1079 lcd_puts(0,0,str(LANG_RESET_ASK_RECORDER));
1080 #endif
1081 lcd_puts(0,line,str(LANG_RESET_CONFIRM));
1082 lcd_puts(0,line+1,str(LANG_RESET_CANCEL));
1084 lcd_update();
1086 while(!done) {
1087 button = button_get(true);
1088 switch(button) {
1089 case SETTINGS_OK:
1090 settings_reset();
1091 settings_apply();
1092 lcd_clear_display();
1093 lcd_puts(0,1,str(LANG_RESET_DONE_CLEAR));
1094 done = true;
1095 break;
1097 case SETTINGS_CANCEL:
1098 lcd_clear_display();
1099 lcd_puts(0,1,str(LANG_RESET_DONE_CANCEL));
1100 done = true;
1101 break;
1103 default:
1104 if(default_event_handler(button) == SYS_USB_CONNECTED)
1105 return true;
1109 lcd_puts(0,0,str(LANG_RESET_DONE_SETTING));
1110 lcd_update();
1111 sleep(HZ);
1112 return false;
1115 static bool fileview_settings_menu(void)
1117 int m;
1118 bool result;
1120 static const struct menu_item items[] = {
1121 { ID2P(LANG_SORT_CASE), sort_case },
1122 { ID2P(LANG_SORT_DIR), sort_dir },
1123 { ID2P(LANG_SORT_FILE), sort_file },
1124 { ID2P(LANG_FILTER), dir_filter },
1125 { ID2P(LANG_FOLLOW), browse_current },
1126 { ID2P(LANG_SHOW_ICONS), show_icons },
1129 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1130 NULL, NULL, NULL);
1131 result = menu_run(m);
1132 menu_exit(m);
1133 return result;
1137 static bool scroll_settings_menu(void)
1139 int m;
1140 bool result;
1142 static const struct menu_item items[] = {
1143 { ID2P(LANG_SCROLL_SPEED), scroll_speed },
1144 { ID2P(LANG_SCROLL_DELAY), scroll_delay },
1145 #ifdef HAVE_LCD_BITMAP
1146 { ID2P(LANG_SCROLL_STEP), scroll_step },
1147 #endif
1148 { ID2P(LANG_BIDIR_SCROLL), bidir_limit },
1149 #ifdef HAVE_LCD_CHARCELLS
1150 { ID2P(LANG_JUMP_SCROLL), jump_scroll },
1151 { ID2P(LANG_JUMP_SCROLL_DELAY), jump_scroll_delay },
1152 #endif
1155 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1156 NULL, NULL, NULL);
1157 result = menu_run(m);
1158 menu_exit(m);
1159 return result;
1162 static bool lcd_settings_menu(void)
1164 int m;
1165 bool result;
1167 static const struct menu_item items[] = {
1168 #ifdef CONFIG_BACKLIGHT
1169 { ID2P(LANG_BACKLIGHT), backlight_timer },
1170 #ifdef HAVE_CHARGING
1171 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_on_when_charging },
1172 #endif
1173 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight },
1174 #endif /* CONFIG_BACKLIGHT */
1175 { ID2P(LANG_CONTRAST), contrast },
1176 #ifdef HAVE_LCD_BITMAP
1177 { ID2P(LANG_INVERT), invert },
1178 { ID2P(LANG_FLIP_DISPLAY), flip_display },
1179 { ID2P(LANG_INVERT_CURSOR), invert_cursor },
1180 #endif
1183 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1184 NULL, NULL, NULL);
1185 result = menu_run(m);
1186 menu_exit(m);
1187 return result;
1190 #ifdef HAVE_LCD_BITMAP
1191 static bool bars_settings_menu(void)
1193 int m;
1194 bool result;
1196 static const struct menu_item items[] = {
1197 { ID2P(LANG_SCROLL_BAR), scroll_bar },
1198 { ID2P(LANG_STATUS_BAR), status_bar },
1199 #if CONFIG_KEYPAD == RECORDER_PAD
1200 { ID2P(LANG_BUTTON_BAR), button_bar },
1201 #endif
1202 { ID2P(LANG_VOLUME_DISPLAY), volume_type },
1203 { ID2P(LANG_BATTERY_DISPLAY), battery_type },
1206 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1207 NULL, NULL, NULL);
1208 result = menu_run(m);
1209 menu_exit(m);
1210 return result;
1212 #endif
1215 static bool display_settings_menu(void)
1217 int m;
1218 bool result;
1220 static const struct menu_item items[] = {
1221 #ifdef HAVE_LCD_BITMAP
1222 { ID2P(LANG_CUSTOM_FONT), font_browse },
1223 #endif
1224 { ID2P(LANG_WHILE_PLAYING), custom_wps_browse },
1225 { ID2P(LANG_LCD_MENU), lcd_settings_menu },
1226 { ID2P(LANG_SCROLL_MENU), scroll_settings_menu },
1227 #ifdef HAVE_LCD_BITMAP
1228 { ID2P(LANG_BARS_MENU), bars_settings_menu },
1229 { ID2P(LANG_PM_MENU), peak_meter_menu },
1230 #endif
1233 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1234 NULL, NULL, NULL);
1235 result = menu_run(m);
1236 menu_exit(m);
1237 return result;
1241 static bool firmware_browse(void)
1243 return rockbox_browse(ROCKBOX_DIR, SHOW_MOD);
1246 static bool battery_settings_menu(void)
1248 int m;
1249 bool result;
1251 static const struct menu_item items[] = {
1252 #ifdef HAVE_CHARGE_CTRL
1253 { ID2P(LANG_DISCHARGE), deep_discharge },
1254 { ID2P(LANG_TRICKLE_CHARGE), trickle_charge },
1255 #endif
1256 #ifndef SIMULATOR
1257 { ID2P(LANG_BATTERY_CAPACITY), battery_capacity },
1258 #else
1259 #ifndef HAVE_CHARGE_CTRL
1260 { "Dummy", NULL }, /* to have an entry at all, in the simulator */
1261 #endif
1262 #endif
1265 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1266 NULL, NULL, NULL);
1267 result = menu_run(m);
1268 menu_exit(m);
1269 return result;
1272 #ifndef HAVE_MMC
1273 static bool disk_settings_menu(void)
1275 int m;
1276 bool result;
1278 static const struct menu_item items[] = {
1279 { ID2P(LANG_SPINDOWN), spindown },
1280 #ifdef HAVE_ATA_POWER_OFF
1281 { ID2P(LANG_POWEROFF), poweroff },
1282 #endif
1285 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1286 NULL, NULL, NULL);
1287 result = menu_run(m);
1288 menu_exit(m);
1289 return result;
1291 #endif /* !HAVE_MMC */
1293 #ifdef HAVE_RTC
1294 static bool time_settings_menu(void)
1296 int m;
1297 bool result;
1299 static const struct menu_item items[] = {
1300 { ID2P(LANG_TIME), timedate_set },
1301 { ID2P(LANG_TIMEFORMAT), timeformat_set },
1304 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1305 NULL, NULL, NULL);
1306 result = menu_run(m);
1307 menu_exit(m);
1308 return result;
1310 #endif
1312 static bool manage_settings_menu(void)
1314 int m;
1315 bool result;
1317 static const struct menu_item items[] = {
1318 { ID2P(LANG_CUSTOM_CFG), custom_cfg_browse },
1319 { ID2P(LANG_FIRMWARE), firmware_browse },
1320 { ID2P(LANG_RESET), reset_settings },
1321 { ID2P(LANG_SAVE_SETTINGS), settings_save_config },
1324 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1325 NULL, NULL, NULL);
1326 result = menu_run(m);
1327 menu_exit(m);
1328 return result;
1331 static bool limits_settings_menu(void)
1333 int m;
1334 bool result;
1336 static const struct menu_item items[] = {
1337 { ID2P(LANG_MAX_FILES_IN_DIR), max_files_in_dir },
1338 { ID2P(LANG_MAX_FILES_IN_PLAYLIST), max_files_in_playlist },
1341 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1342 NULL, NULL, NULL);
1343 result = menu_run(m);
1344 menu_exit(m);
1345 return result;
1349 static bool system_settings_menu(void)
1351 int m;
1352 bool result;
1354 static const struct menu_item items[] = {
1355 { ID2P(LANG_BATTERY_MENU), battery_settings_menu },
1356 #ifndef HAVE_MMC
1357 { ID2P(LANG_DISK_MENU), disk_settings_menu },
1358 #endif
1359 #ifdef HAVE_RTC
1360 { ID2P(LANG_TIME_MENU), time_settings_menu },
1361 #endif
1362 { ID2P(LANG_POWEROFF_IDLE), poweroff_idle_timer },
1363 { ID2P(LANG_SLEEP_TIMER), sleeptimer_screen },
1364 #ifdef HAVE_ALARM_MOD
1365 { ID2P(LANG_ALARM_MOD_ALARM_MENU), alarm_screen },
1366 #endif
1367 { ID2P(LANG_LIMITS_MENU), limits_settings_menu },
1368 #if CONFIG_HWCODEC == MAS3507D
1369 { ID2P(LANG_LINE_IN), line_in },
1370 #endif
1371 #ifdef HAVE_CHARGING
1372 { ID2P(LANG_CAR_ADAPTER_MODE), car_adapter_mode },
1373 #endif
1374 { ID2P(LANG_MANAGE_MENU), manage_settings_menu },
1377 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1378 NULL, NULL, NULL);
1379 result = menu_run(m);
1380 menu_exit(m);
1381 return result;
1384 bool settings_menu(void)
1386 int m;
1387 bool result;
1389 static const struct menu_item items[] = {
1390 { ID2P(LANG_PLAYBACK), playback_settings_menu },
1391 { ID2P(LANG_FILE), fileview_settings_menu },
1392 { ID2P(LANG_DISPLAY), display_settings_menu },
1393 { ID2P(LANG_SYSTEM), system_settings_menu },
1394 { ID2P(LANG_BOOKMARK_SETTINGS),bookmark_settings_menu },
1395 { ID2P(LANG_LANGUAGE), language_browse },
1396 { ID2P(LANG_VOICE), voice_menu },
1399 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
1400 NULL, NULL, NULL);
1401 result = menu_run(m);
1402 menu_exit(m);
1403 return result;