diff --git a/gui/collection.c b/gui/collection.c
index 1336f231..6152d603 100644
--- a/gui/collection.c
+++ b/gui/collection.c
@@ -135,13 +135,6 @@ void __collection_selection_changed(GtkTreeSelection *selection,
}
}
-static gboolean __collection_select(GtkTreeSelection *selection,
- GtkTreeModel *model, GtkTreePath *path,
- gboolean selected, gpointer data)
-{
- return gtk_tree_path_get_depth(path) != 1;
-}
-
static gboolean __collection_on_idle(gpointer data)
{
GtkProgressBar *progress = GTK_PROGRESS_BAR(data);
@@ -184,7 +177,7 @@ void gui_collection_init()
gtk_tree_view_expand_all(treeview);
gtk_tree_selection_set_select_function(
gtk_tree_view_get_selection(treeview),
- __collection_select, NULL, NULL);
+ gui_sidebar_on_select, NULL, NULL);
gui_collection_idle_enable();
}
diff --git a/gui/playlist.c b/gui/playlist.c
index 25e095f7..8ee2da09 100644
--- a/gui/playlist.c
+++ b/gui/playlist.c
@@ -49,13 +49,6 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
}
}
-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;
@@ -65,6 +58,7 @@ void gui_playlist_init()
/* Add "Playlist" header. */
gtk_tree_store_insert(p_store, &parent, NULL, -1);
+ gtk_tree_store_insert(p_store, &parent, NULL, -1);
__playlist_set(&parent, "Playlists",
"emblem-documents", GTK_ICON_SIZE_LARGE_TOOLBAR, 0);
@@ -79,7 +73,7 @@ void gui_playlist_init()
gtk_tree_view_expand_all(treeview);
gtk_tree_selection_set_select_function(
gtk_tree_view_get_selection(treeview),
- __playlist_select, NULL, NULL);
+ gui_sidebar_on_select, NULL, NULL);
gtk_tree_store_insert(p_store, &parent, NULL, -1);
}
diff --git a/gui/sidebar.c b/gui/sidebar.c
index 7bb41893..118aab5d 100644
--- a/gui/sidebar.c
+++ b/gui/sidebar.c
@@ -1,11 +1,27 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
+#include
+#include
+#include
#include
#include
#include
const gchar *SIDEBAR_SETTING = "gui.sidebar.pos";
+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);
+}
void __sidebar_resize(GtkPaned *pane, GParamSpec *pspec, gpointer data)
{
@@ -23,12 +39,31 @@ void __sidebar_deselect(const gchar *widget)
void gui_sidebar_init()
{
GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar"));
- int pos = gui_settings_get(SIDEBAR_SETTING);
+ GtkTreeIter iter;
+ int pos;
+ /* Set up entries in the liststore. */
+ sb_store = GTK_LIST_STORE(gui_builder_object("o_sidebar_store"));
+
+ 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);
if (pos > 0)
gtk_paned_set_position(pane, pos);
}
+gboolean gui_sidebar_on_select(GtkTreeSelection *selection,
+ GtkTreeModel *model, GtkTreePath *path,
+ gboolean selected, gpointer data)
+{
+ return gtk_tree_path_get_depth(path) != 1;
+}
+
void gui_sidebar_selected(enum sidebar_selection_t selected)
{
if (selected != SB_COLLECTION)
diff --git a/include/gui/sidebar.h b/include/gui/sidebar.h
index 43088e5a..309c81ec 100644
--- a/include/gui/sidebar.h
+++ b/include/gui/sidebar.h
@@ -12,6 +12,10 @@ enum sidebar_selection_t {
/* Called to initialize the sidebar. */
void gui_sidebar_init();
+/* Called when a row in the sidebar is selected. */
+gboolean gui_sidebar_on_select(GtkTreeSelection *, GtkTreeModel *,
+ GtkTreePath *path, gboolean, gpointer);
+
/* Called to tell the sidebar that the selection has changed. */
void gui_sidebar_selected(enum sidebar_selection_t);
diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade
index 8a2e5a19..dcd75499 100644
--- a/share/ocarina/ocarina6.glade
+++ b/share/ocarina/ocarina6.glade
@@ -212,7 +212,6 @@
False
window-close
-
+
diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c
index 89579bdb..8e0e698c 100644
--- a/tests/gui/playlist.c
+++ b/tests/gui/playlist.c
@@ -29,6 +29,7 @@ static void test_playlist_sidebar()
model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store"));
test_equal(gtk_tree_model_get_iter_first(model, &iter), true);
+ test_equal(gtk_tree_model_iter_next(model, &iter), true);
test_equal(gtk_tree_model_iter_n_children(model, &iter), 5);
path = gtk_tree_model_get_path(model, &iter);
diff --git a/tests/gui/sidebar.c b/tests/gui/sidebar.c
index 5888d090..51ff982d 100644
--- a/tests/gui/sidebar.c
+++ b/tests/gui/sidebar.c
@@ -4,6 +4,8 @@
#define TEST_NEED_AUDIO
#define TEST_NEED_COLLECTION
#define TEST_NEED_PLAYLIST
+#include
+#include
#include
#include
#include
@@ -34,6 +36,25 @@ static void test_sidebar()
gui_sidebar_init();
test_equal(gui_settings_get("gui.sidebar.pos"), 250);
test_equal(gtk_paned_get_position(paned), 250);
+}
+
+static void test_treeview()
+{
+ struct queue *queue;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ model = GTK_TREE_MODEL(gui_builder_object("o_sidebar_store"));
+
+ test_equal(gtk_tree_model_get_iter_first(model, &iter), true);
+ gtk_tree_model_get(model, &iter, 3, &queue, -1);
+ test_equal((void *)queue, (void *)collection_get_queue());
+
+ test_equal(gtk_tree_model_iter_next(model, &iter), true);
+ gtk_tree_model_get(model, &iter, 3, &queue, -1);
+ test_equal((void *)queue, (void *)history_get_queue());
+
+ test_equal(gtk_tree_model_iter_next(model, &iter), false);
gui_settings_deinit();
gui_builder_deinit();
@@ -41,4 +62,5 @@ static void test_sidebar()
DECLARE_UNIT_TESTS(
UNIT_TEST("Sidebar", test_sidebar),
+ UNIT_TEST("Sidebar Treeview", test_treeview),
);