summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-05-11 18:18:51 +0200
committerChristian Soffke <christian.soffke@gmail.com>2024-05-13 18:06:55 +0200
commitf631bfe5b4fb78d676a37583bb4aa8f3d2e3bf1b (patch)
tree64aa20ca87b55cb7bc5e5ce0fb3ace256dfae552
parentb8b4fdd999178d6292cb6fef97ad3484a1a2dcef (diff)
downloadrockbox-f631bfe5b4fb78d676a37583bb4aa8f3d2e3bf1b.tar.gz
rockbox-f631bfe5b4fb78d676a37583bb4aa8f3d2e3bf1b.zip
shortcuts: sleep timer: allow omitting number of minutes
'sleep' can now appear in the data field of a 'time' shortcut without being followed by a number, allowing you to stop a running timer, or to start a new one using the default sleep timer duration (the duration setting can already be added to the Shortcuts menu as well). Also see here: https://forums.rockbox.org/index.php/topic,54312.msg250940.html Change-Id: I9d0e62ef1b6187c35133067349729a4d94273c7a
-rw-r--r--apps/menus/settings_menu.c8
-rw-r--r--apps/shortcuts.c53
-rw-r--r--manual/main_menu/main.tex6
3 files changed, 50 insertions, 17 deletions
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c
index 191079deb8..03c17b24e5 100644
--- a/apps/menus/settings_menu.c
+++ b/apps/menus/settings_menu.c
@@ -520,8 +520,8 @@ static int seconds_to_min(int secs)
520 520
521/* A string representation of either whether a sleep timer will be started or 521/* A string representation of either whether a sleep timer will be started or
522 canceled, and how long it will be or how long is remaining in brackets */ 522 canceled, and how long it will be or how long is remaining in brackets */
523static char* sleep_timer_getname(int selected_item, void * data, 523char* sleep_timer_getname(int selected_item, void * data,
524 char *buffer, size_t buffer_len) 524 char *buffer, size_t buffer_len)
525{ 525{
526 (void)selected_item; 526 (void)selected_item;
527 (void)data; 527 (void)data;
@@ -537,7 +537,7 @@ static char* sleep_timer_getname(int selected_item, void * data,
537 return buffer; 537 return buffer;
538} 538}
539 539
540static int sleep_timer_voice(int selected_item, void*data) 540int sleep_timer_voice(int selected_item, void*data)
541{ 541{
542 (void)selected_item; 542 (void)selected_item;
543 (void)data; 543 (void)data;
@@ -555,7 +555,7 @@ static int sleep_timer_voice(int selected_item, void*data)
555} 555}
556 556
557/* If a sleep timer is running, cancel it, otherwise start one */ 557/* If a sleep timer is running, cancel it, otherwise start one */
558static int toggle_sleeptimer(void) 558int toggle_sleeptimer(void)
559{ 559{
560 set_sleeptimer_duration(get_sleep_timer() ? 0 560 set_sleeptimer_duration(get_sleep_timer() ? 0
561 : global_settings.sleeptimer_duration); 561 : global_settings.sleeptimer_duration);
diff --git a/apps/shortcuts.c b/apps/shortcuts.c
index c0f9ed2612..c64976c46c 100644
--- a/apps/shortcuts.c
+++ b/apps/shortcuts.c
@@ -244,8 +244,11 @@ static void shortcuts_ata_idle_callback(void)
244#endif 244#endif
245 { 245 {
246 write(fd, "sleep ", 6); 246 write(fd, "sleep ", 6);
247 len = snprintf(buf, MAX_PATH, "%d", sc->u.timedata.sleep_timeout); 247 if (sc->u.timedata.sleep_timeout >= 0)
248 write(fd, buf, len); 248 {
249 len = snprintf(buf, MAX_PATH, "%d", sc->u.timedata.sleep_timeout);
250 write(fd, buf, len);
251 }
249 } 252 }
250 } 253 }
251 else 254 else
@@ -348,8 +351,12 @@ static int readline_cb(int n, char *buf, void *parameters)
348 sc->u.timedata.talktime = true; 351 sc->u.timedata.talktime = true;
349 else 352 else
350#endif 353#endif
351 if (!strncasecmp(value, "sleep ", strlen("sleep "))) 354 if (!strncasecmp(value, "sleep", strlen("sleep")))
352 sc->u.timedata.sleep_timeout = atoi(&value[strlen("sleep ")]); 355 {
356 /* 'sleep' may appear alone or followed by number after a space */
357 sc->u.timedata.sleep_timeout = strlen(&value[5]) > 1 ?
358 atoi(&value[strlen("sleep ")]) : -1;
359 }
353 else 360 else
354 sc->type = SHORTCUT_UNDEFINED; /* error */ 361 sc->type = SHORTCUT_UNDEFINED; /* error */
355 break; 362 break;
@@ -411,6 +418,8 @@ void shortcuts_init(void)
411 --buflib_move_lock; 418 --buflib_move_lock;
412} 419}
413 420
421char* sleep_timer_getname(int selected_item, void * data,
422 char *buffer, size_t buffer_len); /* settings_menu.c */
414static const char * shortcut_menu_get_name(int selected_item, void * data, 423static const char * shortcut_menu_get_name(int selected_item, void * data,
415 char * buffer, size_t buffer_len) 424 char * buffer, size_t buffer_len)
416{ 425{
@@ -420,8 +429,21 @@ static const char * shortcut_menu_get_name(int selected_item, void * data,
420 return ""; 429 return "";
421 if (sc->type == SHORTCUT_SETTING) 430 if (sc->type == SHORTCUT_SETTING)
422 return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)); 431 return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id));
423 else if (sc->type == SHORTCUT_SEPARATOR || sc->type == SHORTCUT_TIME) 432 else if (sc->type == SHORTCUT_SEPARATOR)
433 return sc->name;
434 else if (sc->type == SHORTCUT_TIME)
435 {
436 if (sc->u.timedata.sleep_timeout < 0
437#if CONFIG_RTC
438 && !sc->u.timedata.talktime
439#endif
440 ) /* Toggle Sleep Timer */
441 {
442 sleep_timer_getname(selected_item, data, buffer, buffer_len);
443 return buffer;
444 }
424 return sc->name; 445 return sc->name;
446 }
425 else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0') 447 else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0')
426 { 448 {
427 /* No translation support as only soft_shutdown has LANG_SHUTDOWN defined */ 449 /* No translation support as only soft_shutdown has LANG_SHUTDOWN defined */
@@ -513,6 +535,7 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data
513} 535}
514 536
515void talk_timedate(void); 537void talk_timedate(void);
538int sleep_timer_voice(int selected_item, void*data); /* settings_menu.c */
516static int shortcut_menu_speak_item(int selected_item, void * data) 539static int shortcut_menu_speak_item(int selected_item, void * data)
517{ 540{
518 (void)data; 541 (void)data;
@@ -576,7 +599,9 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
576 talk_timedate(); 599 talk_timedate();
577 else 600 else
578#endif 601#endif
579 if (sc->name[0]) 602 if (sc->u.timedata.sleep_timeout < 0)
603 sleep_timer_voice(selected_item, data);
604 else if (sc->name[0])
580 talk_spell(sc->name, false); 605 talk_spell(sc->name, false);
581 break; 606 break;
582 case SHORTCUT_SHUTDOWN: 607 case SHORTCUT_SHUTDOWN:
@@ -596,7 +621,7 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
596 621
597const char* sleep_timer_formatter(char* buffer, size_t buffer_size, 622const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
598 int value, const char* unit); 623 int value, const char* unit);
599 624int toggle_sleeptimer(void); /* settings_menu.c */
600int do_shortcut_menu(void *ignored) 625int do_shortcut_menu(void *ignored)
601{ 626{
602 (void)ignored; 627 (void)ignored;
@@ -717,10 +742,16 @@ int do_shortcut_menu(void *ignored)
717#endif 742#endif
718 { 743 {
719 char timer_buf[10]; 744 char timer_buf[10];
720 set_sleeptimer_duration(sc->u.timedata.sleep_timeout); 745 if (sc->u.timedata.sleep_timeout >= 0)
721 splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), 746 {
722 sleep_timer_formatter(timer_buf, sizeof(timer_buf), 747 set_sleeptimer_duration(sc->u.timedata.sleep_timeout);
723 sc->u.timedata.sleep_timeout, NULL)); 748 splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER),
749 sleep_timer_formatter(timer_buf, sizeof(timer_buf),
750 sc->u.timedata.sleep_timeout,
751 NULL));
752 }
753 else
754 toggle_sleeptimer();
724 } 755 }
725 break; 756 break;
726 case SHORTCUT_UNDEFINED: 757 case SHORTCUT_UNDEFINED:
diff --git a/manual/main_menu/main.tex b/manual/main_menu/main.tex
index fced43ab98..92ff26b2ec 100644
--- a/manual/main_menu/main.tex
+++ b/manual/main_menu/main.tex
@@ -325,8 +325,10 @@ Available types are:
325\item[separator] \config{data} is ignored; \config{name} can be used to display text, 325\item[separator] \config{data} is ignored; \config{name} can be used to display text,
326 or left blank to make the list more accessible with visual gaps 326 or left blank to make the list more accessible with visual gaps
327\item[time] \config{data} needs to be \opt{rtc}{either ``talk'' to talk the time, or }``sleep X'' 327\item[time] \config{data} needs to be \opt{rtc}{either ``talk'' to talk the time, or }``sleep X''
328 where X is the number of minutes to run the sleep timer for (0 to disable). \config{name} 328 where X can, optionally, be the number of minutes to run the sleep timer for (0 to disable).
329 is required for this shortcut type. 329 If ``sleep'' is not followed by a number, the sleep timer can be stopped, if running,
330 or started using the default duration; \config{name} will be ignored in that case. Otherwise
331 \config{name} is required for this shortcut type.
330\item[shutdown] \config{data} is ignored; \config{name} can be used to display text 332\item[shutdown] \config{data} is ignored; \config{name} can be used to display text
331\end{description} 333\end{description}
332 334