diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/lang/english.lang | 16 | ||||
-rw-r--r-- | apps/menus/settings_menu.c | 96 |
2 files changed, 67 insertions, 45 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index e1f68895c7..cd575e9cfa 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -12863,7 +12863,7 @@ | |||
12863 | </phrase> | 12863 | </phrase> |
12864 | <phrase> | 12864 | <phrase> |
12865 | id: LANG_SLEEP_TIMER_DURATION | 12865 | id: LANG_SLEEP_TIMER_DURATION |
12866 | desc: default sleep timer duration in minutes (unused in UI) | 12866 | desc: default sleep timer duration in minutes |
12867 | user: core | 12867 | user: core |
12868 | <source> | 12868 | <source> |
12869 | *: "Default Sleep Timer Duration" | 12869 | *: "Default Sleep Timer Duration" |
@@ -13024,3 +13024,17 @@ | |||
13024 | quickscreen: "Use Shortcuts Menu Instead of Quick Screen" | 13024 | quickscreen: "Use Shortcuts Menu Instead of Quick Screen" |
13025 | </voice> | 13025 | </voice> |
13026 | </phrase> | 13026 | </phrase> |
13027 | <phrase> | ||
13028 | id: LANG_SLEEP_TIMER_START_CURRENT | ||
13029 | desc: shown when a sleep timer isn't running | ||
13030 | user: core | ||
13031 | <source> | ||
13032 | *: "Start Sleep Timer" | ||
13033 | </source> | ||
13034 | <dest> | ||
13035 | *: "Start Sleep Timer" | ||
13036 | </dest> | ||
13037 | <voice> | ||
13038 | *: "Start Sleep Timer" | ||
13039 | </voice> | ||
13040 | </phrase> | ||
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 0e3e861834..9cdff01d86 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c | |||
@@ -375,29 +375,13 @@ const char* sleep_timer_formatter(char* buffer, size_t buffer_size, | |||
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | static void sleep_timer_set(int minutes) | ||
379 | { | ||
380 | if (minutes) | ||
381 | global_settings.sleeptimer_duration = minutes; | ||
382 | set_sleep_timer(minutes * 60); | ||
383 | } | ||
384 | |||
385 | static int sleep_timer(void) | ||
386 | { | ||
387 | int minutes = global_settings.sleeptimer_duration; | ||
388 | if (get_sleep_timer()) | ||
389 | sleep_timer_set(0); | ||
390 | else | ||
391 | set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes, | ||
392 | &sleep_timer_set, 5, 0, 300, sleep_timer_formatter); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static int seconds_to_min(int secs) | 378 | static int seconds_to_min(int secs) |
397 | { | 379 | { |
398 | return (secs + 10) / 60; /* round up for 50+ seconds */ | 380 | return (secs + 10) / 60; /* round up for 50+ seconds */ |
399 | } | 381 | } |
400 | 382 | ||
383 | /* A string representation of either whether a sleep timer will be started or | ||
384 | canceled, and how long it will be or how long is remaining in brackets */ | ||
401 | static char* sleep_timer_getname(int selected_item, void * data, char *buffer) | 385 | static char* sleep_timer_getname(int selected_item, void * data, char *buffer) |
402 | { | 386 | { |
403 | (void)selected_item; | 387 | (void)selected_item; |
@@ -405,16 +389,12 @@ static char* sleep_timer_getname(int selected_item, void * data, char *buffer) | |||
405 | int sec = get_sleep_timer(); | 389 | int sec = get_sleep_timer(); |
406 | char timer_buf[10]; | 390 | char timer_buf[10]; |
407 | /* we have no sprintf, so MAX_PATH is a guess */ | 391 | /* we have no sprintf, so MAX_PATH is a guess */ |
408 | if (sec > 0) | 392 | snprintf(buffer, MAX_PATH, "%s (%s)", |
409 | { /* show cancel and countdown if running */ | 393 | str(sec ? LANG_SLEEP_TIMER_CANCEL_CURRENT |
410 | snprintf(buffer, MAX_PATH, "%s (%s)", | 394 | : LANG_SLEEP_TIMER_START_CURRENT), |
411 | str(LANG_SLEEP_TIMER_CANCEL_CURRENT), | 395 | sleep_timer_formatter(timer_buf, sizeof(timer_buf), |
412 | sleep_timer_formatter(timer_buf, sizeof(timer_buf), | 396 | sec ? seconds_to_min(sec) |
413 | seconds_to_min(sec), NULL)); | 397 | : global_settings.sleeptimer_duration, NULL)); |
414 | } | ||
415 | else | ||
416 | snprintf(buffer, MAX_PATH, "%s", str(LANG_SLEEP_TIMER)); | ||
417 | |||
418 | return buffer; | 398 | return buffer; |
419 | } | 399 | } |
420 | 400 | ||
@@ -423,27 +403,54 @@ static int sleep_timer_voice(int selected_item, void*data) | |||
423 | (void)selected_item; | 403 | (void)selected_item; |
424 | (void)data; | 404 | (void)data; |
425 | int seconds = get_sleep_timer(); | 405 | int seconds = get_sleep_timer(); |
426 | if (seconds > 0) | 406 | long talk_ids[] = { |
407 | seconds ? LANG_SLEEP_TIMER_CANCEL_CURRENT | ||
408 | : LANG_SLEEP_TIMER_START_CURRENT, | ||
409 | VOICE_PAUSE, | ||
410 | (seconds ? seconds_to_min(seconds) | ||
411 | : global_settings.sleeptimer_duration) | UNIT_MIN << UNIT_SHIFT, | ||
412 | TALK_FINAL_ID | ||
413 | }; | ||
414 | talk_idarray(talk_ids, true); | ||
415 | return 0; | ||
416 | } | ||
417 | |||
418 | /* If a sleep timer is running, cancel it, otherwise start one */ | ||
419 | static int toggle_sleeptimer(void) | ||
420 | { | ||
421 | set_sleep_timer(get_sleep_timer() ? 0 | ||
422 | : global_settings.sleeptimer_duration * 60); | ||
423 | return 0; | ||
424 | } | ||
425 | |||
426 | /* Handle restarting a current sleep timer to the newly set default | ||
427 | duration */ | ||
428 | static int sleeptimer_duration_cb(int action, | ||
429 | const struct menu_item_ex *this_item) | ||
430 | { | ||
431 | (void)this_item; | ||
432 | static int initial_duration; | ||
433 | switch (action) | ||
427 | { | 434 | { |
428 | long talk_ids[] = { | 435 | case ACTION_ENTER_MENUITEM: |
429 | LANG_SLEEP_TIMER_CANCEL_CURRENT, | 436 | initial_duration = global_settings.sleeptimer_duration; |
430 | VOICE_PAUSE, | 437 | break; |
431 | seconds_to_min(seconds) | UNIT_MIN << UNIT_SHIFT, | 438 | case ACTION_EXIT_MENUITEM: |
432 | TALK_FINAL_ID | 439 | if (initial_duration != global_settings.sleeptimer_duration |
433 | }; | 440 | && get_sleep_timer()) |
434 | talk_idarray(talk_ids, true); | 441 | set_sleep_timer(global_settings.sleeptimer_duration * 60); |
435 | } | 442 | } |
436 | else | 443 | return action; |
437 | talk_id(LANG_SLEEP_TIMER, true); | ||
438 | return 0; | ||
439 | } | 444 | } |
440 | 445 | ||
441 | MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); | 446 | MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); |
442 | MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); | 447 | MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); |
443 | MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, sleep_timer, NULL, | 448 | MENUITEM_FUNCTION_DYNTEXT(sleeptimer_toggle, 0, toggle_sleeptimer, NULL, |
444 | sleep_timer_getname, sleep_timer_voice, NULL, NULL, | 449 | sleep_timer_getname, sleep_timer_voice, NULL, |
445 | Icon_Menu_setting); | 450 | NULL, Icon_NOICON); |
446 | /* make it look like a setting to the user */ | 451 | MENUITEM_SETTING(sleeptimer_duration, |
452 | &global_settings.sleeptimer_duration, | ||
453 | sleeptimer_duration_cb); | ||
447 | MENUITEM_SETTING(sleeptimer_on_startup, | 454 | MENUITEM_SETTING(sleeptimer_on_startup, |
448 | &global_settings.sleeptimer_on_startup, NULL); | 455 | &global_settings.sleeptimer_on_startup, NULL); |
449 | MENUITEM_SETTING(keypress_restarts_sleeptimer, | 456 | MENUITEM_SETTING(keypress_restarts_sleeptimer, |
@@ -453,7 +460,8 @@ MAKE_MENU(startup_shutdown_menu, ID2P(LANG_STARTUP_SHUTDOWN), | |||
453 | 0, Icon_System_menu, | 460 | 0, Icon_System_menu, |
454 | &start_screen, | 461 | &start_screen, |
455 | &poweroff, | 462 | &poweroff, |
456 | &sleep_timer_call, | 463 | &sleeptimer_toggle, |
464 | &sleeptimer_duration, | ||
457 | &sleeptimer_on_startup, | 465 | &sleeptimer_on_startup, |
458 | &keypress_restarts_sleeptimer | 466 | &keypress_restarts_sleeptimer |
459 | ); | 467 | ); |