From 29b1ba3445a8acaffe0fb11c267869eccda80883 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 8 Dec 2011 10:23:46 +0000 Subject: [PATCH] shortcuts: talk the time and configure the sleep timeout Use "type: time" and "data: talk" to have the time voiced when the shortcut is run. use "type: time" and "data: sleep X" where X is the number of minutes to run the sleep timer for (0 means disable) the name field is required git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31178 a1c6a512-1295-4272-9138-f99709370657 --- apps/menus/main_menu.c | 2 +- apps/menus/time_menu.c | 2 +- apps/shortcuts.c | 54 ++++++++++++++++++++++++++++++++++----- apps/shortcuts.h | 1 + manual/main_menu/main.tex | 5 ++++ 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index b6ce9e75c6..130d0bc2d5 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c @@ -376,7 +376,7 @@ MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO), /* sleep Menu */ -static const char* sleep_timer_formatter(char* buffer, size_t buffer_size, +const char* sleep_timer_formatter(char* buffer, size_t buffer_size, int value, const char* unit) { (void) unit; diff --git a/apps/menus/time_menu.c b/apps/menus/time_menu.c index 9be335c8ee..a793809800 100644 --- a/apps/menus/time_menu.c +++ b/apps/menus/time_menu.c @@ -139,7 +139,7 @@ MENUITEM_FUNCTION(alarm_wake_up_screen, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN), MENUITEM_SETTING(sleeptimer_on_startup, &global_settings.sleeptimer_on_startup, NULL); -static void talk_timedate(void) +void talk_timedate(void) { struct tm *tm = get_time(); if (!global_settings.talk_menu) diff --git a/apps/shortcuts.c b/apps/shortcuts.c index 10c090f3eb..6997491424 100644 --- a/apps/shortcuts.c +++ b/apps/shortcuts.c @@ -55,6 +55,7 @@ static const char * const type_strings[SHORTCUT_TYPE_COUNT] = { [SHORTCUT_PLAYLISTMENU] = "playlist menu", [SHORTCUT_SEPARATOR] = "separator", [SHORTCUT_SHUTDOWN] = "shutdown", + [SHORTCUT_TIME] = "time", }; struct shortcut { @@ -64,6 +65,12 @@ struct shortcut { union { char path[MAX_PATH]; const struct settings_list *setting; + struct { +#if CONFIG_RTC + bool talktime; +#endif + int sleep_timeout; + } timedata; } u; }; #define SHORTCUTS_PER_HANDLE 32 @@ -135,11 +142,11 @@ static bool verify_shortcut(struct shortcut* sc) case SHORTCUT_BROWSER: case SHORTCUT_FILE: case SHORTCUT_PLAYLISTMENU: - if (sc->u.path[0] == '\0') - return false; - break; + return sc->u.path[0] != '0'; case SHORTCUT_SETTING: return sc->u.setting != NULL; + case SHORTCUT_TIME: + return sc->name[0] != '0'; case SHORTCUT_DEBUGITEM: case SHORTCUT_SEPARATOR: case SHORTCUT_SHUTDOWN: @@ -193,7 +200,7 @@ void shortcuts_ata_idle_callback(void* data) */ reset_shortcuts(); shortcuts_init(); - } + } first_idx_to_writeback = -1; } @@ -212,7 +219,6 @@ void shortcuts_add(enum shortcut_type type, const char* value) first_idx_to_writeback = shortcut_count - 1; register_storage_idle_func(shortcuts_ata_idle_callback); } - int readline_cb(int n, char *buf, void *parameters) { @@ -262,6 +268,20 @@ int readline_cb(int n, char *buf, void *parameters) case SHORTCUT_SETTING: sc->u.setting = find_setting_by_cfgname(value, NULL); break; + case SHORTCUT_TIME: +#if CONFIG_RTC + if (!strcasecmp(value, "talk")) + sc->u.timedata.talktime = true; + else +#endif + if (!strncasecmp(value, "sleep ", strlen("sleep "))) + { + sc->u.timedata.talktime = false; + sc->u.timedata.sleep_timeout = atoi(&value[strlen("sleep ")]); + } + else + sc->type = SHORTCUT_UNDEFINED; /* error */ + break; case SHORTCUT_SEPARATOR: case SHORTCUT_SHUTDOWN: break; @@ -314,7 +334,7 @@ static const char * shortcut_menu_get_name(int selected_item, void * data, return ""; if (sc->type == SHORTCUT_SETTING) return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)); - else if (sc->type == SHORTCUT_SEPARATOR) + else if (sc->type == SHORTCUT_SEPARATOR || sc->type == SHORTCUT_TIME) return sc->name; else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0') { @@ -354,6 +374,8 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data return Icon_Playlist; case SHORTCUT_SHUTDOWN: return Icon_System_menu; + case SHORTCUT_TIME: + return Icon_Menu_functioncall; default: break; } @@ -361,6 +383,10 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data return sc->icon; } +void talk_timedate(void); +const char* sleep_timer_formatter(char* buffer, size_t buffer_size, + int value, const char* unit); + int do_shortcut_menu(void *ignored) { (void)ignored; @@ -377,7 +403,7 @@ int do_shortcut_menu(void *ignored) list.title_icon = Icon_Bookmark; push_current_activity(ACTIVITY_SHORTCUTSMENU); - + while (done == GO_TO_PREVIOUS) { if (simplelist_show_list(&list)) @@ -434,6 +460,20 @@ int do_shortcut_menu(void *ignored) #endif sys_poweroff(); break; + case SHORTCUT_TIME: +#if CONFIG_RTC + if (sc->u.timedata.talktime) + talk_timedate(); + else +#endif + { + char timer_buf[10]; + set_sleep_timer(sc->u.timedata.sleep_timeout * 60); + splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), + sleep_timer_formatter(timer_buf, sizeof(timer_buf), + sc->u.timedata.sleep_timeout, NULL)); + } + break; case SHORTCUT_UNDEFINED: default: break; diff --git a/apps/shortcuts.h b/apps/shortcuts.h index c18834a66f..e5e05628bb 100644 --- a/apps/shortcuts.h +++ b/apps/shortcuts.h @@ -33,6 +33,7 @@ enum shortcut_type { SHORTCUT_PLAYLISTMENU, SHORTCUT_SEPARATOR, SHORTCUT_SHUTDOWN, + SHORTCUT_TIME, SHORTCUT_TYPE_COUNT }; diff --git a/manual/main_menu/main.tex b/manual/main_menu/main.tex index 4d3e223e0f..15da738e1b 100644 --- a/manual/main_menu/main.tex +++ b/manual/main_menu/main.tex @@ -281,6 +281,8 @@ settings. With a shortcut, \setting{Quick Screen}) \item A debug menu item can be displayed (useful for developers mostly) \item The \dap{} can be turned off + \item A shortcut to have the time spoken + \item A shortcut to confgure the sleep timer \end{itemize} \note{Shortcuts into the database are not possible} @@ -311,6 +313,9 @@ Available types are: \item[separator] \config{data} is ignored; \config{name} can be used to display text, or left blank to make the list more accessible with visual gaps \item[shutdown] \config{data} is ignored; \config{name} can be used to display text +\item[time] \config{data} needs to be either ``talk`` to talk the time, or ``sleep X`` + where X is the number of minutes to run the sleep timer for (0 to disable). \config{name} + is required for this shortcut type. \end{description} If the name/icon items are not specified, a sensible default will be used.