diff options
author | Max Kellermann <max@duempel.org> | 2008-09-19 16:23:31 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-19 16:23:31 +0200 |
commit | d1c31cf66398447b5ba0d0a60de5b92ad162675c (patch) | |
tree | 3e8b8868d7078e70408a96a9795acd9b19d7008c /src/filelist.c | |
parent | e3b42caa5d39d084ba511aee43fada91e367ae3e (diff) | |
download | mpd-d1c31cf66398447b5ba0d0a60de5b92ad162675c.tar.gz mpd-d1c31cf66398447b5ba0d0a60de5b92ad162675c.tar.xz mpd-d1c31cf66398447b5ba0d0a60de5b92ad162675c.zip |
filelist: provide more functions for working with a filelist
Avoid direct accesses to the filelist struct, provide an API for that.
Diffstat (limited to 'src/filelist.c')
-rw-r--r-- | src/filelist.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/filelist.c b/src/filelist.c index 55b4cfabf..bfc4c12b5 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -23,6 +23,19 @@ #include <string.h> #include <assert.h> +struct filelist * +filelist_new(const char *path) +{ + struct filelist *filelist = g_malloc(sizeof(*filelist)); + + filelist->path = g_strdup(path); + filelist->length = 0; + filelist->updated = FALSE; + filelist->list = NULL; + + return filelist; +} + void filelist_free(struct filelist *filelist) { @@ -47,6 +60,49 @@ filelist_free(struct filelist *filelist) } struct filelist_entry * +filelist_append(struct filelist *filelist, struct mpd_InfoEntity *entity) +{ + struct filelist_entry *entry = g_malloc(sizeof(*entry)); + + entry->flags = 0; + entry->entity = entity; + + filelist->list = g_list_append(filelist->list, entry); + filelist->length++; + + return entry; +} + +struct filelist_entry * +filelist_prepend(struct filelist *filelist, struct mpd_InfoEntity *entity) +{ + struct filelist_entry *entry = g_malloc(sizeof(*entry)); + + entry->flags = 0; + entry->entity = entity; + + filelist->list = g_list_insert(filelist->list, entry, 0); + filelist->length++; + + return entry; +} + +void +filelist_move(struct filelist *filelist, struct filelist *from) +{ + filelist->list = g_list_concat(filelist->list, from->list); + filelist->length += from->length; + from->list = NULL; + from->length = 0; +} + +void +filelist_sort(struct filelist *filelist, GCompareFunc compare_func) +{ + filelist->list = g_list_sort(filelist->list, compare_func); +} + +struct filelist_entry * filelist_find_song(struct filelist *fl, const struct mpd_song *song) { GList *list = g_list_first(fl->list); |