summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-05-13 17:11:45 +0200
committerChristian Soffke <christian.soffke@gmail.com>2024-05-13 18:18:45 +0200
commitfdba79cd7777d3318531995083984fade98afae8 (patch)
tree908ff3d74414e133456b9f29aab4fedb58f5ba0c
parent8eeef333a15d99a38f733a45612728dfae66b862 (diff)
downloadrockbox-fdba79cd7777d3318531995083984fade98afae8.tar.gz
rockbox-fdba79cd7777d3318531995083984fade98afae8.zip
shortcuts: refactor sleeptimer / talk_timedate
move some functions around, with no effect on behavior Change-Id: I4638a28f5ff2a851534a3dd696ea7e763029cb2f
-rw-r--r--apps/menus/settings_menu.c62
-rw-r--r--apps/menus/time_menu.c17
-rw-r--r--apps/misc.c76
-rw-r--r--apps/misc.h13
-rw-r--r--apps/shortcuts.c164
5 files changed, 173 insertions, 159 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
62static int selectivesoftlock_callback(int action, 63static 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 */
500const 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
516static 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 501char* 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)
523char* 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
540int sleep_timer_voice(int selected_item, void*data) 509int 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 */
558int 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,
587MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); 539MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
588MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); 540MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
589MENUITEM_FUNCTION_DYNTEXT(sleeptimer_toggle, 0, toggle_sleeptimer, 541MENUITEM_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);
592MENUITEM_SETTING(sleeptimer_duration, 544MENUITEM_SETTING(sleeptimer_duration,
593 &global_settings.sleeptimer_duration, 545 &global_settings.sleeptimer_duration,
diff --git a/apps/menus/time_menu.c b/apps/menus/time_menu.c
index e6b5637047..79a38a1a57 100644
--- a/apps/menus/time_menu.c
+++ b/apps/menus/time_menu.c
@@ -144,23 +144,6 @@ MENUITEM_FUNCTION(alarm_wake_up_screen, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN),
144 144
145#endif /* HAVE_RTC_ALARM */ 145#endif /* HAVE_RTC_ALARM */
146 146
147void talk_timedate(void)
148{
149 struct tm *tm = get_time();
150 if (!global_settings.talk_menu)
151 return;
152 talk_id(VOICE_CURRENT_TIME, false);
153 if (valid_time(tm))
154 {
155 talk_time(tm, true);
156 talk_date(get_time(), true);
157 }
158 else
159 {
160 talk_id(LANG_UNKNOWN, true);
161 }
162}
163
164static void draw_timedate(struct viewport *vp, struct screen *display) 147static void draw_timedate(struct viewport *vp, struct screen *display)
165{ 148{
166 struct tm *tm = get_time(); 149 struct tm *tm = get_time();
diff --git a/apps/misc.c b/apps/misc.c
index 4faadb8130..7ba229a6f3 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1467,6 +1467,82 @@ void format_time(char* buf, int buf_size, long t)
1467 t < 0, "-", units_in[UNIT_IDX_HR], hashours, ":", 1467 t < 0, "-", units_in[UNIT_IDX_HR], hashours, ":",
1468 hashours+1, units_in[UNIT_IDX_MIN], units_in[UNIT_IDX_SEC]); 1468 hashours+1, units_in[UNIT_IDX_MIN], units_in[UNIT_IDX_SEC]);
1469} 1469}
1470
1471const char* format_sleeptimer(char* buffer, size_t buffer_size,
1472 int value, const char* unit)
1473{
1474 (void) unit;
1475 int minutes, hours;
1476
1477 if (value) {
1478 hours = value / 60;
1479 minutes = value - (hours * 60);
1480 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
1481 return buffer;
1482 } else {
1483 return str(LANG_OFF);
1484 }
1485}
1486
1487static int seconds_to_min(int secs)
1488{
1489 return (secs + 10) / 60; /* round up for 50+ seconds */
1490}
1491
1492char* string_sleeptimer(char *buffer, size_t buffer_len)
1493{
1494 int sec = get_sleep_timer();
1495 char timer_buf[10];
1496
1497 snprintf(buffer, buffer_len, "%s (%s)",
1498 str(sec ? LANG_SLEEP_TIMER_CANCEL_CURRENT
1499 : LANG_SLEEP_TIMER_START_CURRENT),
1500 format_sleeptimer(timer_buf, sizeof(timer_buf),
1501 sec ? seconds_to_min(sec)
1502 : global_settings.sleeptimer_duration, NULL));
1503 return buffer;
1504}
1505
1506/* If a sleep timer is running, cancel it, otherwise start one */
1507int toggle_sleeptimer(void)
1508{
1509 set_sleeptimer_duration(get_sleep_timer() ? 0
1510 : global_settings.sleeptimer_duration);
1511 return 0;
1512}
1513
1514void talk_sleeptimer(void)
1515{
1516 int seconds = get_sleep_timer();
1517 long talk_ids[] = {
1518 seconds ? LANG_SLEEP_TIMER_CANCEL_CURRENT
1519 : LANG_SLEEP_TIMER_START_CURRENT,
1520 VOICE_PAUSE,
1521 (seconds ? seconds_to_min(seconds)
1522 : global_settings.sleeptimer_duration) | UNIT_MIN << UNIT_SHIFT,
1523 TALK_FINAL_ID
1524 };
1525 talk_idarray(talk_ids, true);
1526}
1527
1528#if CONFIG_RTC
1529void talk_timedate(void)
1530{
1531 struct tm *tm = get_time();
1532 if (!global_settings.talk_menu)
1533 return;
1534 talk_id(VOICE_CURRENT_TIME, false);
1535 if (valid_time(tm))
1536 {
1537 talk_time(tm, true);
1538 talk_date(get_time(), true);
1539 }
1540 else
1541 {
1542 talk_id(LANG_UNKNOWN, true);
1543 }
1544}
1545#endif /* CONFIG_RTC */
1470#endif /* !defined(CHECKWPS) && !defined(DBTOOL)*/ 1546#endif /* !defined(CHECKWPS) && !defined(DBTOOL)*/
1471 1547
1472/** 1548/**
diff --git a/apps/misc.h b/apps/misc.h
index fd48ccf648..28a982d1da 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -93,6 +93,19 @@ const char *format_time_auto(char *buffer, int buf_len, long value,
93 */ 93 */
94void format_time(char* buf, int buf_size, long t); 94void format_time(char* buf, int buf_size, long t);
95 95
96const char* format_sleeptimer(char* buffer, size_t buffer_size,
97 int value, const char* unit);
98
99/* A string representation of either whether a sleep timer will be started or
100 canceled, and how long it will be or how long is remaining in brackets */
101char* string_sleeptimer(char *buffer, size_t buffer_len);
102int toggle_sleeptimer(void);
103void talk_sleeptimer(void);
104
105#if CONFIG_RTC
106void talk_timedate(void);
107#endif
108
96/* Ask the user if they really want to erase the current dynamic playlist 109/* Ask the user if they really want to erase the current dynamic playlist
97 * returns true if the playlist should be replaced */ 110 * returns true if the playlist should be replaced */
98bool warn_on_pl_erase(void); 111bool warn_on_pl_erase(void);
diff --git a/apps/shortcuts.c b/apps/shortcuts.c
index a32c298f6d..a7fbe7ccec 100644
--- a/apps/shortcuts.c
+++ b/apps/shortcuts.c
@@ -421,8 +421,6 @@ void shortcuts_init(void)
421 --buflib_move_lock; 421 --buflib_move_lock;
422} 422}
423 423
424char* sleep_timer_getname(int selected_item, void * data,
425 char *buffer, size_t buffer_len); /* settings_menu.c */
426static const char * shortcut_menu_get_name(int selected_item, void * data, 424static const char * shortcut_menu_get_name(int selected_item, void * data,
427 char * buffer, size_t buffer_len) 425 char * buffer, size_t buffer_len)
428{ 426{
@@ -440,11 +438,9 @@ static const char * shortcut_menu_get_name(int selected_item, void * data,
440#if CONFIG_RTC 438#if CONFIG_RTC
441 && !sc->u.timedata.talktime 439 && !sc->u.timedata.talktime
442#endif 440#endif
443 ) /* Toggle Sleep Timer */ 441 ) /* String representation for toggling sleep timer */
444 { 442 return string_sleeptimer(buffer, buffer_len);
445 sleep_timer_getname(selected_item, data, buffer, buffer_len); 443
446 return buffer;
447 }
448 return sc->name; 444 return sc->name;
449 } 445 }
450 else if ((sc->type == SHORTCUT_SHUTDOWN || sc->type == SHORTCUT_REBOOT) && 446 else if ((sc->type == SHORTCUT_SHUTDOWN || sc->type == SHORTCUT_REBOOT) &&
@@ -466,81 +462,6 @@ static const char * shortcut_menu_get_name(int selected_item, void * data,
466 return sc->name[0] ? sc->name : sc->u.path; 462 return sc->name[0] ? sc->name : sc->u.path;
467} 463}
468 464
469static int shortcut_menu_speak_item(int selected_item, void * data);
470static int shortcut_menu_get_action(int action, struct gui_synclist *lists)
471{
472 (void)lists;
473 if (action == ACTION_STD_OK || action == ACTION_STD_MENU)
474 return ACTION_STD_CANCEL;
475 else if (action == ACTION_STD_QUICKSCREEN && action != ACTION_STD_CONTEXT)
476 return ACTION_STD_CANCEL;
477 else if (action == ACTION_STD_CONTEXT)
478 {
479 int selection = gui_synclist_get_sel_pos(lists);
480
481 if (confirm_delete_yesno("") != YESNO_YES)
482 {
483 gui_synclist_set_title(lists, lists->title, lists->title_icon);
484 shortcut_menu_speak_item(selection, NULL);
485 return ACTION_REDRAW;
486 }
487
488 remove_shortcut(selection);
489 gui_synclist_set_nb_items(lists, shortcut_count);
490 gui_synclist_set_title(lists, lists->title, lists->title_icon);
491 if (selection >= shortcut_count)
492 gui_synclist_select_item(lists, shortcut_count - 1);
493 first_idx_to_writeback = 0;
494 overwrite_shortcuts = true;
495 shortcuts_ata_idle_callback();
496 if (shortcut_count == 0)
497 return ACTION_STD_CANCEL;
498
499 shortcut_menu_speak_item(gui_synclist_get_sel_pos(lists), NULL);
500 return ACTION_REDRAW;
501 }
502 return action;
503}
504
505static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data)
506{
507 (void)data;
508 int icon;
509 struct shortcut *sc = get_shortcut(selected_item);
510 if (!sc)
511 return Icon_NOICON;
512 if (sc->icon == Icon_NOICON)
513 {
514
515 switch (sc->type)
516 {
517 case SHORTCUT_FILE:
518 return filetype_get_icon(filetype_get_attr(sc->u.path));
519 case SHORTCUT_BROWSER:
520 icon = filetype_get_icon(filetype_get_attr(sc->u.path));
521 if (icon <= 0)
522 icon = Icon_Folder;
523 return icon;
524 case SHORTCUT_SETTING:
525 return Icon_Menu_setting;
526 case SHORTCUT_DEBUGITEM:
527 return Icon_Menu_functioncall;
528 case SHORTCUT_PLAYLISTMENU:
529 return Icon_Playlist;
530 case SHORTCUT_SHUTDOWN:
531 case SHORTCUT_REBOOT:
532 return Icon_System_menu;
533 case SHORTCUT_TIME:
534 return Icon_Menu_functioncall;
535 default:
536 break;
537 }
538 }
539 return sc->icon;
540}
541
542void talk_timedate(void);
543int sleep_timer_voice(int selected_item, void*data); /* settings_menu.c */
544static int shortcut_menu_speak_item(int selected_item, void * data) 465static int shortcut_menu_speak_item(int selected_item, void * data)
545{ 466{
546 (void)data; 467 (void)data;
@@ -605,7 +526,7 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
605 else 526 else
606#endif 527#endif
607 if (sc->u.timedata.sleep_timeout < 0) 528 if (sc->u.timedata.sleep_timeout < 0)
608 sleep_timer_voice(selected_item, data); 529 talk_sleeptimer();
609 else if (sc->name[0]) 530 else if (sc->name[0])
610 talk_spell(sc->name, false); 531 talk_spell(sc->name, false);
611 break; 532 break;
@@ -626,9 +547,78 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
626 return 0; 547 return 0;
627} 548}
628 549
629const char* sleep_timer_formatter(char* buffer, size_t buffer_size, 550static int shortcut_menu_get_action(int action, struct gui_synclist *lists)
630 int value, const char* unit); 551{
631int toggle_sleeptimer(void); /* settings_menu.c */ 552 (void)lists;
553 if (action == ACTION_STD_OK || action == ACTION_STD_MENU)
554 return ACTION_STD_CANCEL;
555 else if (action == ACTION_STD_QUICKSCREEN && action != ACTION_STD_CONTEXT)
556 return ACTION_STD_CANCEL;
557 else if (action == ACTION_STD_CONTEXT)
558 {
559 int selection = gui_synclist_get_sel_pos(lists);
560
561 if (confirm_delete_yesno("") != YESNO_YES)
562 {
563 gui_synclist_set_title(lists, lists->title, lists->title_icon);
564 shortcut_menu_speak_item(selection, NULL);
565 return ACTION_REDRAW;
566 }
567
568 remove_shortcut(selection);
569 gui_synclist_set_nb_items(lists, shortcut_count);
570 gui_synclist_set_title(lists, lists->title, lists->title_icon);
571 if (selection >= shortcut_count)
572 gui_synclist_select_item(lists, shortcut_count - 1);
573 first_idx_to_writeback = 0;
574 overwrite_shortcuts = true;
575 shortcuts_ata_idle_callback();
576 if (shortcut_count == 0)
577 return ACTION_STD_CANCEL;
578
579 shortcut_menu_speak_item(gui_synclist_get_sel_pos(lists), NULL);
580 return ACTION_REDRAW;
581 }
582 return action;
583}
584
585static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data)
586{
587 (void)data;
588 int icon;
589 struct shortcut *sc = get_shortcut(selected_item);
590 if (!sc)
591 return Icon_NOICON;
592 if (sc->icon == Icon_NOICON)
593 {
594
595 switch (sc->type)
596 {
597 case SHORTCUT_FILE:
598 return filetype_get_icon(filetype_get_attr(sc->u.path));
599 case SHORTCUT_BROWSER:
600 icon = filetype_get_icon(filetype_get_attr(sc->u.path));
601 if (icon <= 0)
602 icon = Icon_Folder;
603 return icon;
604 case SHORTCUT_SETTING:
605 return Icon_Menu_setting;
606 case SHORTCUT_DEBUGITEM:
607 return Icon_Menu_functioncall;
608 case SHORTCUT_PLAYLISTMENU:
609 return Icon_Playlist;
610 case SHORTCUT_SHUTDOWN:
611 case SHORTCUT_REBOOT:
612 return Icon_System_menu;
613 case SHORTCUT_TIME:
614 return Icon_Menu_functioncall;
615 default:
616 break;
617 }
618 }
619 return sc->icon;
620}
621
632int do_shortcut_menu(void *ignored) 622int do_shortcut_menu(void *ignored)
633{ 623{
634 (void)ignored; 624 (void)ignored;
@@ -761,7 +751,7 @@ int do_shortcut_menu(void *ignored)
761 { 751 {
762 set_sleeptimer_duration(sc->u.timedata.sleep_timeout); 752 set_sleeptimer_duration(sc->u.timedata.sleep_timeout);
763 splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), 753 splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER),
764 sleep_timer_formatter(timer_buf, sizeof(timer_buf), 754 format_sleeptimer(timer_buf, sizeof(timer_buf),
765 sc->u.timedata.sleep_timeout, 755 sc->u.timedata.sleep_timeout,
766 NULL)); 756 NULL));
767 } 757 }