1
0
Fork 0
forked from len0rd/rockbox

More hotkey code cleanup

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25942 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jeffrey Goode 2010-05-11 04:41:15 +00:00
parent f16912f624
commit 156272fced
2 changed files with 25 additions and 34 deletions

View file

@ -1195,15 +1195,11 @@ static bool open_with(void)
return list_viewers(); return list_viewers();
} }
#define HOTKEY_ACTION_MASK 0x0FF /* Mask to apply to get the action (enum) */
#define HOTKEY_CTX_WPS 0x100 /* Mask to apply to check whether it's for WPS */
#define HOTKEY_CTX_TREE 0x200 /* Mask to apply to check whether it's for the tree */
struct hotkey_assignment { struct hotkey_assignment {
int item; /* Bit or'd hotkey_action and HOTKEY_CTX_x */ int action; /* hotkey_action */
int lang_id; /* Language ID */
struct menu_func func; /* Function to run if this entry is selected */ struct menu_func func; /* Function to run if this entry is selected */
int return_code; /* What to return after the function is run */ int return_code; /* What to return after the function is run */
int lang_id; /* Language ID */
}; };
#define HOTKEY_FUNC(func, param) {{(void *)func}, param} #define HOTKEY_FUNC(func, param) {{(void *)func}, param}
@ -1212,61 +1208,56 @@ struct hotkey_assignment {
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 struct hotkey_assignment hotkey_items[] = {
{ HOTKEY_VIEW_PLAYLIST | HOTKEY_CTX_WPS, { HOTKEY_VIEW_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST,
HOTKEY_FUNC(NULL, NULL), HOTKEY_FUNC(NULL, NULL),
ONPLAY_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST }, ONPLAY_PLAYLIST },
{ HOTKEY_SHOW_TRACK_INFO| HOTKEY_CTX_WPS, { HOTKEY_SHOW_TRACK_INFO, LANG_MENU_SHOW_ID3_INFO,
HOTKEY_FUNC(browse_id3, NULL), HOTKEY_FUNC(browse_id3, NULL),
ONPLAY_RELOAD_DIR, LANG_MENU_SHOW_ID3_INFO }, ONPLAY_RELOAD_DIR },
#ifdef HAVE_PITCHSCREEN #ifdef HAVE_PITCHSCREEN
{ HOTKEY_PITCHSCREEN | HOTKEY_CTX_WPS, { HOTKEY_PITCHSCREEN, LANG_PITCH,
HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), HOTKEY_FUNC(gui_syncpitchscreen_run, NULL),
ONPLAY_RELOAD_DIR, LANG_PITCH }, ONPLAY_RELOAD_DIR },
#endif #endif
{ HOTKEY_OPEN_WITH | HOTKEY_CTX_WPS | HOTKEY_CTX_TREE, { HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH,
HOTKEY_FUNC(open_with, NULL), HOTKEY_FUNC(open_with, NULL),
ONPLAY_RELOAD_DIR, LANG_ONPLAY_OPEN_WITH }, ONPLAY_RELOAD_DIR },
{ HOTKEY_DELETE | HOTKEY_CTX_WPS | HOTKEY_CTX_TREE, { HOTKEY_DELETE, LANG_DELETE,
HOTKEY_FUNC(delete_item, NULL), HOTKEY_FUNC(delete_item, NULL),
ONPLAY_RELOAD_DIR, LANG_DELETE }, ONPLAY_RELOAD_DIR },
{ HOTKEY_DELETE | HOTKEY_CTX_TREE, { HOTKEY_INSERT, LANG_INSERT,
HOTKEY_FUNC(delete_item, NULL),
ONPLAY_RELOAD_DIR, LANG_DELETE },
{ HOTKEY_INSERT | HOTKEY_CTX_TREE,
HOTKEY_FUNC(playlist_insert_func, (intptr_t*)PLAYLIST_INSERT), HOTKEY_FUNC(playlist_insert_func, (intptr_t*)PLAYLIST_INSERT),
ONPLAY_START_PLAY, LANG_INSERT }, ONPLAY_START_PLAY },
}; };
static const int num_hotkey_items = sizeof(hotkey_items) / sizeof(hotkey_items[0]); static const int num_hotkey_items = sizeof(hotkey_items) / sizeof(hotkey_items[0]);
/* Return the language ID for the input function */ /* Return the language ID for this action */
int get_hotkey_lang_id(int hk_func) int get_hotkey_lang_id(int action)
{ {
int i; int i = num_hotkey_items;
for (i = 0; i < num_hotkey_items; i++) while (i--)
{ {
if ((hotkey_items[i].item & HOTKEY_ACTION_MASK) == hk_func) if (hotkey_items[i].action == action)
return hotkey_items[i].lang_id; return hotkey_items[i].lang_id;
} }
return LANG_OFF; return LANG_OFF;
} }
/* Execute the hotkey function, if listed for this screen */ /* Execute the hotkey function, if listed */
static int execute_hotkey(bool is_wps) static int execute_hotkey(bool is_wps)
{ {
int i; int i = num_hotkey_items;
struct hotkey_assignment *this_item; struct hotkey_assignment *this_item;
const int context = is_wps ? HOTKEY_CTX_WPS : HOTKEY_CTX_TREE; const int action = (is_wps ? global_settings.hotkey_wps :
const int this_hotkey = (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 */
for (i = 0; i < num_hotkey_items; i++) while (i--)
{ {
this_item = &hotkey_items[i]; this_item = &hotkey_items[i];
if ((this_item->item & context) && if (this_item->action == action)
((this_item->item & HOTKEY_ACTION_MASK) == this_hotkey))
{ {
/* run the associated function (with optional param), if any */ /* run the associated function (with optional param), if any */
const struct menu_func func = this_item->func; const struct menu_func func = this_item->func;

View file

@ -32,7 +32,7 @@ enum {
}; };
#ifdef HAVE_HOTKEY #ifdef HAVE_HOTKEY
int get_hotkey_lang_id(int hk_func); int get_hotkey_lang_id(int action);
enum hotkey_action { enum hotkey_action {
HOTKEY_OFF = 0, HOTKEY_OFF = 0,