gui/playlist: Add artist playlists to the playlist sidebar
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
f2597a8e6c
commit
382ee79c2e
|
@ -2,6 +2,7 @@
|
|||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/collection.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/string.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/playlist.h>
|
||||
|
@ -43,7 +44,7 @@ static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
|
|||
if (gtk_tree_path_get_depth(path) == 1)
|
||||
fmt = "<b>%s</b>\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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -952,6 +952,7 @@
|
|||
<property name="valign">start</property>
|
||||
<property name="model">o_playlist_store</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="search_column">1</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection3">
|
||||
|
|
Loading…
Reference in New Issue