summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-23 18:12:07 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-23 18:12:07 +0200
commit4574b09685bb3e805aeddad956d524941f47cb37 (patch)
tree9999f23b6d6bec62c0a780898d929eec34b27e81
parent9aef30b0bc6eae8053969a6772d0dacadf0f6bab (diff)
Implemented artist search.
-rw-r--r--music.c31
-rw-r--r--music.h13
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 <glib.h>
+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();