From d79eb2c9b89fa79ad71e413b364c545f2cc5092a Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 30 Apr 2016 08:51:34 -0400 Subject: [PATCH] core/tags/album: Add album_artwork_exists() function Signed-off-by: Anna Schumaker --- core/tags/album.c | 25 ++++++++++++++++++++++++- include/core/tags/album.h | 3 +++ tests/core/tags/album.c | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/core/tags/album.c b/core/tags/album.c index e722507a..457e5109 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -4,9 +4,20 @@ #include #include - static struct database album_db; +static inline void __album_init_file(struct album *al, struct cache_file *f) +{ + cache_file_init(f, g_strdup_printf("%d", al->al_year), + g_strdup_printf("%s.jpg", al->al_name)); +} + +static inline void __album_deinit_file(struct cache_file *f) +{ + g_free(f->cf_subdir); + g_free(f->cf_name); +} + static gchar *__album_key(const gchar *name, unsigned int year) { return g_strdup_printf("%u/%s", year, name); @@ -113,6 +124,18 @@ int album_compare_year(struct album *lhs, struct album *rhs) return lhs->al_year - rhs->al_year; } +bool album_artwork_exists(struct album *album) +{ + struct cache_file file; + bool ret; + + __album_init_file(album, &file); + ret = cache_file_exists(&file); + __album_deinit_file(&file); + + return ret; +} + #ifdef CONFIG_TESTING const struct db_ops *test_album_ops() { return &album_ops; } #endif /* CONFIG_TESTING */ diff --git a/include/core/tags/album.h b/include/core/tags/album.h index 7f6d04f8..a01c9f4d 100644 --- a/include/core/tags/album.h +++ b/include/core/tags/album.h @@ -46,6 +46,9 @@ int album_compare(struct album *, struct album *); /* Called to compare two album tags by year. */ int album_compare_year(struct album *, struct album *); +/* Called to check if album artwork has been downloaded. */ +bool album_artwork_exists(struct album *); + #ifdef CONFIG_TESTING const struct db_ops *test_album_ops(); #endif /* CONFIG_TESTING */ diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index 48a394ee..07e88264 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -1,6 +1,7 @@ /* * Copyright 2014 (c) Anna Schumaker. */ +#include #include #include @@ -94,11 +95,25 @@ static void test_album_db() test_equal(album_db.db_size, 1); db_deinit(&album_db); +} + +static void test_album_artwork() +{ + struct album *album; + + idle_deinit(); + idle_init(); + + album = album_find("Hyrule Symphony", 1998); + test_equal(album_artwork_exists(album), (bool)false); + album_db_deinit(); + idle_deinit(); } DECLARE_UNIT_TESTS( UNIT_TEST("Album Tag", test_album), UNIT_TEST("Album Comparison", test_album_compare), UNIT_TEST("Album Database", test_album_db), + UNIT_TEST("Album Artwork", test_album_artwork), );