core/tags/artist: Directly inherit from DatabaseEntry
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
405ff0cf88
commit
fe3d7867d1
|
@ -80,7 +80,7 @@ static inline int track_compare(Track *lhs, Track *rhs, sort_t field)
|
|||
{
|
||||
switch (field) {
|
||||
case SORT_ARTIST:
|
||||
return lhs->artist()->compare(rhs->artist());
|
||||
return artist_compare(lhs->artist(), rhs->artist());
|
||||
case SORT_COUNT:
|
||||
return lhs->count() - rhs->count();
|
||||
case SORT_GENRE:
|
||||
|
|
|
@ -1,17 +1,47 @@
|
|||
/**
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
extern "C" {
|
||||
#include <core/string.h>
|
||||
}
|
||||
#include <core/tags/artist.h>
|
||||
|
||||
|
||||
static database<struct artist> artist_db;
|
||||
|
||||
|
||||
artist :: artist() : GenericTag() {}
|
||||
artist :: artist() {}
|
||||
|
||||
artist :: artist(const std::string &name)
|
||||
: GenericTag(name)
|
||||
{
|
||||
gchar *lower = string_lowercase(name.c_str());
|
||||
|
||||
ar_name = name;
|
||||
ar_lower = lower;
|
||||
|
||||
g_free(lower);
|
||||
}
|
||||
|
||||
const std::string artist :: primary_key() const
|
||||
{
|
||||
return ar_name;
|
||||
}
|
||||
|
||||
void artist :: read(file &file)
|
||||
{
|
||||
gchar *name = file_readl(&file);
|
||||
gchar *g_lc = string_lowercase(name);
|
||||
|
||||
ar_name = name;
|
||||
ar_lower = g_lc;
|
||||
|
||||
g_free(name);
|
||||
g_free(g_lc);
|
||||
}
|
||||
|
||||
void artist :: write(file &file)
|
||||
{
|
||||
file_writef(&file, "%s", ar_name.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,3 +65,8 @@ struct artist *artist_get(const unsigned int index)
|
|||
{
|
||||
return db_at(&artist_db, index);
|
||||
}
|
||||
|
||||
int artist_compare(struct artist *lhs, struct artist *rhs)
|
||||
{
|
||||
return string_compare(lhs->ar_lower.c_str(), rhs->ar_lower.c_str());
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ Track :: Track(struct album *album, struct artist *artist, Genre *genre,
|
|||
{
|
||||
date_set(&_date, 0, 0, 0);
|
||||
filter :: add(this->name(), index());
|
||||
filter :: add(_artist->name(), index());
|
||||
filter :: add(_artist->ar_name, index());
|
||||
filter :: add(_album->al_name, index());
|
||||
_library->inc_size();
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ void Track :: read(file &file)
|
|||
_genre = tags :: get_genre(genre_id);
|
||||
|
||||
filter :: add(name(), index());
|
||||
filter :: add(_artist->name(), index());
|
||||
filter :: add(_artist->ar_name, index());
|
||||
filter :: add(_album->al_name, index());
|
||||
_library->inc_size();
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
g_free(uri);
|
||||
|
||||
set_markup(o_album, "x-large", "From: " + track->album()->al_name);
|
||||
set_markup(o_artist, "x-large", "By: " + track->artist()->name());
|
||||
set_markup(o_artist, "x-large", "By: " + track->artist()->ar_name);
|
||||
set_markup(o_title, "xx-large", track->name());
|
||||
o_duration->set_text(len);
|
||||
g_free(len);
|
||||
|
|
|
@ -117,7 +117,7 @@ void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column,
|
|||
g_free(str);
|
||||
return;
|
||||
case 3:
|
||||
return set_val(track->artist()->name(), value);
|
||||
return set_val(track->artist()->ar_name, value);
|
||||
case 4:
|
||||
return set_val(track->album()->al_name, value);
|
||||
case 5:
|
||||
|
|
|
@ -4,13 +4,16 @@
|
|||
#ifndef OCARINA_CORE_TAGS_ARTIST_H
|
||||
#define OCARINA_CORE_TAGS_ARTIST_H
|
||||
|
||||
#include <core/tags/generic.h>
|
||||
#include <core/database.h>
|
||||
|
||||
/**
|
||||
* The Artist tag is used to store the name of artists added
|
||||
* to the tag database.
|
||||
*/
|
||||
struct artist : public GenericTag {
|
||||
struct artist : public DatabaseEntry {
|
||||
std::string ar_name; /* This artist's name. */
|
||||
std::string ar_lower; /* This artist's name (lowercased). */
|
||||
|
||||
artist(); /**< Artist tag constructor. */
|
||||
|
||||
/**
|
||||
|
@ -19,6 +22,10 @@ struct artist : public GenericTag {
|
|||
* @param name Artist name.
|
||||
*/
|
||||
artist(const std::string &);
|
||||
|
||||
const std::string primary_key() const;
|
||||
void read(file &);
|
||||
void write(file &);
|
||||
};
|
||||
|
||||
|
||||
|
@ -34,4 +41,7 @@ struct artist *artist_find(const std::string &);
|
|||
/* Called to get an artist tag with a specific index. */
|
||||
struct artist *artist_get(const unsigned int);
|
||||
|
||||
/* Called to compare two artist tags. */
|
||||
int artist_compare(struct artist *, struct artist *);
|
||||
|
||||
#endif /* OCARINA_CORE_TAGS_ARTIST_H */
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
static void test_verify_empty(struct artist *artist)
|
||||
{
|
||||
test_equal(artist->name(), "");
|
||||
test_equal(artist->lowercase(), "");
|
||||
test_equal(artist->ar_name, "");
|
||||
test_equal(artist->ar_lower, "");
|
||||
test_equal(artist->primary_key(), "");
|
||||
}
|
||||
|
||||
static void test_verify_koji(struct artist *artist)
|
||||
{
|
||||
test_equal(artist->name(), "Koji Kondo");
|
||||
test_equal(artist->lowercase(), "koji kondo");
|
||||
test_equal(artist->ar_name, "Koji Kondo");
|
||||
test_equal(artist->ar_lower, "koji kondo");
|
||||
test_equal(artist->primary_key(), "Koji Kondo");
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,9 @@ static void test_artist_compare()
|
|||
struct artist *koji = new struct artist("Koji Kondo");
|
||||
struct artist *hajime = new struct artist("hajime wakai");
|
||||
|
||||
test_equal(koji->compare(koji), 0);
|
||||
test_equal(koji->compare(hajime), 1);
|
||||
test_equal(hajime->compare(koji), -1);
|
||||
test_equal(artist_compare(koji, koji), 0);
|
||||
test_equal(artist_compare(koji, hajime), 1);
|
||||
test_equal(artist_compare(hajime, koji), -1);
|
||||
|
||||
delete hajime;
|
||||
delete koji;
|
||||
|
|
Loading…
Reference in New Issue