core/playlists/artist: Save playlist flags between sessions
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
d33245f604
commit
a4692c0fe0
|
@ -3,8 +3,10 @@
|
||||||
*/
|
*/
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <core/playlists/artist.h>
|
#include <core/playlists/artist.h>
|
||||||
|
#include <core/string.h>
|
||||||
|
|
||||||
static struct queue_ops *artist_ops = NULL;
|
static struct queue_ops *artist_ops = NULL;
|
||||||
|
static struct file artist_file = FILE_INIT("playlist.artist", 0, 0);
|
||||||
|
|
||||||
|
|
||||||
static struct playlist *__artist_pl_alloc(gchar *name)
|
static struct playlist *__artist_pl_alloc(gchar *name)
|
||||||
|
@ -26,7 +28,7 @@ static void __artist_pl_free(struct playlist *playlist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __artist_pl_load(void *data)
|
static bool __artist_pl_add(void *data)
|
||||||
{
|
{
|
||||||
struct playlist *playlist = (struct playlist *)data;
|
struct playlist *playlist = (struct playlist *)data;
|
||||||
struct artist *artist = artist_lookup(playlist->pl_name);
|
struct artist *artist = artist_lookup(playlist->pl_name);
|
||||||
|
@ -48,6 +50,49 @@ static struct playlist *__artist_pl_lookup(const gchar *name)
|
||||||
return artist ? artist->ar_playlist : NULL;
|
return artist ? artist->ar_playlist : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __artist_pl_save(void)
|
||||||
|
{
|
||||||
|
struct db_entry *dbe, *next;
|
||||||
|
struct playlist *playlist;
|
||||||
|
|
||||||
|
if (!file_open(&artist_file, OPEN_WRITE))
|
||||||
|
return;
|
||||||
|
|
||||||
|
file_writef(&artist_file, "%u\n", artist_db_get()->db_size);
|
||||||
|
db_for_each(dbe, next, artist_db_get()) {
|
||||||
|
playlist = ARTIST(dbe)->ar_playlist;
|
||||||
|
file_writef(&artist_file, "%s\n", playlist->pl_name);
|
||||||
|
queue_save_flags(&playlist->pl_queue, &artist_file, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_close(&artist_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __artist_pl_load(void *data)
|
||||||
|
{
|
||||||
|
struct playlist *playlist;
|
||||||
|
unsigned int i, n;
|
||||||
|
gchar *name;
|
||||||
|
|
||||||
|
if (!file_open(&artist_file, OPEN_READ))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
file_readf(&artist_file, "%u\n", &n);
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
name = file_readl(&artist_file);
|
||||||
|
playlist = __artist_pl_lookup(name);
|
||||||
|
if (!playlist)
|
||||||
|
continue;
|
||||||
|
queue_load_flags(&playlist->pl_queue, &artist_file, true);
|
||||||
|
queue_iter_set(&playlist->pl_queue, &playlist->pl_queue.q_cur,
|
||||||
|
playlist->pl_queue.q_cur.it_pos);
|
||||||
|
g_free(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_close(&artist_file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct queue *pl_artist_get_queue(const gchar *name)
|
static struct queue *pl_artist_get_queue(const gchar *name)
|
||||||
{
|
{
|
||||||
|
@ -92,18 +137,22 @@ static void pl_artist_set_flag(const gchar *name, enum queue_flags flag,
|
||||||
{
|
{
|
||||||
struct playlist *playlist = __artist_pl_lookup(name);
|
struct playlist *playlist = __artist_pl_lookup(name);
|
||||||
playlist_generic_set_flag(playlist, flag, enabled);
|
playlist_generic_set_flag(playlist, flag, enabled);
|
||||||
|
__artist_pl_save();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pl_artist_sort(const gchar *name, enum compare_t sort, bool reset)
|
static void pl_artist_sort(const gchar *name, enum compare_t sort, bool reset)
|
||||||
{
|
{
|
||||||
struct playlist *playlist = __artist_pl_lookup(name);
|
struct playlist *playlist = __artist_pl_lookup(name);
|
||||||
playlist_generic_sort(playlist, sort, reset);
|
playlist_generic_sort(playlist, sort, reset);
|
||||||
|
__artist_pl_save();
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct track *pl_artist_next(const gchar *name)
|
static struct track *pl_artist_next(const gchar *name)
|
||||||
{
|
{
|
||||||
struct playlist *playlist = __artist_pl_lookup(name);
|
struct playlist *playlist = __artist_pl_lookup(name);
|
||||||
return playlist_generic_next(playlist);
|
struct track *track = playlist_generic_next(playlist);;
|
||||||
|
__artist_pl_save();
|
||||||
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +181,7 @@ static bool __artist_pl_init(void *data)
|
||||||
playlist = __artist_pl_alloc(ARTIST(dbe)->ar_name);
|
playlist = __artist_pl_alloc(ARTIST(dbe)->ar_name);
|
||||||
ARTIST(dbe)->ar_playlist = playlist;
|
ARTIST(dbe)->ar_playlist = playlist;
|
||||||
|
|
||||||
idle_schedule(IDLE_SYNC, __artist_pl_load, playlist);
|
idle_schedule(IDLE_SYNC, __artist_pl_add, playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -142,6 +191,7 @@ void pl_artist_init(struct queue_ops *ops)
|
||||||
{
|
{
|
||||||
artist_ops = ops;
|
artist_ops = ops;
|
||||||
idle_schedule(IDLE_SYNC, __artist_pl_init, NULL);
|
idle_schedule(IDLE_SYNC, __artist_pl_init, NULL);
|
||||||
|
idle_schedule(IDLE_SYNC, __artist_pl_load, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pl_artist_deinit()
|
void pl_artist_deinit()
|
||||||
|
|
Loading…
Reference in New Issue