core/tags/album: Add an album_compare_year() function
With special handling for albums with the same year but different names. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
f44710f7ae
commit
9a16a18b9f
|
@ -94,8 +94,7 @@ static inline int track_compare(struct track *lhs, struct track *rhs, sort_t fie
|
|||
case SORT_TRACK:
|
||||
return lhs->tr_track - rhs->tr_track;
|
||||
case SORT_YEAR:
|
||||
if (lhs->tr_album->al_year - rhs->tr_album->al_year != 0)
|
||||
return lhs->tr_album->al_year - rhs->tr_album->al_year;
|
||||
return album_compare_year(lhs->tr_album, rhs->tr_album);
|
||||
case SORT_ALBUM:
|
||||
return album_compare(lhs->tr_album, rhs->tr_album);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,13 @@ int album_compare(struct album *lhs, struct album *rhs)
|
|||
return string_compare(lhs->al_lower, rhs->al_lower);
|
||||
}
|
||||
|
||||
int album_compare_year(struct album *lhs, struct album *rhs)
|
||||
{
|
||||
if (lhs->al_year - rhs->al_year == 0)
|
||||
return album_compare(lhs, rhs);
|
||||
return lhs->al_year - rhs->al_year;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
const struct db_ops *test_album_ops() { return &album_ops; }
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -38,9 +38,12 @@ struct album *album_find(const gchar *, unsigned int);
|
|||
/* Called to get an album tag with a specific index. */
|
||||
struct album *album_get(const unsigned int);
|
||||
|
||||
/* Called to compare two album tags. */
|
||||
/* Called to compare two album tags by name. */
|
||||
int album_compare(struct album *, struct album *);
|
||||
|
||||
/* Called to compare two album tags by year. */
|
||||
int album_compare_year(struct album *, struct album *);
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
const struct db_ops *test_album_ops();
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -61,6 +61,15 @@ static void test_album_compare()
|
|||
test_equal(album_compare(twilight, skyward), 1);
|
||||
test_equal(album_compare(skyward, twilight), -1);
|
||||
|
||||
test_equal(album_compare_year(twilight, twilight), 0);
|
||||
test_equal(album_compare_year(twilight, skyward), -5);
|
||||
test_equal(album_compare_year(skyward, twilight), 5);
|
||||
|
||||
skyward->al_year = 2006;
|
||||
test_equal(album_compare_year(twilight, twilight), 0);
|
||||
test_equal(album_compare_year(twilight, skyward), 1);
|
||||
test_equal(album_compare_year(skyward, twilight), -1);
|
||||
|
||||
album_ops->dbe_free(&twilight->al_dbe);
|
||||
album_ops->dbe_free(&skyward->al_dbe);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue