core/tags/track: Count the total number of tracks played
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a97ec66e7f
commit
1973d15605
|
@ -11,6 +11,7 @@
|
|||
|
||||
static struct database track_db;
|
||||
static unsigned int unplayed_count = 0;
|
||||
static unsigned int play_count = 0;
|
||||
|
||||
static gchar *__track_key(struct library *library, gchar *path)
|
||||
{
|
||||
|
@ -92,6 +93,7 @@ static void track_free(struct db_entry *dbe)
|
|||
{
|
||||
struct track *track = TRACK(dbe);
|
||||
|
||||
play_count -= track->tr_count;
|
||||
if (track->tr_count == 0)
|
||||
unplayed_count--;
|
||||
if (track->tr_library)
|
||||
|
@ -127,6 +129,7 @@ static struct db_entry *track_read(struct file *file)
|
|||
date_read(file, &track->tr_date);
|
||||
file_readf(file, "%u %u", &track->tr_count, &track->tr_length);
|
||||
|
||||
play_count += track->tr_count;
|
||||
if (track->tr_count == 0)
|
||||
unplayed_count++;
|
||||
|
||||
|
@ -197,6 +200,11 @@ unsigned int track_db_count_unplayed()
|
|||
return unplayed_count;
|
||||
}
|
||||
|
||||
unsigned int track_db_count_plays()
|
||||
{
|
||||
return play_count;
|
||||
}
|
||||
|
||||
struct track *track_add(struct library *library, const gchar *filepath)
|
||||
{
|
||||
unsigned int offset = strlen(library->li_path) + 1;
|
||||
|
@ -275,6 +283,7 @@ void track_played(struct track *track)
|
|||
if (track->tr_count == 0)
|
||||
unplayed_count--;
|
||||
track->tr_count++;
|
||||
play_count++;
|
||||
date_today(&track->tr_date);
|
||||
track_db_commit();
|
||||
}
|
||||
|
|
|
@ -77,6 +77,9 @@ const struct database *track_db_get();
|
|||
/* Called to find the number of unplayed tracks in the database. */
|
||||
unsigned int track_db_count_unplayed();
|
||||
|
||||
/* Called to find the total play count of all tracks in the database. */
|
||||
unsigned int track_db_count_plays();
|
||||
|
||||
/* Called to add a track tag to the database. */
|
||||
struct track *track_add(struct library *, const gchar *);
|
||||
|
||||
|
|
|
@ -231,6 +231,7 @@ static void test_track_db()
|
|||
struct track *track;
|
||||
|
||||
test_equal(track_db_count_unplayed(), 0);
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
track = track_add(library, path);
|
||||
test_verify_track(track);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
|
@ -265,10 +266,13 @@ static void test_track_db()
|
|||
test_equal(track_db_get()->db_size, 2);
|
||||
test_equal(track_db_count_unplayed(), 2);
|
||||
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
track_played(track);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
test_equal(track_db_count_plays(), 1);
|
||||
track_played(track);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
test_equal(track_db_count_plays(), 2);
|
||||
|
||||
track = track_add(library, "tests/Music/invalid_track");
|
||||
test_equal((void *)track, NULL);
|
||||
|
@ -278,11 +282,16 @@ static void test_track_db()
|
|||
/* Reload the database */
|
||||
track_db_deinit();
|
||||
test_equal(track_db_count_unplayed(), 0);
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
test_equal(track_db_get()->db_size, 0);
|
||||
track_db_init();
|
||||
while (idle_run_task()) {};
|
||||
test_equal(track_db_get()->db_size, 2);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
test_equal(track_db_count_plays(), 2);
|
||||
|
||||
track_remove(track_get(2));
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
|
||||
track_remove_all(library);
|
||||
test_equal(track_db_get()->db_size, 0);
|
||||
|
|
Loading…
Reference in New Issue