diff --git a/core/tags/album.c b/core/tags/album.c index 2206270d..ac369539 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -245,6 +245,19 @@ bool album_artwork_exists(struct album *album) return ret; } +gchar *album_artwork_path(struct album *album) +{ + struct cache_file file; + gchar *ret = NULL; + + __album_init_file(album, &file); + if (cache_file_exists(&file)) + ret = cache_file_path(&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 a01c9f4d..1d663350 100644 --- a/include/core/tags/album.h +++ b/include/core/tags/album.h @@ -49,6 +49,12 @@ int album_compare_year(struct album *, struct album *); /* Called to check if album artwork has been downloaded. */ bool album_artwork_exists(struct album *); +/* + * Called to find the path to an album's artwork. + * This function returns a new string that MUST be freed with g_free(). + */ +gchar *album_artwork_path(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 1afd40dd..fc846880 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -102,12 +102,19 @@ static void test_album_db() static void test_album_artwork() { struct album *ocarina, *majora, *wind; + gchar *o_path, *m_path, *w_path; struct artist *koji; + const gchar *cache; artist_db_init(); idle_deinit(); idle_init(); + cache = g_get_user_cache_dir(); + o_path = g_build_filename(cache, "ocarina-test", "1998", "Ocarina of Time.jpg", NULL); + m_path = g_build_filename(cache, "ocarina-test", "2000", "Majora's Mask.jpg", NULL); + w_path = g_build_filename(cache, "ocarina-test", "0", "Wind Waker.jpg", NULL); + ocarina = album_find("Ocarina of Time", 1998); majora = album_find("Majora's Mask", 2000); wind = album_find("Wind Waker", 0); @@ -117,13 +124,22 @@ static void test_album_artwork() test_equal(album_artwork_exists(ocarina), (bool)false); test_equal(album_artwork_exists(majora), (bool)false); test_equal(album_artwork_exists(wind), (bool)false); + test_equal((void *)album_artwork_path(ocarina), NULL); + test_equal((void *)album_artwork_path(majora), NULL); + test_equal((void *)album_artwork_path(wind), NULL); while (idle_run_task()) {} test_equal(album_artwork_exists(ocarina), (bool)true); test_equal(album_artwork_exists(majora), (bool)true); test_equal(album_artwork_exists(wind), (bool)true); + test_str_equal(album_artwork_path(ocarina), o_path); + test_str_equal(album_artwork_path(majora), m_path); + test_str_equal(album_artwork_path(wind), w_path); + g_free(o_path); + g_free(m_path); + g_free(w_path); album_db_deinit(); artist_db_deinit(); idle_deinit();