diff --git a/DESIGN b/DESIGN index 7d813719..8122a01c 100644 --- a/DESIGN +++ b/DESIGN @@ -796,14 +796,14 @@ Track Tag: std :: string length_str; Track(); - Track(Library *, const std::string &); + Track(const std::string &, Library *); const std::string primary_key(); void read(File &); void write(File &); void tag(); const std::string path(); - bool less_than(Track *rhs, sort_t field); + bool less_than(Track *, sort_t); }; - File Format: diff --git a/include/tags.h b/include/tags.h index 1aba8396..c9175eee 100644 --- a/include/tags.h +++ b/include/tags.h @@ -7,6 +7,19 @@ #include +enum sort_t { + SORT_ARTIST, + SORT_ALBUM, + SORT_COUNT, + SORT_GENRE, + SORT_LENGTH, + SORT_PLAYED, + SORT_TITLE, + SORT_TRACK, + SORT_YEAR, +}; + + class Artist : public DatabaseEntry { public: std::string name; @@ -60,4 +73,42 @@ public: void write(File &); }; + +class Track : public DatabaseEntry { +public: + Library *library; + Artist *artist; + Album *album; + Genre *genre; + + unsigned int track; + unsigned int length; + unsigned int play_count; + unsigned int last_year; + unsigned int last_month; + unsigned int last_day; + + std :: string title; + std :: string title_lower; + std :: string filepath; + std :: string length_str; + + Track(); + Track(const std::string &, Library *); + const std::string primary_key(); + void read(File &); + void write(File &); + + void tag(); + const std::string path(); + bool less_than(Track *, sort_t); +}; + + +namespace tagdb { + + Library *add_library(const std::string &); + +} + #endif /* OCARINA_TAGS_H */ diff --git a/lib/tags.cpp b/lib/tags.cpp index b80b3f6d..c5d43711 100644 --- a/lib/tags.cpp +++ b/lib/tags.cpp @@ -8,6 +8,12 @@ #include +Database artist_db("artist.db", true); +Database album_db("album.db", true); +Database genre_db("genre.db", true); +Database library_db("library.db", true); + + /** * * Artist tag @@ -135,3 +141,60 @@ void Library :: write(File &f) { f << enabled << " " << root_path; } + + + +/** + * + * Track tag + * + */ + +Track :: Track() {} + +Track :: Track(const std::string &f, Library *l) + : library(l), play_count(0), last_year(0), last_month(0), last_day(0), + filepath(f.substr(l->root_path.size() + 1)) +{ +} + +const std::string Track :: primary_key() +{ + return path(); +} + +void Track :: read(File &f) +{ +} + +void Track :: write(File &f) +{ +} + +void Track :: tag() +{ +} + +const std::string Track :: path() +{ + return library->root_path + "/" + filepath; +} + +bool Track :: less_than(Track *rhs, sort_t field) +{ + return false; +} + + + +/** + * + * Tagdb functions + * + */ + +Library *tagdb :: add_library(const std::string &filepath) +{ + Database::iterator it = library_db.insert(Library(filepath)); + return &(*it); +} diff --git a/tests/Music/1.ogg b/tests/Music/1.ogg new file mode 100644 index 00000000..b869165d Binary files /dev/null and b/tests/Music/1.ogg differ diff --git a/tests/src/tags.cpp b/tests/src/tags.cpp index e330a6d2..9dfcf266 100644 --- a/tests/src/tags.cpp +++ b/tests/src/tags.cpp @@ -42,6 +42,7 @@ void load_tag(const std::string &file, T &tag) f.close(); } + void artist_test_tags(Artist &artist) { test_results(artist.name == "Artist Name", __LINE__); @@ -59,6 +60,7 @@ void artist_test() artist_test_tags(artist2); } + void album_test_tags(Album &album) { test_results(album.name == "Album Name", __LINE__); @@ -77,6 +79,7 @@ void album_test() album_test_tags(album2); } + void genre_test_tags(Genre &genre) { test_results(genre.name == "Genre Name", __LINE__); @@ -94,6 +97,7 @@ void genre_test() genre_test_tags(genre2); } + void library_test_tags(Library &library) { test_results(library.root_path == "/home/user/Music", __LINE__); @@ -113,11 +117,32 @@ void library_test() library_test_tags(library2); } + +void track_test_tags(Track &track) +{ + test_results(track.filepath == "1.ogg", __LINE__); + test_results(track.path() == "Music/1.ogg", __LINE__); + test_results(track.primary_key() == "Music/1.ogg", __LINE__); + test_results(track.play_count == 0, __LINE__); + test_results(track.last_year == 0, __LINE__); + test_results(track.last_month == 0, __LINE__); + test_results(track.last_day == 0, __LINE__); +} + +void track_test() +{ + Library *library = tagdb :: add_library("Music"); + Track track("Music/1.ogg", library); + + track_test_tags(track); +} + + int main(int argc, char **argv) { char c; - while ((c = getopt(argc, argv, "aAgl")) != -1) { + while ((c = getopt(argc, argv, "aAglt")) != -1) { switch (c) { case 'a': artist_test(); @@ -131,6 +156,9 @@ int main(int argc, char **argv) case 'l': library_test(); break; + case 't': + track_test(); + break; } } diff --git a/tests/tag_db b/tests/tag_db index 007945b9..ffe5cd54 100755 --- a/tests/tag_db +++ b/tests/tag_db @@ -16,3 +16,5 @@ echo test_tag "Genre" "-g" echo test_tag "Library" "-l" +echo +test_tag "Track" "-t"