gui/sidebar: Add Collection and History entries to the sidebar

I could do this as a treeview, but creating this as a liststore in glade
is WAY easier!

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-05 08:51:59 -05:00
parent 84ff59cf81
commit 6c653c6a79
7 changed files with 136 additions and 20 deletions

View File

@ -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();
}

View File

@ -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, "<span size='large'>Playlists</span>",
"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);
}

View File

@ -1,11 +1,27 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/history.h>
#include <core/queue.h>
#include <gui/builder.h>
#include <gui/settings.h>
#include <gui/sidebar.h>
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)

View File

@ -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);

View File

@ -212,7 +212,6 @@
<property name="can_focus">False</property>
<property name="icon_name">window-close</property>
</object>
<object class="GtkListStore" id="liststore1"/>
<object class="GtkTreeStore" id="o_collection_store">
<columns>
<!-- column-name Image -->
@ -246,6 +245,32 @@
<property name="step_increment">1000000000</property>
<property name="page_increment">10000000000</property>
</object>
<object class="GtkListStore" id="o_sidebar_store">
<columns>
<!-- column-name Image -->
<column type="gchararray"/>
<!-- column-name ImageSize -->
<column type="GtkIconSize"/>
<!-- column-name Text -->
<column type="gchararray"/>
<!-- column-name Queue -->
<column type="gpointer"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">media-optical</col>
<col id="1">menu</col>
<col id="2" translatable="yes">&lt;big&gt;Collection&lt;/big&gt;
0 tracks</col>
</row>
<row>
<col id="0" translatable="yes">document-open-recent</col>
<col id="1">menu</col>
<col id="2" translatable="yes">&lt;big&gt;History&lt;/big&gt;
0 tracks</col>
</row>
</data>
</object>
<object class="GtkWindow" id="o_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
@ -631,6 +656,48 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTreeView" id="o_sidebar_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">o_sidebar_store</property>
<property name="headers_visible">False</property>
<property name="show_expanders">False</property>
<property name="level_indentation">10</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection4"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn6">
<property name="title" translatable="yes">Image</property>
<child>
<object class="GtkCellRendererPixbuf" id="cellrendererpixbuf3"/>
<attributes>
<attribute name="icon-name">0</attribute>
<attribute name="stock-size">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn7">
<property name="title" translatable="yes">Text</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="markup">2</attribute>
</attributes>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="o_playlist_view">
<property name="visible">True</property>
@ -673,7 +740,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -733,7 +800,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>

View File

@ -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);

View File

@ -4,6 +4,8 @@
#define TEST_NEED_AUDIO
#define TEST_NEED_COLLECTION
#define TEST_NEED_PLAYLIST
#include <core/collection.h>
#include <core/history.h>
#include <gui/builder.h>
#include <gui/settings.h>
#include <gui/sidebar.h>
@ -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),
);