diff --git a/core/queue.cpp b/core/queue.cpp index 9c976043..e05aa4b4 100644 --- a/core/queue.cpp +++ b/core/queue.cpp @@ -97,7 +97,7 @@ static inline int track_compare(Track *lhs, Track *rhs, sort_t field) if (lhs->album()->al_year - rhs->album()->al_year != 0) return lhs->album()->al_year - rhs->album()->al_year; case SORT_ALBUM: - return lhs->album()->compare(rhs->album()); + return album_compare(lhs->album(), rhs->album()); } return 0; } diff --git a/core/tags/album.cpp b/core/tags/album.cpp index 4164c831..7e1c480a 100644 --- a/core/tags/album.cpp +++ b/core/tags/album.cpp @@ -5,7 +5,6 @@ extern "C" { #include } #include -#include static database album_db; @@ -20,21 +19,24 @@ static const std::string make_key(const std::string &name, unsigned int year) } -album :: album() : GenericTag(), al_year(0) {} +album :: album() : al_year(0), al_name("") {} album :: album(const std::string &name, unsigned int year) - : GenericTag(name), al_year(year) + : al_year(year), al_name(name) { + gchar *lower = string_lowercase(al_name.c_str()); + al_lower = lower; + g_free(lower); } album :: album(const std::string &key) { gchar *name, *lower; - sscanf(key.c_str(), "%u/%m[^\n]", &al_year, &name); + sscanf(key.c_str(), "%u/%m[^\n]\n", &al_year, &name); - lower = string_lowercase(name); - _name = name; - _lower = lower; + lower = string_lowercase(name); + al_name = name; + al_lower = lower; g_free(name); g_free(lower); @@ -42,19 +44,27 @@ album :: album(const std::string &key) const std::string album :: primary_key() const { - return make_key(GenericTag :: primary_key(), al_year); + return make_key(al_name, al_year); } void album :: read(file &file) { + gchar *name, *lower; + file_readf(&file, "%u", &al_year); - GenericTag :: read(file); + + name = file_readl(&file); + lower = string_lowercase(name); + al_name = name; + al_lower = lower; + + g_free(name); + g_free(lower); } void album :: write(file &file) { - file_writef(&file, "%u ", al_year); - GenericTag :: write(file); + file_writef(&file, "%u %s", al_year, al_name.c_str()); } @@ -78,3 +88,8 @@ struct album *album_get(const unsigned int index) { return db_at(&album_db, index); } + +int album_compare(struct album *lhs, struct album *rhs) +{ + return string_compare(lhs->al_lower.c_str(), rhs->al_lower.c_str()); +} diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 727c7dd0..cb93e8b7 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -40,7 +40,7 @@ Track :: Track(struct album *album, Artist *artist, Genre *genre, Library *libra date_set(&_date, 0, 0, 0); filter :: add(this->name(), index()); filter :: add(_artist->name(), index()); - filter :: add(_album->name(), index()); + filter :: add(_album->al_name, index()); _library->inc_size(); } @@ -127,7 +127,7 @@ void Track :: read(file &file) filter :: add(name(), index()); filter :: add(_artist->name(), index()); - filter :: add(_album->name(), index()); + filter :: add(_album->al_name, index()); _library->inc_size(); } diff --git a/gui/gst.cpp b/gui/gst.cpp index 1ebeab25..2d8ec86f 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -66,7 +66,7 @@ public: g_object_set(G_OBJECT(gst_player), "uri", uri, NULL); g_free(uri); - set_markup(o_album, "x-large", "From: " + track->album()->name()); + set_markup(o_album, "x-large", "From: " + track->album()->al_name); set_markup(o_artist, "x-large", "By: " + track->artist()->name()); set_markup(o_title, "xx-large", track->name()); o_duration->set_text(len); diff --git a/gui/queue/model.cpp b/gui/queue/model.cpp index c7fa4821..5fb2585a 100644 --- a/gui/queue/model.cpp +++ b/gui/queue/model.cpp @@ -119,7 +119,7 @@ void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column, case 3: return set_val(track->artist()->name(), value); case 4: - return set_val(track->album()->name(), value); + return set_val(track->album()->al_name, value); case 5: return set_val(track->album()->al_year, value); case 6: diff --git a/include/core/tags/album.h b/include/core/tags/album.h index 6ef0f01d..3f2e3f42 100644 --- a/include/core/tags/album.h +++ b/include/core/tags/album.h @@ -4,7 +4,7 @@ #ifndef OCARINA_CORE_TAGS_ALBUM_H #define OCARINA_CORE_TAGS_ALBUM_H -#include +#include /** * The Album tag is used to store the name and year of albums @@ -17,8 +17,10 @@ * ... << year2 << GenericTag::write() * ... << year3 << GenericTag::write() */ -struct album : public GenericTag { - unsigned int al_year; /* This album's year. */ +struct album : public DatabaseEntry { + unsigned int al_year; /* This album's year. */ + std::string al_name; /* This album's name. */ + std::string al_lower; /* This album's name (lowercased). */ album(); /**< Album tag constructor */ @@ -68,4 +70,7 @@ struct album *album_find(const std::string &, unsigned int); /* Called to get an album tag with a specific index. */ struct album *album_get(const unsigned int); +/* Called to compare two album tags. */ +int album_compare(struct album *, struct album *); + #endif /* OCARINA_CORE_TAGS_ALBUM_H */ diff --git a/tests/core/tags/album.cpp b/tests/core/tags/album.cpp index 679b3265..9a1da6ee 100644 --- a/tests/core/tags/album.cpp +++ b/tests/core/tags/album.cpp @@ -6,17 +6,17 @@ static void test_verify_empty(struct album *album) { - test_equal(album->name(), ""); - test_equal(album->lowercase(), ""); - test_equal(album->al_year, 0); + test_equal(album->al_name, ""); + test_equal(album->al_lower, ""); + test_equal(album->al_year, 0); test_equal(album->primary_key(), "0/"); } static void test_verify_hyrule(struct album *album) { - test_equal(album->name(), "Hyrule Symphony"); - test_equal(album->lowercase(), "hyrule symphony"); - test_equal(album->al_year, 1998); + test_equal(album->al_name, "Hyrule Symphony"); + test_equal(album->al_lower, "hyrule symphony"); + test_equal(album->al_year, 1998); test_equal(album->primary_key(), "1998/Hyrule Symphony"); } @@ -52,9 +52,9 @@ static void test_album_compare() struct album *twilight = new struct album("Twilight Princess", 2006); struct album *skyward = new struct album("skyward sword", 2011); - test_equal(twilight->compare(twilight), 0); - test_equal(twilight->compare(skyward), 1); - test_equal(skyward->compare(twilight), -1); + test_equal(album_compare(twilight, twilight), 0); + test_equal(album_compare(twilight, skyward), 1); + test_equal(album_compare(skyward, twilight), -1); delete skyward; delete twilight;