diff options
Diffstat (limited to 'apps/shortcuts.c')
-rw-r--r-- | apps/shortcuts.c | 54 |
1 files changed, 47 insertions, 7 deletions
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] = { | |||
55 | [SHORTCUT_PLAYLISTMENU] = "playlist menu", | 55 | [SHORTCUT_PLAYLISTMENU] = "playlist menu", |
56 | [SHORTCUT_SEPARATOR] = "separator", | 56 | [SHORTCUT_SEPARATOR] = "separator", |
57 | [SHORTCUT_SHUTDOWN] = "shutdown", | 57 | [SHORTCUT_SHUTDOWN] = "shutdown", |
58 | [SHORTCUT_TIME] = "time", | ||
58 | }; | 59 | }; |
59 | 60 | ||
60 | struct shortcut { | 61 | struct shortcut { |
@@ -64,6 +65,12 @@ struct shortcut { | |||
64 | union { | 65 | union { |
65 | char path[MAX_PATH]; | 66 | char path[MAX_PATH]; |
66 | const struct settings_list *setting; | 67 | const struct settings_list *setting; |
68 | struct { | ||
69 | #if CONFIG_RTC | ||
70 | bool talktime; | ||
71 | #endif | ||
72 | int sleep_timeout; | ||
73 | } timedata; | ||
67 | } u; | 74 | } u; |
68 | }; | 75 | }; |
69 | #define SHORTCUTS_PER_HANDLE 32 | 76 | #define SHORTCUTS_PER_HANDLE 32 |
@@ -135,11 +142,11 @@ static bool verify_shortcut(struct shortcut* sc) | |||
135 | case SHORTCUT_BROWSER: | 142 | case SHORTCUT_BROWSER: |
136 | case SHORTCUT_FILE: | 143 | case SHORTCUT_FILE: |
137 | case SHORTCUT_PLAYLISTMENU: | 144 | case SHORTCUT_PLAYLISTMENU: |
138 | if (sc->u.path[0] == '\0') | 145 | return sc->u.path[0] != '0'; |
139 | return false; | ||
140 | break; | ||
141 | case SHORTCUT_SETTING: | 146 | case SHORTCUT_SETTING: |
142 | return sc->u.setting != NULL; | 147 | return sc->u.setting != NULL; |
148 | case SHORTCUT_TIME: | ||
149 | return sc->name[0] != '0'; | ||
143 | case SHORTCUT_DEBUGITEM: | 150 | case SHORTCUT_DEBUGITEM: |
144 | case SHORTCUT_SEPARATOR: | 151 | case SHORTCUT_SEPARATOR: |
145 | case SHORTCUT_SHUTDOWN: | 152 | case SHORTCUT_SHUTDOWN: |
@@ -193,7 +200,7 @@ void shortcuts_ata_idle_callback(void* data) | |||
193 | */ | 200 | */ |
194 | reset_shortcuts(); | 201 | reset_shortcuts(); |
195 | shortcuts_init(); | 202 | shortcuts_init(); |
196 | } | 203 | } |
197 | first_idx_to_writeback = -1; | 204 | first_idx_to_writeback = -1; |
198 | } | 205 | } |
199 | 206 | ||
@@ -212,7 +219,6 @@ void shortcuts_add(enum shortcut_type type, const char* value) | |||
212 | first_idx_to_writeback = shortcut_count - 1; | 219 | first_idx_to_writeback = shortcut_count - 1; |
213 | register_storage_idle_func(shortcuts_ata_idle_callback); | 220 | register_storage_idle_func(shortcuts_ata_idle_callback); |
214 | } | 221 | } |
215 | |||
216 | 222 | ||
217 | int readline_cb(int n, char *buf, void *parameters) | 223 | int readline_cb(int n, char *buf, void *parameters) |
218 | { | 224 | { |
@@ -262,6 +268,20 @@ int readline_cb(int n, char *buf, void *parameters) | |||
262 | case SHORTCUT_SETTING: | 268 | case SHORTCUT_SETTING: |
263 | sc->u.setting = find_setting_by_cfgname(value, NULL); | 269 | sc->u.setting = find_setting_by_cfgname(value, NULL); |
264 | break; | 270 | break; |
271 | case SHORTCUT_TIME: | ||
272 | #if CONFIG_RTC | ||
273 | if (!strcasecmp(value, "talk")) | ||
274 | sc->u.timedata.talktime = true; | ||
275 | else | ||
276 | #endif | ||
277 | if (!strncasecmp(value, "sleep ", strlen("sleep "))) | ||
278 | { | ||
279 | sc->u.timedata.talktime = false; | ||
280 | sc->u.timedata.sleep_timeout = atoi(&value[strlen("sleep ")]); | ||
281 | } | ||
282 | else | ||
283 | sc->type = SHORTCUT_UNDEFINED; /* error */ | ||
284 | break; | ||
265 | case SHORTCUT_SEPARATOR: | 285 | case SHORTCUT_SEPARATOR: |
266 | case SHORTCUT_SHUTDOWN: | 286 | case SHORTCUT_SHUTDOWN: |
267 | break; | 287 | break; |
@@ -314,7 +334,7 @@ static const char * shortcut_menu_get_name(int selected_item, void * data, | |||
314 | return ""; | 334 | return ""; |
315 | if (sc->type == SHORTCUT_SETTING) | 335 | if (sc->type == SHORTCUT_SETTING) |
316 | return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)); | 336 | return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)); |
317 | else if (sc->type == SHORTCUT_SEPARATOR) | 337 | else if (sc->type == SHORTCUT_SEPARATOR || sc->type == SHORTCUT_TIME) |
318 | return sc->name; | 338 | return sc->name; |
319 | else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0') | 339 | else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0') |
320 | { | 340 | { |
@@ -354,6 +374,8 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data | |||
354 | return Icon_Playlist; | 374 | return Icon_Playlist; |
355 | case SHORTCUT_SHUTDOWN: | 375 | case SHORTCUT_SHUTDOWN: |
356 | return Icon_System_menu; | 376 | return Icon_System_menu; |
377 | case SHORTCUT_TIME: | ||
378 | return Icon_Menu_functioncall; | ||
357 | default: | 379 | default: |
358 | break; | 380 | break; |
359 | } | 381 | } |
@@ -361,6 +383,10 @@ static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data | |||
361 | return sc->icon; | 383 | return sc->icon; |
362 | } | 384 | } |
363 | 385 | ||
386 | void talk_timedate(void); | ||
387 | const char* sleep_timer_formatter(char* buffer, size_t buffer_size, | ||
388 | int value, const char* unit); | ||
389 | |||
364 | int do_shortcut_menu(void *ignored) | 390 | int do_shortcut_menu(void *ignored) |
365 | { | 391 | { |
366 | (void)ignored; | 392 | (void)ignored; |
@@ -377,7 +403,7 @@ int do_shortcut_menu(void *ignored) | |||
377 | list.title_icon = Icon_Bookmark; | 403 | list.title_icon = Icon_Bookmark; |
378 | 404 | ||
379 | push_current_activity(ACTIVITY_SHORTCUTSMENU); | 405 | push_current_activity(ACTIVITY_SHORTCUTSMENU); |
380 | 406 | ||
381 | while (done == GO_TO_PREVIOUS) | 407 | while (done == GO_TO_PREVIOUS) |
382 | { | 408 | { |
383 | if (simplelist_show_list(&list)) | 409 | if (simplelist_show_list(&list)) |
@@ -434,6 +460,20 @@ int do_shortcut_menu(void *ignored) | |||
434 | #endif | 460 | #endif |
435 | sys_poweroff(); | 461 | sys_poweroff(); |
436 | break; | 462 | break; |
463 | case SHORTCUT_TIME: | ||
464 | #if CONFIG_RTC | ||
465 | if (sc->u.timedata.talktime) | ||
466 | talk_timedate(); | ||
467 | else | ||
468 | #endif | ||
469 | { | ||
470 | char timer_buf[10]; | ||
471 | set_sleep_timer(sc->u.timedata.sleep_timeout * 60); | ||
472 | splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), | ||
473 | sleep_timer_formatter(timer_buf, sizeof(timer_buf), | ||
474 | sc->u.timedata.sleep_timeout, NULL)); | ||
475 | } | ||
476 | break; | ||
437 | case SHORTCUT_UNDEFINED: | 477 | case SHORTCUT_UNDEFINED: |
438 | default: | 478 | default: |
439 | break; | 479 | break; |