core/playlists/system: Clean up saving system playlists
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0754f10883
commit
8220dd9932
|
@ -8,7 +8,7 @@
|
|||
static struct playlist *pl_system_lookup(const gchar *);
|
||||
static struct playlist *pl_system_get(unsigned int);
|
||||
static void pl_system_update(const gchar *);
|
||||
static void __sys_pl_save();
|
||||
static void pl_system_save();
|
||||
static bool __sys_pl_load();
|
||||
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0);
|
||||
|
@ -23,7 +23,7 @@ static struct file sys_pl_file = FILE_INIT("playlist.system", 0);
|
|||
static bool sys_pl_delete_clear(struct playlist *playlist)
|
||||
{
|
||||
playlist_generic_clear(playlist);
|
||||
__sys_pl_save();
|
||||
pl_system_save();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -40,18 +40,6 @@ static void sys_pl_update_init(struct playlist *playlist, unsigned int flags,
|
|||
pl_system_update(playlist->pl_name);
|
||||
}
|
||||
|
||||
static void sys_pl_save_partial(struct playlist *playlist, struct file *file)
|
||||
{
|
||||
file_writef(file, "%s\n", playlist->pl_name);
|
||||
queue_save_flags(&playlist->pl_queue, file, true);
|
||||
}
|
||||
|
||||
static void sys_pl_save_full(struct playlist *playlist, struct file *file)
|
||||
{
|
||||
sys_pl_save_partial(playlist, file);
|
||||
queue_save_tracks(&playlist->pl_queue, file);
|
||||
}
|
||||
|
||||
static void sys_pl_load_partial(struct playlist *playlist, struct file *file)
|
||||
{
|
||||
queue_load_flags(&playlist->pl_queue, file, true);
|
||||
|
@ -90,7 +78,6 @@ static struct sys_playlist sys_favorites = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites",
|
||||
SYS_PL_FAVORITES, &favorites_ops),
|
||||
.spl_init = playlist_generic_init,
|
||||
.spl_save = sys_pl_save_full,
|
||||
.spl_load = sys_pl_load_full,
|
||||
};
|
||||
|
||||
|
@ -131,7 +118,7 @@ static bool sys_pl_hidden_clear(struct playlist *playlist)
|
|||
sys_pl_hidden_remove(playlist, track);
|
||||
}
|
||||
|
||||
__sys_pl_save();
|
||||
pl_system_save();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -149,7 +136,6 @@ static struct sys_playlist sys_hidden = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden",
|
||||
SYS_PL_HIDDEN, &hidden_ops),
|
||||
.spl_init = playlist_generic_init,
|
||||
.spl_save = sys_pl_save_full,
|
||||
.spl_load = sys_pl_load_full,
|
||||
};
|
||||
|
||||
|
@ -209,7 +195,6 @@ static struct sys_playlist sys_queued = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Queued Tracks",
|
||||
SYS_PL_QUEUED, &queued_ops),
|
||||
.spl_init = sys_pl_queued_init,
|
||||
.spl_save = sys_pl_save_full,
|
||||
.spl_load = sys_pl_load_full,
|
||||
};
|
||||
|
||||
|
@ -248,7 +233,6 @@ static struct sys_playlist sys_collection = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection",
|
||||
SYS_PL_COLLECTION, &collection_ops),
|
||||
.spl_init = sys_pl_update_init,
|
||||
.spl_save = sys_pl_save_partial,
|
||||
.spl_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_collection_update,
|
||||
};
|
||||
|
@ -279,7 +263,6 @@ static struct sys_playlist sys_history = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History",
|
||||
SYS_PL_HISTORY, &history_ops),
|
||||
.spl_init = sys_pl_history_init,
|
||||
.spl_save = sys_pl_save_partial,
|
||||
.spl_load = sys_pl_load_partial,
|
||||
};
|
||||
|
||||
|
@ -306,7 +289,6 @@ static struct sys_playlist sys_unplayed = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed",
|
||||
SYS_PL_UNPLAYED, &unplayed_ops),
|
||||
.spl_init = sys_pl_update_init,
|
||||
.spl_save = sys_pl_save_partial,
|
||||
.spl_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_unplayed_update,
|
||||
};
|
||||
|
@ -335,7 +317,6 @@ static struct sys_playlist sys_most_played = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played",
|
||||
SYS_PL_MOST_PLAYED, &most_played_ops),
|
||||
.spl_init = sys_pl_update_init,
|
||||
.spl_save = sys_pl_save_partial,
|
||||
.spl_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_most_played_update,
|
||||
};
|
||||
|
@ -364,7 +345,6 @@ static struct sys_playlist sys_least_played = {
|
|||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played",
|
||||
SYS_PL_LEAST_PLAYED, &least_played_ops),
|
||||
.spl_init = sys_pl_update_init,
|
||||
.spl_save = sys_pl_save_partial,
|
||||
.spl_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_least_played_update,
|
||||
};
|
||||
|
@ -393,26 +373,9 @@ static struct sys_playlist * __sys_pl_lookup(const gchar *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void __sys_pl_save()
|
||||
{
|
||||
struct sys_playlist *sys_pl;
|
||||
unsigned int i;
|
||||
|
||||
if (!file_open(&sys_pl_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&sys_pl_file, "%u\n", SYS_PL_NUM_PLAYLISTS);
|
||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||
sys_pl = sys_playlists[i];
|
||||
sys_pl->spl_save(&sys_pl->spl_playlist, &sys_pl_file);
|
||||
}
|
||||
|
||||
file_close(&sys_pl_file);
|
||||
}
|
||||
|
||||
static bool __sys_pl_update_save()
|
||||
{
|
||||
__sys_pl_save();
|
||||
pl_system_save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -474,7 +437,29 @@ static bool __sys_pl_load()
|
|||
|
||||
static void pl_system_save(void)
|
||||
{
|
||||
__sys_pl_save();
|
||||
struct playlist *playlist;
|
||||
unsigned int i;
|
||||
|
||||
if (!file_open(&sys_pl_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&sys_pl_file, "%u\n", SYS_PL_NUM_PLAYLISTS);
|
||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||
playlist = pl_system_get(i);
|
||||
|
||||
file_writef(&sys_pl_file, "%s\n", playlist->pl_name);
|
||||
queue_save_flags(&playlist->pl_queue, &sys_pl_file, true);
|
||||
switch (i) {
|
||||
case SYS_PL_FAVORITES:
|
||||
case SYS_PL_HIDDEN:
|
||||
case SYS_PL_QUEUED:
|
||||
queue_save_tracks(&playlist->pl_queue, &sys_pl_file);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file_close(&sys_pl_file);
|
||||
}
|
||||
|
||||
static struct playlist *pl_system_lookup(const gchar *name)
|
||||
|
|
|
@ -22,7 +22,6 @@ struct sys_playlist {
|
|||
struct playlist spl_playlist;
|
||||
|
||||
void (*spl_init)(struct playlist *, unsigned int, struct queue_ops *);
|
||||
void (*spl_save)(struct playlist *, struct file *);
|
||||
void (*spl_load)(struct playlist *, struct file *);
|
||||
bool (*spl_update)(struct playlist *, struct track *);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue