summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2010-05-11 04:41:15 +0000
committerJeffrey Goode <jeffg7@gmail.com>2010-05-11 04:41:15 +0000
commit156272fced75d2852b2a6c3f68df3d69f0038757 (patch)
tree495ca31c50dbff22f79258ca7f46acdfd471800a
parentf16912f624ed5cb9484b3570d241219ee75e81ac (diff)
downloadrockbox-156272fced75d2852b2a6c3f68df3d69f0038757.tar.gz
rockbox-156272fced75d2852b2a6c3f68df3d69f0038757.zip
More hotkey code cleanup
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25942 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/onplay.c57
-rw-r--r--apps/onplay.h2
2 files changed, 25 insertions, 34 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
index c9ec565a0c..fc236fc854 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -1195,15 +1195,11 @@ static bool open_with(void)
1195 return list_viewers(); 1195 return list_viewers();
1196} 1196}
1197 1197
1198#define HOTKEY_ACTION_MASK 0x0FF /* Mask to apply to get the action (enum) */
1199#define HOTKEY_CTX_WPS 0x100 /* Mask to apply to check whether it's for WPS */
1200#define HOTKEY_CTX_TREE 0x200 /* Mask to apply to check whether it's for the tree */
1201
1202struct hotkey_assignment { 1198struct hotkey_assignment {
1203 int item; /* Bit or'd hotkey_action and HOTKEY_CTX_x */ 1199 int action; /* hotkey_action */
1200 int lang_id; /* Language ID */
1204 struct menu_func func; /* Function to run if this entry is selected */ 1201 struct menu_func func; /* Function to run if this entry is selected */
1205 int return_code; /* What to return after the function is run */ 1202 int return_code; /* What to return after the function is run */
1206 int lang_id; /* Language ID */
1207}; 1203};
1208 1204
1209#define HOTKEY_FUNC(func, param) {{(void *)func}, param} 1205#define HOTKEY_FUNC(func, param) {{(void *)func}, param}
@@ -1212,61 +1208,56 @@ struct hotkey_assignment {
1212 and in the settings menu in settings_list.c. The order here 1208 and in the settings menu in settings_list.c. The order here
1213 is not important. */ 1209 is not important. */
1214static struct hotkey_assignment hotkey_items[] = { 1210static struct hotkey_assignment hotkey_items[] = {
1215 { HOTKEY_VIEW_PLAYLIST | HOTKEY_CTX_WPS, 1211 { HOTKEY_VIEW_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST,
1216 HOTKEY_FUNC(NULL, NULL), 1212 HOTKEY_FUNC(NULL, NULL),
1217 ONPLAY_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST }, 1213 ONPLAY_PLAYLIST },
1218 { HOTKEY_SHOW_TRACK_INFO| HOTKEY_CTX_WPS, 1214 { HOTKEY_SHOW_TRACK_INFO, LANG_MENU_SHOW_ID3_INFO,
1219 HOTKEY_FUNC(browse_id3, NULL), 1215 HOTKEY_FUNC(browse_id3, NULL),
1220 ONPLAY_RELOAD_DIR, LANG_MENU_SHOW_ID3_INFO }, 1216 ONPLAY_RELOAD_DIR },
1221#ifdef HAVE_PITCHSCREEN 1217#ifdef HAVE_PITCHSCREEN
1222 { HOTKEY_PITCHSCREEN | HOTKEY_CTX_WPS, 1218 { HOTKEY_PITCHSCREEN, LANG_PITCH,
1223 HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), 1219 HOTKEY_FUNC(gui_syncpitchscreen_run, NULL),
1224 ONPLAY_RELOAD_DIR, LANG_PITCH }, 1220 ONPLAY_RELOAD_DIR },
1225#endif 1221#endif
1226 { HOTKEY_OPEN_WITH | HOTKEY_CTX_WPS | HOTKEY_CTX_TREE, 1222 { HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH,
1227 HOTKEY_FUNC(open_with, NULL), 1223 HOTKEY_FUNC(open_with, NULL),
1228 ONPLAY_RELOAD_DIR, LANG_ONPLAY_OPEN_WITH }, 1224 ONPLAY_RELOAD_DIR },
1229 { HOTKEY_DELETE | HOTKEY_CTX_WPS | HOTKEY_CTX_TREE, 1225 { HOTKEY_DELETE, LANG_DELETE,
1230 HOTKEY_FUNC(delete_item, NULL), 1226 HOTKEY_FUNC(delete_item, NULL),
1231 ONPLAY_RELOAD_DIR, LANG_DELETE }, 1227 ONPLAY_RELOAD_DIR },
1232 { HOTKEY_DELETE | HOTKEY_CTX_TREE, 1228 { HOTKEY_INSERT, LANG_INSERT,
1233 HOTKEY_FUNC(delete_item, NULL),
1234 ONPLAY_RELOAD_DIR, LANG_DELETE },
1235 { HOTKEY_INSERT | HOTKEY_CTX_TREE,
1236 HOTKEY_FUNC(playlist_insert_func, (intptr_t*)PLAYLIST_INSERT), 1229 HOTKEY_FUNC(playlist_insert_func, (intptr_t*)PLAYLIST_INSERT),
1237 ONPLAY_START_PLAY, LANG_INSERT }, 1230 ONPLAY_START_PLAY },
1238}; 1231};
1239 1232
1240static const int num_hotkey_items = sizeof(hotkey_items) / sizeof(hotkey_items[0]); 1233static const int num_hotkey_items = sizeof(hotkey_items) / sizeof(hotkey_items[0]);
1241 1234
1242/* Return the language ID for the input function */ 1235/* Return the language ID for this action */
1243int get_hotkey_lang_id(int hk_func) 1236int get_hotkey_lang_id(int action)
1244{ 1237{
1245 int i; 1238 int i = num_hotkey_items;
1246 for (i = 0; i < num_hotkey_items; i++) 1239 while (i--)
1247 { 1240 {
1248 if ((hotkey_items[i].item & HOTKEY_ACTION_MASK) == hk_func) 1241 if (hotkey_items[i].action == action)
1249 return hotkey_items[i].lang_id; 1242 return hotkey_items[i].lang_id;
1250 } 1243 }
1251 1244
1252 return LANG_OFF; 1245 return LANG_OFF;
1253} 1246}
1254 1247
1255/* Execute the hotkey function, if listed for this screen */ 1248/* Execute the hotkey function, if listed */
1256static int execute_hotkey(bool is_wps) 1249static int execute_hotkey(bool is_wps)
1257{ 1250{
1258 int i; 1251 int i = num_hotkey_items;
1259 struct hotkey_assignment *this_item; 1252 struct hotkey_assignment *this_item;
1260 const int context = is_wps ? HOTKEY_CTX_WPS : HOTKEY_CTX_TREE; 1253 const int action = (is_wps ? global_settings.hotkey_wps :
1261 const int this_hotkey = (is_wps ? global_settings.hotkey_wps :
1262 global_settings.hotkey_tree); 1254 global_settings.hotkey_tree);
1263 1255
1264 /* search assignment struct for a match for the hotkey setting */ 1256 /* search assignment struct for a match for the hotkey setting */
1265 for (i = 0; i < num_hotkey_items; i++) 1257 while (i--)
1266 { 1258 {
1267 this_item = &hotkey_items[i]; 1259 this_item = &hotkey_items[i];
1268 if ((this_item->item & context) && 1260 if (this_item->action == action)
1269 ((this_item->item & HOTKEY_ACTION_MASK) == this_hotkey))
1270 { 1261 {
1271 /* run the associated function (with optional param), if any */ 1262 /* run the associated function (with optional param), if any */
1272 const struct menu_func func = this_item->func; 1263 const struct menu_func func = this_item->func;
diff --git a/apps/onplay.h b/apps/onplay.h
index 161366ecc2..a489b09cce 100644
--- a/apps/onplay.h
+++ b/apps/onplay.h
@@ -32,7 +32,7 @@ enum {
32}; 32};
33 33
34#ifdef HAVE_HOTKEY 34#ifdef HAVE_HOTKEY
35int get_hotkey_lang_id(int hk_func); 35int get_hotkey_lang_id(int action);
36 36
37enum hotkey_action { 37enum hotkey_action {
38 HOTKEY_OFF = 0, 38 HOTKEY_OFF = 0,