diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/filetypes.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index 5e72fca5a1..b5825044f1 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -421,26 +421,48 @@ bool filetype_supported(int attr) | |||
421 | } | 421 | } |
422 | 422 | ||
423 | /**** Open With Screen ****/ | 423 | /**** Open With Screen ****/ |
424 | struct cb_data { | ||
425 | int *items; | ||
426 | char *current_file; | ||
427 | }; | ||
424 | enum themable_icons openwith_get_icon(int selected_item, void * data) | 428 | enum themable_icons openwith_get_icon(int selected_item, void * data) |
425 | { | 429 | { |
426 | int *items = (int*)data; | 430 | struct cb_data *info = (struct cb_data *)data; |
431 | int *items = info->items; | ||
427 | return filetypes[items[selected_item]].icon; | 432 | return filetypes[items[selected_item]].icon; |
428 | } | 433 | } |
429 | char * openwith_get_name(int selected_item, void * data, char * buffer) | 434 | char * openwith_get_name(int selected_item, void * data, char * buffer) |
430 | { | 435 | { |
431 | (void)buffer; | 436 | (void)buffer; |
432 | int *items = (int*)data; | 437 | struct cb_data *info = (struct cb_data *)data; |
438 | int *items = info->items; | ||
433 | char *s = strrchr(filetypes[items[selected_item]].plugin, '/'); | 439 | char *s = strrchr(filetypes[items[selected_item]].plugin, '/'); |
434 | if (s) | 440 | if (s) |
435 | return s+1; | 441 | return s+1; |
436 | else return filetypes[items[selected_item]].plugin; | 442 | else return filetypes[items[selected_item]].plugin; |
437 | } | 443 | } |
438 | 444 | int openwith_action_callback(int action, struct gui_synclist *lists) | |
445 | { | ||
446 | struct cb_data *info = (struct cb_data *)lists->gui_list[SCREEN_MAIN].data; | ||
447 | int *items = info->items; | ||
448 | int i; | ||
449 | if (action == ACTION_STD_OK) | ||
450 | { | ||
451 | char plugin[MAX_PATH]; | ||
452 | i = items[gui_synclist_get_sel_pos(lists)]; | ||
453 | snprintf(plugin, MAX_PATH, "%s/%s.%s", | ||
454 | PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION); | ||
455 | plugin_load(plugin, info->current_file); | ||
456 | return ACTION_STD_CANCEL; | ||
457 | } | ||
458 | return action; | ||
459 | } | ||
439 | int filetype_list_viewers(const char* current_file) | 460 | int filetype_list_viewers(const char* current_file) |
440 | { | 461 | { |
441 | int i, count = 0, action; | 462 | int i, count = 0; |
442 | int items[MAX_FILETYPES]; | 463 | int items[MAX_FILETYPES]; |
443 | struct gui_synclist lists; | 464 | struct simplelist_info info; |
465 | struct cb_data data = { items, (char*)current_file }; | ||
444 | for (i=0; i<filetype_count && count < MAX_FILETYPES; i++) | 466 | for (i=0; i<filetype_count && count < MAX_FILETYPES; i++) |
445 | { | 467 | { |
446 | if (filetypes[i].plugin) | 468 | if (filetypes[i].plugin) |
@@ -465,30 +487,15 @@ int filetype_list_viewers(const char* current_file) | |||
465 | return PLUGIN_OK; | 487 | return PLUGIN_OK; |
466 | } | 488 | } |
467 | #endif | 489 | #endif |
468 | gui_synclist_init(&lists,openwith_get_name,(void*)items, false, 1); | 490 | info.title = str(LANG_ONPLAY_OPEN_WITH); |
469 | gui_synclist_set_nb_items(&lists, count); | 491 | info.count = count; |
470 | gui_synclist_set_icon_callback(&lists, openwith_get_icon); | 492 | info.selection_size = 1; info.hide_selection = false; |
471 | gui_synclist_set_title(&lists, str(LANG_ONPLAY_OPEN_WITH), Icon_Plugin); | 493 | info.scroll_all = false; |
472 | gui_synclist_select_item(&lists, 0); | 494 | info.action_callback = openwith_action_callback; |
473 | gui_synclist_draw(&lists); | 495 | info.get_name = openwith_get_name; |
474 | while (1) | 496 | info.get_icon = openwith_get_icon; |
475 | { | 497 | info.callback_data = &data; |
476 | gui_syncstatusbar_draw(&statusbars, true); | 498 | return simplelist_show_list(&info); |
477 | action = get_action(CONTEXT_MAINMENU,HZ); | ||
478 | if ((action == ACTION_NONE) || | ||
479 | gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD)) | ||
480 | continue; | ||
481 | else if (action == ACTION_STD_OK) | ||
482 | { | ||
483 | char plugin[MAX_PATH]; | ||
484 | i = items[gui_synclist_get_sel_pos(&lists)]; | ||
485 | snprintf(plugin, MAX_PATH, "%s/%s.%s", | ||
486 | PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION); | ||
487 | return plugin_load(plugin, (char*)current_file); | ||
488 | } | ||
489 | else if (action == ACTION_STD_CANCEL) | ||
490 | return action; | ||
491 | } | ||
492 | } | 499 | } |
493 | 500 | ||
494 | int filetype_load_plugin(const char* plugin, char* file) | 501 | int filetype_load_plugin(const char* plugin, char* file) |