FS#11822: use rockbox_browse() in plugins to select file.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29069 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2011-01-17 12:40:21 +00:00
parent 05f6f3419a
commit 1c14d29370
4 changed files with 40 additions and 161 deletions

View File

@ -773,6 +773,8 @@ static const struct plugin_api rockbox_api = {
/* new stuff at the end, sort into place next time
the API gets incompatible */
filetype_get_attr,
browse_context_init,
rockbox_browse,
};
int plugin_load(const char* plugin, const void* parameter)

View File

@ -149,7 +149,7 @@ void* plugin_get_buffer(size_t *buffer_size);
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 196
#define PLUGIN_API_VERSION 197
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
@ -902,6 +902,11 @@ struct plugin_api {
/* new stuff at the end, sort into place next time
the API gets incompatible */
int (*filetype_get_attr)(const char* file);
void (*browse_context_init)(struct browse_context *browse,
int dirfilter, unsigned flags,
char *title, enum themable_icons icon,
const char *root, const char *selected);
int (*rockbox_browse)(struct browse_context *browse);
};
/* plugin header */

View File

@ -684,136 +684,33 @@ static bool check_extention(const char *filename, const char *ext)
return ( p != NULL && !rb->strcasecmp( p, ext ) );
}
static const char* browse_get_name_cb(int selected_item, void *data,
char *buffer, size_t buffer_len)
/* only displayes directories and .bmp files */
static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{
int *indexes = (int *) data;
struct entry* dc = tree->dircache;
struct entry* e = &dc[indexes[selected_item]];
(void) buffer;
(void) buffer_len;
return e->name;
(void) tc;
if( ( attr & ATTR_DIRECTORY ) ||
( !(attr & ATTR_DIRECTORY) && check_extention( name, ".bmp" ) ) )
{
return true;
}
return false;
}
static bool browse( char *dst, int dst_size, const char *start )
{
struct gui_synclist browse_list;
int item_count = 0, selected, button;
struct tree_context backup;
struct entry *dc, *e;
bool reload = true;
int dirfilter = SHOW_ALL;
int *indexes = (int *) buffer;
size_t bbuf_len, len;
struct browse_context browse;
char *a;
rb->browse_context_init(&browse, SHOW_ALL,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
NULL, NOICON, start, NULL);
rb->strcpy( bbuf, start );
bbuf_len = rb->strlen(bbuf);
if( bbuf[bbuf_len-1] != '/' )
{
bbuf[bbuf_len++] = '/';
bbuf[bbuf_len] = '\0';
}
bbuf_s[0] = '\0';
browse.callback_show_item = callback_show_item;
browse.buf = dst;
browse.bufsize = dst_size;
rb->gui_synclist_init(&browse_list, browse_get_name_cb,
(void*) indexes, false, 1, NULL);
rb->rockbox_browse(&browse);
tree = rb->tree_get_context();
backup = *tree;
dc = tree->dircache;
a = backup.currdir+rb->strlen(backup.currdir)-1;
if( *a != '/' )
{
*++a = '/';
}
rb->strcpy( a+1, dc[tree->selected_item].name );
tree->dirfilter = &dirfilter;
tree->browse = NULL;
while( 1 )
{
if( reload )
{
int i;
rb->set_current_file(bbuf);
item_count = 0;
selected = 0;
for( i = 0; i < tree->filesindir ; i++)
{
e = &dc[i];
/* only displayes directories and .bmp files */
if( ( e->attr & ATTR_DIRECTORY ) ||
( !(e->attr & ATTR_DIRECTORY) &&
check_extention( e->name, ".bmp" ) ) )
{
if( bbuf_s[0] && !rb->strcmp( e->name, bbuf_s ) )
selected = item_count;
indexes[item_count++] = i;
}
}
rb->gui_synclist_set_nb_items(&browse_list,item_count);
rb->gui_synclist_select_item(&browse_list, selected);
rb->gui_synclist_set_title(&browse_list, bbuf, NOICON);
rb->gui_synclist_draw(&browse_list);
reload = false;
}
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&browse_list,&button,LIST_WRAP_UNLESS_HELD))
continue;
switch( button )
{
case ACTION_STD_CANCEL:
if( !rb->strcmp( bbuf, "/" ) )
{
*tree = backup;
rb->set_current_file( backup.currdir );
return false;
}
a = bbuf + bbuf_len - 1;
if( a == bbuf ) break;
while( *a == '/' ) a--;
*(a+1) = '\0';
while( *a != '/' ) a--;
/* select parent directory */
rb->strcpy( bbuf_s, ++a );
*a = '\0';
bbuf_len = a - bbuf;
reload = true;
break;
case ACTION_STD_OK:
selected = rb->gui_synclist_get_sel_pos( &browse_list );
if( selected < 0 || selected >= item_count )
break;
e = &dc[indexes[selected]];
if( !( e->attr & ATTR_DIRECTORY ) )
{
rb->snprintf( dst, dst_size, "%s%s", bbuf, e->name );
*tree = backup;
rb->set_current_file( backup.currdir );
return true;
}
len = rb->strlen(e->name);
if( bbuf_len + len + 2 < (int)sizeof(bbuf) )
{
bbuf_s[0] = '\0';
rb->strcpy( bbuf+bbuf_len, e->name );
bbuf_len += len;
bbuf[bbuf_len++] = '/';
bbuf[bbuf_len] = '\0';
reload = true;
}
break;
case ACTION_STD_MENU:
*tree = backup;
rb->set_current_file( backup.currdir );
return false;
}
}
return (browse.flags & BROWSE_SELECTED);
}
/***********************************************************************

View File

@ -216,53 +216,28 @@ static bool tv_statusbar_setting(void)
static bool tv_font_setting(void)
{
int count = 0;
int i = 0;
int new_font = 0;
int old_font;
bool res;
unsigned char font_path[MAX_PATH];
struct browse_context browse;
char font[MAX_PATH], name[MAX_FILENAME+10];
struct tree_context *tree;
struct tree_context backup;
struct entry *dc;
int dirfilter = SHOW_FONT;
rb->snprintf(name, sizeof(name), "%s.fnt", new_prefs.font_name);
rb->browse_context_init(&browse, SHOW_FONT,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
"Font", Icon_Menu_setting, FONT_DIR, name);
tree = rb->tree_get_context();
backup = *tree;
dc = tree->dircache;
rb->strlcat(backup.currdir, "/", MAX_PATH);
rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH);
tree->dirfilter = &dirfilter;
tree->browse = NULL;
rb->snprintf(font_path, MAX_PATH, "%s/", FONT_DIR);
rb->set_current_file(font_path);
count = tree->filesindir;
browse.buf = font;
browse.bufsize = sizeof(font);
struct opt_items names[count];
rb->rockbox_browse(&browse);
for (i = 0; i < count; i++)
if (browse.flags & BROWSE_SELECTED)
{
char *p = rb->strrchr(dc[i].name, '.');
char *name = rb->strrchr(font, '/')+1;
char *p = rb->strrchr(name, '.');
if (p) *p = 0;
if (!rb->strcmp(dc[i].name, new_prefs.font_name))
new_font = i;
names[i].string = dc[i].name;
names[i].voice_id = -1;
rb->strlcpy(new_prefs.font_name, name, MAX_PATH);
}
old_font = new_font;
res = rb->set_option("Select Font", &new_font, INT,
names, count, NULL);
if (new_font != old_font)
rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
*tree = backup;
rb->set_current_file(backup.currdir);
return res;
return false;
}
#endif