summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2011-01-17 12:40:21 +0000
committerTeruaki Kawashima <teru@rockbox.org>2011-01-17 12:40:21 +0000
commit1c14d29370cfc35d5c89d2256edf00f914e0bc20 (patch)
tree1721ab488af125559b8be06710d744494044bb54
parent05f6f3419aec991307e7c81e0738e0496a21d89b (diff)
downloadrockbox-1c14d29370cfc35d5c89d2256edf00f914e0bc20.tar.gz
rockbox-1c14d29370cfc35d5c89d2256edf00f914e0bc20.zip
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
-rw-r--r--apps/plugin.c2
-rw-r--r--apps/plugin.h7
-rw-r--r--apps/plugins/rockpaint.c139
-rw-r--r--apps/plugins/text_viewer/tv_menu.c59
4 files changed, 43 insertions, 164 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 1cac280e64..20ff190e37 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -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)
diff --git a/apps/plugin.h b/apps/plugin.h
index e9e93d00bd..cd53ac6574 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -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 */
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index fc4621a805..0acbe41aaf 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -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;
-
- char *a;
-
- 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';
-
- rb->gui_synclist_init(&browse_list, browse_get_name_cb,
- (void*) indexes, false, 1, NULL);
+ struct browse_context 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->browse_context_init(&browse, SHOW_ALL,
+ BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
+ NULL, NOICON, start, NULL);
- 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;
+ browse.callback_show_item = callback_show_item;
+ browse.buf = dst;
+ browse.bufsize = dst_size;
- 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;
+ rb->rockbox_browse(&browse);
- case ACTION_STD_MENU:
- *tree = backup;
- rb->set_current_file( backup.currdir );
- return false;
- }
- }
+ return (browse.flags & BROWSE_SELECTED);
}
/***********************************************************************
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c
index 9be8312732..9e796982d3 100644
--- a/apps/plugins/text_viewer/tv_menu.c
+++ b/apps/plugins/text_viewer/tv_menu.c
@@ -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 tree_context *tree;
- struct tree_context backup;
- struct entry *dc;
- int dirfilter = SHOW_FONT;
-
- 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;
-
- struct opt_items names[count];
-
- for (i = 0; i < count; i++)
- {
- char *p = rb->strrchr(dc[i].name, '.');
- if (p) *p = 0;
- if (!rb->strcmp(dc[i].name, new_prefs.font_name))
- new_font = i;
+ struct browse_context browse;
+ char font[MAX_PATH], name[MAX_FILENAME+10];
- names[i].string = dc[i].name;
- names[i].voice_id = -1;
- }
+ 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);
- old_font = new_font;
+ browse.buf = font;
+ browse.bufsize = sizeof(font);
- res = rb->set_option("Select Font", &new_font, INT,
- names, count, NULL);
+ rb->rockbox_browse(&browse);
- if (new_font != old_font)
- rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
+ if (browse.flags & BROWSE_SELECTED)
+ {
+ char *name = rb->strrchr(font, '/')+1;
+ char *p = rb->strrchr(name, '.');
+ if (p) *p = 0;
+ rb->strlcpy(new_prefs.font_name, name, MAX_PATH);
+ }
- *tree = backup;
- rb->set_current_file(backup.currdir);
- return res;
+ return false;
}
#endif