1
0
Fork 0
forked from len0rd/rockbox

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 /* new stuff at the end, sort into place next time
the API gets incompatible */ the API gets incompatible */
filetype_get_attr, filetype_get_attr,
browse_context_init,
rockbox_browse,
}; };
int plugin_load(const char* plugin, const void* parameter) 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 */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* 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 /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any 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 /* new stuff at the end, sort into place next time
the API gets incompatible */ the API gets incompatible */
int (*filetype_get_attr)(const char* file); 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 */ /* 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 ) ); return ( p != NULL && !rb->strcasecmp( p, ext ) );
} }
static const char* browse_get_name_cb(int selected_item, void *data, /* only displayes directories and .bmp files */
char *buffer, size_t buffer_len) static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{ {
int *indexes = (int *) data; (void) tc;
struct entry* dc = tree->dircache; if( ( attr & ATTR_DIRECTORY ) ||
struct entry* e = &dc[indexes[selected_item]]; ( !(attr & ATTR_DIRECTORY) && check_extention( name, ".bmp" ) ) )
(void) buffer; {
(void) buffer_len; return true;
}
return e->name; return false;
} }
static bool browse( char *dst, int dst_size, const char *start ) static bool browse( char *dst, int dst_size, const char *start )
{ {
struct gui_synclist browse_list; struct browse_context browse;
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;
char *a; rb->browse_context_init(&browse, SHOW_ALL,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
NULL, NOICON, start, NULL);
rb->strcpy( bbuf, start ); browse.callback_show_item = callback_show_item;
bbuf_len = rb->strlen(bbuf); browse.buf = dst;
if( bbuf[bbuf_len-1] != '/' ) browse.bufsize = dst_size;
{
bbuf[bbuf_len++] = '/';
bbuf[bbuf_len] = '\0';
}
bbuf_s[0] = '\0';
rb->gui_synclist_init(&browse_list, browse_get_name_cb, rb->rockbox_browse(&browse);
(void*) indexes, false, 1, NULL);
tree = rb->tree_get_context(); return (browse.flags & BROWSE_SELECTED);
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;
}
}
} }
/*********************************************************************** /***********************************************************************

View file

@ -216,53 +216,28 @@ static bool tv_statusbar_setting(void)
static bool tv_font_setting(void) static bool tv_font_setting(void)
{ {
int count = 0; struct browse_context browse;
int i = 0; char font[MAX_PATH], name[MAX_FILENAME+10];
int new_font = 0;
int old_font;
bool res;
unsigned char font_path[MAX_PATH];
struct tree_context *tree; rb->snprintf(name, sizeof(name), "%s.fnt", new_prefs.font_name);
struct tree_context backup; rb->browse_context_init(&browse, SHOW_FONT,
struct entry *dc; BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
int dirfilter = SHOW_FONT; "Font", Icon_Menu_setting, FONT_DIR, name);
tree = rb->tree_get_context(); browse.buf = font;
backup = *tree; browse.bufsize = sizeof(font);
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;
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 (p) *p = 0;
if (!rb->strcmp(dc[i].name, new_prefs.font_name)) rb->strlcpy(new_prefs.font_name, name, MAX_PATH);
new_font = i;
names[i].string = dc[i].name;
names[i].voice_id = -1;
} }
old_font = new_font; return false;
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;
} }
#endif #endif