onplay wps context menus small cleanup

no functional changes just cleaning up some code / logic

Change-Id: Ic03918a70997cfb170a29175361e2df9a9d242d1
This commit is contained in:
William Wilgus 2026-05-28 12:39:49 -04:00
parent c052d11673
commit 3b2555bd4d
2 changed files with 36 additions and 54 deletions

View file

@ -725,8 +725,6 @@ MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice,
/* WPS_CONTEXT_MENU */ /* WPS_CONTEXT_MENU */
/***********************************/ /***********************************/
static char *wps_context_menu_get_name(int selected_item, void * data, static char *wps_context_menu_get_name(int selected_item, void * data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {
@ -764,7 +762,7 @@ static int wps_context_menu_speak_item(int selected_item, void * data)
#endif #endif
{ {
talk_id(LANG_SET_CONTEXT_ITEM, false); talk_id(LANG_SET_CONTEXT_ITEM, false);
talk_number((intptr_t)data, true); talk_number(item, true);
} }
talk_id(cur->lang_id, true); talk_id(cur->lang_id, true);
return 0; return 0;
@ -828,7 +826,6 @@ MAKE_MENU(wps_settings, ID2P(LANG_WPS), 0, Icon_Playback_menu
,&wps_set_context_item_4 ,&wps_set_context_item_4
,&reset_wps_item ,&reset_wps_item
); );
/* WPS Settings MENU */ /* WPS Settings MENU */
/***********************************/ /***********************************/

View file

@ -688,8 +688,6 @@ static char *wps_context_get_item_name(int selected_item, void * data,
static int wps_context_item_speak_item(int selected_item, void * data) static int wps_context_item_speak_item(int selected_item, void * data)
{ {
if (!global_settings.talk_menu)
return 0;
int item = (intptr_t)data; int item = (intptr_t)data;
const struct hotkey_assignment *hkey = const struct hotkey_assignment *hkey =
get_hotkey(HK_CTX_GET(item, global_settings.context_wps)); get_hotkey(HK_CTX_GET(item, global_settings.context_wps));
@ -705,8 +703,6 @@ static int wps_context_item_speak_item(int selected_item, void * data)
int32_t ts = dsp_get_timestretch(); int32_t ts = dsp_get_timestretch();
int32_t pitch = sound_get_pitch(); int32_t pitch = sound_get_pitch();
if (ts != PITCH_SPEED_100 || pitch != PITCH_SPEED_100) if (ts != PITCH_SPEED_100 || pitch != PITCH_SPEED_100)
{
if (global_settings.talk_menu)
{ {
talk_id(hkey->lang_id, false); talk_id(hkey->lang_id, false);
@ -718,7 +714,6 @@ static int wps_context_item_speak_item(int selected_item, void * data)
talk_id(LANG_SPEED, true); talk_id(LANG_SPEED, true);
talk_value_decimal(speed, UNIT_PERCENT, 2, true); talk_value_decimal(speed, UNIT_PERCENT, 2, true);
} }
}
return 0; return 0;
} }
} }
@ -808,7 +803,6 @@ static int wps_context_item_cb(int action,
} }
} }
#endif #endif
} }
else if (action == ACTION_EXIT_MENUITEM) /* selected */ else if (action == ACTION_EXIT_MENUITEM) /* selected */
{ {
@ -1562,42 +1556,34 @@ static int execute_hotkey(int action)
return return_code; /* or return the associated value */ return return_code; /* or return the associated value */
} }
struct hk_menu_data
{
const struct hotkey_assignment **hk_menu;
int hide_off;
};
static const char* hotkey_get_name(int selected_item, void * data, static const char* hotkey_get_name(int selected_item, void * data,
char * buffer, size_t buffer_len) char * buffer, size_t buffer_len)
{ {
(void)buffer; (void)buffer_len; (void)buffer; (void)buffer_len;
struct hk_menu_data *hk_data = (struct hk_menu_data*)data; const struct hotkey_assignment **hk_menu =
return ID2P(hk_data->hk_menu[selected_item + hk_data->hide_off]->lang_id); (const struct hotkey_assignment**)data;
return ID2P(hk_menu[selected_item]->lang_id);
} }
static int hotkey_get_talk(int selected_item, void * data) static int hotkey_get_talk(int selected_item, void * data)
{ {
if (global_settings.talk_menu) const struct hotkey_assignment **hk_menu =
{ (const struct hotkey_assignment**)data;
struct hk_menu_data *hk_data = (struct hk_menu_data*)data; talk_id(hk_menu[selected_item]->lang_id, false);
talk_id(hk_data->hk_menu[selected_item + hk_data->hide_off]->lang_id, false);
}
return 0; return 0;
} }
static enum themable_icons hotkey_get_icon(int selected_item, void * data) static enum themable_icons hotkey_get_icon(int selected_item, void * data)
{ {
struct hk_menu_data *hk_data = (struct hk_menu_data*)data; const struct hotkey_assignment **hk_menu =
return hk_data->hk_menu[selected_item + hk_data->hide_off]->icon; (const struct hotkey_assignment**)data;
return hk_menu[selected_item]->icon;
} }
int hotkey_run_menu(intptr_t flag, bool execute, int current_action) int hotkey_run_menu(intptr_t flag, bool execute, int current_action)
{ {
const struct hotkey_assignment *hk_menu[ARRAYLEN(hotkey_items)]; const struct hotkey_assignment *hk_menu[ARRAYLEN(hotkey_items)];
struct hk_menu_data data = {hk_menu, execute ? 1 : 0};
char *title = str(LANG_ONPLAY_MENU_TITLE); char *title = str(LANG_ONPLAY_MENU_TITLE);
#ifdef HAVE_HOTKEY #ifdef HAVE_HOTKEY
if (flag & HOTKEY_FLAG_TREE) if (flag & HOTKEY_FLAG_TREE)
@ -1609,6 +1595,8 @@ int hotkey_run_menu(intptr_t flag, bool execute, int current_action)
for (size_t i = 0; i < ARRAYLEN(hotkey_items); i++) for (size_t i = 0; i < ARRAYLEN(hotkey_items); i++)
{ {
hk_menu[i] = NULL; /*clear all the hk_menu entries prior to setting them */ hk_menu[i] = NULL; /*clear all the hk_menu entries prior to setting them */
if (hotkey_items[i].action == HOTKEY_OFF && execute)
continue; /* Don't display HOTKEY_OFF item */
if ((hotkey_items[i].flags & flag) == flag) if ((hotkey_items[i].flags & flag) == flag)
{ {
if (!execute || hotkey_items[i].action != HOTKEY_CONTEXT_MENU) if (!execute || hotkey_items[i].action != HOTKEY_CONTEXT_MENU)
@ -1620,30 +1608,26 @@ int hotkey_run_menu(intptr_t flag, bool execute, int current_action)
} }
} }
/* count -1 don't display HOTKEY_OFF item */ simplelist_info_init(&info, title, count, (void*)&hk_menu);
simplelist_info_init(&info, title, count - data.hide_off, (void*)&data);
info.get_name = hotkey_get_name; info.get_name = hotkey_get_name;
info.get_icon = hotkey_get_icon; info.get_icon = hotkey_get_icon;
info.get_talk = hotkey_get_talk; info.get_talk = hotkey_get_talk;
info.selection = selected - data.hide_off; info.selection = selected;
simplelist_show_list(&info); simplelist_show_list(&info);
if (execute) if (execute)
{ {
if (info.selection >= 0) /* run user selected hotkey item */ if (info.selection < 0) /* canceled */
{
return execute_hotkey(hk_menu[info.selection + 1]->action);
}
return ONPLAY_RELOAD_DIR; return ONPLAY_RELOAD_DIR;
return execute_hotkey(hk_menu[info.selection]->action);
} }
else else
{ {
if (info.selection >= 0) /* return selected hotkey item */ if (info.selection < 0) /* canceled */
{ return -1;
return hk_menu[info.selection]->action; return hk_menu[info.selection]->action;
} }
} }
return -1; /* canceled */
}
int onplay(char* file, int attr, int from_context, bool hotkey, int customaction) int onplay(char* file, int attr, int from_context, bool hotkey, int customaction)
{ {
@ -1731,7 +1715,6 @@ int get_onplay_context(void)
static int hotkey_menu_do_setting(void *param, int *setting, int flag) static int hotkey_menu_do_setting(void *param, int *setting, int flag)
{ {
int current = *setting; int current = *setting;
int item = (intptr_t)param; int item = (intptr_t)param;
@ -1800,15 +1783,17 @@ void wps_context_menu_load_from_cfg(void* setting, char *value)
if (*end == ',' || *end == '\0') if (*end == ',' || *end == '\0')
{ {
st = skip_whitespace(st); st = skip_whitespace(st);
if (end - st > 1)
{
for (size_t i = ARRAYLEN(hotkey_items) - 1; i < ARRAYLEN(hotkey_items); i--) for (size_t i = ARRAYLEN(hotkey_items) - 1; i < ARRAYLEN(hotkey_items); i--)
{ {
if (end-st > 1 && const char *this = lang_id_to_english(hotkey_items[i].lang_id);
strncasecmp(st, lang_id_to_english(hotkey_items[i].lang_id), end-st) == 0) if (strncasecmp(st, this, end-st) == 0)
{ {
var |= HK_CTX_SET(item, hotkey_items[i].action); var |= HK_CTX_SET(item, hotkey_items[i].action);
} }
} }
}
st = end + 1; st = end + 1;
item++; item++;
} }