d769140e35
And notebook switching code in playlist.c Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
108 lines
2.9 KiB
C
108 lines
2.9 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/collection.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/playlist.h>
|
|
#include <gui/sidebar.h>
|
|
|
|
enum playlist_sidebar_columns {
|
|
P_SB_IMAGE,
|
|
P_SB_NAME,
|
|
P_SB_PLAYLIST,
|
|
};
|
|
|
|
static GtkTreeStore *p_store;
|
|
static enum playlist_t p_cur;
|
|
|
|
static void __playlist_set(GtkTreeIter *iter, const gchar *name,
|
|
const gchar *image, enum playlist_t plist)
|
|
{
|
|
gtk_tree_store_set(p_store, iter, P_SB_NAME, name,
|
|
P_SB_IMAGE, image,
|
|
P_SB_PLAYLIST, plist, -1);
|
|
}
|
|
|
|
static void __playlist_add(GtkTreeIter *parent, const gchar *name,
|
|
const gchar *image, enum playlist_t plist)
|
|
{
|
|
GtkTreeIter iter;
|
|
gtk_tree_store_insert(p_store, &iter, parent, -1);
|
|
__playlist_set(&iter, name, image, plist);
|
|
}
|
|
|
|
void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
|
{
|
|
GtkStack *stack = GTK_STACK(gui_builder_widget("o_stack"));
|
|
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
|
|
GtkTreeIter iter;
|
|
|
|
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
|
gtk_tree_model_get(model, &iter, P_SB_PLAYLIST, &p_cur, -1);
|
|
|
|
gtk_stack_set_visible_child_name(stack, "queues");
|
|
gui_sidebar_selected(SB_PLAYLIST,
|
|
gui_queue(playlist_get_queue()));
|
|
playlist_select(p_cur);
|
|
}
|
|
}
|
|
|
|
static void *__playlist_init(struct queue *queue)
|
|
{
|
|
return gui_queue_alloc(queue, "Playlist", 0);
|
|
}
|
|
|
|
static bool __playlist_erase(struct queue *queue, struct track *track)
|
|
{
|
|
/* collection_unban() and playlist_remove() handle queue changes */
|
|
if (gui_playlist_cur() == PL_HIDDEN)
|
|
collection_unban(track);
|
|
else
|
|
playlist_remove(gui_playlist_cur(), track);
|
|
return false;
|
|
}
|
|
|
|
void gui_playlist_init()
|
|
{
|
|
GtkTreeView *treeview;
|
|
GtkTreeIter parent;
|
|
|
|
p_store = GTK_TREE_STORE(gui_builder_object("o_playlist_store"));
|
|
|
|
/* Add "Playlist" header. */
|
|
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
|
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
|
__playlist_set(&parent, "<span size='large'>Playlists</span>",
|
|
"emblem-documents", 0);
|
|
|
|
/* Add playlists. */
|
|
__playlist_add(&parent, "Favorites", "emblem-favorite", PL_FAVORITED);
|
|
__playlist_add(&parent, "Hidden", "window-close",PL_HIDDEN);
|
|
__playlist_add(&parent, "Most Played", "go-up", PL_MOST_PLAYED);
|
|
__playlist_add(&parent, "Least Played", "go-down", PL_LEAST_PLAYED);
|
|
__playlist_add(&parent, "Unplayed", "audio-x-generic", PL_UNPLAYED);
|
|
|
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
|
|
gtk_tree_view_expand_all(treeview);
|
|
gtk_tree_selection_set_select_function(
|
|
gtk_tree_view_get_selection(treeview),
|
|
gui_sidebar_on_select, NULL, NULL);
|
|
|
|
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
|
}
|
|
|
|
enum playlist_t gui_playlist_cur()
|
|
{
|
|
return p_cur;
|
|
}
|
|
|
|
struct queue_ops playlist_ops = {
|
|
.qop_init = __playlist_init,
|
|
.qop_deinit = gui_queue_free,
|
|
.qop_added = gui_queue_added,
|
|
.qop_erase = __playlist_erase,
|
|
.qop_removed = gui_queue_removed,
|
|
.qop_cleared = gui_queue_cleared,
|
|
.qop_updated = gui_queue_updated,
|
|
};
|