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
This commit is contained in:
Jonathan Gordon 2011-12-08 10:23:46 +00:00
parent 2376c4f825
commit 29b1ba3445
5 changed files with 55 additions and 9 deletions

View File

@ -376,7 +376,7 @@ MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
/* sleep Menu */ /* 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) int value, const char* unit)
{ {
(void) unit; (void) unit;

View File

@ -139,7 +139,7 @@ MENUITEM_FUNCTION(alarm_wake_up_screen, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN),
MENUITEM_SETTING(sleeptimer_on_startup, MENUITEM_SETTING(sleeptimer_on_startup,
&global_settings.sleeptimer_on_startup, NULL); &global_settings.sleeptimer_on_startup, NULL);
static void talk_timedate(void) void talk_timedate(void)
{ {
struct tm *tm = get_time(); struct tm *tm = get_time();
if (!global_settings.talk_menu) if (!global_settings.talk_menu)

View File

@ -55,6 +55,7 @@ static const char * const type_strings[SHORTCUT_TYPE_COUNT] = {
[SHORTCUT_PLAYLISTMENU] = "playlist menu", [SHORTCUT_PLAYLISTMENU] = "playlist menu",
[SHORTCUT_SEPARATOR] = "separator", [SHORTCUT_SEPARATOR] = "separator",
[SHORTCUT_SHUTDOWN] = "shutdown", [SHORTCUT_SHUTDOWN] = "shutdown",
[SHORTCUT_TIME] = "time",
}; };
struct shortcut { struct shortcut {
@ -64,6 +65,12 @@ struct shortcut {
union { union {
char path[MAX_PATH]; char path[MAX_PATH];
const struct settings_list *setting; const struct settings_list *setting;
struct {
#if CONFIG_RTC
bool talktime;
#endif
int sleep_timeout;
} timedata;
} u; } u;
}; };
#define SHORTCUTS_PER_HANDLE 32 #define SHORTCUTS_PER_HANDLE 32
@ -135,11 +142,11 @@ static bool verify_shortcut(struct shortcut* sc)
case SHORTCUT_BROWSER: case SHORTCUT_BROWSER:
case SHORTCUT_FILE: case SHORTCUT_FILE:
case SHORTCUT_PLAYLISTMENU: case SHORTCUT_PLAYLISTMENU:
if (sc->u.path[0] == '\0') return sc->u.path[0] != '0';
return false;
break;
case SHORTCUT_SETTING: case SHORTCUT_SETTING:
return sc->u.setting != NULL; return sc->u.setting != NULL;
case SHORTCUT_TIME:
return sc->name[0] != '0';
case SHORTCUT_DEBUGITEM: case SHORTCUT_DEBUGITEM:
case SHORTCUT_SEPARATOR: case SHORTCUT_SEPARATOR:
case SHORTCUT_SHUTDOWN: case SHORTCUT_SHUTDOWN:
@ -193,7 +200,7 @@ void shortcuts_ata_idle_callback(void* data)
*/ */
reset_shortcuts(); reset_shortcuts();
shortcuts_init(); shortcuts_init();
} }
first_idx_to_writeback = -1; 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; first_idx_to_writeback = shortcut_count - 1;
register_storage_idle_func(shortcuts_ata_idle_callback); register_storage_idle_func(shortcuts_ata_idle_callback);
} }
int readline_cb(int n, char *buf, void *parameters) 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: case SHORTCUT_SETTING:
sc->u.setting = find_setting_by_cfgname(value, NULL); sc->u.setting = find_setting_by_cfgname(value, NULL);
break; 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_SEPARATOR:
case SHORTCUT_SHUTDOWN: case SHORTCUT_SHUTDOWN:
break; break;
@ -314,7 +334,7 @@ static const char * shortcut_menu_get_name(int selected_item, void * data,
return ""; return "";
if (sc->type == SHORTCUT_SETTING) if (sc->type == SHORTCUT_SETTING)
return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)); 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; return sc->name;
else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0') 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; return Icon_Playlist;
case SHORTCUT_SHUTDOWN: case SHORTCUT_SHUTDOWN:
return Icon_System_menu; return Icon_System_menu;
case SHORTCUT_TIME:
return Icon_Menu_functioncall;
default: default:
break; break;
} }
@ -361,6 +383,10 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data
return sc->icon; 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) int do_shortcut_menu(void *ignored)
{ {
(void)ignored; (void)ignored;
@ -377,7 +403,7 @@ int do_shortcut_menu(void *ignored)
list.title_icon = Icon_Bookmark; list.title_icon = Icon_Bookmark;
push_current_activity(ACTIVITY_SHORTCUTSMENU); push_current_activity(ACTIVITY_SHORTCUTSMENU);
while (done == GO_TO_PREVIOUS) while (done == GO_TO_PREVIOUS)
{ {
if (simplelist_show_list(&list)) if (simplelist_show_list(&list))
@ -434,6 +460,20 @@ int do_shortcut_menu(void *ignored)
#endif #endif
sys_poweroff(); sys_poweroff();
break; 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: case SHORTCUT_UNDEFINED:
default: default:
break; break;

View File

@ -33,6 +33,7 @@ enum shortcut_type {
SHORTCUT_PLAYLISTMENU, SHORTCUT_PLAYLISTMENU,
SHORTCUT_SEPARATOR, SHORTCUT_SEPARATOR,
SHORTCUT_SHUTDOWN, SHORTCUT_SHUTDOWN,
SHORTCUT_TIME,
SHORTCUT_TYPE_COUNT SHORTCUT_TYPE_COUNT
}; };

View File

@ -281,6 +281,8 @@ settings. With a shortcut,
\setting{Quick Screen}) \setting{Quick Screen})
\item A debug menu item can be displayed (useful for developers mostly) \item A debug menu item can be displayed (useful for developers mostly)
\item The \dap{} can be turned off \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} \end{itemize}
\note{Shortcuts into the database are not possible} \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, \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 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[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} \end{description}
If the name/icon items are not specified, a sensible default will be used. If the name/icon items are not specified, a sensible default will be used.