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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-10-29 02:34:12 -04:00
parent 24504c7de8
commit 446f1228cf
4 changed files with 11 additions and 1 deletions

View File

@ -78,3 +78,8 @@ void library_set_enabled(struct library *library, bool enabled)
library->li_enabled = enabled; library->li_enabled = enabled;
db_save(&library_db); db_save(&library_db);
} }
std::string library_file(struct library *library, const std::string &path)
{
return library->li_path + "/" + path;
}

View File

@ -84,7 +84,7 @@ const std::string Track :: date() const
const std::string Track :: path() const const std::string Track :: path() const
{ {
if (_library) if (_library)
return _library->primary_key() + "/" + _path; return library_file(_library, _path);
return ""; return "";
} }

View File

@ -76,4 +76,7 @@ void library_remove(struct library *);
/* Called to configure if the library tag is enabled. */ /* Called to configure if the library tag is enabled. */
void library_set_enabled(struct library *, bool); 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 */ #endif /* OCARINA_CORE_TAGS_LIBRARY_H */

View File

@ -50,10 +50,12 @@ static void test_library()
file_open(&f, OPEN_READ); file_open(&f, OPEN_READ);
library->read(f); library->read(f);
test_verify_link(library); test_verify_link(library);
test_equal(library_file(library, "navi.mp3"), "/home/Link/Music/navi.mp3");
library->read(f); library->read(f);
file_close(&f); file_close(&f);
test_verify_zelda(library); test_verify_zelda(library);
test_equal(library_file(library, "impa.ogg"), "/home/Zelda/Music/impa.ogg");
delete library; delete library;
delete zelda; delete zelda;