core/playlists/generic: Add a playlist_generic_sort() function
I set the history playlist to use a noop function, since changing the history doesn't really make sense. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
d460bcaee8
commit
a80a84a955
|
@ -42,11 +42,16 @@ static bool __artist_pl_load(void *data)
|
|||
return true;
|
||||
}
|
||||
|
||||
static struct playlist *__artist_pl_lookup(const gchar *name)
|
||||
{
|
||||
struct artist *artist = artist_lookup(name);
|
||||
return artist ? artist->ar_playlist : NULL;
|
||||
}
|
||||
|
||||
|
||||
static struct queue *pl_artist_get_queue(const gchar *name)
|
||||
{
|
||||
struct artist *artist = artist_lookup(name);
|
||||
struct playlist *playlist = artist ? artist->ar_playlist : NULL;
|
||||
struct playlist *playlist = __artist_pl_lookup(name);
|
||||
return playlist ? &playlist->pl_queue : NULL;
|
||||
}
|
||||
|
||||
|
@ -73,8 +78,8 @@ static void pl_artist_set_flag(const gchar *name, enum queue_flags flag,
|
|||
|
||||
static void pl_artist_sort(const gchar *name, enum compare_t sort, bool reset)
|
||||
{
|
||||
struct queue *queue = pl_artist_get_queue(name);
|
||||
queue_sort(queue, sort, reset);
|
||||
struct playlist *playlist = __artist_pl_lookup(name);
|
||||
playlist_generic_sort(playlist, sort, reset);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/playlists/type.h>
|
||||
|
||||
|
||||
/*
|
||||
* Noop playlist operations.
|
||||
*/
|
||||
void playlist_noop_sort(struct playlist *playlist,
|
||||
enum compare_t sort, bool reset)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Generic playlist operations.
|
||||
*/
|
||||
void playlist_generic_sort(struct playlist *playlist,
|
||||
enum compare_t sort, bool reset)
|
||||
{
|
||||
queue_sort(&playlist->pl_queue, sort, reset);
|
||||
}
|
|
@ -205,7 +205,7 @@ static void pl_library_set_flag(const gchar *name, enum queue_flags 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);
|
||||
playlist_generic_sort(playlist, sort, reset);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,17 +6,52 @@
|
|||
#include <core/string.h>
|
||||
|
||||
static bool __sys_pl_remove(enum sys_playlist_t, struct track *);
|
||||
static void __sys_pl_save_collection();
|
||||
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
||||
static struct file sys_collection = FILE_INIT("library.q", 0, 0);
|
||||
|
||||
|
||||
/*
|
||||
* Collection playlist operations.
|
||||
*/
|
||||
static void sys_pl_collection_sort(struct playlist *playlist,
|
||||
enum compare_t sort, bool reset)
|
||||
{
|
||||
playlist_generic_sort(playlist, sort, reset);
|
||||
__sys_pl_save_collection();
|
||||
}
|
||||
|
||||
|
||||
static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||
[SYS_PL_FAVORITES] = { DEFINE_PLAYLIST(PL_SYSTEM, "Favorites") },
|
||||
[SYS_PL_HIDDEN] = { DEFINE_PLAYLIST(PL_SYSTEM, "Hidden") },
|
||||
[SYS_PL_COLLECTION] = { DEFINE_PLAYLIST(PL_SYSTEM, "Collection") },
|
||||
[SYS_PL_HISTORY] = { DEFINE_PLAYLIST(PL_SYSTEM, "History") },
|
||||
[SYS_PL_UNPLAYED] = { DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed") },
|
||||
[SYS_PL_MOST_PLAYED] = { DEFINE_PLAYLIST(PL_SYSTEM, "Most Played") },
|
||||
[SYS_PL_LEAST_PLAYED] = { DEFINE_PLAYLIST(PL_SYSTEM, "Least Played") },
|
||||
[SYS_PL_FAVORITES] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"),
|
||||
.spl_sort = playlist_generic_sort,
|
||||
},
|
||||
[SYS_PL_HIDDEN] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"),
|
||||
.spl_sort = playlist_generic_sort,
|
||||
},
|
||||
[SYS_PL_COLLECTION] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"),
|
||||
.spl_sort = sys_pl_collection_sort,
|
||||
},
|
||||
[SYS_PL_HISTORY] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"),
|
||||
.spl_sort = playlist_noop_sort,
|
||||
},
|
||||
[SYS_PL_UNPLAYED] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"),
|
||||
.spl_sort = playlist_generic_sort,
|
||||
},
|
||||
[SYS_PL_MOST_PLAYED] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"),
|
||||
.spl_sort = playlist_generic_sort,
|
||||
},
|
||||
[SYS_PL_LEAST_PLAYED] = {
|
||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"),
|
||||
.spl_sort = playlist_generic_sort,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
@ -257,11 +292,9 @@ static void pl_system_set_flag(const gchar *name, enum queue_flags flag,
|
|||
|
||||
static void pl_system_sort(const gchar *name, enum compare_t sort, bool reset)
|
||||
{
|
||||
enum sys_playlist_t plist = __sys_pl_convert(name);
|
||||
|
||||
queue_sort(__sys_pl_queue(plist), sort, reset);
|
||||
if (plist == SYS_PL_COLLECTION)
|
||||
__sys_pl_save_collection();
|
||||
struct sys_playlist *sys_pl = __sys_pl_lookup(name);
|
||||
if (sys_pl)
|
||||
sys_pl->spl_sort(&sys_pl->spl_playlist, sort, reset);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ enum sys_playlist_t {
|
|||
|
||||
struct sys_playlist {
|
||||
struct playlist spl_playlist;
|
||||
|
||||
void (*spl_sort)(struct playlist *, enum compare_t, bool);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -54,4 +54,12 @@ struct playlist_type {
|
|||
};
|
||||
|
||||
|
||||
/* Noop playlist sorting operation. */
|
||||
void playlist_noop_sort(struct playlist *, enum compare_t, bool);
|
||||
|
||||
|
||||
/* Generic playlist sorting operation. */
|
||||
void playlist_generic_sort(struct playlist *, enum compare_t, bool);
|
||||
|
||||
|
||||
#endif /* OCARINA_CORE_PLAYLISTS_TYPE_H */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/env/bin/python
|
||||
Import("env", "CoreTest", "testing_group")
|
||||
Import("env", "CoreTest", "testing_group", "core_objs")
|
||||
|
||||
res = []
|
||||
|
||||
|
@ -10,6 +10,7 @@ def PlaylistTest(name):
|
|||
Depends(run, res[-1])
|
||||
return run
|
||||
|
||||
core_objs += [ env.Object("../../../core/playlists/generic.c") ]
|
||||
res += [ PlaylistTest("system") ]
|
||||
res += [ PlaylistTest("artist") ]
|
||||
res += [ PlaylistTest("library") ]
|
||||
|
|
|
@ -141,6 +141,10 @@ static void test_history()
|
|||
test_equal(queue_has_flag(queue, Q_ADD_FRONT), (bool)true);
|
||||
test_equal(queue_has_flag(queue, Q_NO_SORT), (bool)true);
|
||||
|
||||
test_equal(g_slist_length(queue->q_sort), 0);
|
||||
pl_system.pl_sort("History", COMPARE_TRACK, true);
|
||||
test_equal(g_slist_length(queue->q_sort), 0);
|
||||
|
||||
test_equal(queue_has_flag(queue, Q_RANDOM), (bool)false);
|
||||
pl_system.pl_set_flag("History", Q_RANDOM, true);
|
||||
test_equal(queue_has_flag(queue, Q_RANDOM), (bool)false);
|
||||
|
|
Loading…
Reference in New Issue