2016-05-15 10:19:31 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/idle.h>
|
|
|
|
#include <core/playlists/artist.h>
|
|
|
|
|
|
|
|
static struct queue_ops *artist_ops = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
static struct playlist *__artist_pl_alloc(gchar *name)
|
|
|
|
{
|
|
|
|
struct playlist *playlist = g_malloc(sizeof(struct playlist));
|
|
|
|
|
|
|
|
playlist->pl_name = name;
|
|
|
|
playlist->pl_type = PL_ARTIST;
|
|
|
|
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, artist_ops, playlist);
|
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __artist_pl_free(struct playlist *playlist)
|
|
|
|
{
|
|
|
|
if (playlist) {
|
|
|
|
queue_deinit(&playlist->pl_queue);
|
|
|
|
g_free(playlist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-15 10:32:58 -04:00
|
|
|
static bool __artist_pl_load(void *data)
|
|
|
|
{
|
|
|
|
struct playlist *playlist;
|
|
|
|
struct db_entry *dbe, *next;
|
|
|
|
|
|
|
|
db_for_each(dbe, next, track_db_get()) {
|
|
|
|
playlist = TRACK(dbe)->tr_artist->ar_playlist;
|
|
|
|
queue_add(&playlist->pl_queue, TRACK(dbe));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-15 10:19:31 -04:00
|
|
|
|
2016-05-15 10:51:33 -04:00
|
|
|
static struct queue *pl_artist_get_queue(const gchar *name)
|
|
|
|
{
|
|
|
|
struct artist *artist = artist_lookup(name);
|
|
|
|
struct playlist *playlist = artist ? artist->ar_playlist : NULL;
|
|
|
|
return playlist ? &playlist->pl_queue : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool pl_artist_new_delete(const gchar *name)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool pl_artist_add_rm(const gchar *name, struct track *track)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pl_artist_update(const gchar *name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pl_artist_set_flag(const gchar *name, enum queue_flags flag,
|
|
|
|
bool enabled)
|
|
|
|
{
|
|
|
|
struct queue *queue = pl_artist_get_queue(name);
|
|
|
|
(enabled ? queue_set_flag : queue_unset_flag)(queue, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pl_artist_sort(const gchar *name, enum compare_t sort, bool reset)
|
|
|
|
{
|
|
|
|
struct queue *queue = pl_artist_get_queue(name);
|
|
|
|
queue_sort(queue, sort, reset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct playlist_type pl_artist = {
|
|
|
|
.pl_get_queue = pl_artist_get_queue,
|
|
|
|
.pl_new = pl_artist_new_delete,
|
|
|
|
.pl_delete = pl_artist_new_delete,
|
|
|
|
.pl_add_track = pl_artist_add_rm,
|
|
|
|
.pl_remove_track = pl_artist_add_rm,
|
|
|
|
.pl_update = pl_artist_update,
|
|
|
|
.pl_set_flag = pl_artist_set_flag,
|
|
|
|
.pl_sort = pl_artist_sort,
|
|
|
|
};
|
2016-05-15 10:19:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
static bool __artist_pl_init(void *data)
|
|
|
|
{
|
|
|
|
struct db_entry *dbe, *next;
|
|
|
|
struct playlist *playlist;
|
|
|
|
|
|
|
|
db_for_each(dbe, next, artist_db_get()) {
|
|
|
|
playlist = __artist_pl_alloc(ARTIST(dbe)->ar_name);
|
|
|
|
ARTIST(dbe)->ar_playlist = playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pl_artist_init(struct queue_ops *ops)
|
|
|
|
{
|
|
|
|
artist_ops = ops;
|
|
|
|
idle_schedule(IDLE_SYNC, __artist_pl_init, NULL);
|
2016-05-15 10:32:58 -04:00
|
|
|
idle_schedule(IDLE_SYNC, __artist_pl_load, NULL);
|
2016-05-15 10:19:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void pl_artist_deinit()
|
|
|
|
{
|
|
|
|
struct db_entry *dbe, *next;
|
|
|
|
struct playlist *playlist;
|
|
|
|
|
|
|
|
db_for_each(dbe, next, artist_db_get()) {
|
|
|
|
playlist = ARTIST(dbe)->ar_playlist;
|
|
|
|
ARTIST(dbe)->ar_playlist = NULL;
|
|
|
|
|
|
|
|
__artist_pl_free(playlist);
|
|
|
|
}
|
|
|
|
}
|