some improvements to FS#8008 - see tracker entry for details

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15371 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Kukla 2007-10-30 10:02:57 +00:00
parent e9001ae514
commit c436657571
3 changed files with 45 additions and 48 deletions

View file

@ -109,10 +109,9 @@ struct tagcache_stat {
// const char *uimessage; /* Pending error message. Implement soon. */ // const char *uimessage; /* Pending error message. Implement soon. */
}; };
enum source_type {source_constant, source_input, enum source_type {source_constant,
source_current_path, /* has different handling to _id3 source_runtime,
so it has to be seperate */ source_current_path /* dont add items after this.
source_current_id3 /* dont add items after this.
it is used as an index it is used as an index
into id3_to_search_mapping */ into id3_to_search_mapping */
}; };

View file

@ -141,9 +141,11 @@
# Define the "same as current" sub menu # Define the "same as current" sub menu
%menu_start "same" "Same as current" %menu_start "same" "Same as current"
"Directory" -> title ? filename ^ "#directory#"
"Title" -> title = "fmt_title" ? title = "#title#"
"Artist" -> album ? artist = "#artist#" -> title = "fmt_title" "Artist" -> album ? artist = "#artist#" -> title = "fmt_title"
"Album" -> title = "fmt_title" ? album = "#album#" "Album" -> title = "fmt_title" ? album = "#album#" & albumartist = "#albumartist#"
"Directory" -> filename ? filename ~ "#directory#" "Composer" -> title = "fmt_title" ? composer = "#composer#"
# Define the runtime sub menu # Define the runtime sub menu
%menu_start "runtime" "Play history" %menu_start "runtime" "Play history"

View file

@ -51,12 +51,14 @@
static int tagtree_play_folder(struct tree_context* c); static int tagtree_play_folder(struct tree_context* c);
#define SEARCHSTR_SIZE 128 #define SEARCHSTR_SIZE 256
static char searchstring[SEARCHSTR_SIZE];
static const struct id3_to_search_mapping { static const struct id3_to_search_mapping {
char *string; char *string;
size_t id3_offset; size_t id3_offset;
} id3_to_search_mapping[] = { } id3_to_search_mapping[] = {
{ "", 0 }, /* offset n/a */
{ "#directory#", 0 }, /* offset n/a */
{ "#title#", offsetof(struct mp3entry, title) }, { "#title#", offsetof(struct mp3entry, title) },
{ "#artist#", offsetof(struct mp3entry, artist) }, { "#artist#", offsetof(struct mp3entry, artist) },
{ "#album#", offsetof(struct mp3entry, album) }, { "#album#", offsetof(struct mp3entry, album) },
@ -288,7 +290,8 @@ static int get_clause(int *condition)
static bool read_clause(struct tagcache_search_clause *clause) static bool read_clause(struct tagcache_search_clause *clause)
{ {
char buf[256]; char buf[SEARCHSTR_SIZE];
unsigned int i;
if (get_tag(&clause->tag) <= 0) if (get_tag(&clause->tag) <= 0)
return false; return false;
@ -298,33 +301,24 @@ static bool read_clause(struct tagcache_search_clause *clause)
if (get_token_str(buf, sizeof buf) < 0) if (get_token_str(buf, sizeof buf) < 0)
return false; return false;
clause->str = buffer_alloc(strlen(buf)+1); for (i=0; i<ARRAYLEN(id3_to_search_mapping); i++)
strcpy(clause->str, buf); {
if (!strcasecmp(buf, id3_to_search_mapping[i].string))
logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str); break;
}
if (*(clause->str) == '\0')
clause->source = source_input; if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */
else if (!strcasecmp(clause->str, "#directory#")) {
clause->source = source_current_path; clause->source = source_runtime+i;
clause->str = buffer_alloc(SEARCHSTR_SIZE);
}
else else
{ {
unsigned int i; clause->source = source_constant;
bool found = false; clause->str = buffer_alloc(strlen(buf)+1);
for (i=0; !found && i<ARRAYLEN(id3_to_search_mapping); i++) strcpy(clause->str, buf);
{ }
if (!strcasecmp(clause->str, id3_to_search_mapping[i].string))
{
found = true;
break;
}
}
if (found)
clause->source = source_current_id3+i;
else
clause->source = source_constant;
}
if (tagcache_is_numeric_tag(clause->tag)) if (tagcache_is_numeric_tag(clause->tag))
{ {
@ -333,6 +327,8 @@ static bool read_clause(struct tagcache_search_clause *clause)
} }
else else
clause->numeric = false; clause->numeric = false;
logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str);
return true; return true;
} }
@ -1419,14 +1415,17 @@ int tagtree_enter(struct tree_context* c)
{ {
for (j = 0; j < csi->clause_count[i]; j++) for (j = 0; j < csi->clause_count[i]; j++)
{ {
*searchstring='\0'; char* searchstring;
source = csi->clause[i][j]->source; source = csi->clause[i][j]->source;
if (source == source_constant) if (source == source_constant)
continue; continue;
searchstring=csi->clause[i][j]->str;
*searchstring = '\0';
id3 = audio_current_track(); id3 = audio_current_track();
if (source == source_current_path && id3) if (source == source_current_path && id3)
{ {
char *e; char *e;
@ -1435,11 +1434,11 @@ int tagtree_enter(struct tree_context* c)
if (e) if (e)
*e = '\0'; *e = '\0';
} }
else if (source > source_runtime && id3)
if (source >= source_current_id3 && id3)
{ {
int i = source-source_current_id3;
int offset = id3_to_search_mapping[i].id3_offset; int k = source-source_runtime;
int offset = id3_to_search_mapping[k].id3_offset;
char **src = (char**)((char*)id3 + offset); char **src = (char**)((char*)id3 + offset);
if (*src) if (*src)
{ {
@ -1447,8 +1446,7 @@ int tagtree_enter(struct tree_context* c)
searchstring[SEARCHSTR_SIZE-1] = '\0'; searchstring[SEARCHSTR_SIZE-1] = '\0';
} }
} }
else
if((source == source_input) || (*searchstring=='\0'))
{ {
rc = kbd_input(searchstring, SEARCHSTR_SIZE); rc = kbd_input(searchstring, SEARCHSTR_SIZE);
if (rc == -1 || !searchstring[0]) if (rc == -1 || !searchstring[0])
@ -1456,18 +1454,16 @@ int tagtree_enter(struct tree_context* c)
tagtree_exit(c); tagtree_exit(c);
return 0; return 0;
} }
if (csi->clause[i][j]->numeric)
csi->clause[i][j]->numeric_data = atoi(searchstring);
} }
if (csi->clause[i][j]->numeric)
csi->clause[i][j]->numeric_data = atoi(searchstring);
/* existing bug: only one dynamic string per clause! */
csi->clause[i][j]->str = searchstring;
} }
} }
} }
c->currtable = newextra; c->currtable = newextra;
break; break;
case navibrowse: case navibrowse: