108 lines
1.8 KiB
C++
108 lines
1.8 KiB
C++
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
#include <libsaria/audio.h>
|
|
#include <libsaria/library.h>
|
|
#include "library.h"
|
|
|
|
void LibraryPath::for_each(libsaria::SourceModel *model)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
|
|
for (it = file_list.begin(); it != file_list.end(); it++) {
|
|
Track track = Track(&(*it));
|
|
model->insert(track);
|
|
}
|
|
}
|
|
|
|
string LibraryPath::get_path()
|
|
{
|
|
return path;
|
|
}
|
|
|
|
list<TrackTag> *LibraryPath::get_list()
|
|
{
|
|
return &file_list;
|
|
}
|
|
|
|
void LibraryPath::get_info(void (*info_func)(struct libsaria::library::PathInfo &))
|
|
{
|
|
struct libsaria::library::PathInfo info;
|
|
info.path = path;
|
|
info.size = size();
|
|
info_func(info);
|
|
}
|
|
|
|
list<TrackTag>::iterator LibraryPath::find_id(ino_t &id)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
for (it = file_list.begin(); it != file_list.end(); it++) {
|
|
if (it->get_inode() == id)
|
|
break;
|
|
}
|
|
return it;
|
|
}
|
|
|
|
bool LibraryPath::get_info_id(ino_t &id, void (*func)(Track &))
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
it = find_id(id);
|
|
if (it != file_list.end()) {
|
|
Track track = Track(&(*it));
|
|
func(track);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool LibraryPath::play_id(ino_t &id)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
it = find_id(id);
|
|
if (it == file_list.end())
|
|
return false;
|
|
libsaria::audio::load(it->get_filepath());
|
|
return true;
|
|
}
|
|
|
|
LibraryPath::LibraryPath(string dir)
|
|
{
|
|
path = dir;
|
|
}
|
|
|
|
LibraryPath::~LibraryPath()
|
|
{
|
|
}
|
|
|
|
unsigned int LibraryPath::size()
|
|
{
|
|
return file_list.size();
|
|
}
|
|
|
|
namespace libsaria
|
|
{
|
|
|
|
void library::add_path(string dir)
|
|
{
|
|
get_path_list()->push_back(LibraryPath(dir));
|
|
update_path(dir);
|
|
}
|
|
|
|
void library::remove_path(string dir)
|
|
{
|
|
list<LibraryPath> *path_list = get_path_list();
|
|
list<LibraryPath>::iterator it;
|
|
|
|
for (it = path_list->begin(); it != path_list->end(); it++) {
|
|
if (it->get_path() == dir) {
|
|
path_list->erase(it);
|
|
save();
|
|
refresh();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}; /* Namespace: libsaria */
|