64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/idle.h>
|
|
#include <core/playlists/library.h>
|
|
|
|
static struct queue_ops *lib_ops = NULL;
|
|
|
|
|
|
static struct playlist *__lib_pl_alloc(const gchar *path)
|
|
{
|
|
struct playlist *playlist = g_malloc(sizeof(struct playlist));
|
|
|
|
playlist->pl_name = path;
|
|
playlist->pl_type = PL_LIBRARY;
|
|
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, lib_ops, playlist);
|
|
|
|
return playlist;
|
|
}
|
|
|
|
static void __lib_pl_free(struct playlist *playlist)
|
|
{
|
|
if (playlist) {
|
|
queue_deinit(&playlist->pl_queue);
|
|
g_free(playlist);
|
|
}
|
|
}
|
|
|
|
|
|
struct playlist_type pl_library;
|
|
|
|
|
|
static bool __lib_pl_init(void *data)
|
|
{
|
|
struct db_entry *dbe, *next;
|
|
struct playlist *playlist;
|
|
|
|
db_for_each(dbe, next, library_db_get()) {
|
|
playlist = __lib_pl_alloc(LIBRARY(dbe)->li_path);
|
|
LIBRARY(dbe)->li_playlist = playlist;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void pl_library_init(struct queue_ops *ops)
|
|
{
|
|
lib_ops = ops;
|
|
idle_schedule(IDLE_SYNC, __lib_pl_init, NULL);
|
|
}
|
|
|
|
void pl_library_deinit()
|
|
{
|
|
struct db_entry *dbe, *next;
|
|
struct playlist *playlist;
|
|
|
|
db_for_each(dbe, next, library_db_get()) {
|
|
playlist = LIBRARY(dbe)->li_playlist;
|
|
LIBRARY(dbe)->li_playlist = NULL;
|
|
|
|
__lib_pl_free(playlist);
|
|
}
|
|
}
|