Anna Schumaker
85bb67feed
I intend to use this for playlist filtering to store filter text. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
120 lines
2.7 KiB
C
120 lines
2.7 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/idle.h>
|
|
#include <core/playlists/type.h>
|
|
|
|
|
|
/*
|
|
* Noop playlist operations.
|
|
*/
|
|
bool playlist_noop_can_select(struct playlist *playlist)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void playlist_noop_clear(struct playlist *playlist)
|
|
{
|
|
}
|
|
|
|
void playlist_noop_set_flag(struct playlist *playlist,
|
|
enum queue_flags flag, bool enabled)
|
|
{
|
|
}
|
|
|
|
void playlist_noop_sort(struct playlist *playlist,
|
|
enum compare_t sort, bool reset)
|
|
{
|
|
}
|
|
|
|
|
|
/*
|
|
* Generic playlist operations.
|
|
*/
|
|
void playlist_generic_init(struct playlist *playlist, unsigned int flags,
|
|
struct queue_ops *ops)
|
|
{
|
|
queue_init(&playlist->pl_queue, flags | Q_ENABLED, ops, playlist);
|
|
queue_sort(&playlist->pl_queue, COMPARE_ARTIST, true);
|
|
queue_sort(&playlist->pl_queue, COMPARE_YEAR, false);
|
|
queue_sort(&playlist->pl_queue, COMPARE_TRACK, false);
|
|
playlist->pl_private = NULL;
|
|
}
|
|
|
|
bool playlist_generic_can_select(struct playlist *playlist)
|
|
{
|
|
return queue_size(&playlist->pl_queue) > 0;
|
|
}
|
|
|
|
void playlist_generic_clear(struct playlist *playlist)
|
|
{
|
|
queue_clear(&playlist->pl_queue);
|
|
}
|
|
|
|
bool playlist_generic_add_track(struct playlist *playlist, struct track *track)
|
|
{
|
|
if (queue_has(&playlist->pl_queue, track))
|
|
return false;
|
|
queue_add(&playlist->pl_queue, track);
|
|
return true;
|
|
}
|
|
|
|
bool playlist_generic_remove_track(struct playlist *playlist, struct track *track)
|
|
{
|
|
return queue_remove_all(&playlist->pl_queue, track);
|
|
}
|
|
|
|
struct pl_update_data {
|
|
struct playlist *pud_playlist;
|
|
bool (*pud_func)(struct playlist *, struct track *);
|
|
};
|
|
|
|
static bool __playlist_generic_update(void *data)
|
|
{
|
|
struct pl_update_data *pud = data;
|
|
struct db_entry *dbe, *next;
|
|
|
|
db_for_each(dbe, next, track_db_get()) {
|
|
if (!pud->pud_func(pud->pud_playlist, TRACK(dbe)))
|
|
playlist_generic_remove_track(pud->pud_playlist, TRACK(dbe));
|
|
}
|
|
|
|
queue_unset_flag(&pud->pud_playlist->pl_queue, Q_ADD_FRONT);
|
|
g_free(pud);
|
|
return true;
|
|
}
|
|
|
|
void playlist_generic_update(struct playlist *playlist,
|
|
bool (*func)(struct playlist *, struct track *))
|
|
{
|
|
struct pl_update_data *data;
|
|
|
|
if (!func)
|
|
return;
|
|
|
|
data = g_malloc(sizeof(struct pl_update_data));
|
|
data->pud_playlist = playlist;
|
|
data->pud_func = func;
|
|
|
|
idle_schedule(IDLE_SYNC, __playlist_generic_update, data);
|
|
}
|
|
|
|
void playlist_generic_set_flag(struct playlist *playlist,
|
|
enum queue_flags flag, bool enabled)
|
|
{
|
|
if (enabled)
|
|
return queue_set_flag(&playlist->pl_queue, flag);
|
|
return queue_unset_flag(&playlist->pl_queue, flag);
|
|
}
|
|
|
|
void playlist_generic_sort(struct playlist *playlist,
|
|
enum compare_t sort, bool reset)
|
|
{
|
|
queue_sort(&playlist->pl_queue, sort, reset);
|
|
}
|
|
|
|
struct track *playlist_generic_next(struct playlist *playlist)
|
|
{
|
|
return queue_next(&playlist->pl_queue);
|
|
}
|