ocarina: Add back the "ban track" button
I moved it to the GtkNotebook action-area for the playlist tabs since I ran out of room in the "Now Playing" section. I made the widgets accessable through my get_widget() function, but it would be nice to figure out how to add them in GtkBuilder. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
2221bca25e
commit
56148e58fe
|
@ -32,14 +32,11 @@ static void on_page_reordered(GtkWidget *t, GtkWidget *page, guint num, gpointer
|
|||
static GtkWidget *init_playlist_action()
|
||||
{
|
||||
GtkWidget *box = gtk_vbox_new(FALSE, 0);
|
||||
GtkWidget *open_button = gtk_button_new();
|
||||
GtkWidget *open_icon = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(open_button), open_icon);
|
||||
gtk_box_pack_start(GTK_BOX(box), open_button, false, false, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), get_widget("OpenButton"), false, false, 0);
|
||||
gtk_box_pack_start(GTK_BOX(box), get_widget("BanButton"), false, false, 0);
|
||||
gtk_widget_show_all(box);
|
||||
|
||||
g_signal_connect(open_button, "clicked", G_CALLBACK(on_click_open), NULL);
|
||||
connect_signal("OpenButton", "clicked", G_CALLBACK(on_click_open), NULL);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
|
||||
static string lib_path;
|
||||
static GtkBuilder *builder;
|
||||
static GtkWidget *ban_button;
|
||||
static GtkWidget *open_button;
|
||||
static GtkWidget *yes_image;
|
||||
static GtkWidget *no_image;
|
||||
|
||||
static void find_exe_path(string &res)
|
||||
{
|
||||
|
@ -79,7 +83,19 @@ GObject *get_object(const string &name)
|
|||
|
||||
GtkWidget *get_widget(const string &name)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET(get_object(name));
|
||||
GtkWidget *widget;
|
||||
/* TODO: Figure out GtkNotebook action area in GtkBuilder */
|
||||
if (name == "BanButton")
|
||||
widget = ban_button;
|
||||
else if (name == "OpenButton")
|
||||
widget = open_button;
|
||||
else if (name == "YesImage")
|
||||
widget = yes_image;
|
||||
else if (name == "NoImage")
|
||||
widget = no_image;
|
||||
else
|
||||
widget = GTK_WIDGET(get_object(name));
|
||||
|
||||
if (!widget)
|
||||
println(name + " is not a widget!");
|
||||
return widget;
|
||||
|
@ -107,6 +123,24 @@ string run_chooser(const string &name)
|
|||
return filename;
|
||||
}
|
||||
|
||||
static void init_widgets()
|
||||
{
|
||||
GtkIconSize size = GTK_ICON_SIZE_BUTTON;
|
||||
GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, size);
|
||||
|
||||
ban_button = gtk_toggle_button_new();
|
||||
yes_image = gtk_image_new_from_stock(GTK_STOCK_YES, size);
|
||||
no_image = gtk_image_new_from_stock(GTK_STOCK_NO, size);
|
||||
gtk_button_set_image(GTK_BUTTON(ban_button), yes_image);
|
||||
|
||||
/* Prevent widgets from being destroyed when toggling banned button */
|
||||
g_object_ref(yes_image);
|
||||
g_object_ref(no_image);
|
||||
|
||||
open_button = gtk_button_new();
|
||||
gtk_button_set_image(GTK_BUTTON(open_button), image);
|
||||
}
|
||||
|
||||
static void init(int argc, char **argv)
|
||||
{
|
||||
gtk_init(&argc, &argv);
|
||||
|
@ -114,16 +148,15 @@ static void init(int argc, char **argv)
|
|||
builder = gtk_builder_new();
|
||||
gtk_builder_add_from_file(builder, lib_file("ocarina.xml").c_str(), NULL);
|
||||
|
||||
/* Initialize window */
|
||||
/* Initialize widgets static to this file */
|
||||
init_widgets();
|
||||
|
||||
/* Other setup */
|
||||
init_window();
|
||||
init_library();
|
||||
init_playlist();
|
||||
init_status();
|
||||
|
||||
/*gtk_notebook_set_action_widget(GTK_NOTEBOOK(get_widget("PlaylistTabs")),
|
||||
get_widget("ActionWidget"),
|
||||
GTK_PACK_START);*/
|
||||
|
||||
/* Connect signals */
|
||||
connect_signal("PlayButton", "clicked", libsaria::audio::play, NULL);
|
||||
connect_signal("PauseButton", "clicked", libsaria::audio::pause, NULL);
|
||||
|
|
|
@ -40,6 +40,8 @@ static void update_labels()
|
|||
|
||||
cur_track = cur;
|
||||
refresh_widgets();
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(get_widget("BanButton")),
|
||||
cur_track->get_banned());
|
||||
}
|
||||
|
||||
static void update_buttons()
|
||||
|
@ -119,6 +121,23 @@ static void counter_changed(GtkWidget *b, GtkScrollType *s, gpointer d)
|
|||
libsaria::deck::set_pause_type(PS_AFTER_N, count);
|
||||
}
|
||||
|
||||
static void toggle_ban(GtkWidget *b, gpointer d)
|
||||
{
|
||||
GtkWidget *ban = get_widget("BanButton");
|
||||
bool banned = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ban));
|
||||
if (banned)
|
||||
gtk_button_set_image(GTK_BUTTON(ban), get_widget("NoImage"));
|
||||
else
|
||||
gtk_button_set_image(GTK_BUTTON(ban), get_widget("YesImage"));
|
||||
|
||||
if (cur_track->get_banned() == banned)
|
||||
return;
|
||||
|
||||
cur_track->set_banned(banned);
|
||||
if (banned)
|
||||
libsaria::deck::next();
|
||||
}
|
||||
|
||||
bool update_idle_bar(int size)
|
||||
{
|
||||
GtkWidget *idle = get_widget("IdleProgress");
|
||||
|
@ -155,4 +174,5 @@ void init_status()
|
|||
connect_signal("NoPause", "toggled", G_CALLBACK(toggle_pause), NULL);
|
||||
connect_signal("PauseAfterN", "toggled", G_CALLBACK(toggle_pause), NULL);
|
||||
connect_signal("PauseCounter", "value-changed", G_CALLBACK(counter_changed), NULL);
|
||||
connect_signal("BanButton", "toggled", G_CALLBACK(toggle_ban), NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue