gui/playlists/artist: Split into a new file and add a unit test
Putting this code in a new file helps make gui/playlist.c less complex, and better matches the organization of files in core/ Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
4fee5f85f0
commit
bb673ddb62
|
@ -46,6 +46,9 @@ static void __playlist_update_sizes(struct queue *queue)
|
|||
if (playlist->pl_type == PL_LIBRARY) {
|
||||
gui_pl_library_update(playlist);
|
||||
return;
|
||||
} else if (playlist->pl_type == PL_ARTIST) {
|
||||
gui_pl_artist_update(playlist);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gui_sidebar_iter_first(&parent))
|
||||
|
@ -71,11 +74,8 @@ static void *__playlist_init(struct queue *queue, void *data)
|
|||
{
|
||||
struct playlist *playlist = (struct playlist *)data;
|
||||
|
||||
if (p_init_done && playlist->pl_type == PL_ARTIST) {
|
||||
p_filter_enable = false;
|
||||
gui_playlist_add_artist(playlist);
|
||||
p_filter_enable = true;
|
||||
}
|
||||
if (p_init_done && playlist->pl_type == PL_ARTIST)
|
||||
gui_pl_artist_add(playlist);
|
||||
if (p_init_done && playlist->pl_type == PL_USER)
|
||||
gui_playlist_add_user(playlist);
|
||||
return playlist;
|
||||
|
@ -152,7 +152,7 @@ bool __gui_playlist_init_idle()
|
|||
gtk_tree_view_expand_all(treeview);
|
||||
|
||||
db_for_each(dbe, next, artist_db_get())
|
||||
gui_playlist_add_artist(ARTIST(dbe)->ar_playlist);
|
||||
gui_pl_artist_add(ARTIST(dbe)->ar_playlist);
|
||||
p_filter_enable = true;
|
||||
|
||||
p_init_done = true;
|
||||
|
@ -189,6 +189,7 @@ void gui_playlist_init()
|
|||
|
||||
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
||||
|
||||
gui_pl_artist_init();
|
||||
gui_pl_library_init();
|
||||
}
|
||||
|
||||
|
@ -199,15 +200,6 @@ const gchar *gui_playlist_cur()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void gui_playlist_add_artist(struct playlist *playlist)
|
||||
{
|
||||
GtkTreeIter parent;
|
||||
|
||||
gui_sidebar_iter_first(&parent);
|
||||
gui_sidebar_iter_find(&parent, "Collection", PL_SYSTEM);
|
||||
gui_sidebar_iter_sort_child(&parent, playlist, "system-users");
|
||||
}
|
||||
|
||||
void gui_playlist_add_user(struct playlist *playlist)
|
||||
{
|
||||
GtkTreeIter parent;
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
|
||||
static bool __gui_pl_artist_header(GtkTreeIter *iter)
|
||||
{
|
||||
if (gui_sidebar_iter_first(iter))
|
||||
return gui_sidebar_iter_find(iter, "Collection", PL_SYSTEM);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool __gui_pl_artist_init_idle()
|
||||
{
|
||||
struct db_entry *artist, *next;
|
||||
struct playlist *playlist;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (!__gui_pl_artist_header(&iter))
|
||||
return false;
|
||||
|
||||
db_for_each(artist, next, artist_db_get()) {
|
||||
playlist = ARTIST(artist)->ar_playlist;
|
||||
gui_sidebar_iter_sort_child(&iter, playlist, "system-users");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_pl_artist_init()
|
||||
{
|
||||
idle_schedule(IDLE_SYNC, __gui_pl_artist_init_idle, NULL);
|
||||
}
|
||||
|
||||
bool gui_pl_artist_add(struct playlist *playlist)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (!__gui_pl_artist_header(&iter))
|
||||
return false;
|
||||
|
||||
gui_sidebar_iter_sort_child(&iter, playlist, "system-users");
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_pl_artist_update(struct playlist *playlist)
|
||||
{
|
||||
GtkTreeIter iter, child;
|
||||
|
||||
if (!__gui_pl_artist_header(&iter))
|
||||
return;
|
||||
if (!gui_sidebar_iter_down(&iter, &child))
|
||||
return;
|
||||
if (gui_sidebar_iter_find(&child, playlist->pl_name, playlist->pl_type))
|
||||
gui_sidebar_iter_update(&child);
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#ifndef OCARINA_GUI_PLAYLIST_H
|
||||
#define OCARINA_GUI_PLAYLIST_H
|
||||
#include <core/playlist.h>
|
||||
#include <gui/playlists/artist.h>
|
||||
#include <gui/playlists/library.h>
|
||||
|
||||
/* Called to initialize the GUI playlist code. */
|
||||
|
@ -12,9 +13,6 @@ void gui_playlist_init();
|
|||
/* Called to get the currently selected playlist. */
|
||||
const gchar *gui_playlist_cur();
|
||||
|
||||
/* Called to add an artist playlist. */
|
||||
void gui_playlist_add_artist(struct playlist *);
|
||||
|
||||
/* Called to add a user playlist. */
|
||||
void gui_playlist_add_user(struct playlist *);
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_GUI_PLAYLISTS_ARTIST_H
|
||||
#define OCARINA_GUI_PLAYLISTS_ARTIST_H
|
||||
|
||||
/* Called to initialize GUI artist playlists. */
|
||||
void gui_pl_artist_init();
|
||||
|
||||
/* Called to add an artist playlist. */
|
||||
bool gui_pl_artist_add(struct playlist *);
|
||||
|
||||
/* Called to update an artist playlist. */
|
||||
void gui_pl_artist_update(struct playlist *);
|
||||
|
||||
#endif /* OCARINA_GUI_PLAYLISTS_ARTIST_H */
|
|
@ -1 +1,2 @@
|
|||
artist
|
||||
library
|
||||
|
|
|
@ -4,4 +4,5 @@ function(gui_playlist_unit_test name)
|
|||
unit_test(Gui/Playlists ${name} guilib ${corefiles})
|
||||
endfunction()
|
||||
|
||||
gui_playlist_unit_test(Artist)
|
||||
gui_playlist_unit_test(Library)
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/filter.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.playlist_ops = &playlist_ops,
|
||||
};
|
||||
|
||||
static void test_artist()
|
||||
{
|
||||
GtkTreeModel *model = gui_sidebar_model();
|
||||
GtkTreeIter iter, child;
|
||||
|
||||
gui_sidebar_iter_first(&iter);
|
||||
gui_sidebar_iter_find(&iter, "Collection", PL_SYSTEM);
|
||||
g_assert_false(gtk_tree_model_iter_has_child(model, &iter));
|
||||
|
||||
g_assert_true(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
||||
g_assert_cmpuint(artist_db_get()->db_size, ==, 0);
|
||||
g_assert_null(playlist_get(PL_ARTIST, "Koji Kondo"));
|
||||
g_assert_false(gtk_tree_model_iter_has_child(model, &iter));
|
||||
while (idle_run_task()) {}
|
||||
g_assert_cmpuint(artist_db_get()->db_size, ==, 1);
|
||||
g_assert_nonnull(playlist_get(PL_ARTIST, "Koji Kondo"));
|
||||
g_assert_cmpuint(playlist_size(PL_ARTIST, "Koji Kondo"), ==, 13);
|
||||
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 1);
|
||||
|
||||
gui_sidebar_iter_down(&iter, &child);
|
||||
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==, "Koji Kondo");
|
||||
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_ARTIST);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
core_init(&argc, &argv, &init_data);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
gui_model_init();
|
||||
gui_filter_init();
|
||||
gui_treeview_init();
|
||||
gui_sidebar_init();
|
||||
gui_playlist_init();
|
||||
while (idle_run_task()) {}
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Playlists/Artist", test_artist);
|
||||
ret = g_test_run();
|
||||
|
||||
core_deinit();
|
||||
gui_treeview_deinit();
|
||||
gui_filter_deinit();
|
||||
gui_model_deinit();
|
||||
gui_builder_deinit();
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue