diff options
Diffstat (limited to 'apps/menus/settings_menu.c')
-rw-r--r-- | apps/menus/settings_menu.c | 62 |
1 files changed, 7 insertions, 55 deletions
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 03c17b24e5..1e1572f15e 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c | |||
@@ -57,6 +57,7 @@ | |||
57 | #endif | 57 | #endif |
58 | #include "plugin.h" | 58 | #include "plugin.h" |
59 | #include "onplay.h" | 59 | #include "onplay.h" |
60 | #include "misc.h" | ||
60 | 61 | ||
61 | #ifndef HAS_BUTTON_HOLD | 62 | #ifndef HAS_BUTTON_HOLD |
62 | static int selectivesoftlock_callback(int action, | 63 | static int selectivesoftlock_callback(int action, |
@@ -496,69 +497,20 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), | |||
496 | /***********************************/ | 497 | /***********************************/ |
497 | /* STARTUP/SHUTDOWN MENU */ | 498 | /* STARTUP/SHUTDOWN MENU */ |
498 | 499 | ||
499 | /* sleep timer option */ | ||
500 | const char* sleep_timer_formatter(char* buffer, size_t buffer_size, | ||
501 | int value, const char* unit) | ||
502 | { | ||
503 | (void) unit; | ||
504 | int minutes, hours; | ||
505 | |||
506 | if (value) { | ||
507 | hours = value / 60; | ||
508 | minutes = value - (hours * 60); | ||
509 | snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); | ||
510 | return buffer; | ||
511 | } else { | ||
512 | return str(LANG_OFF); | ||
513 | } | ||
514 | } | ||
515 | |||
516 | static int seconds_to_min(int secs) | ||
517 | { | ||
518 | return (secs + 10) / 60; /* round up for 50+ seconds */ | ||
519 | } | ||
520 | 500 | ||
521 | /* A string representation of either whether a sleep timer will be started or | 501 | char* sleeptimer_getname(int selected_item, void * data, |
522 | canceled, and how long it will be or how long is remaining in brackets */ | 502 | char *buffer, size_t buffer_len) |
523 | char* sleep_timer_getname(int selected_item, void * data, | ||
524 | char *buffer, size_t buffer_len) | ||
525 | { | 503 | { |
526 | (void)selected_item; | 504 | (void)selected_item; |
527 | (void)data; | 505 | (void)data; |
528 | int sec = get_sleep_timer(); | 506 | return string_sleeptimer(buffer, buffer_len); |
529 | char timer_buf[10]; | ||
530 | |||
531 | snprintf(buffer, buffer_len, "%s (%s)", | ||
532 | str(sec ? LANG_SLEEP_TIMER_CANCEL_CURRENT | ||
533 | : LANG_SLEEP_TIMER_START_CURRENT), | ||
534 | sleep_timer_formatter(timer_buf, sizeof(timer_buf), | ||
535 | sec ? seconds_to_min(sec) | ||
536 | : global_settings.sleeptimer_duration, NULL)); | ||
537 | return buffer; | ||
538 | } | 507 | } |
539 | 508 | ||
540 | int sleep_timer_voice(int selected_item, void*data) | 509 | int sleeptimer_voice(int selected_item, void*data) |
541 | { | 510 | { |
542 | (void)selected_item; | 511 | (void)selected_item; |
543 | (void)data; | 512 | (void)data; |
544 | int seconds = get_sleep_timer(); | 513 | talk_sleeptimer(); |
545 | long talk_ids[] = { | ||
546 | seconds ? LANG_SLEEP_TIMER_CANCEL_CURRENT | ||
547 | : LANG_SLEEP_TIMER_START_CURRENT, | ||
548 | VOICE_PAUSE, | ||
549 | (seconds ? seconds_to_min(seconds) | ||
550 | : global_settings.sleeptimer_duration) | UNIT_MIN << UNIT_SHIFT, | ||
551 | TALK_FINAL_ID | ||
552 | }; | ||
553 | talk_idarray(talk_ids, true); | ||
554 | return 0; | ||
555 | } | ||
556 | |||
557 | /* If a sleep timer is running, cancel it, otherwise start one */ | ||
558 | int toggle_sleeptimer(void) | ||
559 | { | ||
560 | set_sleeptimer_duration(get_sleep_timer() ? 0 | ||
561 | : global_settings.sleeptimer_duration); | ||
562 | return 0; | 514 | return 0; |
563 | } | 515 | } |
564 | 516 | ||
@@ -587,7 +539,7 @@ static int sleeptimer_duration_cb(int action, | |||
587 | MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); | 539 | MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); |
588 | MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); | 540 | MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); |
589 | MENUITEM_FUNCTION_DYNTEXT(sleeptimer_toggle, 0, toggle_sleeptimer, | 541 | MENUITEM_FUNCTION_DYNTEXT(sleeptimer_toggle, 0, toggle_sleeptimer, |
590 | sleep_timer_getname, sleep_timer_voice, NULL, | 542 | sleeptimer_getname, sleeptimer_voice, NULL, |
591 | NULL, Icon_NOICON); | 543 | NULL, Icon_NOICON); |
592 | MENUITEM_SETTING(sleeptimer_duration, | 544 | MENUITEM_SETTING(sleeptimer_duration, |
593 | &global_settings.sleeptimer_duration, | 545 | &global_settings.sleeptimer_duration, |