core/playlist: Add a playlist_init_sorted() function
Sometimes we want to initialize the playlist with sort data, other times we don't. This gives us functions we can call for both! Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
cdbf8b1736
commit
7f54562b71
|
@ -23,7 +23,7 @@ static struct playlist *__artist_pl_alloc(struct artist *artist)
|
|||
playlist->pl_type = PL_ARTIST;
|
||||
playlist->pl_id = artist_index(artist);
|
||||
playlist->pl_ops = &pl_artist_ops;
|
||||
playlist_generic_init(playlist, artist_ops);
|
||||
playlist_generic_init_sorted(playlist, artist_ops);
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
|
|
@ -40,15 +40,25 @@ void playlist_generic_set_callbacks(struct playlist_callbacks *cb)
|
|||
|
||||
void playlist_generic_init(struct playlist *playlist, struct queue_ops *ops)
|
||||
{
|
||||
if (playlist) {
|
||||
g_queue_init(&playlist->pl_tracks);
|
||||
queue_init(&playlist->pl_queue, ops, playlist);
|
||||
playlist->pl_sort = NULL;
|
||||
playlist->pl_current = NULL;
|
||||
playlist->pl_search = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void playlist_generic_init_sorted(struct playlist *playlist,
|
||||
struct queue_ops *ops)
|
||||
{
|
||||
if (playlist) {
|
||||
playlist_generic_init(playlist, ops);
|
||||
playlist_generic_sort(playlist, COMPARE_ARTIST);
|
||||
playlist_generic_sort(playlist, COMPARE_YEAR);
|
||||
playlist_generic_sort(playlist, COMPARE_TRACK);
|
||||
}
|
||||
}
|
||||
|
||||
void playlist_generic_deinit(struct playlist *playlist)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ static struct playlist *__lib_pl_alloc(struct library *library)
|
|||
playlist->pl_type = PL_LIBRARY;
|
||||
playlist->pl_id = library_index(library);
|
||||
playlist->pl_ops = &pl_library_ops;
|
||||
playlist_generic_init(playlist, lib_ops);
|
||||
playlist_generic_init_sorted(playlist, lib_ops);
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
|
|
@ -396,7 +396,7 @@ void pl_system_init(struct queue_ops *ops)
|
|||
switch (i) {
|
||||
case SYS_PL_QUEUED:
|
||||
case SYS_PL_HISTORY:
|
||||
queue_init(&playlist->pl_queue, ops, playlist);
|
||||
playlist_generic_init(playlist, ops);
|
||||
break;
|
||||
case SYS_PL_COLLECTION:
|
||||
case SYS_PL_UNPLAYED:
|
||||
|
@ -405,7 +405,7 @@ void pl_system_init(struct queue_ops *ops)
|
|||
sys_pl_update(playlist);
|
||||
case SYS_PL_FAVORITES:
|
||||
case SYS_PL_HIDDEN:
|
||||
playlist_generic_init(playlist, ops);
|
||||
playlist_generic_init_sorted(playlist, ops);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ static struct user_playlist *__user_db_alloc(gchar *name, unsigned int index)
|
|||
playlist->pl_playlist.pl_type = PL_USER;
|
||||
playlist->pl_playlist.pl_id = index;
|
||||
playlist->pl_playlist.pl_ops = &user_ops;
|
||||
playlist_generic_init(&playlist->pl_playlist, user_pl_ops);
|
||||
playlist_generic_init_sorted(&playlist->pl_playlist, user_pl_ops);
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,9 @@ struct playlist_callbacks {
|
|||
/* Called to set playlist callbacks. */
|
||||
void playlist_generic_set_callbacks(struct playlist_callbacks *);
|
||||
|
||||
/* Generic playlist init function. */
|
||||
/* Generic playlist init functions. */
|
||||
void playlist_generic_init(struct playlist *, struct queue_ops *);
|
||||
void playlist_generic_init_sorted(struct playlist *, struct queue_ops *);
|
||||
|
||||
/* Generic playlist deinit function. */
|
||||
void playlist_generic_deinit(struct playlist *);
|
||||
|
|
|
@ -42,6 +42,8 @@ static void test_null()
|
|||
g_assert_null(playlist_new(PL_MAX_TYPE, NULL));
|
||||
g_assert_false(playlist_delete(NULL));
|
||||
|
||||
playlist_generic_init(NULL, NULL);
|
||||
playlist_generic_init_sorted(NULL, NULL);
|
||||
playlist_generic_deinit(NULL);
|
||||
|
||||
g_assert_null(playlist_lookup(PL_MAX_TYPE, "NULL"));
|
||||
|
@ -193,7 +195,7 @@ static void test_sorting()
|
|||
struct track *track;
|
||||
unsigned int i;
|
||||
|
||||
playlist_generic_init(&p, NULL);
|
||||
playlist_generic_init_sorted(&p, NULL);
|
||||
g_assert_cmpuint(g_slist_length(p.pl_sort), ==, 3);
|
||||
playlist_clear_sort(&p);
|
||||
g_assert_cmpuint(g_slist_length(p.pl_sort), ==, 0);
|
||||
|
|
Loading…
Reference in New Issue