summaryrefslogtreecommitdiff
path: root/apps/tagtree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r--apps/tagtree.c70
1 files changed, 50 insertions, 20 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c
index bac74cf443..94bf726caa 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -53,7 +53,17 @@ static int tagtree_play_folder(struct tree_context* c);
53 53
54#define SEARCHSTR_SIZE 128 54#define SEARCHSTR_SIZE 128
55static char searchstring[SEARCHSTR_SIZE]; 55static char searchstring[SEARCHSTR_SIZE];
56 56static const struct id3_to_search_mapping {
57 char *string;
58 size_t id3_offset;
59} id3_to_search_mapping[] = {
60 { "#title#", offsetof(struct mp3entry, title) },
61 { "#artist#", offsetof(struct mp3entry, artist) },
62 { "#album#", offsetof(struct mp3entry, album) },
63 { "#genre#", offsetof(struct mp3entry, genre_string) },
64 { "#composer#", offsetof(struct mp3entry, composer) },
65 { "#albumartist#", offsetof(struct mp3entry, albumartist) },
66};
57enum variables { 67enum variables {
58 var_sorttype = 100, 68 var_sorttype = 100,
59 var_limit, 69 var_limit,
@@ -296,12 +306,25 @@ static bool read_clause(struct tagcache_search_clause *clause)
296 306
297 if (*(clause->str) == '\0') 307 if (*(clause->str) == '\0')
298 clause->source = source_input; 308 clause->source = source_input;
299 else if (!strcasecmp(clause->str, SOURCE_CURRENT_ALBUM)) 309 else if (!strcasecmp(clause->str, "#directory#"))
300 clause->source = source_current_album; 310 clause->source = source_current_path;
301 else if (!strcasecmp(clause->str, SOURCE_CURRENT_ARTIST)) 311 else
302 clause->source = source_current_artist; 312 {
303 else 313 unsigned int i;
304 clause->source = source_constant; 314 bool found = false;
315 for (i=0; !found && i<ARRAYLEN(id3_to_search_mapping); i++)
316 {
317 if (!strcasecmp(clause->str, id3_to_search_mapping[i].string))
318 {
319 found = true;
320 break;
321 }
322 }
323 if (found)
324 clause->source = source_current_id3+i;
325 else
326 clause->source = source_constant;
327 }
305 328
306 if (tagcache_is_numeric_tag(clause->tag)) 329 if (tagcache_is_numeric_tag(clause->tag))
307 { 330 {
@@ -1403,21 +1426,28 @@ int tagtree_enter(struct tree_context* c)
1403 continue; 1426 continue;
1404 1427
1405 id3 = audio_current_track(); 1428 id3 = audio_current_track();
1406 1429
1407 if ((source == source_current_artist) && 1430 if (source == source_current_path && id3)
1408 (id3) && (id3->artist))
1409 { 1431 {
1410 strncpy(searchstring, id3->artist, SEARCHSTR_SIZE); 1432 char *e;
1411 searchstring[SEARCHSTR_SIZE-1] = '\0'; 1433 strncpy(searchstring, id3->path, SEARCHSTR_SIZE);
1412 } 1434 e = strrchr(searchstring, '/');
1413 1435 if (e)
1414 if ((source == source_current_album) && 1436 *e = '\0';
1415 (id3) && (id3->album)) 1437 }
1438
1439 if (source >= source_current_id3 && id3)
1416 { 1440 {
1417 strncpy(searchstring, id3->album, SEARCHSTR_SIZE); 1441 int i = source-source_current_id3;
1418 searchstring[SEARCHSTR_SIZE-1] = '\0'; 1442 int offset = id3_to_search_mapping[i].id3_offset;
1419 } 1443 char **src = (char**)((char*)id3 + offset);
1420 1444 if (*src)
1445 {
1446 strncpy(searchstring, *src, SEARCHSTR_SIZE);
1447 searchstring[SEARCHSTR_SIZE-1] = '\0';
1448 }
1449 }
1450
1421 if((source == source_input) || (*searchstring=='\0')) 1451 if((source == source_input) || (*searchstring=='\0'))
1422 { 1452 {
1423 rc = kbd_input(searchstring, SEARCHSTR_SIZE); 1453 rc = kbd_input(searchstring, SEARCHSTR_SIZE);