onplay hotkey add flags

idea here as discussed with chris_s is to allow flags
in the hotkey_assignment struct to change how items are displayed

Change-Id: Id4cf1d79fbe3ff8f5590b9a863fccf00ddd457f9
This commit is contained in:
William Wilgus 2022-12-15 03:07:18 -05:00
parent 31759c9e53
commit 28f768cb84
3 changed files with 103 additions and 79 deletions

View file

@ -1846,106 +1846,113 @@ static int hotkey_wps_run_plugin(void)
open_plugin_run(ID2P(LANG_HOTKEY_WPS)); open_plugin_run(ID2P(LANG_HOTKEY_WPS));
return ONPLAY_OK; return ONPLAY_OK;
} }
struct hotkey_assignment {
int action; /* hotkey_action */
int lang_id; /* Language ID */
struct menu_func func; /* Function to run if this entry is selected */
int return_code; /* What to return after the function is run. */
}; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */
#define HOTKEY_FUNC(func, param) {{(void *)func}, param} #define HOTKEY_FUNC(func, param) {{(void *)func}, param}
/* Any desired hotkey functions go here, in the enum in onplay.h, /* Any desired hotkey functions go here, in the enum in onplay.h,
and in the settings menu in settings_list.c. The order here and in the settings menu in settings_list.c. The order here
is not important. */ is not important. */
static struct hotkey_assignment hotkey_items[] = { static const struct hotkey_assignment hotkey_items[] = {
{ HOTKEY_VIEW_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST, [0]{ .action = HOTKEY_OFF,
HOTKEY_FUNC(NULL, NULL), .lang_id = LANG_OFF,
ONPLAY_PLAYLIST }, .func = HOTKEY_FUNC(NULL,NULL),
{ HOTKEY_SHOW_TRACK_INFO, LANG_MENU_SHOW_ID3_INFO, .return_code = ONPLAY_RELOAD_DIR,
HOTKEY_FUNC(browse_id3_wrapper, NULL), .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE },
ONPLAY_RELOAD_DIR }, { .action = HOTKEY_VIEW_PLAYLIST,
.lang_id = LANG_VIEW_DYNAMIC_PLAYLIST,
.func = HOTKEY_FUNC(NULL, NULL),
.return_code = ONPLAY_PLAYLIST,
.flags = HOTKEY_FLAG_WPS },
{ .action = HOTKEY_SHOW_TRACK_INFO,
.lang_id = LANG_MENU_SHOW_ID3_INFO,
.func = HOTKEY_FUNC(browse_id3_wrapper, NULL),
.return_code = ONPLAY_RELOAD_DIR,
.flags = HOTKEY_FLAG_WPS },
#ifdef HAVE_PITCHCONTROL #ifdef HAVE_PITCHCONTROL
{ HOTKEY_PITCHSCREEN, LANG_PITCH, { .action = HOTKEY_PITCHSCREEN,
HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), .lang_id = LANG_PITCH,
ONPLAY_RELOAD_DIR }, .func = HOTKEY_FUNC(gui_syncpitchscreen_run, NULL),
.return_code = ONPLAY_RELOAD_DIR,
.flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS },
#endif #endif
{ HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH, { .action = HOTKEY_OPEN_WITH,
HOTKEY_FUNC(hotkey_open_with, NULL), .lang_id = LANG_ONPLAY_OPEN_WITH,
ONPLAY_RELOAD_DIR }, .func = HOTKEY_FUNC(hotkey_open_with, NULL),
{ HOTKEY_DELETE, LANG_DELETE, .return_code = ONPLAY_RELOAD_DIR,
HOTKEY_FUNC(hotkey_delete_item, NULL), .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE },
ONPLAY_RELOAD_DIR }, { .action = HOTKEY_DELETE,
{ HOTKEY_INSERT, LANG_INSERT, .lang_id = LANG_DELETE,
HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert), .func = HOTKEY_FUNC(hotkey_delete_item, NULL),
ONPLAY_RELOAD_DIR }, .return_code = ONPLAY_RELOAD_DIR,
{ HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED, .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE },
HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL), { .action = HOTKEY_INSERT,
ONPLAY_FUNC_RETURN }, .lang_id = LANG_INSERT,
{ HOTKEY_PLUGIN, LANG_OPEN_PLUGIN, .func = HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert),
HOTKEY_FUNC(hotkey_wps_run_plugin, NULL), .return_code = ONPLAY_RELOAD_DIR,
ONPLAY_FUNC_RETURN }, .flags = HOTKEY_FLAG_TREE },
{ HOTKEY_BOOKMARK, LANG_BOOKMARK_MENU_CREATE, { .action = HOTKEY_INSERT_SHUFFLED,
HOTKEY_FUNC(bookmark_create_menu, NULL), .lang_id = LANG_INSERT_SHUFFLED,
ONPLAY_OK }, .func = HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL),
{ HOTKEY_PROPERTIES, LANG_PROPERTIES, .return_code = ONPLAY_FUNC_RETURN,
HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"), .flags = HOTKEY_FLAG_TREE },
ONPLAY_FUNC_RETURN }, { .action = HOTKEY_PLUGIN,
.lang_id = LANG_OPEN_PLUGIN,
.func = HOTKEY_FUNC(hotkey_wps_run_plugin, NULL),
.return_code = ONPLAY_FUNC_RETURN,
.flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS },
{ .action = HOTKEY_BOOKMARK,
.lang_id = LANG_BOOKMARK_MENU_CREATE,
.func = HOTKEY_FUNC(bookmark_create_menu, NULL),
.return_code = ONPLAY_OK,
.flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS },
{ .action = HOTKEY_PROPERTIES,
.lang_id = LANG_PROPERTIES,
.func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"),
.return_code = ONPLAY_FUNC_RETURN,
.flags = HOTKEY_FLAG_TREE },
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
{ HOTKEY_PICTUREFLOW, LANG_ONPLAY_PICTUREFLOW, { .action = HOTKEY_PICTUREFLOW,
HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"), .lang_id = LANG_ONPLAY_PICTUREFLOW,
ONPLAY_FUNC_RETURN }, .func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"),
.return_code = ONPLAY_FUNC_RETURN,
.flags = HOTKEY_FLAG_TREE },
#endif #endif
}; };
/* Return the language ID for this action */ const struct hotkey_assignment *get_hotkey(int action)
int get_hotkey_lang_id(int action)
{ {
int i = ARRAYLEN(hotkey_items); for (size_t i = ARRAYLEN(hotkey_items) - 1; i < ARRAYLEN(hotkey_items); i--)
while (i--)
{ {
if (hotkey_items[i].action == action) if (hotkey_items[i].action == action)
return hotkey_items[i].lang_id; return &hotkey_items[i];
} }
return &hotkey_items[0]; /* no valid hotkey set, return HOTKEY_OFF*/
return LANG_OFF;
} }
/* Execute the hotkey function, if listed */ /* Execute the hotkey function, if listed */
static int execute_hotkey(bool is_wps) static int execute_hotkey(bool is_wps)
{ {
int i = ARRAYLEN(hotkey_items);
struct hotkey_assignment *this_item;
const int action = (is_wps ? global_settings.hotkey_wps : const int action = (is_wps ? global_settings.hotkey_wps :
global_settings.hotkey_tree); global_settings.hotkey_tree);
/* search assignment struct for a match for the hotkey setting */ /* search assignment struct for a match for the hotkey setting */
while (i--) const struct hotkey_assignment *this_item = get_hotkey(action);
/* run the associated function (with optional param), if any */
const struct menu_func func = this_item->func;
int func_return = ONPLAY_RELOAD_DIR;
if (func.function != NULL)
{ {
this_item = &hotkey_items[i]; if (func.param != NULL)
if (this_item->action == action) func_return = (*func.function_w_param)(func.param);
{ else
/* run the associated function (with optional param), if any */ func_return = (*func.function)();
const struct menu_func func = this_item->func;
int func_return = ONPLAY_RELOAD_DIR;
if (func.function != NULL)
{
if (func.param != NULL)
func_return = (*func.function_w_param)(func.param);
else
func_return = (*func.function)();
}
const int return_code = this_item->return_code;
if (return_code == ONPLAY_FUNC_RETURN)
return func_return; /* Use value returned by function */
return return_code; /* or return the associated value */
}
} }
const int return_code = this_item->return_code;
/* no valid hotkey set, ignore hotkey */ if (return_code == ONPLAY_FUNC_RETURN)
return ONPLAY_RELOAD_DIR; return func_return; /* Use value returned by function */
return return_code; /* or return the associated value */
} }
#endif /* HOTKEY */ #endif /* HOTKEY */

View file

@ -21,6 +21,10 @@
#ifndef _ONPLAY_H_ #ifndef _ONPLAY_H_
#define _ONPLAY_H_ #define _ONPLAY_H_
#ifdef HAVE_HOTKEY
#include "menu.h"
#endif
int onplay(char* file, int attr, int from_screen, bool hotkey); int onplay(char* file, int attr, int from_screen, bool hotkey);
int get_onplay_context(void); int get_onplay_context(void);
@ -37,15 +41,12 @@ enum {
}; };
#ifdef HAVE_HOTKEY #ifdef HAVE_HOTKEY
int get_hotkey_lang_id(int action);
enum hotkey_action { enum hotkey_action {
HOTKEY_OFF = 0, HOTKEY_OFF = 0,
HOTKEY_VIEW_PLAYLIST, HOTKEY_VIEW_PLAYLIST,
HOTKEY_PROPERTIES, HOTKEY_PROPERTIES,
#ifdef HAVE_TAGCACHE
HOTKEY_PICTUREFLOW, HOTKEY_PICTUREFLOW,
#endif
HOTKEY_SHOW_TRACK_INFO, HOTKEY_SHOW_TRACK_INFO,
HOTKEY_PITCHSCREEN, HOTKEY_PITCHSCREEN,
HOTKEY_OPEN_WITH, HOTKEY_OPEN_WITH,
@ -55,6 +56,22 @@ enum hotkey_action {
HOTKEY_INSERT, HOTKEY_INSERT,
HOTKEY_INSERT_SHUFFLED, HOTKEY_INSERT_SHUFFLED,
}; };
enum hotkey_flags {
HOTKEY_FLAG_NONE = 0x0,
HOTKEY_FLAG_WPS = 0x1,
HOTKEY_FLAG_TREE = 0x2,
HOTKEY_FLAG_NOSBS = 0x4,
};
struct hotkey_assignment {
int action; /* hotkey_action */
int lang_id; /* Language ID */
struct menu_func func; /* Function to run if this entry is selected */
int16_t return_code; /* What to return after the function is run. */
uint16_t flags; /* Flags what context, display options */
}; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */
const struct hotkey_assignment *get_hotkey(int action);
#endif #endif
/* needed for the playlist viewer.. eventually clean this up */ /* needed for the playlist viewer.. eventually clean this up */

View file

@ -700,7 +700,7 @@ static void hotkey_callback(int var)
{ {
if (get_current_activity() != ACTIVITY_QUICKSCREEN) if (get_current_activity() != ACTIVITY_QUICKSCREEN)
{ {
if (get_hotkey_lang_id(var) == LANG_OPEN_PLUGIN) if (get_hotkey(var)->action == HOTKEY_PLUGIN)
open_plugin_browse(ID2P(LANG_HOTKEY_WPS)); open_plugin_browse(ID2P(LANG_HOTKEY_WPS));
} }
} }
@ -710,12 +710,12 @@ static const char* hotkey_formatter(char* buffer, size_t buffer_size, int value,
(void)buffer; (void)buffer;
(void)buffer_size; (void)buffer_size;
(void)unit; (void)unit;
return str(get_hotkey_lang_id(value)); return str(get_hotkey(value)->lang_id);
} }
static int32_t hotkey_getlang(int value, int unit) static int32_t hotkey_getlang(int value, int unit)
{ {
(void)unit; (void)unit;
return get_hotkey_lang_id(value); return get_hotkey(value)->lang_id;
} }
#endif /* HAVE_HOTKEY */ #endif /* HAVE_HOTKEY */