summaryrefslogtreecommitdiff
path: root/apps/filetypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/filetypes.c')
-rw-r--r--apps/filetypes.c107
1 files changed, 63 insertions, 44 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 77d73df5cc..530dab18c4 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -381,7 +381,7 @@ int filetype_get_color(const char * name, int attr)
381 if (!extension) 381 if (!extension)
382 return custom_colors[MAX_FILETYPES]; 382 return custom_colors[MAX_FILETYPES];
383 extension++; 383 extension++;
384 logf("%s %s",name,extension); 384
385 for (i=1; i<filetype_count; i++) 385 for (i=1; i<filetype_count; i++)
386 { 386 {
387 if (filetypes[i].extension && 387 if (filetypes[i].extension &&
@@ -420,39 +420,40 @@ bool filetype_supported(int attr)
420 return find_attr(attr) >= 0; 420 return find_attr(attr) >= 0;
421} 421}
422 422
423/**** Open With Screen ****/
424enum themable_icons openwith_get_icon(int selected_item, void * data)
425{
426 int *items = (int*)data;
427 return filetypes[items[selected_item]].icon;
428}
429char * openwith_get_name(int selected_item, void * data, char * buffer)
430{
431 (void)buffer;
432 int *items = (int*)data;
433 char *s = strrchr(filetypes[items[selected_item]].plugin, '/');
434 if (s)
435 return s+1;
436 else return filetypes[items[selected_item]].plugin;
437}
438
423int filetype_list_viewers(const char* current_file) 439int filetype_list_viewers(const char* current_file)
424{ 440{
425 int i, count = 0; 441 int i, count = 0, action;
426 char *strings[MAX_FILETYPES/2]; 442 int items[MAX_FILETYPES];
427 char *ext; 443 struct gui_synclist lists;
428 struct menu_callback_with_desc cb_and_desc = 444 for (i=0; i<filetype_count && count < MAX_FILETYPES; i++)
429 { NULL, ID2P(LANG_ONPLAY_OPEN_WITH), Icon_Plugin };
430 struct menu_item_ex menu;
431
432 ext = strrchr(current_file, '.');
433 if (ext)
434 ext++;
435 for (i=0; i<filetype_count && count < (MAX_FILETYPES/2); i++)
436 { 445 {
437 if (filetypes[i].plugin) 446 if (filetypes[i].plugin)
438 { 447 {
439 int j; 448 int j;
440 for (j=0;j<count;j++) /* check if the plugin is in the list yet */ 449 for (j=0;j<count;j++) /* check if the plugin is in the list yet */
441 { 450 {
442 if (!strcmp(strings[j], filetypes[i].plugin)) 451 if (items[j] == i)
443 break; 452 break;
444 } 453 }
445 if (j<count) 454 if (j<count)
446 continue; /* it is so grab the next plugin */ 455 continue; /* it is so grab the next plugin */
447 if (ext && filetypes[i].extension && 456 items[count++] = i;
448 (filetypes[i].extension[0] != '*'))
449 {
450 if (strcasecmp(filetypes[i].extension, ext))
451 continue; /* skip this one */
452 }
453 strings[count] = strrchr(filetypes[i].plugin,'/');
454 if (strings[count])
455 strings[count++]++;
456 } 457 }
457 } 458 }
458#ifndef HAVE_LCD_BITMAP 459#ifndef HAVE_LCD_BITMAP
@@ -463,35 +464,53 @@ int filetype_list_viewers(const char* current_file)
463 return PLUGIN_OK; 464 return PLUGIN_OK;
464 } 465 }
465#endif 466#endif
466 menu.flags = MT_RETURN_ID|MENU_HAS_DESC|MENU_ITEM_COUNT(count); 467 gui_synclist_init(&lists,openwith_get_name,(void*)items, false, 1);
467 menu.strings = (const char**)strings; 468 gui_synclist_set_nb_items(&lists, count);
468 menu.callback_and_desc = &cb_and_desc; 469 gui_synclist_set_icon_callback(&lists, openwith_get_icon);
469 i = do_menu(&menu, NULL); 470 gui_synclist_set_title(&lists, str(LANG_ONPLAY_OPEN_WITH), Icon_Plugin);
470 if (i >= 0) 471 gui_synclist_select_item(&lists, 0);
471 return filetype_load_plugin(strings[i], (void*)current_file); 472 gui_synclist_draw(&lists);
472 return i; 473 while (1)
474 {
475 gui_syncstatusbar_draw(&statusbars, true);
476 action = get_action(CONTEXT_MAINMENU,HZ);
477 if ((action == ACTION_NONE) ||
478 gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD))
479 continue;
480 else if (action == ACTION_STD_OK)
481 {
482 i = gui_synclist_get_sel_pos(&lists);
483 return filetype_load_plugin(filetypes[i].plugin,
484 (void*)current_file);
485 }
486 else if (action == ACTION_STD_CANCEL)
487 return action;
488 }
473} 489}
474 490
475int filetype_load_plugin(const char* plugin, char* file) 491int filetype_load_plugin(const char* plugin, char* file)
476{ 492{
477 int fd; 493 int i;
478 char plugin_name[MAX_PATH]; 494 char plugin_name[MAX_PATH];
479 snprintf(plugin_name, sizeof(plugin_name), "%s/%s.%s", 495 char *s;
480 VIEWERS_DIR, plugin, ROCK_EXTENSION); 496
481 if ((fd = open(plugin_name,O_RDONLY))>=0) 497 for (i=0;i<filetype_count;i++)
482 { 498 {
483 close(fd); 499 if (filetypes[i].plugin)
484 return plugin_load(plugin_name,file);
485 }
486 else
487 {
488 snprintf(plugin_name, sizeof(plugin_name), "%s/%s.%s",
489 PLUGIN_DIR, plugin, ROCK_EXTENSION);
490 if ((fd = open(plugin_name,O_RDONLY))>=0)
491 { 500 {
492 close(fd); 501 s = strrchr(filetypes[i].plugin, '/');
493 return plugin_load(plugin_name,file); 502 if (s)
503 {
504 if (!strcmp(s+1, plugin))
505 break;
506 }
507 else if (!strcmp(filetypes[i].plugin, plugin))
508 break;
494 } 509 }
495 } 510 }
496 return PLUGIN_ERROR; 511 if (i >= filetype_count)
512 return PLUGIN_ERROR;
513 snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
514 PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
515 return plugin_load(plugin_name,file);
497} 516}