2016-01-01 19:58:30 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-01-04 08:15:55 -05:00
|
|
|
#include <core/tempq.h>
|
2016-01-01 19:58:30 -05:00
|
|
|
#include <gui/builder.h>
|
|
|
|
#include <gui/playlist.h>
|
|
|
|
|
|
|
|
enum playlist_sidebar_columns {
|
|
|
|
P_SB_IMAGE,
|
|
|
|
P_SB_IMAGE_SZ,
|
|
|
|
P_SB_NAME,
|
2016-01-04 08:15:55 -05:00
|
|
|
P_SB_PLAYLIST,
|
2016-01-01 19:58:30 -05:00
|
|
|
};
|
|
|
|
|
2016-01-04 08:15:55 -05:00
|
|
|
static GtkTreeStore *p_store;
|
|
|
|
static enum playlist_t p_cur;
|
2016-01-04 07:55:10 -05:00
|
|
|
|
|
|
|
static void __playlist_set(GtkTreeIter *iter, const gchar *name,
|
2016-01-04 08:15:55 -05:00
|
|
|
const gchar *image, GtkIconSize size,
|
|
|
|
enum playlist_t plist)
|
2016-01-04 07:55:10 -05:00
|
|
|
{
|
2016-01-04 08:15:55 -05:00
|
|
|
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);
|
2016-01-04 07:55:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __playlist_add(GtkTreeIter *parent, const gchar *name,
|
2016-01-04 08:15:55 -05:00
|
|
|
const gchar *image, enum playlist_t plist)
|
2016-01-04 07:55:10 -05:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gtk_tree_store_insert(p_store, &iter, parent, -1);
|
2016-01-04 08:15:55 -05:00
|
|
|
__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);
|
|
|
|
playlist_select(p_cur);
|
|
|
|
}
|
2016-01-04 07:55:10 -05:00
|
|
|
}
|
2016-01-01 19:58:30 -05:00
|
|
|
|
|
|
|
static gboolean __playlist_select(GtkTreeSelection *selection,
|
|
|
|
GtkTreeModel *model, GtkTreePath *path,
|
|
|
|
gboolean selected, gpointer data)
|
|
|
|
{
|
|
|
|
return gtk_tree_path_get_depth(path) != 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_playlist_init()
|
|
|
|
{
|
|
|
|
GtkTreeView *treeview;
|
2016-01-04 07:55:10 -05:00
|
|
|
GtkTreeIter parent;
|
2016-01-01 19:58:30 -05:00
|
|
|
|
2016-01-04 07:55:10 -05:00
|
|
|
p_store = GTK_TREE_STORE(gui_builder_object("o_playlist_store"));
|
2016-01-01 19:58:30 -05:00
|
|
|
|
|
|
|
/* Add "Playlist" header. */
|
2016-01-04 07:55:10 -05:00
|
|
|
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
|
|
|
__playlist_set(&parent, "<span size='large'>Playlists</span>",
|
2016-01-04 08:15:55 -05:00
|
|
|
"emblem-documents", GTK_ICON_SIZE_LARGE_TOOLBAR, 0);
|
2016-01-04 07:55:10 -05:00
|
|
|
|
|
|
|
/* Add playlists. */
|
2016-01-04 08:15:55 -05:00
|
|
|
__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);
|
2016-01-01 19:58:30 -05:00
|
|
|
|
|
|
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
|
2016-01-04 07:55:10 -05:00
|
|
|
gtk_tree_view_expand_all(treeview);
|
2016-01-01 19:58:30 -05:00
|
|
|
gtk_tree_selection_set_select_function(
|
|
|
|
gtk_tree_view_get_selection(treeview),
|
|
|
|
__playlist_select, NULL, NULL);
|
2016-01-04 07:55:10 -05:00
|
|
|
|
|
|
|
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
2016-01-01 19:58:30 -05:00
|
|
|
}
|
2016-01-04 08:15:55 -05:00
|
|
|
|
|
|
|
enum playlist_t gui_playlist_cur()
|
|
|
|
{
|
|
|
|
return p_cur;
|
|
|
|
}
|