Fix the properties and shortucts plugins after accidently breaking them last night.
Also possibly make them load a bit faster. Make the open with screen nicer, and show all aviable viewers again (If people prefered it only showing useful viewers maybe we can make this a setting?) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14227 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c43629f08b
commit
73160322fe
1 changed files with 63 additions and 44 deletions
107
apps/filetypes.c
107
apps/filetypes.c
|
@ -381,7 +381,7 @@ int filetype_get_color(const char * name, int attr)
|
|||
if (!extension)
|
||||
return custom_colors[MAX_FILETYPES];
|
||||
extension++;
|
||||
logf("%s %s",name,extension);
|
||||
|
||||
for (i=1; i<filetype_count; i++)
|
||||
{
|
||||
if (filetypes[i].extension &&
|
||||
|
@ -420,39 +420,40 @@ bool filetype_supported(int attr)
|
|||
return find_attr(attr) >= 0;
|
||||
}
|
||||
|
||||
/**** Open With Screen ****/
|
||||
enum themable_icons openwith_get_icon(int selected_item, void * data)
|
||||
{
|
||||
int *items = (int*)data;
|
||||
return filetypes[items[selected_item]].icon;
|
||||
}
|
||||
char * openwith_get_name(int selected_item, void * data, char * buffer)
|
||||
{
|
||||
(void)buffer;
|
||||
int *items = (int*)data;
|
||||
char *s = strrchr(filetypes[items[selected_item]].plugin, '/');
|
||||
if (s)
|
||||
return s+1;
|
||||
else return filetypes[items[selected_item]].plugin;
|
||||
}
|
||||
|
||||
int filetype_list_viewers(const char* current_file)
|
||||
{
|
||||
int i, count = 0;
|
||||
char *strings[MAX_FILETYPES/2];
|
||||
char *ext;
|
||||
struct menu_callback_with_desc cb_and_desc =
|
||||
{ NULL, ID2P(LANG_ONPLAY_OPEN_WITH), Icon_Plugin };
|
||||
struct menu_item_ex menu;
|
||||
|
||||
ext = strrchr(current_file, '.');
|
||||
if (ext)
|
||||
ext++;
|
||||
for (i=0; i<filetype_count && count < (MAX_FILETYPES/2); i++)
|
||||
int i, count = 0, action;
|
||||
int items[MAX_FILETYPES];
|
||||
struct gui_synclist lists;
|
||||
for (i=0; i<filetype_count && count < MAX_FILETYPES; i++)
|
||||
{
|
||||
if (filetypes[i].plugin)
|
||||
{
|
||||
int j;
|
||||
for (j=0;j<count;j++) /* check if the plugin is in the list yet */
|
||||
{
|
||||
if (!strcmp(strings[j], filetypes[i].plugin))
|
||||
if (items[j] == i)
|
||||
break;
|
||||
}
|
||||
if (j<count)
|
||||
continue; /* it is so grab the next plugin */
|
||||
if (ext && filetypes[i].extension &&
|
||||
(filetypes[i].extension[0] != '*'))
|
||||
{
|
||||
if (strcasecmp(filetypes[i].extension, ext))
|
||||
continue; /* skip this one */
|
||||
}
|
||||
strings[count] = strrchr(filetypes[i].plugin,'/');
|
||||
if (strings[count])
|
||||
strings[count++]++;
|
||||
items[count++] = i;
|
||||
}
|
||||
}
|
||||
#ifndef HAVE_LCD_BITMAP
|
||||
|
@ -463,35 +464,53 @@ int filetype_list_viewers(const char* current_file)
|
|||
return PLUGIN_OK;
|
||||
}
|
||||
#endif
|
||||
menu.flags = MT_RETURN_ID|MENU_HAS_DESC|MENU_ITEM_COUNT(count);
|
||||
menu.strings = (const char**)strings;
|
||||
menu.callback_and_desc = &cb_and_desc;
|
||||
i = do_menu(&menu, NULL);
|
||||
if (i >= 0)
|
||||
return filetype_load_plugin(strings[i], (void*)current_file);
|
||||
return i;
|
||||
gui_synclist_init(&lists,openwith_get_name,(void*)items, false, 1);
|
||||
gui_synclist_set_nb_items(&lists, count);
|
||||
gui_synclist_set_icon_callback(&lists, openwith_get_icon);
|
||||
gui_synclist_set_title(&lists, str(LANG_ONPLAY_OPEN_WITH), Icon_Plugin);
|
||||
gui_synclist_select_item(&lists, 0);
|
||||
gui_synclist_draw(&lists);
|
||||
while (1)
|
||||
{
|
||||
gui_syncstatusbar_draw(&statusbars, true);
|
||||
action = get_action(CONTEXT_MAINMENU,HZ);
|
||||
if ((action == ACTION_NONE) ||
|
||||
gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD))
|
||||
continue;
|
||||
else if (action == ACTION_STD_OK)
|
||||
{
|
||||
i = gui_synclist_get_sel_pos(&lists);
|
||||
return filetype_load_plugin(filetypes[i].plugin,
|
||||
(void*)current_file);
|
||||
}
|
||||
else if (action == ACTION_STD_CANCEL)
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
int filetype_load_plugin(const char* plugin, char* file)
|
||||
{
|
||||
int fd;
|
||||
int i;
|
||||
char plugin_name[MAX_PATH];
|
||||
snprintf(plugin_name, sizeof(plugin_name), "%s/%s.%s",
|
||||
VIEWERS_DIR, plugin, ROCK_EXTENSION);
|
||||
if ((fd = open(plugin_name,O_RDONLY))>=0)
|
||||
char *s;
|
||||
|
||||
for (i=0;i<filetype_count;i++)
|
||||
{
|
||||
close(fd);
|
||||
return plugin_load(plugin_name,file);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(plugin_name, sizeof(plugin_name), "%s/%s.%s",
|
||||
PLUGIN_DIR, plugin, ROCK_EXTENSION);
|
||||
if ((fd = open(plugin_name,O_RDONLY))>=0)
|
||||
if (filetypes[i].plugin)
|
||||
{
|
||||
close(fd);
|
||||
return plugin_load(plugin_name,file);
|
||||
s = strrchr(filetypes[i].plugin, '/');
|
||||
if (s)
|
||||
{
|
||||
if (!strcmp(s+1, plugin))
|
||||
break;
|
||||
}
|
||||
else if (!strcmp(filetypes[i].plugin, plugin))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return PLUGIN_ERROR;
|
||||
if (i >= filetype_count)
|
||||
return PLUGIN_ERROR;
|
||||
snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
|
||||
PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
|
||||
return plugin_load(plugin_name,file);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue