Browse by year (now numeric tags are fully supported too).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10750 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-08-25 21:13:49 +00:00
parent 231adb4f77
commit 93bbd44ccc
3 changed files with 61 additions and 29 deletions

View file

@ -636,8 +636,12 @@ static bool add_uniqbuf(struct tagcache_search *tcs, long id)
int i; int i;
/* If uniq buffer is not defined we must return true for search to work. */ /* If uniq buffer is not defined we must return true for search to work. */
if (tcs->unique_list == NULL || !tagcache_is_unique_tag(tcs->type)) if (tcs->unique_list == NULL
|| (!tagcache_is_unique_tag(tcs->type)
&& !tagcache_is_numeric_tag(tcs->type)))
{
return true; return true;
}
for (i = 0; i < tcs->unique_list_count; i++) for (i = 0; i < tcs->unique_list_count; i++)
{ {
@ -681,7 +685,9 @@ static bool build_lookup_list(struct tagcache_search *tcs)
{ {
if (hdr->indices[i].tag_seek[tcs->filter_tag[j]] != if (hdr->indices[i].tag_seek[tcs->filter_tag[j]] !=
tcs->filter_seek[j]) tcs->filter_seek[j])
{
break ; break ;
}
} }
if (j < tcs->filter_count) if (j < tcs->filter_count)
@ -809,6 +815,8 @@ static bool build_lookup_list(struct tagcache_search *tcs)
tcs->seek_list[tcs->seek_list_count] = entry.tag_seek[tcs->type]; tcs->seek_list[tcs->seek_list_count] = entry.tag_seek[tcs->type];
tcs->seek_flags[tcs->seek_list_count] = entry.flag; tcs->seek_flags[tcs->seek_list_count] = entry.flag;
tcs->seek_list_count++; tcs->seek_list_count++;
yield();
} }
return tcs->seek_list_count > 0; return tcs->seek_list_count > 0;
@ -897,17 +905,13 @@ bool tagcache_search(struct tagcache_search *tcs, int tag)
else else
#endif #endif
{ {
if (tagcache_is_numeric_tag(tcs->type)) if (!tagcache_is_numeric_tag(tcs->type))
{ {
tcs->valid = true; tcs->idxfd[tcs->type] = open_tag_fd(&tag_hdr, tcs->type, false);
tcs->initialized = true; if (tcs->idxfd[tcs->type] < 0)
return true; return false;
} }
tcs->idxfd[tcs->type] = open_tag_fd(&tag_hdr, tcs->type, false);
if (tcs->idxfd[tcs->type] < 0)
return false;
/* Always open as R/W so we can pass tcs to functions that modify data also /* Always open as R/W so we can pass tcs to functions that modify data also
* without failing. */ * without failing. */
tcs->masterfd = open_master_fd(&master_hdr, true); tcs->masterfd = open_master_fd(&master_hdr, true);
@ -1019,25 +1023,26 @@ static bool get_next(struct tagcache_search *tcs)
) )
return false; return false;
/* Searching not supported for numeric tags yet. */
if (tagcache_is_numeric_tag(tcs->type))
return false;
/* Relative fetch. */ /* Relative fetch. */
if (tcs->filter_count > 0 || tcs->clause_count > 0) if (tcs->filter_count > 0 || tcs->clause_count > 0
|| tagcache_is_numeric_tag(tcs->type))
{ {
/* Check for end of list. */ /* Check for end of list. */
if (tcs->seek_list_count == 0) if (tcs->seek_list_count == 0)
{ {
/* Try to fetch more. */ /* Try to fetch more. */
if (!build_lookup_list(tcs)) if (!build_lookup_list(tcs))
{
tcs->valid = false;
return false; return false;
}
} }
tcs->seek_list_count--; tcs->seek_list_count--;
/* Seek stream to the correct position and continue to direct fetch. */ /* Seek stream to the correct position and continue to direct fetch. */
if (!tcs->ramsearch || !TAG_FILENAME_RAM(tcs)) if ((!tcs->ramsearch || !TAG_FILENAME_RAM(tcs))
&& !tagcache_is_numeric_tag(tcs->type))
{ {
if (!open_files(tcs)) if (!open_files(tcs))
return false; return false;
@ -1048,6 +1053,16 @@ static bool get_next(struct tagcache_search *tcs)
tcs->position = tcs->seek_list[tcs->seek_list_count]; tcs->position = tcs->seek_list[tcs->seek_list_count];
} }
if (tagcache_is_numeric_tag(tcs->type))
{
logf("r:%d", tcs->position);
snprintf(buf, sizeof(buf), "%d", tcs->position);
tcs->result_seek = tcs->position;
tcs->result = buf;
tcs->result_len = strlen(buf) + 1;
return true;
}
/* Direct fetch. */ /* Direct fetch. */
#ifdef HAVE_TC_RAMCACHE #ifdef HAVE_TC_RAMCACHE
if (tcs->ramsearch && TAG_FILENAME_RAM(tcs)) if (tcs->ramsearch && TAG_FILENAME_RAM(tcs))

View file

@ -3,15 +3,14 @@
"Genres" genre : artist : album : title = "%02d. %s" tracknum title "Genres" genre : artist : album : title = "%02d. %s" tracknum title
"Composers" composer : album : title = "%02d. %s" tracknum title "Composers" composer : album : title = "%02d. %s" tracknum title
"Tracks" title "Tracks" title
"Year" year ? year > "1000" & year < "2008" : artist : album : title = "%02d. %s" tracknum title
"Search by artist" artist ? artist ~ "" : album : title = "%02d. %s" tracknum title "Search by artist" artist ? artist ~ "" : album : title = "%02d. %s" tracknum title
"Search by album" album ? album ~ "" : title = "%02d. %s" tracknum title "Search by album" album ? album ~ "" : title = "%02d. %s" tracknum title
"Search by title" title ? title ~ "" "Search by title" title ? title ~ ""
"Search by filename" filename ? filename ~ "" "Search by filename" filename ? filename ~ ""
"Search by year" artist ? year = "" : album : title = "%02d. %s" tracknum title "Search by year" artist ? year = "" : album : title = "%02d. %s" tracknum title
"Search by score" title = "(%3d) %s" autoscore title ? autoscore > "" "Search by score" title = "(%3d) %s" autoscore title ? autoscore > ""
"Most played tracks" title = "(%d) %s" playcount title ? playcount > "1" "Most played tracks" title = "(%2d) %s" playcount title ? playcount > "1"
"Never played tracks" artist ? playcount == "0" : album : title = "%02d. %s" tracknum title "Never played tracks" artist ? playcount == "0" : album : title = "%02d. %s" tracknum title
"Best tracks" title ? autoscore > "60" & playcount > "1" "Best tracks" artist ? playcount > "1" & autoscore > "85" : album : title = "%02d. %s (%3d)" tracknum title autoscore
"Example 1" artist ? year >= "2000" & artist ^ "a" : album : title
"Example 2" genre ? genre ~ "metal" : artist ? year >= "2000" : album ? year >= "2000" : title
"List played tracks" title = "(%3d/%d) %s" autoscore playcount title ? playcount > "0" "List played tracks" title = "(%3d/%d) %s" autoscore playcount title ? playcount > "0"

View file

@ -546,7 +546,7 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
int namebufused = 0; int namebufused = 0;
int total_count = 0; int total_count = 0;
int special_entry_count = 0; int special_entry_count = 0;
int extra = c->currextra; int level = c->currextra;
int tag; int tag;
bool sort = false; bool sort = false;
@ -564,10 +564,10 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
if (c->currtable == allsubentries) if (c->currtable == allsubentries)
{ {
tag = tag_title; tag = tag_title;
extra--; level--;
} }
else else
tag = csi->tagorder[extra]; tag = csi->tagorder[level];
if (!tagcache_search(tcs, tag)) if (!tagcache_search(tcs, tag))
return -1; return -1;
@ -575,13 +575,30 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
/* Prevent duplicate entries in the search list. */ /* Prevent duplicate entries in the search list. */
tagcache_search_set_uniqbuf(tcs, uniqbuf, UNIQBUF_SIZE); tagcache_search_set_uniqbuf(tcs, uniqbuf, UNIQBUF_SIZE);
if (extra || csi->clause_count[0]) if (level || csi->clause_count[0] || tagcache_is_numeric_tag(tag))
sort = true; sort = true;
for (i = 0; i < extra; i++) for (i = 0; i < level; i++)
tagcache_search_add_filter(tcs, csi->tagorder[i], csi->result_seek[i]); {
if (tagcache_is_numeric_tag(csi->tagorder[i]))
for (i = 0; i <= extra; i++) {
static struct tagcache_search_clause cc;
memset(&cc, 0, sizeof(struct tagcache_search_clause));
cc.tag = csi->tagorder[i];
cc.type = clause_is;
cc.numeric = true;
cc.numeric_data = csi->result_seek[i];
tagcache_search_add_clause(tcs, &cc);
}
else
{
tagcache_search_add_filter(tcs, csi->tagorder[i],
csi->result_seek[i]);
}
}
for (i = 0; i <= level; i++)
{ {
int j; int j;
@ -609,7 +626,7 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
while (tagcache_get_next(tcs)) while (tagcache_get_next(tcs))
{ {
struct display_format *fmt = &csi->format[extra]; struct display_format *fmt = &csi->format[level];
if (total_count++ < offset) if (total_count++ < offset)
continue; continue;
@ -619,7 +636,8 @@ int retrieve_entries(struct tree_context *c, struct tagcache_search *tcs,
if (tag == tag_title || tag == tag_filename) if (tag == tag_title || tag == tag_filename)
dptr->newtable = playtrack; dptr->newtable = playtrack;
if (!tcs->ramsearch || fmt->valid) if (!tcs->ramsearch || fmt->valid
|| tagcache_is_numeric_tag(tag))
{ {
char buf[MAX_PATH]; char buf[MAX_PATH];
int buf_pos = 0; int buf_pos = 0;