libsaria: Created a SourceModel class

The source model class is used to more tightly control how songs are
inserted into the UI.  I provide an insert() function that the library's
for_each() function can take advantage of.  This allows me to directly
insert songs into the UI rather than having to use a static function as
the "middle man"
This commit is contained in:
Bryan Schumaker 2011-10-29 15:14:01 -04:00
parent e5bd2471b0
commit 136f12bc7c
5 changed files with 37 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#define LIBSARIA_LIBRARY_H
#include <libsaria/track.h>
#include <libsaria/model.h>
#include <list>
#include <string>
@ -26,7 +27,7 @@ namespace libsaria
void remove_path(string);
void play_id(ino_t &);
void get_info(ino_t &, void(*)(Track &));
void for_each(void (*)(Track &));
void for_each(SourceModel *);
void for_each_path(void (*)(struct PathInfo &));
unsigned int size();

19
include/libsaria/model.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef LIBSARIA_SOURCE_H
#define LIBSARIA_SOURCE_H
#include <libsaria/track.h>
namespace libsaria
{
class SourceModel
{
public:
SourceModel();
virtual ~SourceModel() = 0;
virtual void insert(Track &) = 0;
};
}
#endif /* LIBSARIA_SOURCE_H */

View File

@ -4,6 +4,7 @@
using namespace std;
#include <libsaria/audio.h>
#include <libsaria/model.h>
#include <libsaria/callback.h>
#include <libsaria/library.h>
#include "library.h"
@ -24,13 +25,13 @@ LibraryPath *get_library_path(string dir)
return NULL;
}
void LibraryPath::for_each(void (*ins_func)(Track &))
void LibraryPath::for_each(libsaria::SourceModel *model)
{
map<ino_t, TrackTag>::iterator it;
for (it = file_map.begin(); it != file_map.end(); it++) {
Track track = Track(it->first, &it->second);
ins_func(track);
model->insert(track);
}
}
@ -67,11 +68,11 @@ bool LibraryPath::play_id(ino_t &id)
namespace libsaria
{
void library::for_each(void (*ins_func)(Track &))
void library::for_each(SourceModel *model)
{
map<string, LibraryPath>::iterator it;
for (it = path_map.begin(); it != path_map.end(); it++)
it->second.for_each(ins_func);
it->second.for_each(model);
}
void library::for_each_path(void (*info_func)(struct library::PathInfo &))

View File

@ -6,6 +6,7 @@
using namespace std;
#include <libsaria/library.h>
#include <libsaria/model.h>
#include <libsaria/path.h>
class LibraryPath
@ -19,7 +20,7 @@ class LibraryPath
LibraryPath(InFile &, string);
~LibraryPath();
void for_each(void (*)(Track &));
void for_each(libsaria::SourceModel *);
void get_info(void (*)(struct libsaria::library::PathInfo &));
bool get_info_id(ino_t &, void (*)(Track &));
void insert_track(ino_t &, TrackTag &);

9
libsaria/model.cpp Normal file
View File

@ -0,0 +1,9 @@
#include <libsaria/model.h>
namespace libsaria
{
SourceModel::SourceModel(){}
SourceModel::~SourceModel(){}
};