summaryrefslogtreecommitdiff
path: root/apps/filetypes.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-05-09 15:29:54 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2024-05-09 16:13:24 -0400
commit4128a1fe48c63e32196276bbc1eae6ac4871ec5c (patch)
tree95545e2c51a5f826e6f5c4f512d4634197225327 /apps/filetypes.c
parent6e82897bfc2a4b7206e1b6db12002a979b17095e (diff)
downloadrockbox-4128a1fe48c63e32196276bbc1eae6ac4871ec5c.tar.gz
rockbox-4128a1fe48c63e32196276bbc1eae6ac4871ec5c.zip
[Bugfix/Feature] OpenPlugin and default plugins
selecting files to run is nice and all but you might not like the plugin you can edit it OpenPlugin Viewer Plugin but instead pop it when you add a file to reduce suprises shortcut viewer is not ready for this so exclude it for now Change-Id: I950599d87f47d42e8c2d59695f6583d497b217f0 adds: default plugin (if any) is selected in the open with dialog
Diffstat (limited to 'apps/filetypes.c')
-rw-r--r--apps/filetypes.c56
1 files changed, 45 insertions, 11 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