summaryrefslogtreecommitdiffstats
path: root/apps/shortcuts.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/shortcuts.c')
-rw-r--r--apps/shortcuts.c103
1 files changed, 75 insertions, 28 deletions
diff --git a/apps/shortcuts.c b/apps/shortcuts.c
index 7b224dde2f..ad19ec14fc 100644
--- a/apps/shortcuts.c
+++ b/apps/shortcuts.c
@@ -47,9 +47,11 @@
#include "screens.h"
#include "talk.h"
#include "yesno.h"
+#ifdef HAVE_ALBUMART
+#include "playback.h"
+#endif
-
-#define MAX_SHORTCUT_NAME 32
+#define MAX_SHORTCUT_NAME 64
#define SHORTCUTS_FILENAME ROCKBOX_DIR "/shortcuts.txt"
static const char * const type_strings[SHORTCUT_TYPE_COUNT] = {
[SHORTCUT_SETTING] = "setting",
@@ -78,7 +80,7 @@ struct shortcut {
} timedata;
} u;
};
-#define SHORTCUTS_PER_HANDLE 32
+#define SHORTCUTS_PER_HANDLE 4
struct shortcut_handle {
struct shortcut shortcuts[SHORTCUTS_PER_HANDLE];
int next_handle;
@@ -126,8 +128,7 @@ static struct shortcut* get_shortcut(int index)
if (first_handle == 0)
{
- first_handle = core_alloc_ex("shortcuts_head",
- sizeof(struct shortcut_handle), &shortcut_ops);
+ first_handle = core_alloc_ex(sizeof(struct shortcut_handle), &shortcut_ops);
if (first_handle <= 0)
return NULL;
h = core_get_data(first_handle);
@@ -144,11 +145,9 @@ static struct shortcut* get_shortcut(int index)
} while (handle_count > 0 && current_handle > 0);
if (handle_count > 0 && handle_index == 0)
{
- char buf[32];
- snprintf(buf, sizeof buf, "shortcuts_%d", index/SHORTCUTS_PER_HANDLE);
/* prevent invalidation of 'h' during compaction */
++buflib_move_lock;
- h->next_handle = core_alloc_ex(buf, sizeof(struct shortcut_handle), &shortcut_ops);
+ h->next_handle = core_alloc_ex(sizeof(struct shortcut_handle), &shortcut_ops);
--buflib_move_lock;
if (h->next_handle <= 0)
return NULL;
@@ -236,6 +235,19 @@ static void shortcuts_ata_idle_callback(void)
write(fd, buf, len);
if (sc->type == SHORTCUT_SETTING)
write(fd, sc->u.setting->cfg_name, strlen(sc->u.setting->cfg_name));
+ else if (sc->type == SHORTCUT_TIME)
+ {
+#if CONFIG_RTC
+ if (sc->u.timedata.talktime)
+ write(fd, "talk", 4);
+ else
+#endif
+ {
+ write(fd, "sleep ", 6);
+ len = snprintf(buf, MAX_PATH, "%d", sc->u.timedata.sleep_timeout);
+ write(fd, buf, len);
+ }
+ }
else
write(fd, sc->u.path, strlen(sc->u.path));
@@ -269,7 +281,7 @@ void shortcuts_add(enum shortcut_type type, const char* value)
if (type == SHORTCUT_SETTING)
sc->u.setting = (void*)value;
else
- strlcpy(sc->u.path, value, MAX_PATH);
+ strmemccpy(sc->u.path, value, MAX_PATH);
if (first_idx_to_writeback < 0)
first_idx_to_writeback = shortcut_count - 1;
@@ -297,18 +309,22 @@ static int readline_cb(int n, char *buf, void *parameters)
}
else if (sc && settings_parseline(buf, &name, &value))
{
- if (!strcmp(name, "type"))
+ static const char * const nm_options[] = {"type", "name", "data",
+ "icon", "talkclip", NULL};
+ int nm_op = string_option(name, nm_options, false);
+
+ if (nm_op == 0) /*type*/
{
int t = 0;
for (t=0; t<SHORTCUT_TYPE_COUNT && sc->type == SHORTCUT_UNDEFINED; t++)
if (!strcmp(value, type_strings[t]))
sc->type = t;
}
- else if (!strcmp(name, "name"))
+ else if (nm_op == 1) /*name*/
{
- strlcpy(sc->name, value, MAX_SHORTCUT_NAME);
+ strmemccpy(sc->name, value, MAX_SHORTCUT_NAME);
}
- else if (!strcmp(name, "data"))
+ else if (nm_op == 2) /*data*/
{
switch (sc->type)
{
@@ -320,10 +336,10 @@ static int readline_cb(int n, char *buf, void *parameters)
case SHORTCUT_FILE:
case SHORTCUT_DEBUGITEM:
case SHORTCUT_PLAYLISTMENU:
- strlcpy(sc->u.path, value, MAX_PATH);
+ strmemccpy(sc->u.path, value, MAX_PATH);
break;
case SHORTCUT_SETTING:
- sc->u.setting = find_setting_by_cfgname(value, NULL);
+ sc->u.setting = find_setting_by_cfgname(value);
break;
case SHORTCUT_TIME:
#if CONFIG_RTC
@@ -342,7 +358,7 @@ static int readline_cb(int n, char *buf, void *parameters)
break;
}
}
- else if (!strcmp(name, "icon"))
+ else if (nm_op == 3) /*icon*/
{
if (!strcmp(value, "filetype") && sc->type != SHORTCUT_SETTING && sc->u.path[0])
{
@@ -353,9 +369,9 @@ static int readline_cb(int n, char *buf, void *parameters)
sc->icon = atoi(value);
}
}
- else if (!strcmp(name, "talkclip"))
+ else if (nm_op == 4) /*talkclip*/
{
- strlcpy(sc->talk_clip, value, MAX_PATH);
+ strmemccpy(sc->talk_clip, value, MAX_PATH);
}
}
return 0;
@@ -371,7 +387,7 @@ void shortcuts_init(void)
fd = open_utf8(SHORTCUTS_FILENAME, O_RDONLY);
if (fd < 0)
return;
- first_handle = core_alloc_ex("shortcuts_head", sizeof(struct shortcut_handle), &shortcut_ops);
+ first_handle = core_alloc_ex(sizeof(struct shortcut_handle), &shortcut_ops);
if (first_handle <= 0) {
close(fd);
return;
@@ -427,7 +443,7 @@ static const char * shortcut_menu_get_name(int selected_item, void * data,
static int shortcut_menu_get_action(int action, struct gui_synclist *lists)
{
(void)lists;
- if (action == ACTION_STD_OK)
+ if (action == ACTION_STD_OK || action == ACTION_STD_MENU)
return ACTION_STD_CANCEL;
else if (action == ACTION_STD_QUICKSCREEN && action != ACTION_STD_CONTEXT)
return ACTION_STD_CANCEL;
@@ -435,11 +451,15 @@ static int shortcut_menu_get_action(int action, struct gui_synclist *lists)
{
int selection = gui_synclist_get_sel_pos(lists);
- if (!yesno_pop(ID2P(LANG_REALLY_DELETE)))
+ if (confirm_delete_yesno("") != YESNO_YES)
+ {
+ gui_synclist_set_title(lists, lists->title, lists->title_icon);
return ACTION_REDRAW;
+ }
remove_shortcut(selection);
gui_synclist_set_nb_items(lists, shortcut_count);
+ gui_synclist_set_title(lists, lists->title, lists->title_icon);
if (selection >= shortcut_count)
gui_synclist_select_item(lists, shortcut_count - 1);
first_idx_to_writeback = 0;
@@ -511,7 +531,7 @@ static int shortcut_menu_speak_item(int selected_item, void * data)
if (*filename != '\0')
{
int dirlen = (filename - sc->u.path);
- strlcpy(path, sc->u.path, dirlen + 1);
+ strmemccpy(path, sc->u.path, dirlen + 1);
dir = opendir(path);
if (dir)
{
@@ -599,13 +619,17 @@ int do_shortcut_menu(void *ignored)
while (done == GO_TO_PREVIOUS)
{
+ list.count = shortcut_count;
+
if (simplelist_show_list(&list))
break; /* some error happened?! */
+
if (list.selection == -1)
break;
else
{
sc = get_shortcut(list.selection);
+
if (!sc)
continue;
@@ -619,7 +643,10 @@ int do_shortcut_menu(void *ignored)
}
else
{
- onplay_show_playlist_menu(sc->u.path);
+ onplay_show_playlist_menu(sc->u.path,
+ dir_exists(sc->u.path) ? ATTR_DIRECTORY :
+ filetype_get_attr(sc->u.path),
+ NULL);
}
break;
case SHORTCUT_FILE:
@@ -636,18 +663,35 @@ int do_shortcut_menu(void *ignored)
done = GO_TO_PLUGIN;
break;
}
- struct browse_context browse;
- browse_context_init(&browse, global_settings.dirfilter, 0,
- NULL, NOICON, sc->u.path, NULL);
+ struct browse_context browse = {
+ .dirfilter = global_settings.dirfilter,
+ .icon = Icon_NOICON,
+ .root = sc->u.path,
+ };
if (sc->type == SHORTCUT_FILE)
browse.flags |= BROWSE_RUNFILE;
done = rockbox_browse(&browse);
+
}
break;
case SHORTCUT_SETTING:
+ {
+ int old_sleeptimer_duration = global_settings.sleeptimer_duration;
+#ifdef HAVE_ALBUMART
+ int old_album_art = global_settings.album_art;
+#endif
do_setting_screen(sc->u.setting,
sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)),NULL);
+
+#ifdef HAVE_ALBUMART
+ if (old_album_art != global_settings.album_art)
+ set_albumart_mode(global_settings.album_art);
+#endif
+ if (old_sleeptimer_duration != global_settings.sleeptimer_duration &&
+ get_sleep_timer())
+ set_sleeptimer_duration(global_settings.sleeptimer_duration);
break;
+ }
case SHORTCUT_DEBUGITEM:
run_debug_screen(sc->u.path);
break;
@@ -669,7 +713,7 @@ int do_shortcut_menu(void *ignored)
{
char timer_buf[10];
set_sleeptimer_duration(sc->u.timedata.sleep_timeout);
- splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER),
+ splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER),
sleep_timer_formatter(timer_buf, sizeof(timer_buf),
sc->u.timedata.sleep_timeout, NULL));
}
@@ -680,7 +724,10 @@ int do_shortcut_menu(void *ignored)
}
}
}
- pop_current_activity();
+ if (GO_TO_PLUGIN == done)
+ pop_current_activity_without_refresh();
+ else
+ pop_current_activity();
--buflib_move_lock;
return done;