libsaria: Add in a simple notification system
Right now it only notifies that an event happened. I think I should eventually pass in an additional argument related to the event that happened. This will allow me to send out notifications for preferences or library paths changing. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
0402930098
commit
db8be5659c
|
@ -1,6 +1,7 @@
|
|||
#ifndef LIBSARIA_H
|
||||
#define LIBSARIA_H
|
||||
|
||||
#include <libsaria/notify.h>
|
||||
#include <libsaria/track.h>
|
||||
|
||||
namespace libsaria
|
||||
|
@ -9,6 +10,7 @@ namespace libsaria
|
|||
int argc;
|
||||
char **argv;
|
||||
string name;
|
||||
void (*on_notify)(notify_t);
|
||||
};
|
||||
|
||||
void init(struct initdata *);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#ifndef LIBSARIA_NOTIFY_H
|
||||
#define LIBSARIA_NOTIFY_H
|
||||
|
||||
enum notify_t {
|
||||
TRACK_CHANGED,
|
||||
NOTIFY_SIZE,
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
void notify(notify_t);
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_NOTIFY_H */
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef OCARINA_H
|
||||
#define OCARINA_H
|
||||
|
||||
#include <libsaria/notify.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -10,6 +11,9 @@ using namespace std;
|
|||
/* library.cpp */
|
||||
void init_library();
|
||||
|
||||
/* notify.cpp */
|
||||
void on_notify(notify_t);
|
||||
|
||||
/* ocarina.cpp */
|
||||
string lib_file(const string &);
|
||||
GObject *get_object(const string &);
|
||||
|
@ -27,6 +31,7 @@ void init_playlist();
|
|||
bool update_idle_bar(int);
|
||||
void update_length_label(string &);
|
||||
void update_status();
|
||||
void update_labels();
|
||||
void init_status();
|
||||
|
||||
namespace ocarina
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker.
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/notify.h>
|
||||
#include <libsaria/format.h>
|
||||
#include <libsaria/prefs.h>
|
||||
#include <libsaria/print.h>
|
||||
|
@ -12,12 +13,14 @@
|
|||
#include <libsaria/fs.h>
|
||||
|
||||
static libsaria::Track outside_track;
|
||||
static libsaria::initdata *app_data;
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void init(struct initdata *init)
|
||||
{
|
||||
app_data = init;
|
||||
srand( time(NULL) );
|
||||
println("Initializing libsaria");
|
||||
|
||||
|
@ -53,4 +56,10 @@ namespace libsaria
|
|||
outside_track.load(true);
|
||||
}
|
||||
|
||||
void notify(notify_t event)
|
||||
{
|
||||
if (app_data->on_notify)
|
||||
app_data->on_notify(event);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker.
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/notify.h>
|
||||
#include <libsaria/format.h>
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/audio.h>
|
||||
|
@ -183,6 +184,7 @@ namespace libsaria
|
|||
}
|
||||
|
||||
cur = this;
|
||||
notify(TRACK_CHANGED);
|
||||
}
|
||||
|
||||
void Track::load(bool play)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
void on_notify(notify_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case TRACK_CHANGED:
|
||||
update_labels();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker
|
||||
#include <version.h>
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/notify.h>
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/deck.h>
|
||||
#include <libsaria/idle.h>
|
||||
|
@ -175,6 +176,7 @@ int main(int argc, char **argv)
|
|||
argc,
|
||||
argv,
|
||||
"ocarina", /* app name */
|
||||
on_notify, /* notification handler */
|
||||
};
|
||||
println("Ocarina " + vers_str());
|
||||
find_lib_path();
|
||||
|
|
|
@ -32,13 +32,9 @@ static void refresh_widgets()
|
|||
set_label("DurLabel", cur_track->get_lenstr(), "");
|
||||
}
|
||||
|
||||
static void update_labels()
|
||||
void update_labels()
|
||||
{
|
||||
libsaria::Track *cur = libsaria::current_track();
|
||||
if (cur == cur_track)
|
||||
return;
|
||||
|
||||
cur_track = cur;
|
||||
cur_track = libsaria::current_track();
|
||||
refresh_widgets();
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(get_widget("BanButton")),
|
||||
cur_track->get_banned());
|
||||
|
@ -162,7 +158,6 @@ void update_length_label(string &text)
|
|||
|
||||
void update_status()
|
||||
{
|
||||
update_labels();
|
||||
update_buttons();
|
||||
update_progress();
|
||||
update_autopause();
|
||||
|
|
Loading…
Reference in New Issue