core/playlists/library: Save playlist flags between sessions
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a4692c0fe0
commit
54bb0ffe2b
|
@ -13,7 +13,8 @@ struct scan_data {
|
|||
};
|
||||
|
||||
static bool __lib_pl_scan_dir(void *);
|
||||
static struct queue_ops *lib_ops = NULL;
|
||||
static struct queue_ops *lib_ops = NULL;
|
||||
static struct file lib_file = FILE_INIT("playlist.library", 0, 0);
|
||||
|
||||
|
||||
static struct playlist *__lib_pl_alloc(struct library *library)
|
||||
|
@ -35,7 +36,7 @@ static void __lib_pl_free(struct playlist *playlist)
|
|||
}
|
||||
}
|
||||
|
||||
static bool __lib_pl_load(void *data)
|
||||
static bool __lib_pl_add(void *data)
|
||||
{
|
||||
struct playlist *playlist = (struct playlist *)data;
|
||||
struct library *library = library_lookup(playlist->pl_name);
|
||||
|
@ -57,6 +58,49 @@ static struct playlist *__lib_pl_lookup(const gchar *name)
|
|||
return library ? library->li_playlist : NULL;
|
||||
}
|
||||
|
||||
static void __lib_pl_save(void)
|
||||
{
|
||||
struct db_entry *dbe, *next;
|
||||
struct playlist *playlist;
|
||||
|
||||
if (!file_open(&lib_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&lib_file, "%u\n", library_db_get()->db_size);
|
||||
db_for_each(dbe, next, library_db_get()) {
|
||||
playlist = LIBRARY(dbe)->li_playlist;
|
||||
file_writef(&lib_file, "%s\n", playlist->pl_name);
|
||||
queue_save_flags(&playlist->pl_queue, &lib_file, true);
|
||||
}
|
||||
|
||||
file_close(&lib_file);
|
||||
}
|
||||
|
||||
static bool __lib_pl_load(void *data)
|
||||
{
|
||||
struct playlist *playlist;
|
||||
unsigned int i, n;
|
||||
gchar *name;
|
||||
|
||||
if (!file_open(&lib_file, OPEN_READ))
|
||||
return true;
|
||||
|
||||
file_readf(&lib_file, "%u\n", &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
name = file_readl(&lib_file);
|
||||
playlist = __lib_pl_lookup(name);
|
||||
if (!playlist)
|
||||
continue;
|
||||
queue_load_flags(&playlist->pl_queue, &lib_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(&lib_file);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __lib_pl_scan_dir_idle(struct library *library, const gchar *path)
|
||||
{
|
||||
struct scan_data *scan = g_malloc(sizeof(struct scan_data));
|
||||
|
@ -194,6 +238,7 @@ static bool pl_library_delete(const gchar *name)
|
|||
|
||||
track_remove_all(library);
|
||||
library_remove(library);
|
||||
__lib_pl_save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -214,18 +259,22 @@ static void pl_library_set_flag(const gchar *name, enum queue_flags flag,
|
|||
{
|
||||
struct playlist *playlist = __lib_pl_lookup(name);
|
||||
playlist_generic_set_flag(playlist, flag, enabled);
|
||||
__lib_pl_save();
|
||||
}
|
||||
|
||||
static void pl_library_sort(const gchar *name, enum compare_t sort, bool reset)
|
||||
{
|
||||
struct playlist *playlist = __lib_pl_lookup(name);
|
||||
playlist_generic_sort(playlist, sort, reset);
|
||||
__lib_pl_save();
|
||||
}
|
||||
|
||||
static struct track *pl_library_next(const gchar *name)
|
||||
{
|
||||
struct playlist *playlist = __lib_pl_lookup(name);
|
||||
return playlist_generic_next(playlist);
|
||||
struct track *track = playlist_generic_next(playlist);
|
||||
__lib_pl_save();
|
||||
return track;
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,7 +303,7 @@ static bool __lib_pl_init(void *data)
|
|||
playlist = __lib_pl_alloc(LIBRARY(dbe));
|
||||
LIBRARY(dbe)->li_playlist = playlist;
|
||||
|
||||
idle_schedule(IDLE_SYNC, __lib_pl_load, playlist);
|
||||
idle_schedule(IDLE_SYNC, __lib_pl_add, playlist);
|
||||
pl_library_update(playlist->pl_name);
|
||||
}
|
||||
|
||||
|
@ -265,6 +314,7 @@ void pl_library_init(struct queue_ops *ops)
|
|||
{
|
||||
lib_ops = ops;
|
||||
idle_schedule(IDLE_SYNC, __lib_pl_init, NULL);
|
||||
idle_schedule(IDLE_SYNC, __lib_pl_load, NULL);
|
||||
}
|
||||
|
||||
void pl_library_deinit()
|
||||
|
|
Loading…
Reference in New Issue