gui/playlist: Change current playlist when selected

I also add a function to get the currently selected playlist.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-04 08:15:55 -05:00
parent fde59a1868
commit 7439a2a73d
8 changed files with 84 additions and 19 deletions

View File

@ -1,6 +1,7 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/tempq.h>
#include <gui/builder.h>
#include <gui/playlist.h>
@ -8,23 +9,42 @@ enum playlist_sidebar_columns {
P_SB_IMAGE,
P_SB_IMAGE_SZ,
P_SB_NAME,
P_SB_PLAYLIST,
};
static GtkTreeStore *p_store;
static GtkTreeStore *p_store;
static enum playlist_t p_cur;
static void __playlist_set(GtkTreeIter *iter, const gchar *name,
const gchar *image, GtkIconSize size)
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, -1);
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)
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);
__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);
}
}
static gboolean __playlist_select(GtkTreeSelection *selection,
@ -44,14 +64,14 @@ void gui_playlist_init()
/* Add "Playlist" header. */
gtk_tree_store_insert(p_store, &parent, NULL, -1);
__playlist_set(&parent, "<span size='large'>Playlists</span>",
"emblem-documents", GTK_ICON_SIZE_LARGE_TOOLBAR);
"emblem-documents", GTK_ICON_SIZE_LARGE_TOOLBAR, 0);
/* Add playlists. */
__playlist_add(&parent, "Favorites", "emblem-favorite");
__playlist_add(&parent, "Banned", "face-sad");
__playlist_add(&parent, "Most Played", "go-up");
__playlist_add(&parent, "Least Played", "go-down");
__playlist_add(&parent, "Unplayed", "audio-x-generic");
__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);
@ -61,3 +81,8 @@ void gui_playlist_init()
gtk_tree_store_insert(p_store, &parent, NULL, -1);
}
enum playlist_t gui_playlist_cur()
{
return p_cur;
}

View File

@ -4,7 +4,12 @@
#ifndef OCARINA_GUI_PLAYLIST_H
#define OCARINA_GUI_PLAYLIST_H
#include <core/playlist.h>
/* Called to initialize the GUI playlist code. */
void gui_playlist_init();
/* Called to get the currently selected playlist. */
enum playlist_t gui_playlist_cur();
#endif /* OCARINA_GUI_PLAYLIST_H */

View File

@ -23,4 +23,8 @@ void __collection_selection_changed() {}
void __collection_toggled() {}
#endif /* TEST_NEED_COLLECTION */
#ifdef TEST_NEED_PLAYLIST
void __playlist_selection_changed() {}
#endif /* TEST_NEED_PLAYLIST */
#endif /* TESTS_GUI_H */

View File

@ -237,6 +237,8 @@
<column type="GtkIconSize"/>
<!-- column-name Name -->
<column type="gchararray"/>
<!-- column-name Playlist -->
<column type="guint"/>
</columns>
</object>
<object class="GtkAdjustment" id="o_progress">
@ -640,7 +642,9 @@
<property name="level_indentation">10</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection3"/>
<object class="GtkTreeSelection" id="treeview-selection3">
<signal name="changed" handler="__playlist_selection_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">

View File

@ -2,6 +2,7 @@
* Copyright 2015 (c) Anna Schumaker.
*/
#define TEST_NEED_AUDIO
#define TEST_NEED_PLAYLIST
#include <core/core.h>
#include <gui/builder.h>
#include <gui/collection.h>

View File

@ -2,11 +2,14 @@
* Copyright 2016 (c) Anna Schumaker.
*/
#define TEST_NEED_AUDIO
#include <core/core.h>
#include <gui/builder.h>
#include <gui/playlist.h>
#include <tests/gui.h>
#include <tests/test.h>
struct core_init_data init_data;
static void test_playlist_sidebar()
{
GtkTreeSelection *selection;
@ -18,20 +21,41 @@ static void test_playlist_sidebar()
gtk_init(&argc, NULL);
gui_builder_init("share/ocarina/ocarina6.glade");
core_init(&argc, NULL, &init_data);
gui_playlist_init();
treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"));
selection = gtk_tree_view_get_selection(treeview);
model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store"));
test_equal(gtk_tree_model_get_iter_first(model, &iter), true);
path = gtk_tree_model_get_path(model, &iter);
gtk_tree_view_set_cursor(treeview, path, NULL, false);
gtk_tree_path_free(path);
test_equal(gtk_tree_selection_count_selected_rows(selection), 0);
test_equal(gtk_tree_model_iter_n_children(model, &iter), 5);
path = gtk_tree_model_get_path(model, &iter);
gtk_tree_selection_select_path(selection, path);
test_equal(gtk_tree_selection_count_selected_rows(selection), 0);
gtk_tree_path_down(path);
gtk_tree_selection_select_path(selection, path);
test_equal(gui_playlist_cur(), PL_FAVORITED);
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
test_equal(gui_playlist_cur(), PL_HIDDEN);
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
test_equal(gui_playlist_cur(), PL_MOST_PLAYED);
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
test_equal(gui_playlist_cur(), PL_LEAST_PLAYED);
gtk_tree_path_next(path);
gtk_tree_selection_select_path(selection, path);
test_equal(gui_playlist_cur(), PL_UNPLAYED);
gtk_tree_path_free(path);
gui_builder_deinit();
}

View File

@ -3,6 +3,7 @@
*/
#define TEST_NEED_AUDIO
#define TEST_NEED_COLLECTION
#define TEST_NEED_PLAYLIST
#include <gui/builder.h>
#include <gui/settings.h>
#include <gui/sidebar.h>

View File

@ -4,6 +4,7 @@
#define TEST_NEED_AUDIO
#define TEST_NEED_SIDEBAR
#define TEST_NEED_COLLECTION
#define TEST_NEED_PLAYLIST
#include <gui/builder.h>
#include <gui/settings.h>
#include <gui/window.h>