From 072228bb70c71bd05eff848d15c36d7f540972b3 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 20 Jul 2024 00:06:31 -0400 Subject: [feature] playlist. show search progressbar when iterating playlist entries Change-Id: Ib38363f7495ca523e7cc401c0d39e060ed1705ad --- apps/misc.c | 12 ++++++++++-- apps/misc.h | 2 +- apps/playlist.c | 15 +++++++++------ apps/tagtree.c | 8 ++++---- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/apps/misc.c b/apps/misc.c index d8caabd397..bd7aa9485b 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -200,7 +200,7 @@ bool warn_on_pl_erase(void) 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; @@ -214,7 +214,15 @@ bool show_search_progress(bool init, int count) /* Update progress every 1/10 of a second */ 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)) return false; last_tick = current_tick; diff --git a/apps/misc.h b/apps/misc.h index e5fb7a3d1f..3b7ce89d22 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -110,7 +110,7 @@ void talk_timedate(void); * returns true if the playlist should be replaced */ 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 (which may be larger than the number of bytes stored in buffer). If diff --git a/apps/playlist.c b/apps/playlist.c index 70637b39a2..d23f3ec0d1 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -2519,6 +2519,7 @@ bool playlist_entries_iterate(const char *filename, bool ret = false; int max; char *dir; + off_t filesize; char temp_buf[MAX_PATH+1]; char trackname[MAX_PATH+1]; @@ -2533,14 +2534,16 @@ bool playlist_entries_iterate(const char *filename, notify_access_error(); 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 */ size_t dirlen = path_dirname(filename, (const char **)&dir); //dir = strmemdupa(dir, dirlen); 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) { @@ -2561,17 +2564,17 @@ bool playlist_entries_iterate(const char *filename, /* we need to format so that relative paths are correctly handled */ - if (format_track_path(trackname, temp_buf, - sizeof(trackname), dir, dirlen) < 0) + if ((max = format_track_path(trackname, temp_buf, + sizeof(trackname), dir, dirlen)) < 0) { goto out; } - + start += max; if (action_cb) { if (!action_cb(trackname)) goto out; - else if (!show_search_progress(false, i)) + else if (!show_search_progress(false, i, start, filesize)) break; } else if (playlist_insert_context_add(pl_context, trackname) < 0) diff --git a/apps/tagtree.c b/apps/tagtree.c index ea2a756a46..d2e27a3e58 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -1452,7 +1452,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init) #else true #endif - , 0); + , 0, 0, 0); if (c->currtable == ALLSUBENTRIES) { @@ -1676,7 +1676,7 @@ entry_skip_formatter: if (init) { - if (!show_search_progress(false, total_count)) + if (!show_search_progress(false, total_count, 0, 0)) { /* user aborted */ tagcache_search_finish(&tcs); tree_unlock_cache(c); @@ -1710,7 +1710,7 @@ entry_skip_formatter: 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; total_count++; } @@ -2229,7 +2229,7 @@ static bool tagtree_insert_selection(int position, bool queue, #else true #endif - , 0); + , 0, 0, 0); newtable = tagtree_get_entry(tc, tc->selected_item)->newtable; -- cgit v1.2.3