ocarina: Re-enable automatic pause

I modified the code slightly from what I used to have.  The biggest
difference is changing the counter will always enable automatic pausing,
so I no longer need the extra click to enable this feature.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-05 08:54:40 -04:00
parent 761842869e
commit aebcfaab45
5 changed files with 36 additions and 82 deletions

View File

@ -25,7 +25,6 @@ namespace ocarina
void hide_idle_progress();
void set_now_playing();
void update_automatic_pause();
GtkWidget *playlist_init();
GtkWidget *footer_init();

View File

@ -109,7 +109,6 @@ namespace ocarina
return;
current = cur;
refresh_widgets();
update_automatic_pause();
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ban), current->get_banned());
println("Current track changed");

View File

@ -1,79 +0,0 @@
// Copyright (c) 2012 Bryan Schumaker
#include <ocarina/ocarina.h>
#include <ocarina/body.h>
#include <libsaria/deck.h>
static GtkWidget *no_pause;
static GtkWidget *after_n;
static GtkWidget *pause_counter;
static void counter_changed(GtkWidget *b, GtkScrollType *s, gpointer d)
{
unsigned short count;
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(after_n)))
return;
count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pause_counter));
libsaria::deck::set_pause_type(PS_AFTER_N, count);
}
static void on_toggle(GtkWidget *b, gpointer d)
{
unsigned short count;
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b)))
return;
if (b == no_pause)
libsaria::deck::set_pause_type(PS_NONE, 0);
else if (b == after_n) {
count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pause_counter));
libsaria::deck::set_pause_type(PS_AFTER_N, count);
}
}
namespace ocarina
{
GtkWidget *body::pause_page()
{
GtkWidget *box = gtk_vbox_new(FALSE, 0);
GtkWidget *after_n_box = gtk_hbox_new(FALSE, 0);
GtkWidget *label1 = gtk_label_new("Pause after ");
GtkWidget *label2 = gtk_label_new(" song(s)");
no_pause = gtk_radio_button_new_with_label(NULL, "No automatic pause");
gtk_box_pack_start(GTK_BOX(box), no_pause, TRUE, TRUE, 0);
g_signal_connect(no_pause, "toggled", G_CALLBACK(on_toggle), NULL);
after_n = gtk_radio_button_new_from_widget(GTK_RADIO_BUTTON(no_pause));
pause_counter = gtk_spin_button_new_with_range(0, 65535, 1);
gtk_box_pack_start(GTK_BOX(after_n_box), after_n, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(after_n_box), label1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(after_n_box), pause_counter, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(after_n_box), label2, FALSE, FALSE, 0);
g_signal_connect(pause_counter, "value-changed", G_CALLBACK(counter_changed), NULL);
gtk_box_pack_start(GTK_BOX(box), after_n_box, TRUE, TRUE, 0);
g_signal_connect(after_n, "toggled", G_CALLBACK(on_toggle), NULL);
gtk_widget_show_all(box);
return box;
}
void body::update_automatic_pause()
{
unsigned short count;
switch (libsaria::deck::get_pause_type()) {
case PS_NONE:
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(no_pause), true);
break;
case PS_AFTER_N:
count = libsaria::deck::get_pause_count();
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(after_n), true);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(pause_counter), count);
break;
}
}
}; /* Namespace: ocarina */

View File

@ -2,6 +2,7 @@
#include <ocarina/ocarina.h>
#include <libsaria/audio.h>
#include <libsaria/track.h>
#include <libsaria/deck.h>
#include <libsaria/idle.h>
static libsaria::Track *cur_track = NULL;
@ -88,6 +89,36 @@ static void slider_changed(GtkWidget *w, GtkScrollType s, gdouble v, gpointer d)
libsaria::audio::seek_to(v);
}
static void update_autopause()
{
if (libsaria::deck::get_pause_type() == PS_NONE)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(get_widget("NoPause")), true);
else {
unsigned short count = libsaria::deck::get_pause_count();
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(get_widget("PauseAfterN")), true);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget("PauseCounter")), count);
}
}
static void toggle_pause(GtkWidget *b, gpointer d)
{
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b)))
return;
if (b == get_widget("NoPause"))
libsaria::deck::set_pause_type(PS_NONE, 0);
else {
unsigned short count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(get_widget("PauseCounter")));
libsaria::deck::set_pause_type(PS_AFTER_N, count);
}
}
static void counter_changed(GtkWidget *b, GtkScrollType *s, gpointer d)
{
unsigned short count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(get_widget("PauseCounter")));
libsaria::deck::set_pause_type(PS_AFTER_N, count);
}
bool update_idle_bar(int size)
{
GtkWidget *idle = get_widget("IdleProgress");
@ -115,9 +146,13 @@ void update_status()
update_labels();
update_buttons();
update_progress();
update_autopause();
}
void init_status()
{
connect_signal("TrackProgress", "change-value", G_CALLBACK(slider_changed), NULL);
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);
}

View File

@ -318,7 +318,7 @@
</packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton1">
<object class="GtkSpinButton" id="PauseCounter">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char"></property>