libsaria: Refresh index while scanning
This keeps the index up-to-date with the library. Tracks are indexed as they are scanned, then the current filter string is run through the index again to update it.
This commit is contained in:
parent
26a18f331e
commit
abfd67cc84
|
@ -11,6 +11,7 @@ namespace libsaria
|
|||
|
||||
void add_track(libsaria::Track &);
|
||||
void filter(string &);
|
||||
void refresh();
|
||||
bool is_visible(sid_t &);
|
||||
bool is_filtered();
|
||||
unsigned int size();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "index.h"
|
||||
|
||||
set<sid_t> results;
|
||||
list<string> *cur_terms;
|
||||
static bool filtered = false;
|
||||
|
||||
/*
|
||||
|
@ -76,21 +77,31 @@ static void do_filter(list<string> *terms)
|
|||
}
|
||||
}
|
||||
|
||||
static void run_filter()
|
||||
{
|
||||
results.clear();
|
||||
|
||||
if (cur_terms == NULL || cur_terms->size() == 0)
|
||||
filtered = false;
|
||||
else {
|
||||
do_filter(cur_terms);
|
||||
filtered = true;
|
||||
}
|
||||
trigger_callback(REFILTER);
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void index::filter(string &search)
|
||||
{
|
||||
list<string> *terms = format_text(search);
|
||||
results.clear();
|
||||
cur_terms = format_text(search);
|
||||
run_filter();
|
||||
}
|
||||
|
||||
if (terms->size() == 0)
|
||||
filtered = false;
|
||||
else {
|
||||
do_filter(terms);
|
||||
filtered = true;
|
||||
}
|
||||
trigger_callback(REFILTER);
|
||||
void index::refresh()
|
||||
{
|
||||
run_filter();
|
||||
}
|
||||
|
||||
bool index::is_visible(sid_t &songid)
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/index.h>
|
||||
#include "library.h"
|
||||
|
||||
void LibraryPath::insert_track(sid_t &inode, libsaria::Track &tag)
|
||||
void LibraryPath::insert_track(sid_t &inode, libsaria::Track &track)
|
||||
{
|
||||
if (find_id(inode) == file_list.end())
|
||||
file_list.push_back(tag);
|
||||
if (find_id(inode) == file_list.end()) {
|
||||
file_list.push_back(track);
|
||||
libsaria::index::add_track(track);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryPath::update()
|
||||
|
@ -68,6 +71,7 @@ void ScanTask::run_task()
|
|||
println("Library path size: %d", library->size());
|
||||
save = new SaveTask(libsaria::library::save);
|
||||
save->queue_front();
|
||||
libsaria::index::refresh();
|
||||
libsaria::library::refresh();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue