libsaria: Move library update code to new file
Putting it all in path.cpp along with other LibraryPath functions was getting confusing. I'd rather just have it all in a new file for simplicity.
This commit is contained in:
parent
297c0637ea
commit
d23c1c72f0
|
@ -2,7 +2,6 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <libsaria/tags.h>
|
||||
#include <libsaria/library.h>
|
||||
#include "library.h"
|
||||
|
||||
|
@ -18,83 +17,14 @@ LibraryPath::~LibraryPath()
|
|||
{
|
||||
}
|
||||
|
||||
void LibraryPath::insert_track(TrackTag &tag)
|
||||
{
|
||||
file_list.push_back(tag);
|
||||
}
|
||||
|
||||
void LibraryPath::update()
|
||||
{
|
||||
ScanTask *task = new ScanTask(this, path, false);
|
||||
task->queue();
|
||||
}
|
||||
|
||||
unsigned int LibraryPath::size()
|
||||
{
|
||||
return file_list.size();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Definitions for the ScanTask class
|
||||
*/
|
||||
ScanTask::ScanTask(LibraryPath *lib_path, string scan_dir, bool end)
|
||||
{
|
||||
library = lib_path;
|
||||
dir = scan_dir;
|
||||
end_dir = end;
|
||||
}
|
||||
|
||||
ScanTask::~ScanTask()
|
||||
{}
|
||||
|
||||
void ScanTask::tag_file(file filepath)
|
||||
{
|
||||
try {
|
||||
TrackTag tag(dir + "/" + filepath.name, filepath.d_ino);
|
||||
library->insert_track(tag);
|
||||
} catch (string message) {
|
||||
println(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 1) Read a directory
|
||||
* 2) Find tags for each music file
|
||||
* 3) Create and queue a new ScanTask for each subdirectory
|
||||
*/
|
||||
void ScanTask::run_task()
|
||||
{
|
||||
int last, i = 0;
|
||||
list<file> files;
|
||||
list<file> dirs;
|
||||
list<file>::iterator it;
|
||||
ScanTask *scan;
|
||||
SaveTask *save;
|
||||
|
||||
readdir(dir, files, dirs);
|
||||
|
||||
for (it = files.begin(); it != files.end(); it++)
|
||||
tag_file(*it);
|
||||
|
||||
last = dirs.size() - 1;
|
||||
for (it = dirs.begin(); it != dirs.end(); it++) {
|
||||
scan = new ScanTask(library, dir + "/" + (*it).name, i == last);
|
||||
scan->queue();
|
||||
i++;
|
||||
}
|
||||
|
||||
if (end_dir == true) {
|
||||
print("Library path size: ");
|
||||
println(library->size());
|
||||
save = new SaveTask(libsaria::library::save);
|
||||
save->queue_front();
|
||||
libsaria::library::refresh();
|
||||
}
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void library::add_path(string dir)
|
||||
{
|
||||
get_path_list()->push_back(LibraryPath(dir));
|
||||
|
@ -116,8 +46,4 @@ namespace libsaria
|
|||
}
|
||||
}
|
||||
|
||||
void library::update_path(string dir)
|
||||
{
|
||||
get_path(dir)->update();
|
||||
}
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
|
||||
#include <libsaria/tags.h>
|
||||
#include <libsaria/library.h>
|
||||
#include "library.h"
|
||||
|
||||
void LibraryPath::insert_track(TrackTag &tag)
|
||||
{
|
||||
file_list.push_back(tag);
|
||||
}
|
||||
|
||||
void LibraryPath::update()
|
||||
{
|
||||
ScanTask *task = new ScanTask(this, path, false);
|
||||
task->queue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Definitions for the ScanTask class
|
||||
*/
|
||||
ScanTask::ScanTask(LibraryPath *lib_path, string scan_dir, bool end)
|
||||
{
|
||||
library = lib_path;
|
||||
dir = scan_dir;
|
||||
end_dir = end;
|
||||
}
|
||||
|
||||
ScanTask::~ScanTask()
|
||||
{}
|
||||
|
||||
void ScanTask::tag_file(file filepath)
|
||||
{
|
||||
try {
|
||||
TrackTag tag(dir + "/" + filepath.name, filepath.d_ino);
|
||||
library->insert_track(tag);
|
||||
} catch (string message) {
|
||||
println(message);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 1) Read a directory
|
||||
* 2) Find tags for each music file
|
||||
* 3) Create and queue a new ScanTask for each subdirectory
|
||||
*/
|
||||
void ScanTask::run_task()
|
||||
{
|
||||
int last, i = 0;
|
||||
list<file> files;
|
||||
list<file> dirs;
|
||||
list<file>::iterator it;
|
||||
ScanTask *scan;
|
||||
SaveTask *save;
|
||||
|
||||
readdir(dir, files, dirs);
|
||||
|
||||
for (it = files.begin(); it != files.end(); it++)
|
||||
tag_file(*it);
|
||||
|
||||
last = dirs.size() - 1;
|
||||
for (it = dirs.begin(); it != dirs.end(); it++) {
|
||||
scan = new ScanTask(library, dir + "/" + (*it).name, i == last);
|
||||
scan->queue();
|
||||
i++;
|
||||
}
|
||||
|
||||
if (end_dir == true) {
|
||||
print("Library path size: ");
|
||||
println(library->size());
|
||||
save = new SaveTask(libsaria::library::save);
|
||||
save->queue_front();
|
||||
libsaria::library::refresh();
|
||||
}
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void library::update_path(string dir)
|
||||
{
|
||||
get_path(dir)->update();
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
Loading…
Reference in New Issue