diff --git a/DESIGN b/DESIGN index 66715845..a7c47696 100644 --- a/DESIGN +++ b/DESIGN @@ -120,44 +120,6 @@ Tag Database: -Genre Tag: - The genre tag is used to collect basic information about the various - genres of songs in the library. - -- Genre: - class Genre : public DatabaseEntry { - public: - std::string genre; - std::string lower; - - Genre(); - Genre(const std::string &); - const std::string primary_key() const; - void read(File &); - void write(File &); - }; - -- File Format: - File << name; - -- API: - Genre(); - Initialize an invalid Genre instance. - - Genre(const std::string &genre_name); - Set genre from genre name and find the lowercase form. - - const std::string Genre :: primary_key() const; - Use genre as primary key. - - void Genre :: read(File &f); - Read genre from file and find the lowercase form. - - void Genre :: write(File &f); - Write genre to file. - - - Library Tag: The library tag is used to store a single directory added to Ocarina by the user. It is not an ID3 tag, and is instead something I use diff --git a/core/tags.cpp b/core/tags.cpp index a18eccd9..b45ef1db 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -18,37 +18,6 @@ Database library_db("library.db", true); Database track_db("track.db", false); -/** - * - * Genre tag - * - */ - -Genre :: Genre() {} - -Genre :: Genre(const std::string &s) - : name(s), lower(filter :: lowercase(name)) -{ -} - -const std::string Genre :: primary_key() const -{ - return name; -} - -void Genre :: read(File &f) -{ - name = f.getline(); - lower = filter :: lowercase(name); -} - -void Genre :: write(File &f) -{ - f << name; -} - - - /** * * Library tag @@ -253,7 +222,7 @@ int Track :: less_than(Track *rhs, sort_t field) case SORT_COUNT: return compare_uint(play_count, rhs->play_count); case SORT_GENRE: - return compare_string(genre->lower, rhs->genre->lower); + return compare_string(genre->lowercase(), rhs->genre->lowercase()); case SORT_LENGTH: return compare_uint(length, rhs->length); case SORT_PLAYED: diff --git a/core/tags/genre.cpp b/core/tags/genre.cpp new file mode 100644 index 00000000..96211c55 --- /dev/null +++ b/core/tags/genre.cpp @@ -0,0 +1,12 @@ +/** + * @file + * Copyright 2014 (c) Anna Schumaker. + */ +#include + +Genre :: Genre() : GenericTag() {} + +Genre :: Genre(const std::string &name) + : GenericTag(name) +{ +} diff --git a/include/core/tags.h b/include/core/tags.h index a0cba4cc..c2097903 100644 --- a/include/core/tags.h +++ b/include/core/tags.h @@ -8,6 +8,7 @@ #include #include #include +#include /** @@ -35,45 +36,6 @@ enum sort_t { }; -/** - * Genre tag - */ -class Genre : public DatabaseEntry { -public: - /** Genre name */ - std::string name; - /** Genre name (lowercase) */ - std::string lower; - - /** Genre tag constructor */ - Genre(); - - /** - * Genre tag constructor - * @param name Genre name - */ - Genre(const std::string &); - - /** - * Called to access the artist tag's primary key - * @return Genre::name - */ - const std::string primary_key() const; - - /** - * Read genre information from file. - * @param file The file to read from. - */ - void read(File &); - - /** - * Write genre information to file. - * @param file The file to write to. - */ - void write(File &); -}; - - /** * Library tag */ diff --git a/include/core/tags/genre.h b/include/core/tags/genre.h new file mode 100644 index 00000000..57491cc6 --- /dev/null +++ b/include/core/tags/genre.h @@ -0,0 +1,26 @@ +/** + * @file + * Copyright 2014 (c) Anna Schumaker. + */ +#ifndef OCARINA_CORE_TAGS_GENRE_H +#define OCARINA_CORE_TAGS_GENRE_H + +#include + +/** + * The Genre tag is used to store the name of genres added + * to the tag database. + */ +class Genre : public GenericTag { +public: + Genre(); /**< Genre tag constructor. */ + + /** + * Genre tag constructor. + * + * @param name Genre name. + */ + Genre(const std::string &); +}; + +#endif /* OCARINA_CORE_TAGS_GENRE_H */ diff --git a/lib/model.cpp b/lib/model.cpp index 1515a16c..b85f5200 100644 --- a/lib/model.cpp +++ b/lib/model.cpp @@ -152,7 +152,7 @@ void QueueModel::get_value_str(Track *track, int column, specific.set(track->album->name()); break; case 6: - specific.set(track->genre->name); + specific.set(track->genre->name()); break; case 8: if (track->play_count == 0) diff --git a/tests/core/Sconscript b/tests/core/Sconscript index b00bd8d3..7a059fda 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -17,6 +17,7 @@ test( "idle" ) test( "tags/generic" ) test( "tags/artist" ) test( "tags/album" ) +test( "tags/genre" ) test_env.UsePackage("taglib") objs += [ get_test_obj("tags", "core") ] diff --git a/tests/core/tags/.gitignore b/tests/core/tags/.gitignore index 183d6287..717416fc 100644 --- a/tests/core/tags/.gitignore +++ b/tests/core/tags/.gitignore @@ -1,3 +1,4 @@ album artist generic +genre diff --git a/tests/core/tags/genre.cpp b/tests/core/tags/genre.cpp new file mode 100644 index 00000000..785ecf17 --- /dev/null +++ b/tests/core/tags/genre.cpp @@ -0,0 +1,25 @@ +/** + * @file + * Copyright 2014 (c) Anna Schumaker. + */ +#include +#include + +static void test_artist_tag() +{ + Genre genre; + test_equal(genre.name(), (std::string)""); + test_equal(genre.lowercase(), (std::string)""); + test_equal(genre.primary_key(), (std::string)""); + + genre = Genre("Video Game Music"); + test_equal(genre.name(), (std::string)"Video Game Music"); + test_equal(genre.lowercase(), (std::string)"video game music"); + test_equal(genre.primary_key(), (std::string)"Video Game Music"); +} + +int main(int argc, char **argv) +{ + run_test("Genre Tag Test", test_artist_tag); + return 0; +}