libsaria: Create notifications for autopause

- Send one when the pause type changes
- Send another when the pause count changes

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-22 08:04:21 -04:00
parent 00111fc87b
commit fc40dd535c
6 changed files with 35 additions and 23 deletions

View File

@ -9,6 +9,8 @@ enum notify_t {
PATH_UPDATED, // libsaria::library::Path *
PLAYING, // NULL
PAUSED, // NULL
PAUSE_TYPE, // AutoPauseType *
PAUSE_COUNT, // unsigned int *
NOTIFY_SIZE,
};

View File

@ -4,6 +4,7 @@
#include <libsaria/notify.h>
#include <libsaria/track.h>
#include <libsaria/print.h>
#include <libsaria/deck.h>
#include <gtk/gtk.h>
#include <string>
@ -32,9 +33,11 @@ void init_playlist();
/* status.cpp */
bool update_idle_bar(int);
void update_length_label(string &);
void update_status();
void update_labels(libsaria::Track *);
void update_buttons(notify_t);
void update_progress();
void update_autopause_type(AutoPauseType *);
void update_autopause_count(unsigned int *);
void init_status();
namespace ocarina

View File

@ -1,6 +1,7 @@
// Copyright (c) 2012 Bryan Schumaker.
#include <libsaria/playlist.h>
#include <libsaria/library.h>
#include <libsaria/notify.h>
#include <libsaria/audio.h>
#include <libsaria/track.h>
#include <libsaria/print.h>
@ -41,20 +42,20 @@ static libsaria::Playlist *get_active_playlist()
static bool check_play()
{
bool ret = true;
switch(pause_type) {
case PS_AFTER_N:
if (pause_count == 0) {
ret = false;
pause_type = PS_NONE;
libsaria::deck::set_pause_type(PS_NONE, 0);
return false;
} else {
pause_count--;
libsaria::notify(PAUSE_COUNT, &pause_count);
}
pause_count--;
default:
break;
}
return ret;
return true;
}
namespace libsaria
@ -213,6 +214,8 @@ namespace libsaria
{
pause_type = type;
pause_count = count;
notify(PAUSE_TYPE, &pause_type);
notify(PAUSE_COUNT, &count);
}
AutoPauseType deck::get_pause_type()

View File

@ -15,6 +15,12 @@ void on_notify(notify_t event, void *data)
case PLAYING:
case PAUSED:
update_buttons(event);
break;
case PAUSE_TYPE:
update_autopause_type((AutoPauseType *)data);
break;
case PAUSE_COUNT:
update_autopause_count((unsigned int *)data);
default:
break;
}

View File

@ -73,7 +73,7 @@ static void idle_add()
static gboolean timeout_poll(gpointer data)
{
idle_add();
update_status();
update_progress();
return TRUE;
}

View File

@ -47,7 +47,7 @@ void update_buttons(notify_t event)
}
}
static void update_progress()
void update_progress()
{
GtkWidget *label = get_widget("PosLabel");
GtkWidget *progress = get_widget("TrackProgress");
@ -72,15 +72,19 @@ static void slider_changed(GtkWidget *w, GtkScrollType s, gdouble v, gpointer d)
libsaria::audio::seek_to(v);
}
static void update_autopause()
void update_autopause_type(AutoPauseType *type)
{
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);
}
GtkWidget *button;
if (*type == PS_NONE)
button = get_widget("NoPause");
else
button = get_widget("PauseAfterN");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), true);
}
void update_autopause_count(unsigned int *count)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget("PauseCounter")), *count);
}
static void toggle_pause(GtkWidget *b, gpointer d)
@ -142,12 +146,6 @@ void update_length_label(string &text)
gtk_label_set_text(GTK_LABEL(label), text.c_str());
}
void update_status()
{
update_progress();
update_autopause();
}
void init_status()
{
connect_signal("TrackProgress", "change-value", G_CALLBACK(slider_changed), NULL);