core/playlists/library: Add pl_library_sort() function

Used to sort library playlists.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-09 09:23:41 -04:00 committed by Anna Schumaker
parent 7f867199cb
commit 78aa0f9ff6
2 changed files with 18 additions and 0 deletions

View File

@ -14,6 +14,9 @@ static struct playlist *__lib_pl_alloc(const gchar *path)
playlist->pl_name = path;
playlist->pl_type = PL_LIBRARY;
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, lib_ops, playlist);
queue_sort(&playlist->pl_queue, COMPARE_ARTIST, true);
queue_sort(&playlist->pl_queue, COMPARE_YEAR, false);
queue_sort(&playlist->pl_queue, COMPARE_TRACK, false);
return playlist;
}
@ -71,12 +74,19 @@ static void pl_library_set_flag(const gchar *name, enum queue_flags flag,
queue_unset_flag(&playlist->pl_queue, flag);
}
static void pl_library_sort(const gchar *name, enum compare_t sort, bool reset)
{
struct playlist *playlist = __lib_pl_lookup(name);
queue_sort(&playlist->pl_queue, sort, reset);
}
struct playlist_type pl_library = {
.pl_get_queue = pl_library_get_queue,
.pl_add_track = pl_library_add_rm,
.pl_remove_track = pl_library_add_rm,
.pl_set_flag = pl_library_set_flag,
.pl_sort = pl_library_sort,
};

View File

@ -51,6 +51,14 @@ void test_library()
pl_library.pl_set_flag("tests/Music", Q_RANDOM, false);
test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)false);
test_equal(g_slist_length(playlist->pl_queue.q_sort), 3);
pl_library.pl_sort("tests/Music", COMPARE_ARTIST, true);
test_equal(g_slist_length(playlist->pl_queue.q_sort), 1);
pl_library.pl_sort("tests/Music", COMPARE_YEAR, false);
test_equal(g_slist_length(playlist->pl_queue.q_sort), 2);
pl_library.pl_sort("tests/Music", COMPARE_TRACK, false);
test_equal(g_slist_length(playlist->pl_queue.q_sort), 3);
pl_library_deinit();
test_equal(library->li_playlist, NULL);