core/playlists/system: Clean up loading system playlists
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8220dd9932
commit
8a5163fb68
|
@ -9,7 +9,6 @@ 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 pl_system_save();
|
||||
static bool __sys_pl_load();
|
||||
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0);
|
||||
static struct file sys_deck_f = FILE_INIT("deck", 1);
|
||||
|
@ -40,17 +39,6 @@ static void sys_pl_update_init(struct playlist *playlist, unsigned int flags,
|
|||
pl_system_update(playlist->pl_name);
|
||||
}
|
||||
|
||||
static void sys_pl_load_partial(struct playlist *playlist, struct file *file)
|
||||
{
|
||||
queue_load_flags(&playlist->pl_queue, file, true);
|
||||
}
|
||||
|
||||
static void sys_pl_load_full(struct playlist *playlist, struct file *file)
|
||||
{
|
||||
sys_pl_load_partial(playlist, file);
|
||||
queue_load_tracks(&playlist->pl_queue, file);
|
||||
}
|
||||
|
||||
static bool sys_pl_generic_add_front(struct playlist *playlist,
|
||||
struct track *track)
|
||||
{
|
||||
|
@ -78,7 +66,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_load = sys_pl_load_full,
|
||||
};
|
||||
|
||||
|
||||
|
@ -136,7 +123,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_load = sys_pl_load_full,
|
||||
};
|
||||
|
||||
|
||||
|
@ -195,7 +181,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_load = sys_pl_load_full,
|
||||
};
|
||||
|
||||
|
||||
|
@ -233,7 +218,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_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_collection_update,
|
||||
};
|
||||
|
||||
|
@ -263,7 +247,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_load = sys_pl_load_partial,
|
||||
};
|
||||
|
||||
|
||||
|
@ -289,7 +272,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_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_unplayed_update,
|
||||
};
|
||||
|
||||
|
@ -317,7 +299,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_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_most_played_update,
|
||||
};
|
||||
|
||||
|
@ -345,7 +326,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_load = sys_pl_load_partial,
|
||||
.spl_update = sys_pl_least_played_update,
|
||||
};
|
||||
|
||||
|
@ -379,36 +359,9 @@ static bool __sys_pl_update_save()
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool __sys_pl_load_new()
|
||||
{
|
||||
struct sys_playlist *sys_pl;
|
||||
unsigned int i, n;
|
||||
gchar *name;
|
||||
|
||||
if (!file_open(&sys_pl_file, OPEN_READ)) {
|
||||
__sys_pl_load();
|
||||
sys_pl_collection_load();
|
||||
sys_pl_queued_load();
|
||||
__sys_pl_update_save();
|
||||
return true;
|
||||
}
|
||||
|
||||
file_readf(&sys_pl_file, "%u\n", &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
name = file_readl(&sys_pl_file);
|
||||
sys_pl = __sys_pl_lookup(name);
|
||||
if (sys_pl)
|
||||
sys_pl->spl_load(&sys_pl->spl_playlist, &sys_pl_file);
|
||||
g_free(name);
|
||||
}
|
||||
|
||||
file_close(&sys_pl_file);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool __sys_pl_load()
|
||||
{
|
||||
struct sys_playlist *plist;
|
||||
struct playlist *playlist;
|
||||
unsigned int i, n;
|
||||
gchar *name;
|
||||
|
||||
|
@ -422,11 +375,11 @@ static bool __sys_pl_load()
|
|||
g_free(name);
|
||||
name = g_strdup("Hidden");
|
||||
}
|
||||
|
||||
plist = __sys_pl_lookup(name);
|
||||
if (plist)
|
||||
queue_load_tracks(&plist->spl_playlist.pl_queue, &sys_file);
|
||||
playlist = pl_system_lookup(name);
|
||||
g_free(name);
|
||||
|
||||
if (playlist)
|
||||
queue_load_tracks(&playlist->pl_queue, &sys_file);
|
||||
}
|
||||
|
||||
file_close(&sys_file);
|
||||
|
@ -434,6 +387,41 @@ static bool __sys_pl_load()
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool __sys_pl_load_new()
|
||||
{
|
||||
struct playlist *playlist;
|
||||
unsigned int i, n;
|
||||
gchar *name;
|
||||
|
||||
if (!file_open(&sys_pl_file, OPEN_READ)) {
|
||||
__sys_pl_load();
|
||||
sys_pl_collection_load();
|
||||
sys_pl_queued_load();
|
||||
__sys_pl_update_save();
|
||||
return true;
|
||||
}
|
||||
|
||||
file_readf(&sys_pl_file, "%u\n", &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
name = file_readl(&sys_pl_file);
|
||||
playlist = pl_system_lookup(name);
|
||||
g_free(name);
|
||||
|
||||
queue_load_flags(&playlist->pl_queue, &sys_pl_file, true);
|
||||
switch (i) {
|
||||
case SYS_PL_FAVORITES:
|
||||
case SYS_PL_HIDDEN:
|
||||
case SYS_PL_QUEUED:
|
||||
queue_load_tracks(&playlist->pl_queue, &sys_pl_file);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file_close(&sys_pl_file);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void pl_system_save(void)
|
||||
{
|
||||
|
|
|
@ -22,7 +22,6 @@ struct sys_playlist {
|
|||
struct playlist spl_playlist;
|
||||
|
||||
void (*spl_init)(struct playlist *, unsigned int, struct queue_ops *);
|
||||
void (*spl_load)(struct playlist *, struct file *);
|
||||
bool (*spl_update)(struct playlist *, struct track *);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue