Create an IDLE_ADD notification

Used for setting up g_idle_add().  Without this, banning songs will save
but unbanning them won't.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-29 10:17:17 -04:00
parent e9f8c34e5a
commit 9801e9335b
5 changed files with 17 additions and 13 deletions

View File

@ -3,6 +3,7 @@
#define LIBSARIA_NOTIFY_H
enum notify_t {
IDLE_ADD, // NULL
TRACK_CHANGED, // libsaria::Track *
PATH_ADDED, // libsaria::library::Path *
PATH_DELETED, // libsaria::library::Path *

View File

@ -19,6 +19,7 @@ void on_notify(notify_t, void *);
/* ocarina.cpp */
string lib_file(const string &);
gboolean ocarina_idle(gpointer);
GObject *get_object(const string &);
GtkWidget *get_widget(const string &);
void connect_signal(const string &, const string &, GCallback, void *);

View File

@ -1,4 +1,5 @@
// Copyright (c) 2011 Bryan Schumaker.
#include <libsaria/notify.h>
#include <libsaria/idle.h>
#include <libsaria/list.h>
#include <libsaria/print.h>
@ -55,6 +56,7 @@ namespace libsaria
else
idle_queue.push_back(task);
queued += 1.0;
notify(IDLE_ADD, NULL);
}
void idle::cancel_all(void *data)

View File

@ -1,10 +1,22 @@
// Copyright (c) 2012 Bryan Schumaker.
#include <libsaria/idle.h>
#include <ocarina/ocarina.h>
static void idle_add()
{
if (libsaria::idle::size() == 1) {
println("Adding idle callback");
g_idle_add(ocarina_idle, NULL);
}
}
void on_notify(notify_t event, void *data)
{
/* TODO: Array of function pointers */
switch (event) {
case IDLE_ADD:
idle_add();
break;
case TRACK_CHANGED:
update_labels((libsaria::Track *)data);
break;

View File

@ -53,26 +53,14 @@ string lib_file(const string &path)
return res;
}
static gboolean ocarina_idle(gpointer data)
gboolean ocarina_idle(gpointer data)
{
int size = libsaria::idle::run_task();
return update_idle_bar(size);
}
static void idle_add()
{
static int size = 0;
int cur = libsaria::idle::size();
if ((cur > 0) && (cur > size)) {
println("Adding idle callback");
g_idle_add(ocarina_idle, NULL);
size = cur;
}
}
static gboolean timeout_poll(gpointer data)
{
idle_add();
update_progress();
return TRUE;
}