From 382ee79c2e11a165e94dc9a73dd064d3349e1dd7 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 15 May 2016 19:53:59 -0400 Subject: [PATCH] gui/playlist: Add artist playlists to the playlist sidebar Signed-off-by: Anna Schumaker --- gui/playlist.c | 52 +++++++++++++++++++++++++++++++++++- include/gui/playlist.h | 3 +++ share/ocarina/ocarina6.glade | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/gui/playlist.c b/gui/playlist.c index 6508366f..804a04ea 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -2,6 +2,7 @@ * Copyright 2016 (c) Anna Schumaker. */ #include +#include #include #include #include @@ -43,7 +44,7 @@ static void __playlist_set_size(GtkTreeIter *iter, const gchar *name) if (gtk_tree_path_get_depth(path) == 1) fmt = "%s\n%d track%s"; - text = g_strdup_printf(fmt, name, size, (size == 1) ? "" : "s"); + text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s"); gtk_tree_store_set(p_store, iter, P_SB_NAME, text, -1); gtk_tree_path_free(path); @@ -178,6 +179,16 @@ static bool __playlist_erase(struct queue *queue, struct track *track) return false; } +bool __gui_playlist_init_idle() +{ + struct db_entry *artist, *next; + + db_for_each(artist, next, artist_db_get()) + gui_playlist_add_artist(ARTIST(artist)); + + return true; +} + void gui_playlist_init() { GtkTreeSelection *selection; @@ -222,6 +233,8 @@ void gui_playlist_init() gtk_tree_selection_set_select_function( gtk_tree_view_get_selection(treeview), __playlist_on_select, NULL, NULL); + + idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL); } gchar *gui_playlist_cur() @@ -246,6 +259,43 @@ void gui_playlist_add_library(struct library *library) GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"))); } +void gui_playlist_add_artist(struct artist *artist) +{ + GtkTreeIter parent, sibling, iter; + gchar *name; + bool match; + + gtk_tree_model_get_iter_first(GTK_TREE_MODEL(p_store), &parent); + do { + name = __playlist_name(&parent); + match = string_match(name, "Collection"); + g_free(name); + + if (match) + break; + } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &parent)); + + if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(p_store), &sibling, &parent)) { + __playlist_add(&parent, artist->ar_name, "system-users", PL_ARTIST); + return; + } + + do { + name = __playlist_name(&sibling); + match = string_compare(name, artist->ar_name) >= 0; + g_free(name); + + if (match) { + gtk_tree_store_insert_before(p_store, &iter, &parent, &sibling); + __playlist_set(&iter, artist->ar_name, "system-users", PL_ARTIST); + __playlist_set_size(&iter, artist->ar_name); + return; + } + } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &sibling)); + + __playlist_add(&parent, artist->ar_name, "system-users", PL_ARTIST); +} + struct queue_ops playlist_ops = { .qop_init = __playlist_init, .qop_deinit = gui_queue_free, diff --git a/include/gui/playlist.h b/include/gui/playlist.h index 1021f12e..be0deb24 100644 --- a/include/gui/playlist.h +++ b/include/gui/playlist.h @@ -15,6 +15,9 @@ gchar *gui_playlist_cur(); /* Called to add a library playlist. */ void gui_playlist_add_library(struct library *); +/* Called to add an artist playlist. */ +void gui_playlist_add_artist(struct artist *); + /* Playlist operations passed to core_init() */ extern struct queue_ops playlist_ops; diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index d4cb3f57..03a8c450 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -952,6 +952,7 @@ start o_playlist_store False + 1 True