core/tags/track: Replace tags :: track_size() with track_db_get()
We want to loop over the track database in several places, so let's make this easier by just returning the database itself. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
eea0f57cf8
commit
192bdc3ac7
|
@ -142,11 +142,10 @@ static void scan_path(struct scan_info &scan)
|
|||
|
||||
static void validate_library(struct library *&library)
|
||||
{
|
||||
struct track *track;
|
||||
struct track *track, *next;
|
||||
|
||||
for (unsigned int i = 0; i < tags :: track_size(); i++) {
|
||||
track = track_get(i);
|
||||
if (!track || (track->library() != library))
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (track->library() != library)
|
||||
continue;
|
||||
|
||||
if (g_file_test(track->path().c_str(), G_FILE_TEST_EXISTS) == false) {
|
||||
|
@ -164,13 +163,12 @@ static void validate_library(struct library *&library)
|
|||
|
||||
void collection :: init()
|
||||
{
|
||||
struct track *track;
|
||||
struct track *track, *next;
|
||||
|
||||
library_q.load();
|
||||
|
||||
for (unsigned int i = 0; i < tags :: track_size(); i++) {
|
||||
track = track_get(i);
|
||||
if (track && (track->library()->li_enabled))
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (track->library()->li_enabled)
|
||||
library_q.add(track);
|
||||
}
|
||||
}
|
||||
|
@ -220,16 +218,15 @@ void collection :: update_all()
|
|||
|
||||
void collection :: set_enabled(struct library *library, bool enabled)
|
||||
{
|
||||
struct track *track;
|
||||
struct track *track, *next;
|
||||
|
||||
if (!library || (library->li_enabled == enabled))
|
||||
return;
|
||||
|
||||
library_set_enabled(library, enabled);
|
||||
|
||||
for (unsigned int i = 0; i < tags :: track_size(); i++) {
|
||||
track = track_get(i);
|
||||
if (track && (track->library() == library)) {
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (track->library() == library) {
|
||||
if (enabled)
|
||||
library_q.add(track);
|
||||
else
|
||||
|
|
|
@ -33,15 +33,12 @@ public:
|
|||
|
||||
unsigned int find_average_count()
|
||||
{
|
||||
struct track *track;
|
||||
struct track *track, *next;
|
||||
unsigned int total = 0, count = 0;
|
||||
|
||||
for (unsigned int i = 0; i < tags :: track_size(); i++) {
|
||||
track = track_get(i);
|
||||
if (track != NULL) {
|
||||
total += track->count();
|
||||
count++;
|
||||
}
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
total += track->count();
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
|
@ -61,18 +58,15 @@ public:
|
|||
|
||||
void dynamic_fill(const std::string &name)
|
||||
{
|
||||
struct track *track;
|
||||
struct track *track, *next;
|
||||
unsigned int avg = 0;
|
||||
|
||||
if ((name == "Most Played") || (name == "Least Played"))
|
||||
avg = find_average_count();
|
||||
|
||||
clear();
|
||||
for (unsigned int i = 0; i < tags :: track_size(); i++) {
|
||||
track = track_get(i);
|
||||
if (track != NULL)
|
||||
dynamic_add(name, track, avg);
|
||||
}
|
||||
db_for_each(track, next, track_db_get())
|
||||
dynamic_add(name, track, avg);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -162,6 +162,11 @@ void track_db_commit()
|
|||
db_save(&track_db);
|
||||
}
|
||||
|
||||
const database<struct track> *track_db_get()
|
||||
{
|
||||
return &track_db;
|
||||
}
|
||||
|
||||
struct track *track_add(struct album *album, struct artist *artist,
|
||||
struct genre *genre, struct library *library,
|
||||
const std::string &filepath, const std::string &name,
|
||||
|
@ -194,8 +199,3 @@ struct track *track_get(const unsigned int index)
|
|||
{
|
||||
return db_at(&track_db, index);
|
||||
}
|
||||
|
||||
unsigned int tags :: track_size()
|
||||
{
|
||||
return db_actual_size(&track_db);
|
||||
}
|
||||
|
|
|
@ -115,17 +115,6 @@ struct track : public GenericTag {
|
|||
void write(file &);
|
||||
};
|
||||
|
||||
namespace tags
|
||||
{
|
||||
/**
|
||||
* Called to find the number of rows in the track_db,
|
||||
* including NULL rows.
|
||||
*
|
||||
* @return The Database::actual_size() of the track_db.
|
||||
*/
|
||||
unsigned int track_size();
|
||||
}
|
||||
|
||||
|
||||
/* Called to initialize the track database. */
|
||||
void track_db_init();
|
||||
|
@ -136,6 +125,9 @@ void track_db_deinit();
|
|||
/* Called to commit the track database. */
|
||||
void track_db_commit();
|
||||
|
||||
/* Called to access the track database. */
|
||||
const database<struct track> *track_db_get();
|
||||
|
||||
/* Called to add a track tag to the database. */
|
||||
struct track *track_add(struct album *, struct artist *, struct genre *,
|
||||
struct library *, const std::string &,
|
||||
|
|
|
@ -138,7 +138,7 @@ static void test_track_tag_lookup()
|
|||
"Ocarina Medley", 232, 12);
|
||||
test_not_equal(b, a);
|
||||
test_equal(library->li_size, (unsigned)2);
|
||||
test_equal(tags :: track_size(), b->index() + 1);
|
||||
test_equal(track_db_get()->db_size, b->index() + 1);
|
||||
|
||||
|
||||
test_equal(track_get(a->index()), a);
|
||||
|
@ -157,7 +157,7 @@ static void test_track_tag_lookup()
|
|||
track_db_commit();
|
||||
test_track_tag_load_db(1);
|
||||
test_equal(library->li_size, (unsigned)1);
|
||||
test_equal(tags :: track_size(), b->index() + 1);
|
||||
test_equal(db_actual_size(track_db_get()), b->index() + 1);
|
||||
|
||||
|
||||
a = track_add(album, artist, genre, library,
|
||||
|
@ -165,7 +165,7 @@ static void test_track_tag_lookup()
|
|||
"Legend of Zelda Medley", 288, 13);
|
||||
test_not_equal(a, (struct track *)NULL);
|
||||
verify_track_tag(a, 2);
|
||||
test_equal(tags :: track_size(), a->index() + 1);
|
||||
test_equal(db_actual_size(track_db_get()), a->index() + 1);
|
||||
|
||||
track_remove_all(library);
|
||||
test_track_tag_load_db(0);
|
||||
|
|
Loading…
Reference in New Issue