2015-12-29 09:11:51 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-01-05 08:51:59 -05:00
|
|
|
#include <core/collection.h>
|
|
|
|
#include <core/history.h>
|
|
|
|
#include <core/queue.h>
|
2015-12-29 09:11:51 -05:00
|
|
|
#include <gui/builder.h>
|
|
|
|
#include <gui/settings.h>
|
|
|
|
#include <gui/sidebar.h>
|
|
|
|
|
|
|
|
const gchar *SIDEBAR_SETTING = "gui.sidebar.pos";
|
2016-01-05 08:51:59 -05:00
|
|
|
static GtkListStore *sb_store;
|
|
|
|
|
|
|
|
enum sidebar_columns {
|
|
|
|
SB_IMAGE,
|
|
|
|
SB_IMAGE_SZ,
|
|
|
|
SB_TEXT,
|
|
|
|
SB_QUEUE,
|
|
|
|
};
|
|
|
|
|
|
|
|
void __sidebar_set_queue(GtkTreeIter *iter, struct queue *queue)
|
|
|
|
{
|
|
|
|
gtk_list_store_set(sb_store, iter, SB_QUEUE, queue, -1);
|
|
|
|
}
|
2015-12-29 09:11:51 -05:00
|
|
|
|
|
|
|
void __sidebar_resize(GtkPaned *pane, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
gui_settings_set(SIDEBAR_SETTING, gtk_paned_get_position(pane));
|
|
|
|
}
|
|
|
|
|
2016-01-04 08:27:30 -05:00
|
|
|
void __sidebar_deselect(const gchar *widget)
|
|
|
|
{
|
|
|
|
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget(widget));
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
|
|
|
|
|
|
|
gtk_tree_selection_unselect_all(selection);
|
|
|
|
}
|
|
|
|
|
2015-12-29 09:11:51 -05:00
|
|
|
void gui_sidebar_init()
|
|
|
|
{
|
|
|
|
GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar"));
|
2016-01-05 08:51:59 -05:00
|
|
|
GtkTreeIter iter;
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
/* Set up entries in the liststore. */
|
|
|
|
sb_store = GTK_LIST_STORE(gui_builder_object("o_sidebar_store"));
|
2015-12-29 09:11:51 -05:00
|
|
|
|
2016-01-05 08:51:59 -05:00
|
|
|
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sb_store), &iter);
|
|
|
|
__sidebar_set_queue(&iter, collection_get_queue());
|
|
|
|
|
|
|
|
gtk_tree_model_iter_next(GTK_TREE_MODEL(sb_store), &iter);
|
|
|
|
__sidebar_set_queue(&iter, history_get_queue());
|
|
|
|
|
|
|
|
/* Set sidebar width. */
|
|
|
|
pos = gui_settings_get(SIDEBAR_SETTING);
|
2015-12-29 09:11:51 -05:00
|
|
|
if (pos > 0)
|
|
|
|
gtk_paned_set_position(pane, pos);
|
|
|
|
}
|
2016-01-04 08:27:30 -05:00
|
|
|
|
2016-01-05 08:51:59 -05:00
|
|
|
gboolean gui_sidebar_on_select(GtkTreeSelection *selection,
|
|
|
|
GtkTreeModel *model, GtkTreePath *path,
|
|
|
|
gboolean selected, gpointer data)
|
|
|
|
{
|
|
|
|
return gtk_tree_path_get_depth(path) != 1;
|
|
|
|
}
|
|
|
|
|
2016-01-04 08:27:30 -05:00
|
|
|
void gui_sidebar_selected(enum sidebar_selection_t selected)
|
|
|
|
{
|
|
|
|
if (selected != SB_COLLECTION)
|
|
|
|
__sidebar_deselect("o_collection_view");
|
|
|
|
if (selected != SB_PLAYLIST)
|
|
|
|
__sidebar_deselect("o_playlist_view");
|
|
|
|
}
|