a313160f94
The eventual goal is to replace the notebook, but this is a good start. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
85 lines
2.4 KiB
C
85 lines
2.4 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tempq.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)
|
|
{
|
|
GtkNotebook *notebook = GTK_NOTEBOOK(gui_builder_widget("o_notebook"));
|
|
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");
|
|
gtk_notebook_set_current_page(notebook, tempq_count() + 2);
|
|
gui_sidebar_selected(SB_PLAYLIST,
|
|
gui_queue(playlist_get_queue()));
|
|
playlist_select(p_cur);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|