forked from len0rd/rockbox
Bug fix dynamic menus
Dynamic menus had a buffer_len variable in the parent function but it was discarded before passing to the callbacks Why!!?? No clue but everything that used it was assuming MAXPATH Wouldn't be surprised to see some bugs pop out from this one.. init_menu_lists() was assuming MENU_HAS_DESC and setting the menu title + icon based on such even though it could be invalid didn't see anywhere in the code that was currently using MENU_DYNAMIC_DESC in relation to a top level menu but considering it caused all kinds of corruption to the menu when I tried its probably been tried and abandoned before... Change-Id: I8d961d748918bfa8ea6adb5ad60491af4d739d6e
This commit is contained in:
parent
d0883d747a
commit
10e5e56f3c
6 changed files with 43 additions and 19 deletions
37
apps/menu.c
37
apps/menu.c
|
@ -104,13 +104,12 @@ static const char* get_menu_item_name(int selected_item,
|
||||||
int type = (menu->flags&MENU_TYPE_MASK);
|
int type = (menu->flags&MENU_TYPE_MASK);
|
||||||
selected_item = get_menu_selection(selected_item, menu);
|
selected_item = get_menu_selection(selected_item, menu);
|
||||||
|
|
||||||
(void)buffer_len;
|
|
||||||
/* only MT_MENU or MT_RETURN_ID is allowed in here */
|
/* only MT_MENU or MT_RETURN_ID is allowed in here */
|
||||||
if (type == MT_RETURN_ID)
|
if (type == MT_RETURN_ID)
|
||||||
{
|
{
|
||||||
if (menu->flags&MENU_DYNAMIC_DESC)
|
if (menu->flags&MENU_DYNAMIC_DESC)
|
||||||
return menu->menu_get_name_and_icon->list_get_name(selected_item,
|
return menu->menu_get_name_and_icon->list_get_name(selected_item,
|
||||||
menu->menu_get_name_and_icon->list_get_name_data, buffer);
|
menu->menu_get_name_and_icon->list_get_name_data, buffer, buffer_len);
|
||||||
return menu->strings[selected_item];
|
return menu->strings[selected_item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +117,7 @@ static const char* get_menu_item_name(int selected_item,
|
||||||
|
|
||||||
if ((menu->flags&MENU_DYNAMIC_DESC) && (type != MT_SETTING_W_TEXT))
|
if ((menu->flags&MENU_DYNAMIC_DESC) && (type != MT_SETTING_W_TEXT))
|
||||||
return menu->menu_get_name_and_icon->list_get_name(selected_item,
|
return menu->menu_get_name_and_icon->list_get_name(selected_item,
|
||||||
menu->menu_get_name_and_icon->list_get_name_data, buffer);
|
menu->menu_get_name_and_icon->list_get_name_data, buffer, buffer_len);
|
||||||
|
|
||||||
type = (menu->flags&MENU_TYPE_MASK);
|
type = (menu->flags&MENU_TYPE_MASK);
|
||||||
if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT))
|
if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT))
|
||||||
|
@ -177,6 +176,7 @@ static void init_menu_lists(const struct menu_item_ex *menu,
|
||||||
int type = (menu->flags&MENU_TYPE_MASK);
|
int type = (menu->flags&MENU_TYPE_MASK);
|
||||||
menu_callback_type menu_callback = NULL;
|
menu_callback_type menu_callback = NULL;
|
||||||
int icon;
|
int icon;
|
||||||
|
char * title;
|
||||||
current_subitems_count = 0;
|
current_subitems_count = 0;
|
||||||
|
|
||||||
if (type == MT_RETURN_ID)
|
if (type == MT_RETURN_ID)
|
||||||
|
@ -206,14 +206,33 @@ static void init_menu_lists(const struct menu_item_ex *menu,
|
||||||
|
|
||||||
gui_synclist_init(lists,get_menu_item_name,(void*)menu,false,1, parent);
|
gui_synclist_init(lists,get_menu_item_name,(void*)menu,false,1, parent);
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
if (menu->callback_and_desc->icon_id == Icon_NOICON)
|
|
||||||
icon = Icon_Submenu_Entered;
|
if (menu->flags&MENU_HAS_DESC)
|
||||||
else
|
{
|
||||||
icon = menu->callback_and_desc->icon_id;
|
icon = menu->callback_and_desc->icon_id;
|
||||||
gui_synclist_set_title(lists, P2STR(menu->callback_and_desc->desc), icon);
|
title = P2STR(menu->callback_and_desc->desc);
|
||||||
|
}
|
||||||
|
else if (menu->flags&MENU_DYNAMIC_DESC)
|
||||||
|
{
|
||||||
|
char buffer[80];
|
||||||
|
icon = menu->menu_get_name_and_icon->icon_id;
|
||||||
|
title = menu->menu_get_name_and_icon->
|
||||||
|
list_get_name(-1, menu->menu_get_name_and_icon->
|
||||||
|
list_get_name_data, buffer, sizeof(buffer));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
icon = Icon_NOICON;
|
||||||
|
title = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (icon == Icon_NOICON)
|
||||||
|
icon = Icon_Submenu_Entered;
|
||||||
|
gui_synclist_set_title(lists, title, icon);
|
||||||
gui_synclist_set_icon_callback(lists, global_settings.show_icons?menu_get_icon:NULL);
|
gui_synclist_set_icon_callback(lists, global_settings.show_icons?menu_get_icon:NULL);
|
||||||
#else
|
#else
|
||||||
(void)icon;
|
(void)icon;
|
||||||
|
(void)title;
|
||||||
gui_synclist_set_icon_callback(lists, NULL);
|
gui_synclist_set_icon_callback(lists, NULL);
|
||||||
#endif
|
#endif
|
||||||
if(global_settings.talk_menu)
|
if(global_settings.talk_menu)
|
||||||
|
@ -256,8 +275,8 @@ static int talk_menu_item(int selected_item, void *data)
|
||||||
char buffer[80];
|
char buffer[80];
|
||||||
str = menu->submenus[sel]->menu_get_name_and_icon->
|
str = menu->submenus[sel]->menu_get_name_and_icon->
|
||||||
list_get_name(sel, menu->submenus[sel]->
|
list_get_name(sel, menu->submenus[sel]->
|
||||||
menu_get_name_and_icon->
|
menu_get_name_and_icon->
|
||||||
list_get_name_data, buffer);
|
list_get_name_data, buffer, sizeof(buffer));
|
||||||
id = P2ID(str);
|
id = P2ID(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,8 @@ struct menu_item_ex {
|
||||||
const struct menu_get_name_and_icon {
|
const struct menu_get_name_and_icon {
|
||||||
int (*menu_callback)(int action,
|
int (*menu_callback)(int action,
|
||||||
const struct menu_item_ex *this_item);
|
const struct menu_item_ex *this_item);
|
||||||
char *(*list_get_name)(int selected_item, void * data, char *buffer);
|
char *(*list_get_name)(int selected_item, void * data,
|
||||||
|
char *buffer, size_t buffer_len);
|
||||||
int (*list_speak_item)(int selected_item, void * data);
|
int (*list_speak_item)(int selected_item, void * data);
|
||||||
void *list_get_name_data;
|
void *list_get_name_data;
|
||||||
int icon_id;
|
int icon_id;
|
||||||
|
|
|
@ -41,9 +41,10 @@ static unsigned short hw_eq_setting_lang_ids[AUDIOHW_EQ_SETTING_NUM] =
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static char * hw_eq_get_name(int selected_item, void * data, char *buffer)
|
static char * hw_eq_get_name(int selected_item, void * data,
|
||||||
|
char *buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
snprintf(buffer, MAX_PATH,
|
snprintf(buffer, buffer_len,
|
||||||
str(hw_eq_setting_lang_ids[HW_EQ_IDX_SETTING(data)]),
|
str(hw_eq_setting_lang_ids[HW_EQ_IDX_SETTING(data)]),
|
||||||
HW_EQ_IDX_BAND(data) + 1);
|
HW_EQ_IDX_BAND(data) + 1);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
@ -100,11 +100,12 @@ MENUITEM_SETTING(force_mono, &global_settings.fm_force_mono, NULL);
|
||||||
|
|
||||||
#ifndef FM_MODE
|
#ifndef FM_MODE
|
||||||
extern int radio_mode;
|
extern int radio_mode;
|
||||||
static char* get_mode_text(int selected_item, void * data, char *buffer)
|
static char* get_mode_text(int selected_item, void * data,
|
||||||
|
char *buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
(void)selected_item;
|
(void)selected_item;
|
||||||
(void)data;
|
(void)data;
|
||||||
snprintf(buffer, MAX_PATH, "%s %s", str(LANG_MODE),
|
snprintf(buffer, buffer_len, "%s %s", str(LANG_MODE),
|
||||||
radio_mode ? str(LANG_PRESET) :
|
radio_mode ? str(LANG_PRESET) :
|
||||||
str(LANG_RADIO_SCAN_MODE));
|
str(LANG_RADIO_SCAN_MODE));
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
@ -500,14 +500,15 @@ static int seconds_to_min(int secs)
|
||||||
|
|
||||||
/* A string representation of either whether a sleep timer will be started or
|
/* A string representation of either whether a sleep timer will be started or
|
||||||
canceled, and how long it will be or how long is remaining in brackets */
|
canceled, and how long it will be or how long is remaining in brackets */
|
||||||
static char* sleep_timer_getname(int selected_item, void * data, char *buffer)
|
static char* sleep_timer_getname(int selected_item, void * data,
|
||||||
|
char *buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
(void)selected_item;
|
(void)selected_item;
|
||||||
(void)data;
|
(void)data;
|
||||||
int sec = get_sleep_timer();
|
int sec = get_sleep_timer();
|
||||||
char timer_buf[10];
|
char timer_buf[10];
|
||||||
/* we have no sprintf, so MAX_PATH is a guess */
|
|
||||||
snprintf(buffer, MAX_PATH, "%s (%s)",
|
snprintf(buffer, buffer_len, "%s (%s)",
|
||||||
str(sec ? LANG_SLEEP_TIMER_CANCEL_CURRENT
|
str(sec ? LANG_SLEEP_TIMER_CANCEL_CURRENT
|
||||||
: LANG_SLEEP_TIMER_START_CURRENT),
|
: LANG_SLEEP_TIMER_START_CURRENT),
|
||||||
sleep_timer_formatter(timer_buf, sizeof(timer_buf),
|
sleep_timer_formatter(timer_buf, sizeof(timer_buf),
|
||||||
|
|
|
@ -454,9 +454,10 @@ MENUITEM_RETURNVALUE(rocks_browser, ID2P(LANG_PLUGINS), GO_TO_BROWSEPLUGINS,
|
||||||
MENUITEM_RETURNVALUE(playlist_browser, ID2P(LANG_CATALOG), GO_TO_PLAYLIST_VIEWER,
|
MENUITEM_RETURNVALUE(playlist_browser, ID2P(LANG_CATALOG), GO_TO_PLAYLIST_VIEWER,
|
||||||
NULL, Icon_Playlist);
|
NULL, Icon_Playlist);
|
||||||
|
|
||||||
static char *get_wps_item_name(int selected_item, void * data, char *buffer)
|
static char *get_wps_item_name(int selected_item, void * data,
|
||||||
|
char *buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
(void)selected_item; (void)data; (void)buffer;
|
(void)selected_item; (void)data; (void)buffer; (void)buffer_len;
|
||||||
if (audio_status())
|
if (audio_status())
|
||||||
return ID2P(LANG_NOW_PLAYING);
|
return ID2P(LANG_NOW_PLAYING);
|
||||||
return ID2P(LANG_RESUME_PLAYBACK);
|
return ID2P(LANG_RESUME_PLAYBACK);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue