1
0
Fork 0
forked from len0rd/rockbox

Revert "tree.c cleanup update_dir()"

This reverts commit 1d2dfb3a76.

Reason for revert: crash on ipod Classic boot

Change-Id: Ie0fe569515f73bb7853796e5e7df13fde42e8642
This commit is contained in:
William Wilgus 2023-11-22 13:43:53 -05:00
parent 1d2dfb3a76
commit b6ac9a9f39

View file

@ -352,20 +352,9 @@ static int tree_get_file_position(char * filename)
*/ */
static int update_dir(void) static int update_dir(void)
{ {
struct gui_synclist * const list = &tree_lists;
int show_path_in_browser = global_settings.show_path_in_browser;
bool changed = false; bool changed = false;
const char* title = NULL;/* Must clear the title as the list is reused */
int icon = NOICON;
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
bool id3db = *tc.dirfilter == SHOW_ID3DB; bool id3db = *tc.dirfilter == SHOW_ID3DB;
#else
const bool id3db = false;
#endif
#ifdef HAVE_TAGCACHE
/* Checks for changes */ /* Checks for changes */
if (id3db) { if (id3db) {
if (tc.currtable != lasttable || if (tc.currtable != lasttable ||
@ -396,7 +385,9 @@ static int update_dir(void)
/* if selected item is undefined */ /* if selected item is undefined */
if (tc.selected_item == -1) if (tc.selected_item == -1)
{ {
#ifdef HAVE_TAGCACHE
if (!id3db) if (!id3db)
#endif
/* use lastfile to determine the selected item */ /* use lastfile to determine the selected item */
tc.selected_item = tree_get_file_position(lastfile); tc.selected_item = tree_get_file_position(lastfile);
@ -407,22 +398,31 @@ static int update_dir(void)
} }
if (changed) if (changed)
{ {
if( !id3db && tc.dirfull ) if(
#ifdef HAVE_TAGCACHE
!id3db &&
#endif
tc.dirfull )
{ {
splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL)); splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL));
} }
} }
gui_synclist_init(list, &tree_get_filename, &tc, false, 1, NULL); gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1, NULL);
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
if (id3db) if (id3db)
{ {
if (show_path_in_browser == SHOW_PATH_FULL if (global_settings.show_path_in_browser == SHOW_PATH_FULL
|| show_path_in_browser == SHOW_PATH_CURRENT) || global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
{ {
title = tagtree_get_title(&tc); gui_synclist_set_title(&tree_lists, tagtree_get_title(&tc),
icon = filetype_get_icon(ATTR_DIRECTORY); filetype_get_icon(ATTR_DIRECTORY));
}
else
{
/* Must clear the title as the list is reused */
gui_synclist_set_title(&tree_lists, NULL, NOICON);
} }
} }
else else
@ -430,52 +430,49 @@ static int update_dir(void)
{ {
if (tc.browse && tc.browse->title) if (tc.browse && tc.browse->title)
{ {
title = tc.browse->title; int icon = tc.browse->icon;
icon = tc.browse->icon;
if (icon == NOICON) if (icon == NOICON)
icon = filetype_get_icon(ATTR_DIRECTORY); icon = filetype_get_icon(ATTR_DIRECTORY);
gui_synclist_set_title(&tree_lists, tc.browse->title, icon);
} }
else else if (global_settings.show_path_in_browser == SHOW_PATH_FULL)
{ {
if (show_path_in_browser == SHOW_PATH_FULL) gui_synclist_set_title(&tree_lists, tc.currdir,
{ filetype_get_icon(ATTR_DIRECTORY));
title = tc.currdir;
icon = filetype_get_icon(ATTR_DIRECTORY);
} }
else if (show_path_in_browser == SHOW_PATH_CURRENT) else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
{ {
title = strrchr(tc.currdir, '/'); char *title = strrchr(tc.currdir, '/') + 1;
if (title != NULL)
{
title++; /* step past the separator */
if (*title == '\0') if (*title == '\0')
{ {
/* Display "Files" for the root dir */ /* Display "Files" for the root dir */
title = str(LANG_DIR_BROWSER); gui_synclist_set_title(&tree_lists, str(LANG_DIR_BROWSER),
} filetype_get_icon(ATTR_DIRECTORY));
icon = filetype_get_icon(ATTR_DIRECTORY);
} }
else
gui_synclist_set_title(&tree_lists, title,
filetype_get_icon(ATTR_DIRECTORY));
} }
else
{
/* Must clear the title as the list is reused */
gui_synclist_set_title(&tree_lists, NULL, NOICON);
} }
} }
/* set title and icon, if nothing is set, clear the title gui_synclist_set_nb_items(&tree_lists, tc.filesindir);
* with NULL and icon as NOICON as the list is reused */ gui_synclist_set_icon_callback(&tree_lists,
gui_synclist_set_title(list, title, icon);
gui_synclist_set_nb_items(list, tc.filesindir);
gui_synclist_set_icon_callback(list,
global_settings.show_icons?tree_get_fileicon:NULL); global_settings.show_icons?tree_get_fileicon:NULL);
gui_synclist_set_voice_callback(list, &tree_voice_cb); gui_synclist_set_voice_callback(&tree_lists, tree_voice_cb);
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
gui_synclist_set_color_callback(list, &tree_get_filecolor); gui_synclist_set_color_callback(&tree_lists, &tree_get_filecolor);
#endif #endif
if( tc.selected_item >= tc.filesindir) if( tc.selected_item >= tc.filesindir)
tc.selected_item=tc.filesindir-1; tc.selected_item=tc.filesindir-1;
gui_synclist_select_item(list, tc.selected_item); gui_synclist_select_item(&tree_lists, tc.selected_item);
gui_synclist_draw(list); gui_synclist_draw(&tree_lists);
gui_synclist_speak_item(list); gui_synclist_speak_item(&tree_lists);
return tc.filesindir; return tc.filesindir;
} }
@ -486,13 +483,13 @@ void resume_directory(const char *dir)
int ret; int ret;
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
bool id3db = *tc.dirfilter == SHOW_ID3DB; bool id3db = *tc.dirfilter == SHOW_ID3DB;
#else
const bool id3db = false;
#endif #endif
/* make sure the dirfilter is sane. The only time it should be possible /* make sure the dirfilter is sane. The only time it should be possible
* thats its not is when resume playlist is called from a plugin * thats its not is when resume playlist is called from a plugin
*/ */
#ifdef HAVE_TAGCACHE
if (!id3db) if (!id3db)
#endif
*tc.dirfilter = global_settings.dirfilter; *tc.dirfilter = global_settings.dirfilter;
ret = ft_load(&tc, dir); ret = ft_load(&tc, dir);
*tc.dirfilter = dirfilter; *tc.dirfilter = dirfilter;
@ -560,9 +557,10 @@ void set_dirfilter(int l_dirfilter)
*tc.dirfilter = l_dirfilter; *tc.dirfilter = l_dirfilter;
} }
/* Selects a path + file and update tree context properly */ /* Selects a file and update tree context properly */
static void set_current_file_ex(const char *path, const char *filename) void set_current_file(const char *path)
{ {
const char *name;
int i; int i;
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
@ -572,27 +570,21 @@ static void set_current_file_ex(const char *path, const char *filename)
return; return;
#endif #endif
if (!filename) /* path and filename supplied combined */
{
/* separate directory from filename */ /* separate directory from filename */
/* gets the directory's name and put it into tc.currdir */ /* gets the directory's name and put it into tc.currdir */
filename = strrchr(path+1,'/'); name = strrchr(path+1,'/');
if (filename) if (name)
{ {
strmemccpy(tc.currdir, path, filename - path + 1); strmemccpy(tc.currdir, path, name - path + 1);
filename++; name++;
} }
else else
{ {
strcpy(tc.currdir, "/"); strcpy(tc.currdir, "/");
filename = path+1; name = path+1;
} }
}
else /* path and filename came in separate */ strmemccpy(lastfile, name, MAX_PATH);
{
strmemccpy(tc.currdir, path, MAX_PATH);
}
strmemccpy(lastfile, filename, MAX_PATH);
/* If we changed dir we must recalculate the dirlevel /* If we changed dir we must recalculate the dirlevel
@ -625,12 +617,6 @@ static void set_current_file_ex(const char *path, const char *filename)
} }
} }
/* Selects a file and update tree context properly */
void set_current_file(const char *path)
{
set_current_file_ex(path, NULL);
}
/* main loop, handles key events */ /* main loop, handles key events */
static int dirbrowse(void) static int dirbrowse(void)
@ -995,6 +981,7 @@ static int backup_count = -1;
int rockbox_browse(struct browse_context *browse) int rockbox_browse(struct browse_context *browse)
{ {
tc.is_browsing = (browse != NULL); tc.is_browsing = (browse != NULL);
static char current[MAX_PATH];
int ret_val = 0; int ret_val = 0;
int dirfilter = browse->dirfilter; int dirfilter = browse->dirfilter;
@ -1034,7 +1021,9 @@ int rockbox_browse(struct browse_context *browse)
if (browse->selected) if (browse->selected)
{ {
set_current_file_ex(browse->root, browse->selected); snprintf(current, sizeof(current), "%s/%s",
browse->root, browse->selected);
set_current_file(current);
/* set_current_file changes dirlevel, change it back */ /* set_current_file changes dirlevel, change it back */
tc.dirlevel = 0; tc.dirlevel = 0;
} }
@ -1047,7 +1036,8 @@ int rockbox_browse(struct browse_context *browse)
if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0) if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0)
tc.dirfilter = &global_settings.dirfilter; tc.dirfilter = &global_settings.dirfilter;
tc.browse = browse; tc.browse = browse;
set_current_file(browse->root); strmemccpy(current, browse->root, MAX_PATH);
set_current_file(current);
if (browse->flags&BROWSE_RUNFILE) if (browse->flags&BROWSE_RUNFILE)
ret_val = ft_enter(&tc); ret_val = ft_enter(&tc);
else else