From 4574b09685bb3e805aeddad956d524941f47cb37 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 23 Aug 2010 18:12:07 +0200 Subject: Implemented artist search. --- music.c | 31 +++++++++++++++++++++++++++++++ music.h | 13 +++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/music.c b/music.c index 559abc4..0bbaa0f 100644 --- a/music.c +++ b/music.c @@ -45,6 +45,7 @@ gboolean music_scan(struct directory *directory) { if(S_ISREG(st.st_mode)) { struct file *f = g_new0(struct file, 1); f->name = g_strdup(entry); + f->parent = directory; directory->files = g_slist_prepend(directory->files, f); @@ -164,6 +165,36 @@ void music_free() { music_root = NULL; } +GSList *music_find_artist_rec(struct directory *directory, const gchar *name) { + 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)); + } + + 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)); + if(strstr(str, name) != NULL) { + list = g_slist_prepend(list, f); + } + g_free(str); + } + + return list; +} + +GSList *music_find_artist(const gchar *_name) { + gchar *name = g_utf8_casefold(_name, strlen(_name)); + + GSList *list = music_find_artist_rec(music_root, name); + + g_free(name); + return list; +} + gchar *music_get_full_path(const gchar *path) { return g_build_filename(music_root->path, path, NULL); } diff --git a/music.h b/music.h index 7a4fe32..c4d3bbf 100644 --- a/music.h +++ b/music.h @@ -5,19 +5,20 @@ #include +struct directory { + gchar *path; + GSList *sub; + GSList *files; +}; + struct file { gchar *name; gssize size; + struct directory *parent; struct tag *tag; }; -struct directory { - gchar *path; - GSList *sub; - GSList *files; -}; - extern struct directory *music_root; gboolean music_init(); -- cgit v1.2.3