gui/sidebar: Handle random button clicks
This makes the most sense here, and lets us remove gui/queue.c at some point in the future. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
3562e164b0
commit
828f861d9a
|
@ -66,7 +66,7 @@ void gui_queue_free(struct queue *queue)
|
||||||
|
|
||||||
void gui_queue_show(struct gui_queue *queue)
|
void gui_queue_show(struct gui_queue *queue)
|
||||||
{
|
{
|
||||||
GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random"));
|
GtkButton *random = GTK_BUTTON(gui_builder_widget("random_button"));
|
||||||
bool has_random = false;
|
bool has_random = false;
|
||||||
|
|
||||||
gq_queue = queue;
|
gq_queue = queue;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
#include <core/settings.h>
|
#include <core/settings.h>
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
|
#include <gui/model.h>
|
||||||
#include <gui/sidebar.h>
|
#include <gui/sidebar.h>
|
||||||
#include <gui/treeview.h>
|
#include <gui/treeview.h>
|
||||||
|
|
||||||
|
@ -115,6 +116,7 @@ static gboolean __gui_sidebar_can_select(GtkTreeSelection *selection,
|
||||||
void __gui_sidebar_selection_changed(GtkTreeSelection *selection, gpointer data)
|
void __gui_sidebar_selection_changed(GtkTreeSelection *selection, gpointer data)
|
||||||
{
|
{
|
||||||
GtkTreeModel *model = GTK_TREE_MODEL(gui_sidebar_filter());
|
GtkTreeModel *model = GTK_TREE_MODEL(gui_sidebar_filter());
|
||||||
|
bool active = false, sensitive = false;
|
||||||
struct playlist *playlist = NULL;
|
struct playlist *playlist = NULL;
|
||||||
enum playlist_type_t type;
|
enum playlist_type_t type;
|
||||||
GtkTreeIter iter, child;
|
GtkTreeIter iter, child;
|
||||||
|
@ -125,10 +127,17 @@ void __gui_sidebar_selection_changed(GtkTreeSelection *selection, gpointer data)
|
||||||
|
|
||||||
name = gui_sidebar_iter_name(&child);
|
name = gui_sidebar_iter_name(&child);
|
||||||
type = gui_sidebar_iter_type(&child);
|
type = gui_sidebar_iter_type(&child);
|
||||||
playlist = playlist_get(type, name);
|
|
||||||
|
playlist = playlist_get(type, name);
|
||||||
|
active = playlist_get_random(type, name);
|
||||||
|
sensitive = (type != PL_SYSTEM) ||
|
||||||
|
!string_match(name, "History");
|
||||||
|
|
||||||
g_free(name);
|
g_free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_toggle_button_set_active(gui_random_button(), active);
|
||||||
|
gtk_widget_set_sensitive(GTK_WIDGET(gui_random_button()), sensitive);
|
||||||
gui_treeview_set_playlist(playlist);
|
gui_treeview_set_playlist(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +146,17 @@ void __gui_sidebar_resized(GtkPaned *pane, GParamSpec *pspec, gpointer data)
|
||||||
settings_set(SIDEBAR_SETTING, gtk_paned_get_position(pane));
|
settings_set(SIDEBAR_SETTING, gtk_paned_get_position(pane));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __gui_sidebar_random_toggled(GtkToggleButton *button, gpointer data)
|
||||||
|
{
|
||||||
|
struct playlist *playlist = gui_model_get_playlist();
|
||||||
|
bool active = gtk_toggle_button_get_active(button);
|
||||||
|
|
||||||
|
if (playlist) {
|
||||||
|
playlist_set_random(playlist->pl_type,
|
||||||
|
playlist->pl_name, active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void gui_sidebar_init()
|
void gui_sidebar_init()
|
||||||
{
|
{
|
||||||
int pos = settings_get(SIDEBAR_SETTING);
|
int pos = settings_get(SIDEBAR_SETTING);
|
||||||
|
|
|
@ -75,4 +75,10 @@ static inline GtkTreeView *gui_sidebar_treeview()
|
||||||
return GTK_TREE_VIEW(gui_builder_widget("sidebar_treeview"));
|
return GTK_TREE_VIEW(gui_builder_widget("sidebar_treeview"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called to get the random button. */
|
||||||
|
static inline GtkToggleButton *gui_random_button()
|
||||||
|
{
|
||||||
|
return GTK_TOGGLE_BUTTON(gui_builder_widget("random_button"));
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* OCARINA_GUI_SIDEBAR_H */
|
#endif /* OCARINA_GUI_SIDEBAR_H */
|
||||||
|
|
|
@ -390,14 +390,14 @@
|
||||||
<property name="valign">end</property>
|
<property name="valign">end</property>
|
||||||
<property name="layout_style">end</property>
|
<property name="layout_style">end</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToggleButton" id="o_random">
|
<object class="GtkToggleButton" id="random_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="tooltip_text" translatable="yes">Randomly pick tracks</property>
|
<property name="tooltip_text" translatable="yes">Randomly pick tracks</property>
|
||||||
<property name="halign">start</property>
|
<property name="halign">start</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<signal name="toggled" handler="__queue_random" swapped="no"/>
|
<signal name="toggled" handler="__gui_sidebar_random_toggled" swapped="no"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="image9">
|
<object class="GtkImage" id="image9">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -1105,7 +1105,7 @@ audio-volume-medium</property>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkSizeGroup">
|
<object class="GtkSizeGroup">
|
||||||
<widgets>
|
<widgets>
|
||||||
<widget name="o_random"/>
|
<widget name="random_button"/>
|
||||||
<widget name="o_volume"/>
|
<widget name="o_volume"/>
|
||||||
</widgets>
|
</widgets>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -47,7 +47,7 @@ static void test_queue()
|
||||||
struct queue q;
|
struct queue q;
|
||||||
|
|
||||||
search = GTK_ENTRY(gui_filter_search());
|
search = GTK_ENTRY(gui_filter_search());
|
||||||
random = GTK_TOGGLE_BUTTON(gui_builder_widget("o_random"));
|
random = GTK_TOGGLE_BUTTON(gui_builder_widget("random_button"));
|
||||||
|
|
||||||
/* Test initialization */
|
/* Test initialization */
|
||||||
queue_init(&q, Q_ENABLED, &test_ops, NULL);
|
queue_init(&q, Q_ENABLED, &test_ops, NULL);
|
||||||
|
@ -65,13 +65,6 @@ static void test_queue()
|
||||||
g_assert_false(gtk_toggle_button_get_active(random));
|
g_assert_false(gtk_toggle_button_get_active(random));
|
||||||
g_assert_cmpstr(gtk_entry_get_text(search), ==, "");
|
g_assert_cmpstr(gtk_entry_get_text(search), ==, "");
|
||||||
|
|
||||||
/* Test clicking random button. */
|
|
||||||
gtk_toggle_button_set_active(random, true);
|
|
||||||
g_assert_true(queue_has_flag(&q, Q_RANDOM));
|
|
||||||
|
|
||||||
gtk_toggle_button_set_active(random, false);
|
|
||||||
g_assert_false(queue_has_flag(&q, Q_RANDOM));
|
|
||||||
|
|
||||||
/* Show a queue where random and repeat are enabled */
|
/* Show a queue where random and repeat are enabled */
|
||||||
gq->gq_flags = GQ_CAN_RANDOM;
|
gq->gq_flags = GQ_CAN_RANDOM;
|
||||||
q.q_flags = Q_RANDOM | Q_REPEAT | Q_ENABLED;
|
q.q_flags = Q_RANDOM | Q_REPEAT | Q_ENABLED;
|
||||||
|
|
|
@ -35,6 +35,9 @@ static void test_sidebar()
|
||||||
g_assert_nonnull(gui_sidebar_treeview());
|
g_assert_nonnull(gui_sidebar_treeview());
|
||||||
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
g_assert_true(GTK_IS_TREE_VIEW(gui_sidebar_treeview()));
|
||||||
|
|
||||||
|
g_assert_nonnull(gui_random_button());
|
||||||
|
g_assert_true(GTK_IS_TOGGLE_BUTTON(gui_random_button()));
|
||||||
|
|
||||||
g_assert_true(gui_sidebar_iter_first(&iter));
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
||||||
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Collection"), NULL);
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Collection"), NULL);
|
||||||
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "History"), NULL);
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "History"), NULL);
|
||||||
|
@ -98,6 +101,7 @@ static void test_sidebar()
|
||||||
static void test_sidebar_selection()
|
static void test_sidebar_selection()
|
||||||
{
|
{
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
|
GtkToggleButton *random;
|
||||||
GtkTreeModel *filter;
|
GtkTreeModel *filter;
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
@ -105,6 +109,7 @@ static void test_sidebar_selection()
|
||||||
|
|
||||||
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
|
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
|
||||||
filter = GTK_TREE_MODEL(gui_sidebar_filter());
|
filter = GTK_TREE_MODEL(gui_sidebar_filter());
|
||||||
|
random = gui_random_button();
|
||||||
|
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 6);
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 6);
|
||||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
|
@ -112,6 +117,7 @@ static void test_sidebar_selection()
|
||||||
playlist_add(PL_SYSTEM, "History", track_get(0));
|
playlist_add(PL_SYSTEM, "History", track_get(0));
|
||||||
gtk_tree_model_filter_refilter(gui_sidebar_filter());
|
gtk_tree_model_filter_refilter(gui_sidebar_filter());
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 8);
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 8);
|
||||||
|
playlist_set_random(PL_SYSTEM, "Collection", true);
|
||||||
|
|
||||||
g_assert_true(gui_sidebar_iter_first(&iter));
|
g_assert_true(gui_sidebar_iter_first(&iter));
|
||||||
path = gtk_tree_model_get_path(gui_sidebar_model(), &iter);
|
path = gtk_tree_model_get_path(gui_sidebar_model(), &iter);
|
||||||
|
@ -119,14 +125,31 @@ static void test_sidebar_selection()
|
||||||
gtk_tree_selection_select_path(selection, path);
|
gtk_tree_selection_select_path(selection, path);
|
||||||
n = gtk_tree_selection_count_selected_rows(selection);
|
n = gtk_tree_selection_count_selected_rows(selection);
|
||||||
g_assert_cmpuint(n, ==, (i < 2) ? 1 : 0);
|
g_assert_cmpuint(n, ==, (i < 2) ? 1 : 0);
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
g_assert(gui_model_get_playlist() ==
|
g_assert(gui_model_get_playlist() ==
|
||||||
playlist_get(PL_SYSTEM, "Collection"));
|
playlist_get(PL_SYSTEM, "Collection"));
|
||||||
else if (i == 1)
|
g_assert_true(gtk_toggle_button_get_active(random));
|
||||||
|
g_assert_true(gtk_widget_get_sensitive(
|
||||||
|
GTK_WIDGET(random)));
|
||||||
|
|
||||||
|
gtk_toggle_button_set_active(random, false);
|
||||||
|
g_assert_false(
|
||||||
|
playlist_get_random(PL_SYSTEM, "Collection"));
|
||||||
|
gtk_toggle_button_set_active(random, true);
|
||||||
|
g_assert_true(
|
||||||
|
playlist_get_random(PL_SYSTEM, "Collection"));
|
||||||
|
} else if (i == 1) {
|
||||||
g_assert(gui_model_get_playlist() ==
|
g_assert(gui_model_get_playlist() ==
|
||||||
playlist_get(PL_SYSTEM, "History"));
|
playlist_get(PL_SYSTEM, "History"));
|
||||||
else
|
g_assert_false(gtk_toggle_button_get_active(random));
|
||||||
|
g_assert_false(gtk_widget_get_sensitive(
|
||||||
|
GTK_WIDGET(random)));
|
||||||
|
} else {
|
||||||
g_assert_null(gui_model_get_playlist());
|
g_assert_null(gui_model_get_playlist());
|
||||||
|
g_assert_false(gtk_toggle_button_get_active(random));
|
||||||
|
g_assert_false(gtk_widget_get_sensitive(
|
||||||
|
GTK_WIDGET(random)));
|
||||||
|
}
|
||||||
gtk_tree_selection_unselect_all(selection);
|
gtk_tree_selection_unselect_all(selection);
|
||||||
gtk_tree_path_next(path);
|
gtk_tree_path_next(path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue