summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/filetypes.c56
-rw-r--r--apps/filetypes.h5
-rw-r--r--apps/open_plugin.c6
3 files changed, 52 insertions, 15 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index e992b86060..38ed7650e3 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -604,11 +604,11 @@ int filetype_get_icon(int attr)
604 return filetypes[index].icon; 604 return filetypes[index].icon;
605} 605}
606 606
607char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len) 607static int filetype_get_plugin_index(int attr)
608{ 608{
609 int index = find_attr(attr); 609 int index = find_attr(attr);
610 if (index < 0 || !buffer) 610 if (index < 0)
611 return NULL; 611 return -1;
612 struct file_type *ft_indexed = &filetypes[index]; 612 struct file_type *ft_indexed = &filetypes[index];
613 613
614 /* attempt to find a suitable viewer by file extension */ 614 /* attempt to find a suitable viewer by file extension */
@@ -621,17 +621,27 @@ char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len)
621 ft = &filetypes[i]; 621 ft = &filetypes[i];
622 if (ft->plugin == NULL || ft->extension == NULL) 622 if (ft->plugin == NULL || ft->extension == NULL)
623 continue; 623 continue;
624 else if (strcmp(ft->extension, ft_indexed->extension) == 0) 624 else if (ft->plugin != NULL &&
625 strcmp(ft->extension, ft_indexed->extension) == 0)
625 { 626 {
626 /*splashf(HZ*3, "Found %d %s %s", i, ft->extension, ft->plugin);*/ 627 /*splashf(HZ*3, "Found %d %s %s", i, ft->extension, ft->plugin);*/
627 ft_indexed = ft; 628 return i;
628 break;
629 } 629 }
630 } 630 }
631 } 631 }
632 if (ft_indexed->plugin == NULL) 632 if (ft_indexed->plugin == NULL)
633 index = -1;
634 return index; /* Not Found */
635}
636
637char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len)
638{
639 int index = filetype_get_plugin_index(attr);
640 if (index < 0 || !buffer)
633 return NULL; 641 return NULL;
634 642
643 struct file_type *ft_indexed = &filetypes[index];
644
635 snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION, 645 snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION,
636 PLUGIN_DIR, ft_indexed->plugin); 646 PLUGIN_DIR, ft_indexed->plugin);
637 return buffer; 647 return buffer;
@@ -674,24 +684,48 @@ static int openwith_get_talk(int selected_item, void * data)
674 return 0; 684 return 0;
675} 685}
676 686
677int filetype_list_viewers(const char* current_file) 687char* filetype_get_viewer(char *buffer, size_t buffer_len, const char* current_file)
678{ 688{
689 int attr = filetype_get_attr(current_file);
690
679 struct simplelist_info info; 691 struct simplelist_info info;
680 simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), viewer_count, NULL); 692 simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), viewer_count, NULL);
693
694 int default_index = filetype_get_plugin_index(attr);
695
696 if (default_index >= 0)
697 {
698 for (int i = 0; i < viewer_count; i++)
699 if (viewers[i] == default_index)
700 {
701 info.selection = i;
702 break;
703 }
704 }
705
681 info.get_name = openwith_get_name; 706 info.get_name = openwith_get_name;
682 info.get_icon = global_settings.show_icons?openwith_get_icon:NULL; 707 info.get_icon = global_settings.show_icons?openwith_get_icon:NULL;
683 info.get_talk = openwith_get_talk; 708 info.get_talk = openwith_get_talk;
684 709
685 int ret = simplelist_show_list(&info); 710 simplelist_show_list(&info);
686 711
687 if (info.selection >= 0) /* run user selected viewer */ 712 if (info.selection >= 0) /* run user selected viewer */
688 { 713 {
689 char plugin[MAX_PATH];
690 int i = viewers[info.selection]; 714 int i = viewers[info.selection];
691 snprintf(plugin, MAX_PATH, "%s/%s." ROCK_EXTENSION, 715 snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION,
692 PLUGIN_DIR, filetypes[i].plugin); 716 PLUGIN_DIR, filetypes[i].plugin);
693 ret = plugin_load(plugin, current_file); 717 return buffer;
694 } 718 }
719 return NULL;
720
721}
722
723int filetype_list_viewers(const char* current_file)
724{
725 int ret = PLUGIN_ERROR;
726 char plugin[MAX_PATH];
727 if (filetype_get_viewer(plugin, sizeof(plugin), current_file) != NULL)
728 ret = plugin_load(plugin, current_file);
695 return ret; 729 return ret;
696} 730}
697 731
diff --git a/apps/filetypes.h b/apps/filetypes.h
index 36d9009a87..4039daf497 100644
--- a/apps/filetypes.h
+++ b/apps/filetypes.h
@@ -79,9 +79,12 @@ char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len);
79/* returns true if the attr is supported */ 79/* returns true if the attr is supported */
80bool filetype_supported(int attr); 80bool filetype_supported(int attr);
81 81
82/* List avialable viewers */ 82/* List avialable viewers and start selected plugin with current_file as argument */
83int filetype_list_viewers(const char* current_file); 83int filetype_list_viewers(const char* current_file);
84 84
85/* return the plugin filename the user selected for the file Returns NULL if canceled */
86char* filetype_get_viewer(char *buffer, size_t buffer_len, const char* current_file);
87
85/* start a plugin with file as the argument (called from onplay.c) */ 88/* start a plugin with file as the argument (called from onplay.c) */
86int filetype_load_plugin(const char* plugin, const char* file); 89int filetype_load_plugin(const char* plugin, const char* file);
87 90
diff --git a/apps/open_plugin.c b/apps/open_plugin.c
index e10463d260..8b5fce1d29 100644
--- a/apps/open_plugin.c
+++ b/apps/open_plugin.c
@@ -323,10 +323,10 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
323 /* get the entry from the opx file */ 323 /* get the entry from the opx file */
324 op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin); 324 op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin);
325 } 325 }
326 else if(!parameter) 326 else if(!parameter && lang_id != LANG_SHORTCUTS)
327 { 327 {
328 strmemccpy(op_entry->param, plugin, OPEN_PLUGIN_BUFSZ); 328 strmemccpy(op_entry->param, plugin, OPEN_PLUGIN_BUFSZ);
329 plugin = filetype_get_plugin(fattr, op_entry->path, OPEN_PLUGIN_BUFSZ); 329 plugin = filetype_get_viewer(op_entry->path, OPEN_PLUGIN_BUFSZ, plugin);
330 if (!plugin) 330 if (!plugin)
331 { 331 {
332 logf("OP no plugin found to run %s", op_entry->param); 332 logf("OP no plugin found to run %s", op_entry->param);
@@ -376,7 +376,7 @@ static bool callback_show_item(char *name, int attr, struct tree_context *tc)
376 return false; 376 return false;
377#endif 377#endif
378 return attr & ATTR_DIRECTORY || 378 return attr & ATTR_DIRECTORY ||
379 (filetype_supported(attr) && (attr & FILE_ATTR_AUDIO) == 0); 379 (filetype_supported(attr) && (attr & FILE_ATTR_AUDIO) != FILE_ATTR_AUDIO);
380} 380}
381 381
382/* open_plugin_browse() 382/* open_plugin_browse()