1
0
Fork 0
forked from len0rd/rockbox

tree.c cleanup update_dir()

Change-Id: I46a78a3df5ec76a5cd3ae1d6bb236fa40ae75533
This commit is contained in:
William Wilgus 2023-11-22 11:30:11 -05:00
parent 72c539d35e
commit 1d2dfb3a76

View file

@ -352,9 +352,20 @@ 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 ||
@ -385,9 +396,7 @@ 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);
@ -398,31 +407,22 @@ static int update_dir(void)
} }
if (changed) if (changed)
{ {
if( if( !id3db && tc.dirfull )
#ifdef HAVE_TAGCACHE
!id3db &&
#endif
tc.dirfull )
{ {
splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL)); splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL));
} }
} }
gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1, NULL); gui_synclist_init(list, &tree_get_filename, &tc, false, 1, NULL);
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
if (id3db) if (id3db)
{ {
if (global_settings.show_path_in_browser == SHOW_PATH_FULL if (show_path_in_browser == SHOW_PATH_FULL
|| global_settings.show_path_in_browser == SHOW_PATH_CURRENT) || show_path_in_browser == SHOW_PATH_CURRENT)
{ {
gui_synclist_set_title(&tree_lists, tagtree_get_title(&tc), title = tagtree_get_title(&tc);
filetype_get_icon(ATTR_DIRECTORY)); icon = 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,49 +430,52 @@ static int update_dir(void)
{ {
if (tc.browse && tc.browse->title) if (tc.browse && tc.browse->title)
{ {
int icon = tc.browse->icon; title = tc.browse->title;
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 if (global_settings.show_path_in_browser == SHOW_PATH_FULL) else
{ {
gui_synclist_set_title(&tree_lists, tc.currdir, if (show_path_in_browser == SHOW_PATH_FULL)
filetype_get_icon(ATTR_DIRECTORY)); {
title = tc.currdir;
icon = filetype_get_icon(ATTR_DIRECTORY);
} }
else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT) else if (show_path_in_browser == SHOW_PATH_CURRENT)
{ {
char *title = strrchr(tc.currdir, '/') + 1; title = strrchr(tc.currdir, '/');
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 */
gui_synclist_set_title(&tree_lists, str(LANG_DIR_BROWSER), title = 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);
} }
} }
gui_synclist_set_nb_items(&tree_lists, tc.filesindir); /* set title and icon, if nothing is set, clear the title
gui_synclist_set_icon_callback(&tree_lists, * with NULL and icon as NOICON as the list is reused */
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(&tree_lists, tree_voice_cb); gui_synclist_set_voice_callback(list, &tree_voice_cb);
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
gui_synclist_set_color_callback(&tree_lists, &tree_get_filecolor); gui_synclist_set_color_callback(list, &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(&tree_lists, tc.selected_item); gui_synclist_select_item(list, tc.selected_item);
gui_synclist_draw(&tree_lists); gui_synclist_draw(list);
gui_synclist_speak_item(&tree_lists); gui_synclist_speak_item(list);
return tc.filesindir; return tc.filesindir;
} }
@ -483,13 +486,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;
@ -557,10 +560,9 @@ void set_dirfilter(int l_dirfilter)
*tc.dirfilter = l_dirfilter; *tc.dirfilter = l_dirfilter;
} }
/* Selects a file and update tree context properly */ /* Selects a path + file and update tree context properly */
void set_current_file(const char *path) static void set_current_file_ex(const char *path, const char *filename)
{ {
const char *name;
int i; int i;
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
@ -570,21 +572,27 @@ void set_current_file(const char *path)
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 */
name = strrchr(path+1,'/'); filename = strrchr(path+1,'/');
if (name) if (filename)
{ {
strmemccpy(tc.currdir, path, name - path + 1); strmemccpy(tc.currdir, path, filename - path + 1);
name++; filename++;
} }
else else
{ {
strcpy(tc.currdir, "/"); strcpy(tc.currdir, "/");
name = path+1; filename = path+1;
} }
}
strmemccpy(lastfile, name, MAX_PATH); else /* path and filename came in separate */
{
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
@ -617,6 +625,12 @@ void set_current_file(const char *path)
} }
} }
/* 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)
@ -981,7 +995,6 @@ 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;
@ -1021,9 +1034,7 @@ int rockbox_browse(struct browse_context *browse)
if (browse->selected) if (browse->selected)
{ {
snprintf(current, sizeof(current), "%s/%s", set_current_file_ex(browse->root, browse->selected);
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;
} }
@ -1036,8 +1047,7 @@ 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;
strmemccpy(current, browse->root, MAX_PATH); set_current_file(browse->root);
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