gui/playlists/system: Respond to favorite and hide buttons
I also take this opportunity to rename these widgets and add accessor functions. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
36f399ecb7
commit
cebf2069cb
24
gui/audio.c
24
gui/audio.c
|
@ -7,6 +7,7 @@
|
|||
#include <gui/artwork.h>
|
||||
#include <gui/audio.h>
|
||||
#include <gui/idle.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
|
@ -36,11 +37,7 @@ static void __audio_load(struct track *track)
|
|||
__audio_set_label("o_album", "x-large", track->tr_album->al_name);
|
||||
__audio_set_time_label("o_duration", track->tr_length);
|
||||
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_hide")),
|
||||
playlist_has(PL_SYSTEM, "Hidden", track));
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")),
|
||||
playlist_has(PL_SYSTEM, "Favorites", track));
|
||||
|
||||
gui_pl_system_track_loaded(track);
|
||||
gui_treeview_scroll();
|
||||
gui_artwork_set_cover();
|
||||
gui_idle_enable();
|
||||
|
@ -79,23 +76,6 @@ void __audio_volume_changed(GtkScaleButton *button, gdouble value, gpointer data
|
|||
audio_set_volume((unsigned int)value);
|
||||
}
|
||||
|
||||
void __audio_favorite(GtkToggleButton *toggle, gpointer data)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(toggle))
|
||||
playlist_add(PL_SYSTEM, "Favorites", audio_cur_track());
|
||||
else
|
||||
playlist_remove(PL_SYSTEM, "Favorites", audio_cur_track());
|
||||
}
|
||||
|
||||
void __audio_hide(GtkToggleButton *toggle, gpointer data)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(toggle)) {
|
||||
if (playlist_add(PL_SYSTEM, "Hidden", audio_cur_track()))
|
||||
audio_next();
|
||||
} else
|
||||
playlist_remove(PL_SYSTEM, "Hidden", audio_cur_track());
|
||||
}
|
||||
|
||||
static int __audio_timeout(gpointer data)
|
||||
{
|
||||
GtkAdjustment *progress = data;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/string.h>
|
||||
#include <gui/playlists/system.h>
|
||||
#include <gui/sidebar.h>
|
||||
|
||||
static bool __gui_pl_system_is_playlist(struct playlist *playlist)
|
||||
|
@ -31,6 +33,23 @@ static bool __gui_pl_system_find_descend_header(GtkTreeIter *iter,
|
|||
return gui_sidebar_iter_down(&header, iter);
|
||||
}
|
||||
|
||||
void __gui_pl_system_favorite_toggled(GtkToggleButton *toggle, gpointer data)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(toggle))
|
||||
playlist_add(PL_SYSTEM, "Favorites", audio_cur_track());
|
||||
else
|
||||
playlist_remove(PL_SYSTEM, "Favorites", audio_cur_track());
|
||||
}
|
||||
|
||||
void __gui_pl_system_hide_toggled(GtkToggleButton *toggle, gpointer data)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(toggle)) {
|
||||
if (playlist_add(PL_SYSTEM, "Hidden", audio_cur_track()))
|
||||
audio_next();
|
||||
} else
|
||||
playlist_remove(PL_SYSTEM, "Hidden", audio_cur_track());
|
||||
}
|
||||
|
||||
static bool __gui_pl_system_init_idle()
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
@ -86,3 +105,11 @@ void gui_pl_system_update(struct playlist *playlist)
|
|||
if (gui_sidebar_iter_find(&iter, playlist->pl_name, playlist->pl_type))
|
||||
gui_sidebar_iter_update(&iter);
|
||||
}
|
||||
|
||||
void gui_pl_system_track_loaded(struct track *track)
|
||||
{
|
||||
gtk_toggle_button_set_active(gui_favorite_button(),
|
||||
playlist_has(PL_SYSTEM, "Favorites", track));
|
||||
gtk_toggle_button_set_active(gui_hide_button(),
|
||||
playlist_has(PL_SYSTEM, "Hidden", track));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
#ifndef OCARINA_GUI_PLAYLISTS_SYSTEM_H
|
||||
#define OCARINA_GUI_PLAYLISTS_SYSTEM_H
|
||||
#include <gui/builder.h>
|
||||
|
||||
/* Called to initialize GUI system playlists. */
|
||||
void gui_pl_system_init();
|
||||
|
@ -10,4 +11,19 @@ void gui_pl_system_init();
|
|||
/* Called to update a system playlist. */
|
||||
void gui_pl_system_update(struct playlist *);
|
||||
|
||||
/* Called to set favorites and hidden button states. */
|
||||
void gui_pl_system_track_loaded(struct track *);
|
||||
|
||||
/* Called to get the favorite toggle button. */
|
||||
static inline GtkToggleButton *gui_favorite_button()
|
||||
{
|
||||
return GTK_TOGGLE_BUTTON(gui_builder_widget("favorite_button"));
|
||||
}
|
||||
|
||||
/* Called to get the hidden toggle button. */
|
||||
static inline GtkToggleButton *gui_hide_button()
|
||||
{
|
||||
return GTK_TOGGLE_BUTTON(gui_builder_widget("hide_button"));
|
||||
}
|
||||
|
||||
#endif /* OCARINA_GUI_PLAYLISTS_SYSTEM_H */
|
||||
|
|
|
@ -682,14 +682,14 @@ audio-volume-medium</property>
|
|||
<property name="spacing">5</property>
|
||||
<property name="layout_style">expand</property>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="o_favorite">
|
||||
<object class="GtkToggleButton" id="favorite_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Add this track to Favorites playlist</property>
|
||||
<property name="inconsistent">True</property>
|
||||
<signal name="toggled" handler="__audio_favorite" swapped="no"/>
|
||||
<signal name="toggled" handler="__gui_pl_system_favorite_toggled" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="image8">
|
||||
<property name="visible">True</property>
|
||||
|
@ -705,13 +705,13 @@ audio-volume-medium</property>
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="o_hide">
|
||||
<object class="GtkToggleButton" id="hide_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Hide this track from the Collection</property>
|
||||
<signal name="toggled" handler="__audio_hide" swapped="no"/>
|
||||
<signal name="toggled" handler="__gui_pl_system_hide_toggled" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="image14">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
@ -62,8 +62,8 @@ static void test_audio()
|
|||
g_assert_true(gtk_widget_is_visible(gui_builder_widget("o_play")));
|
||||
g_assert_false(gtk_widget_is_visible(gui_builder_widget("o_pause")));
|
||||
g_assert_cmpstr_free(test_get_pause_text(), ==, "(disabled)");
|
||||
g_assert_false(test_get_toggle_state("o_favorite"));
|
||||
g_assert_false(test_get_toggle_state("o_hide"));
|
||||
g_assert_false(test_get_toggle_state("favorite_button"));
|
||||
g_assert_false(test_get_toggle_state("hide_button"));
|
||||
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
if (TRACK(dbe)->tr_track == 1) {
|
||||
|
@ -84,8 +84,8 @@ static void test_audio()
|
|||
g_assert_cmpstr(test_get_label_text("o_artist"), ==, track->tr_album->al_artist->ar_name);
|
||||
g_assert_cmpstr(test_get_label_text("o_position"), ==, "0:00");
|
||||
g_assert_cmpstr(test_get_label_text("o_duration"), ==, duration);
|
||||
g_assert_true(test_get_toggle_state("o_favorite"));
|
||||
g_assert_true(test_get_toggle_state("o_hide"));
|
||||
g_assert_true(test_get_toggle_state("favorite_button"));
|
||||
g_assert_true(test_get_toggle_state("hide_button"));
|
||||
g_free(duration);
|
||||
|
||||
test_click_button("o_play");
|
||||
|
@ -103,8 +103,8 @@ static void test_audio()
|
|||
|
||||
test_click_button("o_next");
|
||||
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 3);
|
||||
g_assert_false(test_get_toggle_state("o_favorite"));
|
||||
g_assert_false(test_get_toggle_state("o_hide"));
|
||||
g_assert_false(test_get_toggle_state("favorite_button"));
|
||||
g_assert_false(test_get_toggle_state("hide_button"));
|
||||
|
||||
test_set_pause_after(1);
|
||||
g_assert_cmpstr_free(test_get_pause_text(), ==, "next track");
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/filter.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
|
@ -11,8 +11,20 @@
|
|||
#include <gui/treeview.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static void test_audio_load(struct track *track)
|
||||
{ gui_pl_system_track_loaded(track); }
|
||||
static void test_change_state(GstState state) { }
|
||||
static void test_config_pause(int n) { }
|
||||
|
||||
static struct audio_ops test_audio_ops = {
|
||||
.on_load = test_audio_load,
|
||||
.on_state_change = test_change_state,
|
||||
.on_config_pause = test_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.playlist_ops = &playlist_ops,
|
||||
.audio_ops = &test_audio_ops,
|
||||
};
|
||||
|
||||
static const gchar *toplevel[3] = { "Queued Tracks", "Collection", "History" };
|
||||
|
@ -49,9 +61,37 @@ static void test_system()
|
|||
g_assert_cmpuint(gui_sidebar_iter_type(&child), ==, PL_SYSTEM);
|
||||
gui_sidebar_iter_next(&child);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_buttons()
|
||||
{
|
||||
g_assert_true(gui_pl_library_add("tests/Music/Hyrule Symphony"));
|
||||
while (idle_run_task()) {}
|
||||
|
||||
g_assert_false(gtk_toggle_button_get_active(gui_favorite_button()));
|
||||
g_assert_false(gtk_toggle_button_get_active(gui_hide_button()));
|
||||
|
||||
playlist_add(PL_SYSTEM, "Favorites", track_get(0));
|
||||
audio_load(track_get(0));
|
||||
g_assert_true( gtk_toggle_button_get_active(gui_favorite_button()));
|
||||
g_assert_false(gtk_toggle_button_get_active(gui_hide_button()));
|
||||
|
||||
gtk_toggle_button_set_active(gui_favorite_button(), false);
|
||||
g_assert_false(playlist_has(PL_SYSTEM, "Favorites", track_get(0)));
|
||||
gtk_toggle_button_set_active(gui_favorite_button(), true);
|
||||
g_assert_true(playlist_has(PL_SYSTEM, "Favorites", track_get(0)));
|
||||
|
||||
playlist_add(PL_SYSTEM, "Hidden", track_get(1));
|
||||
audio_load(track_get(1));
|
||||
g_assert_false(gtk_toggle_button_get_active(gui_favorite_button()));
|
||||
g_assert_true(gtk_toggle_button_get_active(gui_hide_button()));
|
||||
|
||||
gtk_toggle_button_set_active(gui_hide_button(), false);
|
||||
g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(1)));
|
||||
g_assert(audio_cur_track() == track_get(1));
|
||||
gtk_toggle_button_set_active(gui_hide_button(), true);
|
||||
g_assert_true(playlist_has(PL_SYSTEM, "Hidden", track_get(1)));
|
||||
g_assert(audio_cur_track() != track_get(1));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -70,6 +110,7 @@ int main(int argc, char **argv)
|
|||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Playlists/System", test_system);
|
||||
g_test_add_func("/Gui/Playlists/System/Buttons", test_buttons);
|
||||
ret = g_test_run();
|
||||
|
||||
core_deinit();
|
||||
|
|
Loading…
Reference in New Issue