ocarina/gui/playlist.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_IMAGE_SZ,
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, GtkIconSize size,
enum playlist_t plist)
{
gtk_tree_store_set(p_store, iter, P_SB_NAME, name,
P_SB_IMAGE, image,
P_SB_IMAGE_SZ, size,
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, GTK_ICON_SIZE_MENU, plist);
}
void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
{
GtkNotebook *notebook = GTK_NOTEBOOK(gui_builder_widget("o_notebook"));
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_notebook_set_current_page(notebook, tempq_count() + 2);
gui_sidebar_selected(SB_PLAYLIST);
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", GTK_ICON_SIZE_LARGE_TOOLBAR, 0);
/* Add playlists. */
__playlist_add(&parent, "Favorites", "emblem-favorite", PL_FAVORITED);
__playlist_add(&parent, "Banned", "face-sad",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;
}