mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
[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
This commit is contained in:
parent
6e82897bfc
commit
4128a1fe48
3 changed files with 52 additions and 15 deletions
|
@ -604,11 +604,11 @@ int filetype_get_icon(int attr)
|
||||||
return filetypes[index].icon;
|
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);
|
int index = find_attr(attr);
|
||||||
if (index < 0 || !buffer)
|
if (index < 0)
|
||||||
return NULL;
|
return -1;
|
||||||
struct file_type *ft_indexed = &filetypes[index];
|
struct file_type *ft_indexed = &filetypes[index];
|
||||||
|
|
||||||
/* attempt to find a suitable viewer by file extension */
|
/* 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];
|
ft = &filetypes[i];
|
||||||
if (ft->plugin == NULL || ft->extension == NULL)
|
if (ft->plugin == NULL || ft->extension == NULL)
|
||||||
continue;
|
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);*/
|
/*splashf(HZ*3, "Found %d %s %s", i, ft->extension, ft->plugin);*/
|
||||||
ft_indexed = ft;
|
return i;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ft_indexed->plugin == NULL)
|
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;
|
return NULL;
|
||||||
|
|
||||||
|
struct file_type *ft_indexed = &filetypes[index];
|
||||||
|
|
||||||
snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION,
|
snprintf(buffer, buffer_len, "%s/%s." ROCK_EXTENSION,
|
||||||
PLUGIN_DIR, ft_indexed->plugin);
|
PLUGIN_DIR, ft_indexed->plugin);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -674,24 +684,48 @@ static int openwith_get_talk(int selected_item, void * data)
|
||||||
return 0;
|
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;
|
struct simplelist_info info;
|
||||||
simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), viewer_count, NULL);
|
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_name = openwith_get_name;
|
||||||
info.get_icon = global_settings.show_icons?openwith_get_icon:NULL;
|
info.get_icon = global_settings.show_icons?openwith_get_icon:NULL;
|
||||||
info.get_talk = openwith_get_talk;
|
info.get_talk = openwith_get_talk;
|
||||||
|
|
||||||
int ret = simplelist_show_list(&info);
|
simplelist_show_list(&info);
|
||||||
|
|
||||||
if (info.selection >= 0) /* run user selected viewer */
|
if (info.selection >= 0) /* run user selected viewer */
|
||||||
{
|
{
|
||||||
char plugin[MAX_PATH];
|
|
||||||
int i = viewers[info.selection];
|
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);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,12 @@ char* filetype_get_plugin(int attr, char *buffer, size_t buffer_len);
|
||||||
/* returns true if the attr is supported */
|
/* returns true if the attr is supported */
|
||||||
bool filetype_supported(int attr);
|
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);
|
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) */
|
/* start a plugin with file as the argument (called from onplay.c) */
|
||||||
int filetype_load_plugin(const char* plugin, const char* file);
|
int filetype_load_plugin(const char* plugin, const char* file);
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
/* get the entry from the opx file */
|
||||||
op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin);
|
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);
|
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)
|
if (!plugin)
|
||||||
{
|
{
|
||||||
logf("OP no plugin found to run %s", op_entry->param);
|
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;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
return attr & ATTR_DIRECTORY ||
|
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()
|
/* open_plugin_browse()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue