summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Peskett <rockbox@peskett.co.uk>2012-03-29 07:58:31 +0100
committerNick Peskett <rockbox@peskett.co.uk>2012-03-29 09:01:33 +0200
commit10d8717e9460eca1fe76e4897f94fb544f25e197 (patch)
tree5763785c79a6b3a32323f9783bc22f9f0983c2bf
parent0e4a29811bda742062e126db5b8572459f511739 (diff)
downloadrockbox-10d8717e9460eca1fe76e4897f94fb544f25e197.tar.gz
rockbox-10d8717e9460eca1fe76e4897f94fb544f25e197.zip
Split sleep timer activation and default duration setting.
Where before there was a single sleep timer menu option which handled initiating/ cancelling a sleep timer as well as setting the default duration, now there is one menu option to either start or cancel a sleep timer and another to set the default duration that will be used for future sleep timers. Change-Id: Ibea3711ec6406845ff5d0c0568fe5d1739eb8deb Reviewed-on: http://gerrit.rockbox.org/201 Reviewed-by: Nick Peskett <rockbox@peskett.co.uk>
-rw-r--r--apps/lang/english.lang16
-rw-r--r--apps/menus/settings_menu.c96
-rw-r--r--manual/configure_rockbox/startup_shutdown_options.tex22
3 files changed, 81 insertions, 53 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
378static void sleep_timer_set(int minutes)
379{
380 if (minutes)
381 global_settings.sleeptimer_duration = minutes;
382 set_sleep_timer(minutes * 60);
383}
384
385static 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
396static int seconds_to_min(int secs) 378static 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 */
401static char* sleep_timer_getname(int selected_item, void * data, char *buffer) 385static 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 */
419static 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 */
428static 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
441MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); 446MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
442MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL); 447MENUITEM_SETTING(poweroff, &global_settings.poweroff, NULL);
443MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, sleep_timer, NULL, 448MENUITEM_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 */ 451MENUITEM_SETTING(sleeptimer_duration,
452 &global_settings.sleeptimer_duration,
453 sleeptimer_duration_cb);
447MENUITEM_SETTING(sleeptimer_on_startup, 454MENUITEM_SETTING(sleeptimer_on_startup,
448 &global_settings.sleeptimer_on_startup, NULL); 455 &global_settings.sleeptimer_on_startup, NULL);
449MENUITEM_SETTING(keypress_restarts_sleeptimer, 456MENUITEM_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 );
diff --git a/manual/configure_rockbox/startup_shutdown_options.tex b/manual/configure_rockbox/startup_shutdown_options.tex
index ef84358af7..20dd21356d 100644
--- a/manual/configure_rockbox/startup_shutdown_options.tex
+++ b/manual/configure_rockbox/startup_shutdown_options.tex
@@ -43,14 +43,20 @@ are run at startup, or initiate a shutdown when conditions are met.
43 The \setting{Sleep Timer} powers off your \dap{} after a given time, whether 43 The \setting{Sleep Timer} powers off your \dap{} after a given time, whether
44 playing or not. 44 playing or not.
45 \begin{description} 45 \begin{description}
46 \item[Sleep Timer:] 46 \item[Start Sleep Timer (\emph{duration}):]
47 Shown when the \setting{Sleep Timer} is inactive, it can be set from 47 Shown when the \setting{Sleep Timer} is inactive, this option will
48 \setting{Off} to 5 hours in 5 minute steps. 48 initiate a \setting{Sleep Timer} with the duration shown in brackets.
49 While the \setting{Sleep Timer} is reset on boot, the value selected is 49 \item[Cancel Sleep Timer (\emph{remaining}):]
50 retained and will be used as the default from then on. 50 Shown when the \setting{Sleep Timer} is active, this option will cancel
51 \item[Cancel Sleep Timer (h:mm):] 51 the current \setting{Sleep Timer}.\\
52 Shown when the \setting{Sleep Timer} is active, this option disables the 52 The time remaining before completion is shown in brackets.
53 current \setting{Sleep Timer}. 53 \item[Default Sleep Timer Duration:]
54 The default number of minutes a new \setting{Sleep Timer} will run
55 for.\\
56 The values range from 5 minutes to 5 hours in 5 minute steps.\\
57 If a timer is currently active, the timer's duration will be set to the
58 newly entered value.\\
59 The value set is persistent, see \reference{ref:config_file_options}.
54 \item[Start Sleep Timer On Boot:] 60 \item[Start Sleep Timer On Boot:]
55 If set, a \setting{Sleep Timer} will be initiated when the device 61 If set, a \setting{Sleep Timer} will be initiated when the device
56 starts. 62 starts.