libsaria: Only use the library::Driver for notifications

This allows other tools to be written to modify the library of a
currently running program without having to create a library driver
instance.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-17 09:00:13 -04:00
parent a029a30d3a
commit 03d35fee77
3 changed files with 26 additions and 16 deletions

View File

@ -23,10 +23,11 @@ namespace libsaria
Driver();
~Driver();
void add_path(string);
virtual void path_added(Path *) = 0;
};
void add_path(string);
/*namespace iter
{
void reset();

View File

@ -12,6 +12,7 @@ using namespace std;
#include <libsaria/stack.h>*/
static list<struct libsaria::library::Path> path_list;
static list<libsaria::library::Driver *> driver_list;
/*list<libsaria::LibraryPath> path_list;
libsaria::Playlist lib_playlist(PL_RANDOM | PL_SEQUENTIAL | PL_FILTER);
static map<sid_t, libsaria::Track *> lookup_map;
@ -32,15 +33,37 @@ static void do_update(libsaria::LibraryPath *path):
path->update();
}
*/
namespace libsaria
{
void library::add_path(string dir)
{
struct Path path;
list<libsaria::library::Driver *>::iterator it;
path.visible = true;
path.lib_id = lookup_fileid(dir);
path.path = dir;
if (path.lib_id < 0)
return;
path_list.push_back(path);
/* Notify library drivers that a new path has been added */
for (it = driver_list.begin(); it != driver_list.end(); it++)
(*it)->path_added(&path);
}
library::Driver::Driver()
{
driver_list.push_back(this);
}
library::Driver::~Driver()
{
driver_list.remove(this);
}
/*
void library::init()
@ -79,21 +102,7 @@ namespace libsaria
{
trigger_callback(LIBRARY_REFRESH);
}
*/
void library::Driver::add_path(string dir)
{
struct Path path;
path.visible = true;
path.lib_id = lookup_fileid(dir);
path.path = dir;
if (path.lib_id < 0)
return;
path_list.push_back(path);
path_added(&path);
}
/*
void library::remove_path(string dir)
{
list<LibraryPath>::iterator it;

View File

@ -49,7 +49,7 @@ static void on_click_add(GtkWidget *b, GdkEvent *e, gpointer d)
string dir = ocarina::choose_dir();
if (dir != "") {
println("Scanning dir: " + dir);
driver.add_path(dir);
libsaria::library::add_path(dir);
}
}