[feature] playlist. show search progressbar when iterating playlist entries

Change-Id: Ib38363f7495ca523e7cc401c0d39e060ed1705ad
This commit is contained in:
William Wilgus 2024-07-20 00:06:31 -04:00 committed by William Wilgus
parent 82cf845625
commit 072228bb70
4 changed files with 24 additions and 13 deletions

View file

@ -200,7 +200,7 @@ bool warn_on_pl_erase(void)
return true; return true;
} }
bool show_search_progress(bool init, int count) bool show_search_progress(bool init, int display_count, int current, int total)
{ {
static int last_tick = 0; static int last_tick = 0;
@ -214,7 +214,15 @@ bool show_search_progress(bool init, int count)
/* Update progress every 1/10 of a second */ /* Update progress every 1/10 of a second */
if (TIME_AFTER(current_tick, last_tick + HZ/10)) if (TIME_AFTER(current_tick, last_tick + HZ/10))
{ {
splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), count, str(LANG_OFF_ABORT)); if (total != current)
{
splash_progress(current, total, str(LANG_PLAYLIST_SEARCH_MSG),
display_count, str(LANG_OFF_ABORT));
}
else
splashf(0, str(LANG_PLAYLIST_SEARCH_MSG),
display_count, str(LANG_OFF_ABORT));
if (action_userabort(TIMEOUT_NOBLOCK)) if (action_userabort(TIMEOUT_NOBLOCK))
return false; return false;
last_tick = current_tick; last_tick = current_tick;

View file

@ -110,7 +110,7 @@ void talk_timedate(void);
* returns true if the playlist should be replaced */ * returns true if the playlist should be replaced */
bool warn_on_pl_erase(void); bool warn_on_pl_erase(void);
bool show_search_progress(bool init, int count); bool show_search_progress(bool init, int count, int current, int total);
/* Read (up to) a line of text from fd into buffer and return number of bytes /* Read (up to) a line of text from fd into buffer and return number of bytes
* read (which may be larger than the number of bytes stored in buffer). If * read (which may be larger than the number of bytes stored in buffer). If

View file

@ -2519,6 +2519,7 @@ bool playlist_entries_iterate(const char *filename,
bool ret = false; bool ret = false;
int max; int max;
char *dir; char *dir;
off_t filesize;
char temp_buf[MAX_PATH+1]; char temp_buf[MAX_PATH+1];
char trackname[MAX_PATH+1]; char trackname[MAX_PATH+1];
@ -2533,14 +2534,16 @@ bool playlist_entries_iterate(const char *filename,
notify_access_error(); notify_access_error();
goto out; goto out;
} }
off_t start = lseek(fd, 0, SEEK_CUR);
filesize = lseek(fd, 0, SEEK_END);
lseek(fd, start, SEEK_SET);
/* we need the directory name for formatting purposes */ /* we need the directory name for formatting purposes */
size_t dirlen = path_dirname(filename, (const char **)&dir); size_t dirlen = path_dirname(filename, (const char **)&dir);
//dir = strmemdupa(dir, dirlen); //dir = strmemdupa(dir, dirlen);
if (action_cb) if (action_cb)
show_search_progress(true, 0); show_search_progress(true, 0, 0, 0);
while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0)
{ {
@ -2561,17 +2564,17 @@ bool playlist_entries_iterate(const char *filename,
/* we need to format so that relative paths are correctly /* we need to format so that relative paths are correctly
handled */ handled */
if (format_track_path(trackname, temp_buf, if ((max = format_track_path(trackname, temp_buf,
sizeof(trackname), dir, dirlen) < 0) sizeof(trackname), dir, dirlen)) < 0)
{ {
goto out; goto out;
} }
start += max;
if (action_cb) if (action_cb)
{ {
if (!action_cb(trackname)) if (!action_cb(trackname))
goto out; goto out;
else if (!show_search_progress(false, i)) else if (!show_search_progress(false, i, start, filesize))
break; break;
} }
else if (playlist_insert_context_add(pl_context, trackname) < 0) else if (playlist_insert_context_add(pl_context, trackname) < 0)

View file

@ -1452,7 +1452,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
#else #else
true true
#endif #endif
, 0); , 0, 0, 0);
if (c->currtable == ALLSUBENTRIES) if (c->currtable == ALLSUBENTRIES)
{ {
@ -1676,7 +1676,7 @@ entry_skip_formatter:
if (init) if (init)
{ {
if (!show_search_progress(false, total_count)) if (!show_search_progress(false, total_count, 0, 0))
{ /* user aborted */ { /* user aborted */
tagcache_search_finish(&tcs); tagcache_search_finish(&tcs);
tree_unlock_cache(c); tree_unlock_cache(c);
@ -1710,7 +1710,7 @@ entry_skip_formatter:
while (tagcache_get_next(&tcs, tcs_buf, tcs_bufsz)) while (tagcache_get_next(&tcs, tcs_buf, tcs_bufsz))
{ {
if (!show_search_progress(false, total_count)) if (!show_search_progress(false, total_count, 0, 0))
break; break;
total_count++; total_count++;
} }
@ -2229,7 +2229,7 @@ static bool tagtree_insert_selection(int position, bool queue,
#else #else
true true
#endif #endif
, 0); , 0, 0, 0);
newtable = tagtree_get_entry(tc, tc->selected_item)->newtable; newtable = tagtree_get_entry(tc, tc->selected_item)->newtable;