gui/playlists/system: Split into a new file and add a unit test
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
83db8e4ae7
commit
36f399ecb7
|
@ -49,6 +49,9 @@ static void __playlist_update_sizes(struct queue *queue)
|
||||||
} else if (playlist->pl_type == PL_USER) {
|
} else if (playlist->pl_type == PL_USER) {
|
||||||
gui_pl_user_update(playlist);
|
gui_pl_user_update(playlist);
|
||||||
return;
|
return;
|
||||||
|
} else if (playlist->pl_type == PL_SYSTEM) {
|
||||||
|
gui_pl_system_update(playlist);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gui_sidebar_iter_first(&parent))
|
if (!gui_sidebar_iter_first(&parent))
|
||||||
|
@ -146,37 +149,12 @@ bool __gui_playlist_init_idle()
|
||||||
|
|
||||||
void gui_playlist_init()
|
void gui_playlist_init()
|
||||||
{
|
{
|
||||||
GtkTreeIter parent;
|
gui_pl_system_init();
|
||||||
|
|
||||||
gui_sidebar_iter_first(&parent);
|
|
||||||
gui_sidebar_iter_add(&parent, playlist_get(PL_SYSTEM, "Queued Tracks"),
|
|
||||||
"audio-x-generic");
|
|
||||||
gui_sidebar_iter_add(&parent, playlist_get(PL_SYSTEM, "Collection"),
|
|
||||||
"media-optical");
|
|
||||||
gui_sidebar_iter_add(&parent, playlist_get(PL_SYSTEM, "History"),
|
|
||||||
"document-open-recent");
|
|
||||||
|
|
||||||
/* Add "Playlists" header and playlists. */
|
|
||||||
gui_sidebar_iter_find(&parent, "Playlists", PL_MAX_TYPE);
|
|
||||||
gui_sidebar_iter_append_child(&parent, playlist_get(PL_SYSTEM, "Favorites"),
|
|
||||||
"emblem-favorite");
|
|
||||||
gui_sidebar_iter_append_child(&parent, playlist_get(PL_SYSTEM, "Hidden"),
|
|
||||||
"window-close");
|
|
||||||
|
|
||||||
/* Add "Dynamic" header. */
|
|
||||||
gui_sidebar_iter_find(&parent, "Dynamic", PL_MAX_TYPE);
|
|
||||||
gui_sidebar_iter_append_child(&parent, playlist_get(PL_SYSTEM, "Most Played"),
|
|
||||||
"go-up");
|
|
||||||
gui_sidebar_iter_append_child(&parent, playlist_get(PL_SYSTEM, "Least Played"),
|
|
||||||
"go-down");
|
|
||||||
gui_sidebar_iter_append_child(&parent, playlist_get(PL_SYSTEM, "Unplayed"),
|
|
||||||
"audio-x-generic");
|
|
||||||
|
|
||||||
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
|
||||||
|
|
||||||
gui_pl_artist_init();
|
gui_pl_artist_init();
|
||||||
gui_pl_user_init();
|
gui_pl_user_init();
|
||||||
gui_pl_library_init();
|
gui_pl_library_init();
|
||||||
|
|
||||||
|
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *gui_playlist_cur()
|
const gchar *gui_playlist_cur()
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/idle.h>
|
||||||
|
#include <core/playlist.h>
|
||||||
|
#include <core/string.h>
|
||||||
|
#include <gui/sidebar.h>
|
||||||
|
|
||||||
|
static bool __gui_pl_system_is_playlist(struct playlist *playlist)
|
||||||
|
{
|
||||||
|
return string_match(playlist->pl_name, "Favorites") ||
|
||||||
|
string_match(playlist->pl_name, "Hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __gui_pl_system_is_dynamic(struct playlist *playlist)
|
||||||
|
{
|
||||||
|
return string_match(playlist->pl_name, "Most Played") ||
|
||||||
|
string_match(playlist->pl_name, "Least Played") ||
|
||||||
|
string_match(playlist->pl_name, "Unplayed");
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __gui_pl_system_find_descend_header(GtkTreeIter *iter,
|
||||||
|
const gchar *name)
|
||||||
|
{
|
||||||
|
GtkTreeIter header;
|
||||||
|
|
||||||
|
if (!gui_sidebar_iter_first(&header))
|
||||||
|
return false;
|
||||||
|
if (!gui_sidebar_iter_find(&header, name, PL_MAX_TYPE))
|
||||||
|
return false;
|
||||||
|
return gui_sidebar_iter_down(&header, iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool __gui_pl_system_init_idle()
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
/* Add toplevel playlists. */
|
||||||
|
gui_sidebar_iter_first(&iter);
|
||||||
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Queued Tracks"),
|
||||||
|
"audio-x-generic");
|
||||||
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Collection"),
|
||||||
|
"media-optical");
|
||||||
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "History"),
|
||||||
|
"document-open-recent");
|
||||||
|
|
||||||
|
/* Add user-modifiable playlists. */
|
||||||
|
gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE);
|
||||||
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Favorites"),
|
||||||
|
"emblem-favorite");
|
||||||
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Hidden"),
|
||||||
|
"window-close");
|
||||||
|
|
||||||
|
/* Add dynamic playlists. */
|
||||||
|
gui_sidebar_iter_find(&iter, "Dynamic", PL_MAX_TYPE);
|
||||||
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Most Played"),
|
||||||
|
"go-up");
|
||||||
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Least Played"),
|
||||||
|
"go-down");
|
||||||
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Unplayed"),
|
||||||
|
"audio-x-generic");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_pl_system_init()
|
||||||
|
{
|
||||||
|
idle_schedule(IDLE_SYNC, __gui_pl_system_init_idle, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_pl_system_update(struct playlist *playlist)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
if (__gui_pl_system_is_playlist(playlist)) {
|
||||||
|
if (!__gui_pl_system_find_descend_header(&iter, "Playlists"))
|
||||||
|
return;
|
||||||
|
} else if (__gui_pl_system_is_dynamic(playlist)) {
|
||||||
|
if (!__gui_pl_system_find_descend_header(&iter, "Dynamic"))
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (!gui_sidebar_iter_first(&iter))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gui_sidebar_iter_find(&iter, playlist->pl_name, playlist->pl_type))
|
||||||
|
gui_sidebar_iter_update(&iter);
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <gui/playlists/artist.h>
|
#include <gui/playlists/artist.h>
|
||||||
#include <gui/playlists/library.h>
|
#include <gui/playlists/library.h>
|
||||||
|
#include <gui/playlists/system.h>
|
||||||
#include <gui/playlists/user.h>
|
#include <gui/playlists/user.h>
|
||||||
|
|
||||||
/* Called to initialize the GUI playlist code. */
|
/* Called to initialize the GUI playlist code. */
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_GUI_PLAYLISTS_SYSTEM_H
|
||||||
|
#define OCARINA_GUI_PLAYLISTS_SYSTEM_H
|
||||||
|
|
||||||
|
/* Called to initialize GUI system playlists. */
|
||||||
|
void gui_pl_system_init();
|
||||||
|
|
||||||
|
/* Called to update a system playlist. */
|
||||||
|
void gui_pl_system_update(struct playlist *);
|
||||||
|
|
||||||
|
#endif /* OCARINA_GUI_PLAYLISTS_SYSTEM_H */
|
|
@ -1,3 +1,4 @@
|
||||||
|
system
|
||||||
artist
|
artist
|
||||||
user
|
user
|
||||||
library
|
library
|
||||||
|
|
|
@ -4,6 +4,7 @@ function(gui_playlist_unit_test name)
|
||||||
unit_test(Gui/Playlists ${name} guilib ${corefiles})
|
unit_test(Gui/Playlists ${name} guilib ${corefiles})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
gui_playlist_unit_test(System)
|
||||||
gui_playlist_unit_test(Artist)
|
gui_playlist_unit_test(Artist)
|
||||||
gui_playlist_unit_test(User)
|
gui_playlist_unit_test(User)
|
||||||
gui_playlist_unit_test(Library)
|
gui_playlist_unit_test(Library)
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* 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 const gchar *toplevel[3] = { "Queued Tracks", "Collection", "History" };
|
||||||
|
static const gchar *playlists[2] = {"Favorites", "Hidden" };
|
||||||
|
static const gchar *dynamic[3] = {"Most Played", "Least Played", "Unplayed" };
|
||||||
|
|
||||||
|
static void test_system()
|
||||||
|
{
|
||||||
|
GtkTreeIter iter, child;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
gui_sidebar_iter_first(&iter);
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&iter), ==,
|
||||||
|
toplevel[i]);
|
||||||
|
g_assert_cmpuint(gui_sidebar_iter_type(&iter), ==, PL_SYSTEM);
|
||||||
|
gui_sidebar_iter_next(&iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE);
|
||||||
|
gui_sidebar_iter_down(&iter, &child);
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
||||||
|
playlists[i]);
|
||||||
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
||||||
|
gui_sidebar_iter_next(&child);
|
||||||
|
}
|
||||||
|
|
||||||
|
gui_sidebar_iter_find(&iter, "Dynamic", PL_MAX_TYPE);
|
||||||
|
gui_sidebar_iter_down(&iter, &child);
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==,
|
||||||
|
dynamic[i]);
|
||||||
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
||||||
|
gui_sidebar_iter_next(&child);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert_true(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
||||||
|
while (idle_run_task()) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
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/System", test_system);
|
||||||
|
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