1
0
Fork 0
forked from len0rd/rockbox

Allow all tag type in formatting string. Included example with

tagnavi.config.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11324 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-10-24 16:20:48 +00:00
parent 748036bb70
commit 02df5a8068
4 changed files with 92 additions and 66 deletions

View file

@ -1288,7 +1288,7 @@ bool tagcache_get_next(struct tagcache_search *tcs)
} }
bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
char *buf, long size) int tag, char *buf, long size)
{ {
struct index_entry idx; 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)) if (!get_index(tcs->masterfd, idxid, &idx, true))
return false; return false;
return retrieve(tcs, &idx, tcs->type, buf, size); return retrieve(tcs, &idx, tag, buf, size);
} }
#if 0 #if 0
@ -2860,7 +2860,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
} }
tcs->type = j; 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); write_tag(clfd, tagcache_tag_to_str(j), buf);
} }

View file

@ -150,7 +150,7 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs,
struct tagcache_search_clause *clause); struct tagcache_search_clause *clause);
bool tagcache_get_next(struct tagcache_search *tcs); bool tagcache_get_next(struct tagcache_search *tcs);
bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, 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); void tagcache_search_finish(struct tagcache_search *tcs);
long tagcache_get_numeric(const struct tagcache_search *tcs, int tag); long tagcache_get_numeric(const struct tagcache_search *tcs, int tag);
long tagcache_increase_serial(void); long tagcache_increase_serial(void);

View file

@ -8,8 +8,8 @@
# Basic format declarations # Basic format declarations
%format "fmt_title" "%02d. %s" tracknum title ? tracknum > "0" %format "fmt_title" "%02d. %s" tracknum title ? tracknum > "0"
%format "fmt_title" "%s" title %format "fmt_title" "%s" title
%format "fmt_mostplayed" "(%3d) %s" playcount title %sort = "inverse" %limit = "100" %format "fmt_mostplayed" "(%3d) %s - %s" playcount artist title %sort = "inverse" %limit = "100"
%format "fmt_lastplayed" "%06d%s" lastplayed title %sort = "inverse" %limit = "99" %strip = "6" %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_best_tracks" "%02d. %s (%3d)" tracknum title autoscore
%format "fmt_played" "(%3d/%d) %s" autoscore playcount title %format "fmt_played" "(%3d/%d) %s" autoscore playcount title
%format "fmt_score" "(%3d) %s" autoscore title %format "fmt_score" "(%3d) %s" autoscore title

View file

@ -881,6 +881,86 @@ bool show_search_progress(bool init, int count)
return true; 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 retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
int offset, bool init) int offset, bool init)
{ {
@ -1022,73 +1102,19 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
if (!tcs->ramresult || fmt) if (!tcs->ramresult || fmt)
{ {
char buf[MAX_PATH]; char buf[MAX_PATH];
int buf_pos = 0;
if (fmt) if (fmt)
{ {
char fmtbuf[8]; if (format_str(tcs, fmt, buf, sizeof buf) < 0)
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 (fmt->formatstr[i] == '%') logf("format_str() failed");
{
read_format = true;
fmtbuf_pos = 0;
if (parpos >= fmt->tag_count)
{
logf("too many format tags");
return 0; 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;
}
}
buf[buf_pos++] = '\0';
}
dptr->name = &c->name_buffer[namebufused]; dptr->name = &c->name_buffer[namebufused];
if (fmt) if (fmt)
namebufused += buf_pos; namebufused += strlen(buf)+1;
else else
namebufused += tcs->result_len; 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)) if (!tagcache_search(&tcs, tag_filename))
return -1; return -1;
if (!tagcache_retrieve(&tcs, entry->extraseek, buf, buflen)) if (!tagcache_retrieve(&tcs, entry->extraseek, tcs.type, buf, buflen))
{ {
tagcache_search_finish(&tcs); tagcache_search_finish(&tcs);
return -2; return -2;
@ -1447,7 +1473,7 @@ bool insert_all_playlist(struct tree_context *c, int position, bool queue)
break; break;
if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, i)->extraseek, if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, i)->extraseek,
buf, sizeof buf)) tcs.type, buf, sizeof buf))
{ {
continue; continue;
} }