libsaria: Create an IdleTask for indexing the library
Right now this will only be triggered when the library is loaded from disk. Once I get farther I can easily create a function to index a track as it is added to the library (so I won't need to reindex everything during this case)
This commit is contained in:
parent
eab73ffb39
commit
ef36c58e96
|
@ -48,6 +48,7 @@ namespace libsaria
|
|||
}
|
||||
|
||||
rebuild_list();
|
||||
reindex();
|
||||
}
|
||||
|
||||
void library::save()
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#include "library.h"
|
||||
|
||||
IndexTask::IndexTask() {};
|
||||
IndexTask::~IndexTask() {};
|
||||
|
||||
void IndexTask::index_track(TrackTag *tag)
|
||||
{
|
||||
track_list.push_back(tag);
|
||||
}
|
||||
|
||||
void IndexTask::run_task()
|
||||
{
|
||||
println("Indexing!");
|
||||
}
|
||||
|
||||
static void reindex_path(list<TrackTag> *tag_list)
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
unsigned int i = 0, j = 0;
|
||||
IndexTask *task = new IndexTask();
|
||||
|
||||
for (it = tag_list->begin(); it != tag_list->end(); it++) {
|
||||
task->index_track(&(*it));
|
||||
i++;
|
||||
if (i == 50) {
|
||||
task->queue();
|
||||
task = new IndexTask();
|
||||
i = 0;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
task->queue();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void library::reindex()
|
||||
{
|
||||
list<LibraryPath> *path_list = get_path_list();
|
||||
list<LibraryPath>::iterator it;
|
||||
|
||||
for (it = path_list->begin(); it != path_list->end(); it++)
|
||||
reindex_path(it->get_list());
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
|
@ -45,6 +45,17 @@ class ScanTask : public IdleTask
|
|||
void run_task();
|
||||
};
|
||||
|
||||
class IndexTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
list<TrackTag *> track_list;
|
||||
public:
|
||||
IndexTask();
|
||||
~IndexTask();
|
||||
void index_track(TrackTag *);
|
||||
void run_task();
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
namespace library
|
||||
|
@ -52,6 +63,7 @@ namespace libsaria
|
|||
list<LibraryPath> *get_path_list();
|
||||
LibraryPath *get_path(string);
|
||||
void rebuild_list();
|
||||
void reindex();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue