From 446f1228cf8011a0cc16ef690f5b20438c516c27 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 29 Oct 2015 02:34:12 -0400 Subject: [PATCH] core/tags/library: Add library_file() function To help with finding the full path of files that are located in the library's directory. Signed-off-by: Anna Schumaker --- core/tags/library.cpp | 5 +++++ core/tags/track.cpp | 2 +- include/core/tags/library.h | 3 +++ tests/core/tags/library.cpp | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/tags/library.cpp b/core/tags/library.cpp index b38ed00b..1cfb4eb8 100644 --- a/core/tags/library.cpp +++ b/core/tags/library.cpp @@ -78,3 +78,8 @@ void library_set_enabled(struct library *library, bool enabled) library->li_enabled = enabled; db_save(&library_db); } + +std::string library_file(struct library *library, const std::string &path) +{ + return library->li_path + "/" + path; +} diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 616690ac..b3683588 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -84,7 +84,7 @@ const std::string Track :: date() const const std::string Track :: path() const { if (_library) - return _library->primary_key() + "/" + _path; + return library_file(_library, _path); return ""; } diff --git a/include/core/tags/library.h b/include/core/tags/library.h index 6f582e06..ea587f14 100644 --- a/include/core/tags/library.h +++ b/include/core/tags/library.h @@ -76,4 +76,7 @@ void library_remove(struct library *); /* Called to configure if the library tag is enabled. */ void library_set_enabled(struct library *, bool); +/* Called to find the full path of files under the library directory. */ +std::string library_file(struct library *, const std::string &); + #endif /* OCARINA_CORE_TAGS_LIBRARY_H */ diff --git a/tests/core/tags/library.cpp b/tests/core/tags/library.cpp index cd077f8f..ba340048 100644 --- a/tests/core/tags/library.cpp +++ b/tests/core/tags/library.cpp @@ -50,10 +50,12 @@ static void test_library() file_open(&f, OPEN_READ); library->read(f); test_verify_link(library); + test_equal(library_file(library, "navi.mp3"), "/home/Link/Music/navi.mp3"); library->read(f); file_close(&f); test_verify_zelda(library); + test_equal(library_file(library, "impa.ogg"), "/home/Zelda/Music/impa.ogg"); delete library; delete zelda;