diff --git a/apps/tagcache.c b/apps/tagcache.c index 3ba1f21e24..ffafe5b8df 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -1288,7 +1288,7 @@ bool tagcache_get_next(struct tagcache_search *tcs) } bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, - char *buf, long size) + int tag, char *buf, long size) { struct index_entry idx; @@ -1296,7 +1296,7 @@ bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, if (!get_index(tcs->masterfd, idxid, &idx, true)) return false; - return retrieve(tcs, &idx, tcs->type, buf, size); + return retrieve(tcs, &idx, tag, buf, size); } #if 0 @@ -2860,7 +2860,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) } tcs->type = j; - tagcache_retrieve(tcs, i, buf, sizeof buf); + tagcache_retrieve(tcs, i, tcs->type, buf, sizeof buf); write_tag(clfd, tagcache_tag_to_str(j), buf); } diff --git a/apps/tagcache.h b/apps/tagcache.h index 37423e63c8..cdd4722b79 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -150,7 +150,7 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, struct tagcache_search_clause *clause); bool tagcache_get_next(struct tagcache_search *tcs); bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, - char *buf, long size); + int tag, char *buf, long size); void tagcache_search_finish(struct tagcache_search *tcs); long tagcache_get_numeric(const struct tagcache_search *tcs, int tag); long tagcache_increase_serial(void); diff --git a/apps/tagnavi.config b/apps/tagnavi.config index 191b4bdda5..9dc24b606c 100644 --- a/apps/tagnavi.config +++ b/apps/tagnavi.config @@ -8,8 +8,8 @@ # Basic format declarations %format "fmt_title" "%02d. %s" tracknum title ? tracknum > "0" %format "fmt_title" "%s" title -%format "fmt_mostplayed" "(%3d) %s" playcount title %sort = "inverse" %limit = "100" -%format "fmt_lastplayed" "%06d%s" lastplayed title %sort = "inverse" %limit = "99" %strip = "6" +%format "fmt_mostplayed" "(%3d) %s - %s" playcount artist title %sort = "inverse" %limit = "100" +%format "fmt_lastplayed" "%06d%s - %s" lastplayed artist title %sort = "inverse" %limit = "99" %strip = "6" %format "fmt_best_tracks" "%02d. %s (%3d)" tracknum title autoscore %format "fmt_played" "(%3d/%d) %s" autoscore playcount title %format "fmt_score" "(%3d) %s" autoscore title diff --git a/apps/tagtree.c b/apps/tagtree.c index 082e10d7d9..d2a9e11191 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -881,6 +881,86 @@ bool show_search_progress(bool init, int count) return true; } +int format_str(struct tagcache_search *tcs, struct display_format *fmt, + char *buf, int buf_size) +{ + char fmtbuf[8]; + bool read_format = false; + int fmtbuf_pos = 0; + int parpos = 0; + int buf_pos = 0; + int i; + + memset(buf, 0, buf_size); + for (i = 0; fmt->formatstr[i] != '\0'; i++) + { + if (fmt->formatstr[i] == '%') + { + read_format = true; + fmtbuf_pos = 0; + if (parpos >= fmt->tag_count) + { + logf("too many format tags"); + return -1; + } + } + + if (read_format) + { + fmtbuf[fmtbuf_pos++] = fmt->formatstr[i]; + if (fmtbuf_pos >= buf_size) + { + logf("format parse error"); + return -2; + } + + if (fmt->formatstr[i] == 's') + { + fmtbuf[fmtbuf_pos] = '\0'; + read_format = false; + if (fmt->tags[parpos] == tcs->type) + { + snprintf(&buf[buf_pos], buf_size - buf_pos, fmtbuf, tcs->result); + } + else + { + /* Need to fetch the tag data. */ + if (!tagcache_retrieve(tcs, tcs->idx_id, fmt->tags[parpos], + &buf[buf_pos], buf_size - buf_pos)) + { + logf("retrieve failed"); + return -3; + } + } + buf_pos += strlen(&buf[buf_pos]); + parpos++; + } + else if (fmt->formatstr[i] == 'd') + { + fmtbuf[fmtbuf_pos] = '\0'; + read_format = false; + snprintf(&buf[buf_pos], buf_size - buf_pos, fmtbuf, + tagcache_get_numeric(tcs, fmt->tags[parpos])); + buf_pos += strlen(&buf[buf_pos]); + parpos++; + } + continue; + } + + buf[buf_pos++] = fmt->formatstr[i]; + + if (buf_pos - 1 >= buf_size) + { + logf("buffer overflow"); + return -4; + } + } + + buf[buf_pos++] = '\0'; + + return 0; +} + int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs, int offset, bool init) { @@ -1022,73 +1102,19 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs, if (!tcs->ramresult || fmt) { char buf[MAX_PATH]; - int buf_pos = 0; if (fmt) { - char fmtbuf[8]; - bool read_format = false; - int fmtbuf_pos = 0; - int parpos = 0; - - memset(buf, 0, sizeof buf); - for (i = 0; fmt->formatstr[i] != '\0'; i++) + if (format_str(tcs, fmt, buf, sizeof buf) < 0) { - if (fmt->formatstr[i] == '%') - { - read_format = true; - fmtbuf_pos = 0; - if (parpos >= fmt->tag_count) - { - logf("too many format tags"); - return 0; - } - } - - if (read_format) - { - fmtbuf[fmtbuf_pos++] = fmt->formatstr[i]; - if (fmtbuf_pos >= (long)sizeof(fmtbuf)) - { - logf("format parse error"); - return 0; - } - - if (fmt->formatstr[i] == 's') - { - fmtbuf[fmtbuf_pos] = '\0'; - read_format = false; - snprintf(&buf[buf_pos], MAX_PATH - buf_pos, fmtbuf, tcs->result); - buf_pos += strlen(&buf[buf_pos]); - parpos++; - } - else if (fmt->formatstr[i] == 'd') - { - fmtbuf[fmtbuf_pos] = '\0'; - read_format = false; - snprintf(&buf[buf_pos], MAX_PATH - buf_pos, fmtbuf, - tagcache_get_numeric(tcs, fmt->tags[parpos])); - buf_pos += strlen(&buf[buf_pos]); - parpos++; - } - continue; - } - - buf[buf_pos++] = fmt->formatstr[i]; - - if (buf_pos - 1 >= (long)sizeof(buf)) - { - logf("buffer overflow"); - return 0; - } + logf("format_str() failed"); + return 0; } - - buf[buf_pos++] = '\0'; } dptr->name = &c->name_buffer[namebufused]; if (fmt) - namebufused += buf_pos; + namebufused += strlen(buf)+1; else namebufused += tcs->result_len; @@ -1401,7 +1427,7 @@ int tagtree_get_filename(struct tree_context* c, char *buf, int buflen) if (!tagcache_search(&tcs, tag_filename)) return -1; - if (!tagcache_retrieve(&tcs, entry->extraseek, buf, buflen)) + if (!tagcache_retrieve(&tcs, entry->extraseek, tcs.type, buf, buflen)) { tagcache_search_finish(&tcs); return -2; @@ -1447,7 +1473,7 @@ bool insert_all_playlist(struct tree_context *c, int position, bool queue) break; if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, i)->extraseek, - buf, sizeof buf)) + tcs.type, buf, sizeof buf)) { continue; }