diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2010-12-14 13:37:58 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2010-12-14 13:37:58 +0000 |
commit | 08af5d84044a7f18a619e1cb38cd183819be41b9 (patch) | |
tree | e441cf84b0268e5b008d044902641f063f218152 /apps | |
parent | fbd75fcc86304ccf44ad8174c91684b687a877ec (diff) | |
download | rockbox-08af5d84044a7f18a619e1cb38cd183819be41b9.tar.gz rockbox-08af5d84044a7f18a619e1cb38cd183819be41b9.zip |
FS#11777: enhancement for rockbox_browse()
* Add struct browse_context to be passed to rockbox_browse.
* Show proper title when selecting e.g. .wps file or .sbs file from the settings menu.
* Add select only mode to rockbox_browse(). when a file is selected, it's path is stored to buffer and the browser exits without 'playing' the file.
this will allow to use the browser in more places to select file including plugins.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28831 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/filetree.c | 7 | ||||
-rw-r--r-- | apps/menus/theme_menu.c | 78 | ||||
-rw-r--r-- | apps/plugins/rockpaint.c | 2 | ||||
-rw-r--r-- | apps/plugins/text_viewer/tv_menu.c | 1 | ||||
-rw-r--r-- | apps/radio/presets.c | 8 | ||||
-rw-r--r-- | apps/root_menu.c | 21 | ||||
-rw-r--r-- | apps/tree.c | 148 | ||||
-rw-r--r-- | apps/tree.h | 28 |
8 files changed, 196 insertions, 97 deletions
diff --git a/apps/filetree.c b/apps/filetree.c index 1dc510f8c7..6fb0ed5469 100644 --- a/apps/filetree.c +++ b/apps/filetree.c | |||
@@ -269,12 +269,16 @@ int ft_load(struct tree_context* c, const char* tempdir) | |||
269 | { | 269 | { |
270 | int i; | 270 | int i; |
271 | int name_buffer_used = 0; | 271 | int name_buffer_used = 0; |
272 | bool (*callback_show_item)(char *, int, struct tree_context *) = NULL; | ||
272 | DIR *dir; | 273 | DIR *dir; |
273 | 274 | ||
274 | if (tempdir) | 275 | if (tempdir) |
275 | dir = opendir(tempdir); | 276 | dir = opendir(tempdir); |
276 | else | 277 | else |
278 | { | ||
277 | dir = opendir(c->currdir); | 279 | dir = opendir(c->currdir); |
280 | callback_show_item = c->browse? c->browse->callback_show_item: NULL; | ||
281 | } | ||
278 | if(!dir) | 282 | if(!dir) |
279 | return -1; /* not a directory */ | 283 | return -1; /* not a directory */ |
280 | 284 | ||
@@ -351,7 +355,8 @@ int ft_load(struct tree_context* c, const char* tempdir) | |||
351 | (*c->dirfilter == SHOW_LNG && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LNG) || | 355 | (*c->dirfilter == SHOW_LNG && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LNG) || |
352 | (*c->dirfilter == SHOW_MOD && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_MOD) || | 356 | (*c->dirfilter == SHOW_MOD && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_MOD) || |
353 | (*c->dirfilter == SHOW_PLUGINS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_ROCK && | 357 | (*c->dirfilter == SHOW_PLUGINS && (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_ROCK && |
354 | (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LUA)) | 358 | (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LUA) || |
359 | (callback_show_item && !callback_show_item(entry->d_name, dptr->attr, c))) | ||
355 | { | 360 | { |
356 | i--; | 361 | i--; |
357 | continue; | 362 | continue; |
diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c index 983eca9445..b483a7ef11 100644 --- a/apps/menus/theme_menu.c +++ b/apps/menus/theme_menu.c | |||
@@ -246,9 +246,85 @@ static struct browse_folder_info themes = {THEME_DIR, SHOW_CFG}; | |||
246 | 246 | ||
247 | int browse_folder(void *param) | 247 | int browse_folder(void *param) |
248 | { | 248 | { |
249 | const char *ext, *setting; | ||
250 | int lang_id = -1; | ||
251 | char selected[MAX_FILENAME+10]; | ||
249 | const struct browse_folder_info *info = | 252 | const struct browse_folder_info *info = |
250 | (const struct browse_folder_info*)param; | 253 | (const struct browse_folder_info*)param; |
251 | return rockbox_browse(info->dir, info->show_options); | 254 | struct browse_context browse; |
255 | browse_context_init(&browse, info->show_options, 0, | ||
256 | NULL, NOICON, info->dir, NULL); | ||
257 | |||
258 | /* if we are in a special settings folder, center the current setting */ | ||
259 | switch(info->show_options) | ||
260 | { | ||
261 | case SHOW_LNG: | ||
262 | ext = "lng"; | ||
263 | if (global_settings.lang_file[0]) | ||
264 | setting = global_settings.lang_file; | ||
265 | else | ||
266 | setting = "english"; | ||
267 | lang_id = LANG_LANGUAGE; | ||
268 | break; | ||
269 | case SHOW_WPS: | ||
270 | ext = "wps"; | ||
271 | setting = global_settings.wps_file; | ||
272 | lang_id = LANG_WHILE_PLAYING; | ||
273 | break; | ||
274 | #ifdef HAVE_LCD_BITMAP | ||
275 | case SHOW_FONT: | ||
276 | ext = "fnt"; | ||
277 | setting = global_settings.font_file; | ||
278 | lang_id = LANG_CUSTOM_FONT; | ||
279 | break; | ||
280 | case SHOW_SBS: | ||
281 | ext = "sbs"; | ||
282 | setting = global_settings.sbs_file; | ||
283 | lang_id = LANG_BASE_SKIN; | ||
284 | break; | ||
285 | #if CONFIG_TUNER | ||
286 | case SHOW_FMS: | ||
287 | ext = "fms"; | ||
288 | setting = global_settings.fms_file; | ||
289 | lang_id = LANG_RADIOSCREEN; | ||
290 | break; | ||
291 | #endif /* CONFIG_TUNER */ | ||
292 | #endif | ||
293 | #ifdef HAVE_REMOTE_LCD | ||
294 | case SHOW_RWPS: | ||
295 | ext = "rwps"; | ||
296 | setting = global_settings.rwps_file; | ||
297 | lang_id = LANG_REMOTE_WHILE_PLAYING; | ||
298 | break; | ||
299 | case SHOW_RSBS: | ||
300 | ext = "rsbs"; | ||
301 | setting = global_settings.rsbs_file; | ||
302 | lang_id = LANG_REMOTE_BASE_SKIN; | ||
303 | break; | ||
304 | #if CONFIG_TUNER | ||
305 | case SHOW_RFMS: | ||
306 | ext = "rfms"; | ||
307 | setting = global_settings.rfms_file; | ||
308 | lang_id = LANG_REMOTE_RADIOSCREEN; | ||
309 | break; | ||
310 | #endif /* CONFIG_TUNER */ | ||
311 | #endif | ||
312 | default: | ||
313 | ext = setting = NULL; | ||
314 | break; | ||
315 | } | ||
316 | |||
317 | /* If we've found a file to center on, do it */ | ||
318 | if (setting) | ||
319 | { | ||
320 | /* if setting != NULL, ext is initialized */ | ||
321 | snprintf(selected, sizeof(selected), "%s.%s", setting, ext); | ||
322 | browse.selected = selected; | ||
323 | browse.icon = Icon_Questionmark; | ||
324 | browse.title = str(lang_id); | ||
325 | } | ||
326 | |||
327 | return rockbox_browse(&browse); | ||
252 | } | 328 | } |
253 | 329 | ||
254 | #ifdef HAVE_LCD_BITMAP | 330 | #ifdef HAVE_LCD_BITMAP |
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index 4ef139a526..fc4621a805 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c | |||
@@ -731,6 +731,7 @@ static bool browse( char *dst, int dst_size, const char *start ) | |||
731 | } | 731 | } |
732 | rb->strcpy( a+1, dc[tree->selected_item].name ); | 732 | rb->strcpy( a+1, dc[tree->selected_item].name ); |
733 | tree->dirfilter = &dirfilter; | 733 | tree->dirfilter = &dirfilter; |
734 | tree->browse = NULL; | ||
734 | while( 1 ) | 735 | while( 1 ) |
735 | { | 736 | { |
736 | if( reload ) | 737 | if( reload ) |
@@ -880,6 +881,7 @@ static bool browse_fonts( char *dst, int dst_size ) | |||
880 | } | 881 | } |
881 | rb->strcpy( a+1, dc[tree->selected_item].name ); | 882 | rb->strcpy( a+1, dc[tree->selected_item].name ); |
882 | tree->dirfilter = &dirfilter; | 883 | tree->dirfilter = &dirfilter; |
884 | tree->browse = NULL; | ||
883 | rb->strcpy( bbuf, FONT_DIR "/" ); | 885 | rb->strcpy( bbuf, FONT_DIR "/" ); |
884 | rb->set_current_file( bbuf ); | 886 | rb->set_current_file( bbuf ); |
885 | 887 | ||
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c index 1d1e07f3e8..5e79fd469a 100644 --- a/apps/plugins/text_viewer/tv_menu.c +++ b/apps/plugins/text_viewer/tv_menu.c | |||
@@ -234,6 +234,7 @@ static bool tv_font_setting(void) | |||
234 | rb->strlcat(backup.currdir, "/", MAX_PATH); | 234 | rb->strlcat(backup.currdir, "/", MAX_PATH); |
235 | rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH); | 235 | rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH); |
236 | tree->dirfilter = &dirfilter; | 236 | tree->dirfilter = &dirfilter; |
237 | tree->browse = NULL; | ||
237 | rb->snprintf(font_path, MAX_PATH, "%s/", FONT_DIR); | 238 | rb->snprintf(font_path, MAX_PATH, "%s/", FONT_DIR); |
238 | rb->set_current_file(font_path); | 239 | rb->set_current_file(font_path); |
239 | count = tree->filesindir; | 240 | count = tree->filesindir; |
diff --git a/apps/radio/presets.c b/apps/radio/presets.c index e900afe734..9c6fedecc7 100644 --- a/apps/radio/presets.c +++ b/apps/radio/presets.c | |||
@@ -353,7 +353,13 @@ static int radio_delete_preset(void) | |||
353 | 353 | ||
354 | int preset_list_load(void) | 354 | int preset_list_load(void) |
355 | { | 355 | { |
356 | return !rockbox_browse(FMPRESET_PATH, SHOW_FMR); | 356 | char selected[MAX_PATH]; |
357 | struct browse_context browse; | ||
358 | snprintf(selected, sizeof(selected), "%s.%s", global_settings.fmr_file, "fmr"); | ||
359 | browse_context_init(&browse, SHOW_FMR, 0, | ||
360 | str(LANG_FM_PRESET_LOAD), NOICON, | ||
361 | FMPRESET_PATH, selected); | ||
362 | return !rockbox_browse(&browse); | ||
357 | } | 363 | } |
358 | 364 | ||
359 | int preset_list_save(void) | 365 | int preset_list_save(void) |
diff --git a/apps/root_menu.c b/apps/root_menu.c index a65ceb51b9..27242c9797 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c | |||
@@ -96,6 +96,7 @@ static int browser(void* param) | |||
96 | #ifdef HAVE_TAGCACHE | 96 | #ifdef HAVE_TAGCACHE |
97 | struct tree_context* tc = tree_get_context(); | 97 | struct tree_context* tc = tree_get_context(); |
98 | #endif | 98 | #endif |
99 | struct browse_context browse; | ||
99 | int filter = SHOW_SUPPORTED; | 100 | int filter = SHOW_SUPPORTED; |
100 | char folder[MAX_PATH] = "/"; | 101 | char folder[MAX_PATH] = "/"; |
101 | /* stuff needed to remember position in file browser */ | 102 | /* stuff needed to remember position in file browser */ |
@@ -104,7 +105,7 @@ static int browser(void* param) | |||
104 | #ifdef HAVE_TAGCACHE | 105 | #ifdef HAVE_TAGCACHE |
105 | static int last_db_dirlevel = 0, last_db_selection = 0; | 106 | static int last_db_dirlevel = 0, last_db_selection = 0; |
106 | #endif | 107 | #endif |
107 | 108 | ||
108 | switch ((intptr_t)param) | 109 | switch ((intptr_t)param) |
109 | { | 110 | { |
110 | case GO_TO_FILEBROWSER: | 111 | case GO_TO_FILEBROWSER: |
@@ -247,12 +248,10 @@ static int browser(void* param) | |||
247 | tc->selected_item = last_db_selection; | 248 | tc->selected_item = last_db_selection; |
248 | break; | 249 | break; |
249 | #endif | 250 | #endif |
250 | case GO_TO_BROWSEPLUGINS: | ||
251 | filter = SHOW_PLUGINS; | ||
252 | strlcpy(folder, PLUGIN_DIR, MAX_PATH); | ||
253 | break; | ||
254 | } | 251 | } |
255 | ret_val = rockbox_browse(folder, filter); | 252 | |
253 | browse_context_init(&browse, filter, 0, NULL, NOICON, folder, NULL); | ||
254 | ret_val = rockbox_browse(&browse); | ||
256 | switch ((intptr_t)param) | 255 | switch ((intptr_t)param) |
257 | { | 256 | { |
258 | case GO_TO_FILEBROWSER: | 257 | case GO_TO_FILEBROWSER: |
@@ -352,8 +351,11 @@ static int plugins_menu(void* param) | |||
352 | ID2P(LANG_PLUGIN_GAMES), | 351 | ID2P(LANG_PLUGIN_GAMES), |
353 | ID2P(LANG_PLUGIN_APPS), ID2P(LANG_PLUGIN_DEMOS)); | 352 | ID2P(LANG_PLUGIN_APPS), ID2P(LANG_PLUGIN_DEMOS)); |
354 | const char *folder; | 353 | const char *folder; |
354 | struct browse_context browse; | ||
355 | char *title; | ||
355 | int retval = GO_TO_PREVIOUS; | 356 | int retval = GO_TO_PREVIOUS; |
356 | int selection = 0, current = 0; | 357 | int selection = 0, current = 0; |
358 | |||
357 | while (retval == GO_TO_PREVIOUS) | 359 | while (retval == GO_TO_PREVIOUS) |
358 | { | 360 | { |
359 | selection = do_menu(&plugins_menu_items, ¤t, NULL, false); | 361 | selection = do_menu(&plugins_menu_items, ¤t, NULL, false); |
@@ -361,17 +363,22 @@ static int plugins_menu(void* param) | |||
361 | { | 363 | { |
362 | case 0: | 364 | case 0: |
363 | folder = PLUGIN_GAMES_DIR; | 365 | folder = PLUGIN_GAMES_DIR; |
366 | title = str(LANG_PLUGIN_GAMES); | ||
364 | break; | 367 | break; |
365 | case 1: | 368 | case 1: |
366 | folder = PLUGIN_APPS_DIR; | 369 | folder = PLUGIN_APPS_DIR; |
370 | title = str(LANG_PLUGIN_APPS); | ||
367 | break; | 371 | break; |
368 | case 2: | 372 | case 2: |
369 | folder = PLUGIN_DEMOS_DIR; | 373 | folder = PLUGIN_DEMOS_DIR; |
374 | title = str(LANG_PLUGIN_DEMOS); | ||
370 | break; | 375 | break; |
371 | default: | 376 | default: |
372 | return selection; | 377 | return selection; |
373 | } | 378 | } |
374 | retval = rockbox_browse(folder, SHOW_PLUGINS); | 379 | browse_context_init(&browse, SHOW_PLUGINS, 0, |
380 | title, Icon_Plugin, folder, NULL); | ||
381 | retval = rockbox_browse(&browse); | ||
375 | } | 382 | } |
376 | return retval; | 383 | return retval; |
377 | } | 384 | } |
diff --git a/apps/tree.c b/apps/tree.c index 98880f001a..b0e94bf936 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -417,18 +417,12 @@ static int update_dir(void) | |||
417 | #endif | 417 | #endif |
418 | { | 418 | { |
419 | #ifdef HAVE_LCD_BITMAP | 419 | #ifdef HAVE_LCD_BITMAP |
420 | if (global_settings.show_path_in_browser && | 420 | if (tc.browse && tc.browse->title) |
421 | *(tc.dirfilter) == SHOW_PLUGINS) | ||
422 | { | 421 | { |
423 | char *title; | 422 | int icon = tc.browse->icon; |
424 | if (!strcmp(tc.currdir, PLUGIN_GAMES_DIR)) | 423 | if (icon == NOICON) |
425 | title = str(LANG_PLUGIN_GAMES); | 424 | icon = filetype_get_icon(ATTR_DIRECTORY); |
426 | else if (!strcmp(tc.currdir, PLUGIN_APPS_DIR)) | 425 | gui_synclist_set_title(&tree_lists, tc.browse->title, icon); |
427 | title = str(LANG_PLUGIN_APPS); | ||
428 | else if (!strcmp(tc.currdir, PLUGIN_DEMOS_DIR)) | ||
429 | title = str(LANG_PLUGIN_DEMOS); | ||
430 | else title = str(LANG_PLUGINS); | ||
431 | gui_synclist_set_title(&tree_lists, title, Icon_Plugin); | ||
432 | } | 426 | } |
433 | else if (global_settings.show_path_in_browser == SHOW_PATH_FULL) | 427 | else if (global_settings.show_path_in_browser == SHOW_PATH_FULL) |
434 | { | 428 | { |
@@ -616,7 +610,7 @@ void set_current_file(const char *path) | |||
616 | 610 | ||
617 | 611 | ||
618 | /* main loop, handles key events */ | 612 | /* main loop, handles key events */ |
619 | static int dirbrowse() | 613 | static int dirbrowse(void) |
620 | { | 614 | { |
621 | int numentries=0; | 615 | int numentries=0; |
622 | char buf[MAX_PATH]; | 616 | char buf[MAX_PATH]; |
@@ -653,7 +647,7 @@ static int dirbrowse() | |||
653 | if (*tc.dirfilter > NUM_FILTER_MODES && numentries==0) | 647 | if (*tc.dirfilter > NUM_FILTER_MODES && numentries==0) |
654 | { | 648 | { |
655 | splash(HZ*2, ID2P(LANG_NO_FILES)); | 649 | splash(HZ*2, ID2P(LANG_NO_FILES)); |
656 | return GO_TO_PREVIOUS; /* No files found for rockbox_browser() */ | 650 | return GO_TO_PREVIOUS; /* No files found for rockbox_browse() */ |
657 | } | 651 | } |
658 | 652 | ||
659 | gui_synclist_draw(&tree_lists); | 653 | gui_synclist_draw(&tree_lists); |
@@ -683,6 +677,14 @@ static int dirbrowse() | |||
683 | if ( numentries == 0 ) | 677 | if ( numentries == 0 ) |
684 | break; | 678 | break; |
685 | 679 | ||
680 | if ((tc.browse->flags & BROWSE_SELECTONLY) && | ||
681 | !(dircache[tc.selected_item].attr & ATTR_DIRECTORY)) | ||
682 | { | ||
683 | tc.browse->flags |= BROWSE_SELECTED; | ||
684 | get_current_file(tc.browse->buf, tc.browse->bufsize); | ||
685 | return GO_TO_PREVIOUS; | ||
686 | } | ||
687 | |||
686 | #ifdef HAVE_TAGCACHE | 688 | #ifdef HAVE_TAGCACHE |
687 | switch (id3db?tagtree_enter(&tc):ft_enter(&tc)) | 689 | switch (id3db?tagtree_enter(&tc):ft_enter(&tc)) |
688 | #else | 690 | #else |
@@ -781,6 +783,11 @@ static int dirbrowse() | |||
781 | int onplay_result; | 783 | int onplay_result; |
782 | int attr = 0; | 784 | int attr = 0; |
783 | 785 | ||
786 | /* no context menu while in select only mode | ||
787 | to prevent recursive call */ | ||
788 | if ((tc.browse->flags & BROWSE_SELECTONLY)) | ||
789 | break; | ||
790 | |||
784 | if(!numentries) | 791 | if(!numentries) |
785 | onplay_result = onplay(NULL, 0, curr_context, hotkey); | 792 | onplay_result = onplay(NULL, 0, curr_context, hotkey); |
786 | else { | 793 | else { |
@@ -924,108 +931,77 @@ bool create_playlist(void) | |||
924 | return true; | 931 | return true; |
925 | } | 932 | } |
926 | 933 | ||
927 | int rockbox_browse(const char *root, int dirfilter) | 934 | void browse_context_init(struct browse_context *browse, |
935 | int dirfilter, unsigned flags, | ||
936 | char *title, enum themable_icons icon, | ||
937 | const char *root, const char *selected) | ||
938 | { | ||
939 | browse->dirfilter = dirfilter; | ||
940 | browse->flags = flags; | ||
941 | browse->callback_show_item = NULL; | ||
942 | browse->title = title; | ||
943 | browse->icon = icon; | ||
944 | browse->root = root; | ||
945 | browse->selected = selected; | ||
946 | browse->buf = NULL; | ||
947 | browse->bufsize = 0; | ||
948 | } | ||
949 | |||
950 | #define NUM_TC_BACKUP 3 | ||
951 | static struct tree_context backups[NUM_TC_BACKUP]; | ||
952 | /* do not make backup if it is not recursive call */ | ||
953 | static int backup_count = -1; | ||
954 | int rockbox_browse(struct browse_context *browse) | ||
928 | { | 955 | { |
929 | static char current[MAX_PATH]; | 956 | static char current[MAX_PATH]; |
930 | int ret_val = 0; | 957 | int ret_val = 0; |
931 | int *last_filter = tc.dirfilter; | 958 | int dirfilter = browse->dirfilter; |
959 | |||
960 | if (backup_count >= NUM_TC_BACKUP) | ||
961 | return GO_TO_PREVIOUS; | ||
962 | if (backup_count >= 0) | ||
963 | backups[backup_count] = tc; | ||
964 | backup_count++; | ||
965 | |||
932 | tc.dirfilter = &dirfilter; | 966 | tc.dirfilter = &dirfilter; |
933 | tc.sort_dir = global_settings.sort_dir; | 967 | tc.sort_dir = global_settings.sort_dir; |
934 | 968 | ||
935 | reload_dir = true; | 969 | reload_dir = true; |
936 | if (dirfilter >= NUM_FILTER_MODES) | 970 | if (*tc.dirfilter >= NUM_FILTER_MODES) |
937 | { | 971 | { |
938 | static struct tree_context backup; | ||
939 | int last_context; | 972 | int last_context; |
940 | const char *ext, *setting; | 973 | |
941 | 974 | tc.browse = browse; | |
942 | backup = tc; | ||
943 | tc.selected_item = 0; | 975 | tc.selected_item = 0; |
944 | tc.dirlevel = 0; | 976 | tc.dirlevel = 0; |
945 | memcpy(tc.currdir, root, sizeof(tc.currdir)); | 977 | strlcpy(tc.currdir, browse->root, sizeof(tc.currdir)); |
946 | start_wps = false; | 978 | start_wps = false; |
947 | last_context = curr_context; | 979 | last_context = curr_context; |
948 | 980 | ||
949 | /* if we are in a special settings folder, center the current setting */ | 981 | if (browse->selected) |
950 | switch(dirfilter) | ||
951 | { | ||
952 | case SHOW_LNG: | ||
953 | ext = "lng"; | ||
954 | if (global_settings.lang_file[0]) | ||
955 | setting = global_settings.lang_file; | ||
956 | else | ||
957 | setting = "english"; | ||
958 | break; | ||
959 | case SHOW_WPS: | ||
960 | ext = "wps"; | ||
961 | setting = global_settings.wps_file; | ||
962 | break; | ||
963 | #ifdef HAVE_REMOTE_LCD | ||
964 | case SHOW_RWPS: | ||
965 | ext = "rwps"; | ||
966 | setting = global_settings.rwps_file; | ||
967 | break; | ||
968 | case SHOW_RSBS: | ||
969 | ext = "rsbs"; | ||
970 | setting = global_settings.rsbs_file; | ||
971 | break; | ||
972 | #if CONFIG_TUNER | ||
973 | case SHOW_RFMS: | ||
974 | ext = "rfms"; | ||
975 | setting = global_settings.rfms_file; | ||
976 | break; | ||
977 | #endif /* CONFIG_TUNER */ | ||
978 | #endif | ||
979 | #ifdef HAVE_LCD_BITMAP | ||
980 | case SHOW_FONT: | ||
981 | ext = "fnt"; | ||
982 | setting = global_settings.font_file; | ||
983 | break; | ||
984 | case SHOW_SBS: | ||
985 | ext = "sbs"; | ||
986 | setting = global_settings.sbs_file; | ||
987 | break; | ||
988 | #if CONFIG_TUNER | ||
989 | case SHOW_FMS: | ||
990 | ext = "fms"; | ||
991 | setting = global_settings.fms_file; | ||
992 | break; | ||
993 | #endif /* CONFIG_TUNER */ | ||
994 | #endif | ||
995 | #if CONFIG_TUNER | ||
996 | case SHOW_FMR: | ||
997 | ext = "fmr"; | ||
998 | setting = global_settings.fmr_file; | ||
999 | break; | ||
1000 | #endif | ||
1001 | default: | ||
1002 | ext = setting = NULL; | ||
1003 | break; | ||
1004 | } | ||
1005 | |||
1006 | /* If we've found a file to center on, do it */ | ||
1007 | if (setting) | ||
1008 | { | 982 | { |
1009 | /* if setting != NULL, ext is initialized */ | 983 | snprintf(current, sizeof(current), "%s/%s", |
1010 | snprintf(current, sizeof(current), "%s/%s.%s", root, setting, ext); | 984 | browse->root, browse->selected); |
1011 | set_current_file(current); | 985 | set_current_file(current); |
1012 | /* set_current_file changes dirlevel, change it back */ | 986 | /* set_current_file changes dirlevel, change it back */ |
1013 | tc.dirlevel = 0; | 987 | tc.dirlevel = 0; |
1014 | } | 988 | } |
1015 | 989 | ||
1016 | ret_val = dirbrowse(); | 990 | ret_val = dirbrowse(); |
1017 | tc = backup; | ||
1018 | curr_context = last_context; | 991 | curr_context = last_context; |
1019 | } | 992 | } |
1020 | else | 993 | else |
1021 | { | 994 | { |
1022 | if (dirfilter != SHOW_ID3DB) | 995 | if (dirfilter != SHOW_ID3DB) |
1023 | tc.dirfilter = &global_settings.dirfilter; | 996 | tc.dirfilter = &global_settings.dirfilter; |
1024 | strcpy(current,root); | 997 | tc.browse = browse; |
998 | strcpy(current, browse->root); | ||
1025 | set_current_file(current); | 999 | set_current_file(current); |
1026 | ret_val = dirbrowse(); | 1000 | ret_val = dirbrowse(); |
1027 | } | 1001 | } |
1028 | tc.dirfilter = last_filter; | 1002 | backup_count--; |
1003 | if (backup_count >= 0) | ||
1004 | tc = backups[backup_count]; | ||
1029 | return ret_val; | 1005 | return ret_val; |
1030 | } | 1006 | } |
1031 | 1007 | ||
diff --git a/apps/tree.h b/apps/tree.h index a74960f7a5..103a20eea6 100644 --- a/apps/tree.h +++ b/apps/tree.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <stdbool.h> | 24 | #include <stdbool.h> |
25 | #include <applimits.h> | 25 | #include <applimits.h> |
26 | #include <file.h> | 26 | #include <file.h> |
27 | #include "icon.h" | ||
27 | 28 | ||
28 | struct entry { | 29 | struct entry { |
29 | short attr; /* FAT attributes + file type flags */ | 30 | short attr; /* FAT attributes + file type flags */ |
@@ -32,6 +33,26 @@ struct entry { | |||
32 | }; | 33 | }; |
33 | 34 | ||
34 | 35 | ||
36 | #define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */ | ||
37 | #define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */ | ||
38 | |||
39 | struct tree_context; | ||
40 | |||
41 | struct browse_context { | ||
42 | int dirfilter; | ||
43 | unsigned flags; /* ored BROWSE_* */ | ||
44 | bool (*callback_show_item)(char *name, int attr, struct tree_context *tc); | ||
45 | /* callback function to determine to show/hide | ||
46 | the item for custom browser */ | ||
47 | char *title; /* title of the browser. if set to NULL, | ||
48 | directory name is used. */ | ||
49 | enum themable_icons icon; /* title icon */ | ||
50 | const char *root; /* full path of start directory */ | ||
51 | const char *selected; /* name of selected file in the root */ | ||
52 | char *buf; /* buffer to store selected file */ | ||
53 | size_t bufsize; /* size of the buffer */ | ||
54 | }; | ||
55 | |||
35 | /* browser context for file or db */ | 56 | /* browser context for file or db */ |
36 | struct tree_context { | 57 | struct tree_context { |
37 | /* The directory we are browsing */ | 58 | /* The directory we are browsing */ |
@@ -68,6 +89,7 @@ struct tree_context { | |||
68 | int dentry_size; | 89 | int dentry_size; |
69 | bool dirfull; | 90 | bool dirfull; |
70 | int sort_dir; /* directory sort order */ | 91 | int sort_dir; /* directory sort order */ |
92 | struct browse_context *browse; | ||
71 | }; | 93 | }; |
72 | 94 | ||
73 | void tree_drawlists(void); | 95 | void tree_drawlists(void); |
@@ -76,7 +98,11 @@ void tree_gui_init(void) INIT_ATTR; | |||
76 | char* get_current_file(char* buffer, size_t buffer_len); | 98 | char* get_current_file(char* buffer, size_t buffer_len); |
77 | void set_dirfilter(int l_dirfilter); | 99 | void set_dirfilter(int l_dirfilter); |
78 | void set_current_file(const char *path); | 100 | void set_current_file(const char *path); |
79 | int rockbox_browse(const char *root, int dirfilter); | 101 | void browse_context_init(struct browse_context *browse, |
102 | int dirfilter, unsigned flags, | ||
103 | char *title, enum themable_icons icon, | ||
104 | const char *root, const char *selected); | ||
105 | int rockbox_browse(struct browse_context *browse); | ||
80 | bool create_playlist(void); | 106 | bool create_playlist(void); |
81 | void resume_directory(const char *dir); | 107 | void resume_directory(const char *dir); |
82 | #ifdef WIN32 | 108 | #ifdef WIN32 |