From 89217bfc20237a4de1011dd4396b892d5db30af0 Mon Sep 17 00:00:00 2001
From: Jon Bergli Heier <snakebite@jvnv.net>
Date: Thu, 26 Aug 2010 21:54:57 +0200
Subject: Generalized music search.

---
 music.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/music.c b/music.c
index 0bbaa0f..0f6656a 100644
--- a/music.c
+++ b/music.c
@@ -165,18 +165,23 @@ void music_free() {
 	music_root = NULL;
 }
 
-GSList *music_find_artist_rec(struct directory *directory, const gchar *name) {
+static GSList *music_find_rec(struct directory *directory, const gchar *name, enum tag_type type) {
 	GSList *list = NULL;
 
 	for(GSList *node = directory->sub; node; node = g_slist_next(node)) {
 		struct directory *d = node->data;
 		g_debug("searching in dir %s", d->path);
-		list = g_slist_concat(list, music_find_artist_rec(d, name));
+		list = g_slist_concat(list, music_find_rec(d, name, type));
 	}
 
 	for(GSList *node = directory->files; node; node = g_slist_next(node)) {
 		struct file *f = node->data;
-		gchar *str = g_utf8_casefold(f->name, strlen(f->name));
+		const gchar *tag_str = tag_get(f->tag, type);
+		if(tag_str == NULL) {
+			continue;
+		}
+
+		gchar *str = g_utf8_casefold(tag_str, strlen(tag_str));
 		if(strstr(str, name) != NULL) {
 			list = g_slist_prepend(list, f);
 		}
@@ -189,7 +194,7 @@ GSList *music_find_artist_rec(struct directory *directory, const gchar *name) {
 GSList *music_find_artist(const gchar *_name) {
 	gchar *name = g_utf8_casefold(_name, strlen(_name));
 
-	GSList *list = music_find_artist_rec(music_root, name);
+	GSList *list = music_find_rec(music_root, name, TAG_TYPE_ARTIST);
 
 	g_free(name);
 	return list;
-- 
cgit v1.2.3