1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Jonathan Gordon
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 ****************************************************************************/
29 #include "sound_menu.h"
30 #include "exported_menus.h"
37 #include "powermgmt.h"
39 #include "alarm_menu.h"
48 #include "statusbar.h"
52 /***********************************/
56 static void tagcache_rebuild_with_splash(void)
59 gui_syncsplash(HZ
*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH
));
62 static void tagcache_update_with_splash(void)
65 gui_syncsplash(HZ
*2, ID2P(LANG_TAGCACHE_FORCE_UPDATE_SPLASH
));
68 #ifdef HAVE_TC_RAMCACHE
69 MENUITEM_SETTING(tagcache_ram
, &global_settings
.tagcache_ram
, NULL
);
71 MENUITEM_SETTING(tagcache_autoupdate
, &global_settings
.tagcache_autoupdate
, NULL
);
72 MENUITEM_FUNCTION(tc_init
, 0, ID2P(LANG_TAGCACHE_FORCE_UPDATE
),
73 (int(*)(void))tagcache_rebuild_with_splash
,
74 NULL
, NULL
, Icon_NOICON
);
75 MENUITEM_FUNCTION(tc_update
, 0, ID2P(LANG_TAGCACHE_UPDATE
),
76 (int(*)(void))tagcache_update_with_splash
,
77 NULL
, NULL
, Icon_NOICON
);
78 MENUITEM_SETTING(runtimedb
, &global_settings
.runtimedb
, NULL
);
79 MENUITEM_FUNCTION(tc_export
, 0, ID2P(LANG_TAGCACHE_EXPORT
),
80 (int(*)(void))tagtree_export
, NULL
,
82 MENUITEM_FUNCTION(tc_import
, 0, ID2P(LANG_TAGCACHE_IMPORT
),
83 (int(*)(void))tagtree_import
, NULL
,
85 MAKE_MENU(tagcache_menu
, ID2P(LANG_TAGCACHE
), 0, Icon_NOICON
,
86 #ifdef HAVE_TC_RAMCACHE
89 &tagcache_autoupdate
, &tc_init
, &tc_update
, &runtimedb
,
90 &tc_export
, &tc_import
);
91 #endif /* HAVE_TAGCACHE */
93 /***********************************/
95 /***********************************/
97 static int fileview_callback(int action
,const struct menu_item_ex
*this_item
);
98 MENUITEM_SETTING(sort_case
, &global_settings
.sort_case
, NULL
);
99 MENUITEM_SETTING(sort_dir
, &global_settings
.sort_dir
, fileview_callback
);
100 MENUITEM_SETTING(sort_file
, &global_settings
.sort_file
, fileview_callback
);
101 MENUITEM_SETTING(dirfilter
, &global_settings
.dirfilter
, NULL
);
102 MENUITEM_SETTING(show_filename_ext
, &global_settings
.show_filename_ext
, NULL
);
103 MENUITEM_SETTING(browse_current
, &global_settings
.browse_current
, NULL
);
104 MENUITEM_SETTING(show_path_in_browser
, &global_settings
.show_path_in_browser
, NULL
);
105 static int fileview_callback(int action
,const struct menu_item_ex
*this_item
)
108 int *variable
= this_item
->variable
;
111 case ACTION_ENTER_MENUITEM
: /* on entering an item */
114 case ACTION_EXIT_MENUITEM
: /* on exit */
115 if (*variable
!= oldval
)
116 reload_directory(); /* force reload if this has changed */
122 MAKE_MENU(file_menu
, ID2P(LANG_FILE
), 0, Icon_file_view_menu
,
123 &sort_case
, &sort_dir
, &sort_file
,
124 &dirfilter
, &show_filename_ext
, &browse_current
,
125 &show_path_in_browser
);
127 /***********************************/
130 /***********************************/
134 #if BATTERY_CAPACITY_INC > 0
135 MENUITEM_SETTING(battery_capacity
, &global_settings
.battery_capacity
, NULL
);
137 #if BATTERY_TYPES_COUNT > 1
138 MENUITEM_SETTING(battery_type
, &global_settings
.battery_type
, NULL
);
140 #ifdef HAVE_USB_POWER
142 static int usbcharging_callback(int action
,const struct menu_item_ex
*this_item
)
147 case ACTION_EXIT_MENUITEM
: /* on exit */
148 usb_charging_enable(global_settings
.usb_charging
);
153 MENUITEM_SETTING(usb_charging
, &global_settings
.usb_charging
, usbcharging_callback
);
156 MAKE_MENU(battery_menu
, ID2P(LANG_BATTERY_MENU
), 0, Icon_NOICON
,
157 #if BATTERY_CAPACITY_INC > 0
160 #if BATTERY_TYPES_COUNT > 1
163 #ifdef HAVE_USB_POWER
170 #ifndef HAVE_FLASH_STORAGE
171 MENUITEM_SETTING(disk_spindown
, &global_settings
.disk_spindown
, NULL
);
174 static int dircache_callback(int action
,const struct menu_item_ex
*this_item
)
179 case ACTION_EXIT_MENUITEM
: /* on exit */
180 switch (global_settings
.dircache
)
183 if (!dircache_is_enabled())
184 gui_syncsplash(HZ
*2, ID2P(LANG_PLEASE_REBOOT
));
187 if (dircache_is_enabled())
195 MENUITEM_SETTING(dircache
, &global_settings
.dircache
, dircache_callback
);
197 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
198 MAKE_MENU(disk_menu
, ID2P(LANG_DISK_MENU
), 0, Icon_NOICON
,
199 #ifndef HAVE_FLASH_STORAGE
210 static int timedate_set(void)
215 /* Make a local copy of the time struct */
216 memcpy(&tm
, get_time(), sizeof(struct tm
));
218 /* do some range checks */
219 /* This prevents problems with time/date setting after a power loss */
220 if (!valid_time(&tm
))
222 /* Macros to convert a 2-digit string to a decimal constant.
223 (YEAR), MONTH and DAY are set by the date command, which outputs
224 DAY as 00..31 and MONTH as 01..12. The leading zero would lead to
225 misinterpretation as an octal constant. */
226 #define S100(x) 1 ## x
227 #define C2DIG2DEC(x) (S100(x)-100)
232 tm
.tm_mday
= C2DIG2DEC(DAY
);
233 tm
.tm_mon
= C2DIG2DEC(MONTH
)-1;
235 tm
.tm_year
= YEAR
-1900;
238 result
= (int)set_time_screen(str(LANG_SET_TIME
), &tm
);
240 if(tm
.tm_year
!= -1) {
246 MENUITEM_FUNCTION(time_set
, 0, ID2P(LANG_SET_TIME
),
247 timedate_set
, NULL
, NULL
, Icon_NOICON
);
248 MENUITEM_SETTING(timeformat
, &global_settings
.timeformat
, NULL
);
249 MAKE_MENU(time_menu
, ID2P(LANG_TIME_MENU
), 0, Icon_NOICON
, &time_set
, &timeformat
);
253 MENUITEM_SETTING(poweroff
, &global_settings
.poweroff
, NULL
);
255 #ifdef HAVE_RTC_ALARM
256 MENUITEM_FUNCTION(alarm_screen_call
, 0, ID2P(LANG_ALARM_MOD_ALARM_MENU
),
257 (menu_function
)alarm_screen
, NULL
, NULL
, Icon_NOICON
);
258 #if CONFIG_TUNER || defined(HAVE_RECORDING)
260 #if CONFIG_TUNER && !defined(HAVE_RECORDING)
261 /* This need only be shown if we dont have recording, because if we do
262 then always show the setting item, because there will always be at least
264 static int alarm_callback(int action
,const struct menu_item_ex
*this_item
)
269 case ACTION_REQUEST_MENUITEM
:
270 if (radio_hardware_present() == 0)
271 return ACTION_EXIT_MENUITEM
;
277 #define alarm_callback NULL
278 #endif /* CONFIG_TUNER && !HAVE_RECORDING */
279 /* have to do this manually because the setting screen
280 doesnt handle variable item count */
281 static int alarm_setting(void)
283 struct opt_items items
[ALARM_START_COUNT
];
285 items
[i
].string
= str(LANG_RESUME_PLAYBACK
);
286 items
[i
].voice_id
= LANG_RESUME_PLAYBACK
;
289 if (radio_hardware_present())
291 items
[i
].string
= str(LANG_FM_RADIO
);
292 items
[i
].voice_id
= LANG_FM_RADIO
;
296 #ifdef HAVE_RECORDING
297 items
[i
].string
= str(LANG_RECORDING
);
298 items
[i
].voice_id
= LANG_RECORDING
;
301 return set_option(str(LANG_ALARM_WAKEUP_SCREEN
),
302 &global_settings
.alarm_wake_up_screen
,
303 INT
, items
, i
, NULL
);
306 MENUITEM_FUNCTION(alarm_wake_up_screen
, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN
),
307 alarm_setting
, NULL
, alarm_callback
, Icon_Menu_setting
);
308 #endif /* CONFIG_TUNER || defined(HAVE_RECORDING) */
309 #endif /* HAVE_RTC_ALARM */
312 MENUITEM_SETTING(max_files_in_dir
, &global_settings
.max_files_in_dir
, NULL
);
313 MENUITEM_SETTING(max_files_in_playlist
, &global_settings
.max_files_in_playlist
, NULL
);
314 MAKE_MENU(limits_menu
, ID2P(LANG_LIMITS_MENU
), 0, Icon_NOICON
,
315 &max_files_in_dir
, &max_files_in_playlist
);
317 #if CONFIG_CODEC == MAS3507D
318 void dac_line_in(bool enable
);
319 static int linein_callback(int action
,const struct menu_item_ex
*this_item
)
324 case ACTION_EXIT_MENUITEM
: /* on exit */
326 dac_line_in(global_settings
.line_in
);
332 MENUITEM_SETTING(line_in
, &global_settings
.line_in
, linein_callback
);
335 MENUITEM_SETTING(car_adapter_mode
, &global_settings
.car_adapter_mode
, NULL
);
337 MENUITEM_SETTING(start_screen
, &global_settings
.start_in_screen
, NULL
);
339 #ifdef HAVE_BUTTON_LIGHT
340 MENUITEM_SETTING(button_light_timeout
, &global_settings
.button_light_timeout
, NULL
);
343 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
344 MENUITEM_SETTING(buttonlight_brightness
, &global_settings
.buttonlight_brightness
, NULL
);
347 MAKE_MENU(system_menu
, ID2P(LANG_SYSTEM
),
350 #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1)
353 #if defined(HAVE_DIRCACHE) || !defined(HAVE_FLASH_STORAGE)
360 #ifdef HAVE_RTC_ALARM
362 #if defined(HAVE_RECORDING) || CONFIG_TUNER
363 &alarm_wake_up_screen
,
367 #if CONFIG_CODEC == MAS3507D
373 #ifdef HAVE_BUTTON_LIGHT
374 &button_light_timeout
,
376 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
377 &buttonlight_brightness
382 /***********************************/
385 /***********************************/
387 static int bmark_callback(int action
,const struct menu_item_ex
*this_item
)
392 case ACTION_EXIT_MENUITEM
: /* on exit */
393 if(global_settings
.autocreatebookmark
== BOOKMARK_RECENT_ONLY_YES
||
394 global_settings
.autocreatebookmark
== BOOKMARK_RECENT_ONLY_ASK
)
396 if(global_settings
.usemrb
== BOOKMARK_NO
)
397 global_settings
.usemrb
= BOOKMARK_YES
;
404 MENUITEM_SETTING(autocreatebookmark
,
405 &global_settings
.autocreatebookmark
, bmark_callback
);
406 MENUITEM_SETTING(autoloadbookmark
, &global_settings
.autoloadbookmark
, NULL
);
407 MENUITEM_SETTING(usemrb
, &global_settings
.usemrb
, NULL
);
408 MAKE_MENU(bookmark_settings_menu
, ID2P(LANG_BOOKMARK_SETTINGS
), 0,
410 &autocreatebookmark
, &autoloadbookmark
, &usemrb
);
412 /***********************************/
414 /***********************************/
416 static int talk_callback(int action
,const struct menu_item_ex
*this_item
);
417 MENUITEM_SETTING(talk_menu_item
, &global_settings
.talk_menu
, NULL
);
418 MENUITEM_SETTING(talk_dir_item
, &global_settings
.talk_dir
, NULL
);
419 MENUITEM_SETTING(talk_dir_clip_item
, &global_settings
.talk_dir_clip
, talk_callback
);
420 MENUITEM_SETTING(talk_file_item
, &global_settings
.talk_file
, NULL
);
421 MENUITEM_SETTING(talk_file_clip_item
, &global_settings
.talk_file_clip
, talk_callback
);
422 static int talk_callback(int action
,const struct menu_item_ex
*this_item
)
424 static int oldval
= 0;
427 case ACTION_ENTER_MENUITEM
:
428 oldval
= global_settings
.talk_file_clip
;
430 case ACTION_EXIT_MENUITEM
:
431 #if CONFIG_CODEC == SWCODEC
432 audio_set_crossfade(global_settings
.crossfade
);
434 if (this_item
== &talk_dir_clip_item
)
436 if (!oldval
&& global_settings
.talk_file_clip
)
438 /* force reload if newly talking thumbnails,
439 because the clip presence is cached only if enabled */
446 MAKE_MENU(voice_settings_menu
, ID2P(LANG_VOICE
), 0, Icon_Voice
,
447 &talk_menu_item
, &talk_dir_item
, &talk_dir_clip_item
,
448 &talk_file_item
, &talk_file_clip_item
);
450 /***********************************/
453 /***********************************/
455 char drivers
[16][32];
456 static char* usb_menu_getname(int item
, void * data
, char *buffer
)
458 (void)data
; (void)buffer
;
459 return drivers
[item
];
461 int usbdriver_menuitem(void)
463 struct gui_synclist lists
;
464 int action
, count
= 0;
465 char *s
= device_driver_names
, *e
;
470 strncpy(drivers
[count
++], s
, e
-s
);
473 } while (e
&& count
< 16);
475 strcpy(drivers
[count
++], s
);
476 for (action
=0; action
<count
; action
++)
478 if (!strcmp(drivers
[action
],
479 global_settings
.usb_stack_device_driver
))
483 gui_synclist_init(&lists
, usb_menu_getname
, drivers
, false, 1);
484 gui_synclist_set_title(&lists
, str(LANG_USBSTACK_DEVICE_DRIVER
), NOICON
);
485 gui_synclist_set_icon_callback(&lists
, NULL
);
486 gui_synclist_set_nb_items(&lists
, count
);
487 gui_synclist_select_item(&lists
, action
==count
?0:action
);
488 gui_synclist_draw(&lists
);
492 gui_syncstatusbar_draw(&statusbars
, true);
493 action
= get_action(CONTEXT_STD
, HZ
/5);
494 if (gui_synclist_do_button(&lists
, action
, LIST_WRAP_UNLESS_HELD
))
496 if (action
== ACTION_STD_CANCEL
)
498 /* setting was canceled */
501 else if (action
== ACTION_STD_OK
)
503 /* setting was accepted... save */
504 strcpy(global_settings
.usb_stack_device_driver
,
505 drivers
[gui_synclist_get_sel_pos(&lists
)]);
507 /* switch device driver */
508 usb_device_driver_bind(drivers
[gui_synclist_get_sel_pos(&lists
)]);
511 else if (action
== ACTION_REDRAW
)
512 gui_synclist_draw(&lists
);
513 else if(default_event_handler(action
) == SYS_USB_CONNECTED
)
519 MENUITEM_SETTING(usbstack_mode
, &global_settings
.usb_stack_mode
, NULL
);
520 MENUITEM_FUNCTION(usbdriver
, 0, ID2P(LANG_USBSTACK_DEVICE_DRIVER
),
521 usbdriver_menuitem
, 0, NULL
, Icon_NOICON
);
523 MAKE_MENU(usbstack_menu
, ID2P(LANG_USBSTACK
), 0, Icon_NOICON
,
524 &usbstack_mode
, &usbdriver
);
526 /***********************************/
529 /***********************************/
531 /***********************************/
533 static int language_browse(void)
535 return (int)rockbox_browse(LANG_DIR
, SHOW_LNG
);
537 MENUITEM_FUNCTION(browse_langs
, 0, ID2P(LANG_LANGUAGE
), language_browse
,
538 NULL
, NULL
, Icon_Language
);
540 MAKE_MENU(settings_menu_item
, ID2P(LANG_GENERAL_SETTINGS
), 0,
541 Icon_General_settings_menu
,
542 &playback_menu_item
, &playlist_settings
, &file_menu
,
546 &display_menu
, &system_menu
,
547 &bookmark_settings_menu
, &browse_langs
, &voice_settings_menu
553 /***********************************/