From 4128a1fe48c63e32196276bbc1eae6ac4871ec5c Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 9 May 2024 15:29:54 -0400 Subject: [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 --- apps/filetypes.c | 56 +++++++++++++++++++++++++++++++++++++++++++----------- apps/filetypes.h | 5 ++++- apps/open_plugin.c | 6 +++--- 3 files changed, 52 insertions(+), 15 deletions(-) (limited to 'apps') 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) return filetypes[index].icon; } -char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len) +static int filetype_get_plugin_index(int attr) { int index = find_attr(attr); - if (index < 0 || !buffer) - return NULL; + if (index < 0) + return -1; struct file_type *ft_indexed = &filetypes[index]; /* 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) ft = &filetypes[i]; if (ft->plugin == NULL || ft->extension == NULL) continue; - else if (strcmp(ft->extension, ft_indexed->extension) == 0) + else if (ft->plugin != NULL && + strcmp(ft->extension, ft_indexed->extension) == 0) { /*splashf(HZ*3, "Found %d %s %s", i, ft->extension, ft->plugin);*/ - ft_indexed = ft; - break; + return i; } } } if (ft_indexed->plugin == NULL) + index = -1; + return index; /* Not Found */ +} + +char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len) +{ + int index = filetype_get_plugin_index(attr); + if (index < 0 || !buffer) return NULL; + struct file_type *ft_indexed = &filetypes[index]; + snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION, PLUGIN_DIR, ft_indexed->plugin); return buffer; @@ -674,24 +684,48 @@ static int openwith_get_talk(int selected_item, void * data) return 0; } -int filetype_list_viewers(const char* current_file) +char* filetype_get_viewer(char *buffer, size_t buffer_len, const char* current_file) { + int attr = filetype_get_attr(current_file); + struct simplelist_info info; simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), viewer_count, NULL); + + int default_index = filetype_get_plugin_index(attr); + + if (default_index >= 0) + { + for (int i = 0; i < viewer_count; i++) + if (viewers[i] == default_index) + { + info.selection = i; + break; + } + } + info.get_name = openwith_get_name; info.get_icon = global_settings.show_icons?openwith_get_icon:NULL; info.get_talk = openwith_get_talk; - int ret = simplelist_show_list(&info); + simplelist_show_list(&info); if (info.selection >= 0) /* run user selected viewer */ { - char plugin[MAX_PATH]; int i = viewers[info.selection]; - snprintf(plugin, MAX_PATH, "%s/%s." ROCK_EXTENSION, + snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION, PLUGIN_DIR, filetypes[i].plugin); - ret = plugin_load(plugin, current_file); + return buffer; } + return NULL; + +} + +int filetype_list_viewers(const char* current_file) +{ + int ret = PLUGIN_ERROR; + char plugin[MAX_PATH]; + if (filetype_get_viewer(plugin, sizeof(plugin), current_file) != NULL) + ret = plugin_load(plugin, current_file); return ret; } 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); /* returns true if the attr is supported */ bool filetype_supported(int attr); -/* List avialable viewers */ +/* List avialable viewers and start selected plugin with current_file as argument */ int filetype_list_viewers(const char* current_file); +/* return the plugin filename the user selected for the file Returns NULL if canceled */ +char* filetype_get_viewer(char *buffer, size_t buffer_len, const char* current_file); + /* start a plugin with file as the argument (called from onplay.c) */ int filetype_load_plugin(const char* plugin, const char* file); 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 /* get the entry from the opx file */ op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin); } - else if(!parameter) + else if(!parameter && lang_id != LANG_SHORTCUTS) { strmemccpy(op_entry->param, plugin, OPEN_PLUGIN_BUFSZ); - plugin = filetype_get_plugin(fattr, op_entry->path, OPEN_PLUGIN_BUFSZ); + plugin = filetype_get_viewer(op_entry->path, OPEN_PLUGIN_BUFSZ, plugin); if (!plugin) { 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) return false; #endif return attr & ATTR_DIRECTORY || - (filetype_supported(attr) && (attr & FILE_ATTR_AUDIO) == 0); + (filetype_supported(attr) && (attr & FILE_ATTR_AUDIO) != FILE_ATTR_AUDIO); } /* open_plugin_browse() -- cgit v1.2.3