diff options
author | Nick Peskett <rockbox@peskett.co.uk> | 2011-12-26 08:26:38 +0000 |
---|---|---|
committer | Nick Peskett <rockbox@peskett.co.uk> | 2011-12-26 08:26:38 +0000 |
commit | 2ecaca91f028fec8bae7b66ffb014f60afd7b34f (patch) | |
tree | 54efdbda16def5680097c11f060e9e5e606dd023 /apps/menus/settings_menu.c | |
parent | 3bc771d669676e9295c3f369955b7e46f5b413d2 (diff) | |
download | rockbox-2ecaca91f028fec8bae7b66ffb014f60afd7b34f.tar.gz rockbox-2ecaca91f028fec8bae7b66ffb014f60afd7b34f.zip |
New General Settings submenu: Startup/Shutdown
A dedicated submenu for items which are run at startup, or initiate a shutdown.
Currently containing: Start Screen, Idle Poweroff, Sleep Timer & Start Sleep Timer on Boot.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31435 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/menus/settings_menu.c')
-rw-r--r-- | apps/menus/settings_menu.c | 109 |
1 files changed, 103 insertions, 6 deletions
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index bcb182ebca..cce5dd751d 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c | |||
@@ -215,9 +215,6 @@ MAKE_MENU(disk_menu, ID2P(LANG_DISK_MENU), 0, Icon_NOICON, | |||
215 | ); | 215 | ); |
216 | #endif | 216 | #endif |
217 | 217 | ||
218 | /* System menu */ | ||
219 | MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); | ||
220 | |||
221 | /* Limits menu */ | 218 | /* Limits menu */ |
222 | MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL); | 219 | MENUITEM_SETTING(max_files_in_dir, &global_settings.max_files_in_dir, NULL); |
223 | MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL); | 220 | MENUITEM_SETTING(max_files_in_playlist, &global_settings.max_files_in_playlist, NULL); |
@@ -276,7 +273,6 @@ MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL); | |||
276 | #ifdef HAVE_LINEOUT_POWEROFF | 273 | #ifdef HAVE_LINEOUT_POWEROFF |
277 | MENUITEM_SETTING(lineout_onoff, &global_settings.lineout_active, NULL); | 274 | MENUITEM_SETTING(lineout_onoff, &global_settings.lineout_active, NULL); |
278 | #endif | 275 | #endif |
279 | MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); | ||
280 | #ifdef USB_ENABLE_HID | 276 | #ifdef USB_ENABLE_HID |
281 | MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL); | 277 | MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL); |
282 | MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL); | 278 | MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL); |
@@ -303,14 +299,12 @@ MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NU | |||
303 | 299 | ||
304 | MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), | 300 | MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), |
305 | 0, Icon_System_menu, | 301 | 0, Icon_System_menu, |
306 | &start_screen, | ||
307 | #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1) | 302 | #if (BATTERY_CAPACITY_INC > 0) || (BATTERY_TYPES_COUNT > 1) |
308 | &battery_menu, | 303 | &battery_menu, |
309 | #endif | 304 | #endif |
310 | #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE) | 305 | #if defined(HAVE_DIRCACHE) || defined(HAVE_DISK_STORAGE) |
311 | &disk_menu, | 306 | &disk_menu, |
312 | #endif | 307 | #endif |
313 | &poweroff, | ||
314 | &limits_menu, | 308 | &limits_menu, |
315 | #ifdef HAVE_MORSE_INPUT | 309 | #ifdef HAVE_MORSE_INPUT |
316 | &morse_input, | 310 | &morse_input, |
@@ -354,6 +348,108 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), | |||
354 | /* SYSTEM MENU */ | 348 | /* SYSTEM MENU */ |
355 | /***********************************/ | 349 | /***********************************/ |
356 | 350 | ||
351 | /***********************************/ | ||
352 | /* STARTUP/SHUTDOWN MENU */ | ||
353 | |||
354 | /* sleep timer option */ | ||
355 | const char* sleep_timer_formatter(char* buffer, size_t buffer_size, | ||
356 | int value, const char* unit) | ||
357 | { | ||
358 | (void) unit; | ||
359 | int minutes, hours; | ||
360 | |||
361 | if (value) { | ||
362 | hours = value / 60; | ||
363 | minutes = value - (hours * 60); | ||
364 | snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); | ||
365 | return buffer; | ||
366 | } else { | ||
367 | return str(LANG_OFF); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | static void sleep_timer_set(int minutes) | ||
372 | { | ||
373 | if (minutes) | ||
374 | global_settings.sleeptimer_duration = minutes; | ||
375 | set_sleep_timer(minutes * 60); | ||
376 | } | ||
377 | |||
378 | static int sleep_timer(void) | ||
379 | { | ||
380 | int minutes = global_settings.sleeptimer_duration; | ||
381 | if (get_sleep_timer()) | ||
382 | sleep_timer_set(0); | ||
383 | else | ||
384 | set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes, | ||
385 | &sleep_timer_set, 5, 0, 300, sleep_timer_formatter); | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | static int seconds_to_min(int secs) | ||
390 | { | ||
391 | return (secs + 10) / 60; /* round up for 50+ seconds */ | ||
392 | } | ||
393 | |||
394 | static char* sleep_timer_getname(int selected_item, void * data, char *buffer) | ||
395 | { | ||
396 | (void)selected_item; | ||
397 | (void)data; | ||
398 | int sec = get_sleep_timer(); | ||
399 | char timer_buf[10]; | ||
400 | /* we have no sprintf, so MAX_PATH is a guess */ | ||
401 | if (sec > 0) | ||
402 | { /* show cancel and countdown if running */ | ||
403 | snprintf(buffer, MAX_PATH, "%s (%s)", | ||
404 | str(LANG_SLEEP_TIMER_CANCEL_CURRENT), | ||
405 | sleep_timer_formatter(timer_buf, sizeof(timer_buf), | ||
406 | seconds_to_min(sec), NULL)); | ||
407 | } | ||
408 | else | ||
409 | snprintf(buffer, MAX_PATH, "%s", str(LANG_SLEEP_TIMER)); | ||
410 | |||
411 | return buffer; | ||
412 | } | ||
413 | |||
414 | static int sleep_timer_voice(int selected_item, void*data) | ||
415 | { | ||
416 | (void)selected_item; | ||
417 | (void)data; | ||
418 | int seconds = get_sleep_timer(); | ||
419 | if (seconds > 0) | ||
420 | { | ||
421 | long talk_ids[] = { | ||
422 | LANG_SLEEP_TIMER_CANCEL_CURRENT, | ||
423 | VOICE_PAUSE, | ||
424 | seconds_to_min(seconds) | UNIT_MIN << UNIT_SHIFT, | ||
425 | TALK_FINAL_ID | ||
426 | }; | ||
427 | talk_idarray(talk_ids, true); | ||
428 | } | ||
429 | else | ||
430 | talk_id(LANG_SLEEP_TIMER, true); | ||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); | ||
435 | MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); | ||
436 | MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, sleep_timer, NULL, | ||
437 | sleep_timer_getname, sleep_timer_voice, NULL, NULL, | ||
438 | Icon_Menu_setting); | ||
439 | /* make it look like a setting to the user */ | ||
440 | MENUITEM_SETTING(sleeptimer_on_startup, | ||
441 | &global_settings.sleeptimer_on_startup, NULL); | ||
442 | |||
443 | MAKE_MENU(startup_shutdown_menu, ID2P(LANG_STARTUP_SHUTDOWN), | ||
444 | 0, Icon_System_menu, | ||
445 | &start_screen, | ||
446 | &poweroff, | ||
447 | &sleep_timer_call, | ||
448 | &sleeptimer_on_startup | ||
449 | ); | ||
450 | |||
451 | /* STARTUP/SHUTDOWN MENU */ | ||
452 | /***********************************/ | ||
357 | 453 | ||
358 | /***********************************/ | 454 | /***********************************/ |
359 | /* BOOKMARK MENU */ | 455 | /* BOOKMARK MENU */ |
@@ -513,6 +609,7 @@ MAKE_MENU(settings_menu_item, ID2P(LANG_GENERAL_SETTINGS), 0, | |||
513 | &tagcache_menu, | 609 | &tagcache_menu, |
514 | #endif | 610 | #endif |
515 | &display_menu, &system_menu, | 611 | &display_menu, &system_menu, |
612 | &startup_shutdown_menu, | ||
516 | &bookmark_settings_menu, | 613 | &bookmark_settings_menu, |
517 | #ifdef HAVE_TAGCACHE | 614 | #ifdef HAVE_TAGCACHE |
518 | #if CONFIG_CODEC == SWCODEC | 615 | #if CONFIG_CODEC == SWCODEC |