gui/playlists/library: Add new library paths to the sidebar
... without passing through gui/playlist.c first. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e550638823
commit
ab47a7ac88
|
@ -193,15 +193,6 @@ const gchar *gui_playlist_cur()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_playlist_add_library(struct playlist *playlist)
|
|
||||||
{
|
|
||||||
GtkTreeIter parent;
|
|
||||||
|
|
||||||
gui_sidebar_iter_first(&parent);
|
|
||||||
gui_sidebar_iter_find(&parent, "Library", PL_MAX_TYPE);
|
|
||||||
gui_sidebar_iter_sort_child(&parent, playlist, "folder");
|
|
||||||
}
|
|
||||||
|
|
||||||
void gui_playlist_add_artist(struct playlist *playlist)
|
void gui_playlist_add_artist(struct playlist *playlist)
|
||||||
{
|
{
|
||||||
GtkTreeIter parent;
|
GtkTreeIter parent;
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <gui/idle.h>
|
#include <gui/idle.h>
|
||||||
#include <gui/playlist.h>
|
#include <gui/playlists/library.h>
|
||||||
|
#include <gui/sidebar.h>
|
||||||
#include <gui/window.h>
|
#include <gui/window.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
@ -42,14 +43,25 @@ void __gui_pl_library_choose(GtkButton *button, gpointer data)
|
||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool __gui_pl_library_header(GtkTreeIter *iter)
|
||||||
|
{
|
||||||
|
if (gui_sidebar_iter_first(iter))
|
||||||
|
return gui_sidebar_iter_find(iter, "Library", PL_MAX_TYPE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool __gui_pl_library_init_idle()
|
static bool __gui_pl_library_init_idle()
|
||||||
{
|
{
|
||||||
struct db_entry *library, *next;
|
struct db_entry *library, *next;
|
||||||
struct playlist *playlist;
|
struct playlist *playlist;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
if (!__gui_pl_library_header(&iter))
|
||||||
|
return false;
|
||||||
|
|
||||||
db_for_each(library, next, library_db_get()) {
|
db_for_each(library, next, library_db_get()) {
|
||||||
playlist = playlist_get(PL_LIBRARY, LIBRARY(library)->li_path);
|
playlist = LIBRARY(library)->li_playlist;
|
||||||
gui_playlist_add_library(playlist);
|
gui_sidebar_iter_sort_child(&iter, playlist, "folder");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_TESTING
|
#ifndef CONFIG_TESTING
|
||||||
|
@ -68,14 +80,15 @@ void gui_pl_library_init()
|
||||||
bool gui_pl_library_add(const gchar *filename)
|
bool gui_pl_library_add(const gchar *filename)
|
||||||
{
|
{
|
||||||
struct playlist *playlist;
|
struct playlist *playlist;
|
||||||
struct library *library;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
if (playlist_new(PL_LIBRARY, filename)) {
|
if (!__gui_pl_library_header(&iter))
|
||||||
library = library_lookup(filename);
|
return false;
|
||||||
playlist = playlist_get(PL_LIBRARY, library->li_path);
|
if (!playlist_new(PL_LIBRARY, filename))
|
||||||
gui_playlist_add_library(playlist);
|
return false;
|
||||||
gui_idle_enable();
|
|
||||||
return true;
|
playlist = playlist_get(PL_LIBRARY, filename);
|
||||||
}
|
gui_sidebar_iter_sort_child(&iter, playlist, "folder");
|
||||||
return false;
|
gui_idle_enable();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,6 @@ void gui_playlist_init();
|
||||||
/* Called to get the currently selected playlist. */
|
/* Called to get the currently selected playlist. */
|
||||||
const gchar *gui_playlist_cur();
|
const gchar *gui_playlist_cur();
|
||||||
|
|
||||||
/* Called to add a library playlist. */
|
|
||||||
void gui_playlist_add_library(struct playlist *);
|
|
||||||
|
|
||||||
/* Called to add an artist playlist. */
|
/* Called to add an artist playlist. */
|
||||||
void gui_playlist_add_artist(struct playlist *);
|
void gui_playlist_add_artist(struct playlist *);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <gui/playlist.h>
|
#include <gui/playlist.h>
|
||||||
#include <gui/sidebar.h>
|
#include <gui/sidebar.h>
|
||||||
#include <gui/treeview.h>
|
#include <gui/treeview.h>
|
||||||
|
#include <tests/test.h>
|
||||||
|
|
||||||
struct core_init_data init_data = {
|
struct core_init_data init_data = {
|
||||||
.playlist_ops = &playlist_ops,
|
.playlist_ops = &playlist_ops,
|
||||||
|
@ -17,30 +18,40 @@ struct core_init_data init_data = {
|
||||||
static void test_library()
|
static void test_library()
|
||||||
{
|
{
|
||||||
GtkTreeModel *model = gui_sidebar_model();
|
GtkTreeModel *model = gui_sidebar_model();
|
||||||
struct playlist *playlist;
|
struct playlist *hyrule, *ocarina;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter, child;
|
||||||
|
|
||||||
gui_sidebar_iter_first(&iter);
|
gui_sidebar_iter_first(&iter);
|
||||||
gui_sidebar_iter_find(&iter, "Library", PL_MAX_TYPE);
|
gui_sidebar_iter_find(&iter, "Library", PL_MAX_TYPE);
|
||||||
g_assert_false(gtk_tree_model_iter_has_child(model, &iter));
|
g_assert_false(gtk_tree_model_iter_has_child(model, &iter));
|
||||||
|
|
||||||
g_assert_cmpuint(library_db_get()->db_size, ==, 0);
|
g_assert_cmpuint(library_db_get()->db_size, ==, 0);
|
||||||
|
g_assert_null(playlist_get(PL_LIBRARY, "tests/Music/Ocarina of Time"));
|
||||||
g_assert_null(playlist_get(PL_LIBRARY, "tests/Music/Hyrule Symphony"));
|
g_assert_null(playlist_get(PL_LIBRARY, "tests/Music/Hyrule Symphony"));
|
||||||
|
|
||||||
|
g_assert_true(gui_pl_library_add("tests/Music/Ocarina of Time"));
|
||||||
g_assert_true(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
g_assert_true(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
||||||
playlist = playlist_get(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
g_assert_cmpuint(library_db_get()->db_size, ==, 2);
|
||||||
g_assert_cmpuint(library_db_get()->db_size, ==, 1);
|
|
||||||
g_assert_cmpuint(playlist_size(playlist->pl_type,
|
|
||||||
playlist->pl_name), ==, 0);
|
|
||||||
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 1);
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 2);
|
||||||
|
|
||||||
|
ocarina = playlist_get(PL_LIBRARY, "tests/Music/Ocarina of Time");
|
||||||
|
hyrule = playlist_get(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
|
|
||||||
|
g_assert_cmpuint(playlist_size(ocarina->pl_type, ocarina->pl_name), ==, 0);
|
||||||
|
g_assert_cmpuint(playlist_size(hyrule->pl_type, hyrule->pl_name), ==, 0);
|
||||||
while (idle_run_task()) {}
|
while (idle_run_task()) {}
|
||||||
g_assert_cmpuint(library_db_get()->db_size, ==, 1);
|
g_assert_cmpuint(playlist_size(hyrule->pl_type, hyrule->pl_name), ==, 13);
|
||||||
g_assert_cmpuint(playlist_size(playlist->pl_type,
|
g_assert_cmpuint(playlist_size(ocarina->pl_type, ocarina->pl_name), ==, 35);
|
||||||
playlist->pl_name), ==, 13);
|
|
||||||
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
g_assert_true(gtk_tree_model_iter_has_child(model, &iter));
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 1);
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, &iter), ==, 2);
|
||||||
|
g_assert_true(gui_sidebar_iter_down(&iter, &child));
|
||||||
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==, hyrule->pl_name);
|
||||||
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_LIBRARY);
|
||||||
|
g_assert_true(gui_sidebar_iter_next(&child));
|
||||||
|
g_assert_cmpstr_free(gui_sidebar_iter_name(&child), ==, ocarina->pl_name);
|
||||||
|
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_LIBRARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
Loading…
Reference in New Issue