Track: Hide the genre tag from the public

And set it using the new constructor.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-21 08:25:35 -05:00
parent c6029f13f2
commit 2dfa9bf168
5 changed files with 18 additions and 16 deletions

View File

@ -22,7 +22,7 @@ Database<Track> track_db("track.db", false);
*/
Track :: Track(const std::string &f, Library *library)
: _album(NULL), _artist(NULL), _library(library), genre(NULL),
: _album(NULL), _artist(NULL), _genre(NULL), _library(library),
play_count(0), last_year(0), last_month(0), last_day(0),
filepath(f.substr(library->primary_key().size() + 1))
{
@ -54,7 +54,7 @@ void Track :: read(File &f)
_library = tags :: get_library(library_id);
_artist = tags :: get_artist(artist_id);
_album = tags :: get_album(album_id);
genre = tags :: get_genre(genre_id);
_genre = tags :: get_genre(genre_id);
title_lower = filter :: add(title, index());
filter :: add(_artist->name(), index());
@ -66,7 +66,7 @@ void Track :: read(File &f)
void Track :: write(File &f)
{
f << _library->index() << " " << _artist->index() << " ";
f << _album->index() << " " << genre->index() << " " << track << " ";
f << _album->index() << " " << _genre->index() << " " << track << " ";
f << last_year << " " << last_month << " " << last_day << " ";
f << play_count << " " << length << " " << title << std::endl;
f << filepath << std::endl;
@ -116,7 +116,7 @@ bool Track :: tag()
_artist = tags :: get_artist(format_tag(tag->artist()));
_album = tags :: get_album(format_tag(tag->album()), tag->year());
genre = tags :: get_genre(format_tag(tag->genre()));
_genre = tags :: get_genre(format_tag(tag->genre()));
track = tag->track();
length = audio->length();
title = format_tag(tag->title());
@ -185,7 +185,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 genre->compare(rhs->genre);
return _genre->compare(rhs->genre());
case SORT_LENGTH:
return compare_uint(length, rhs->length);
case SORT_PLAYED:

View File

@ -7,17 +7,17 @@
Track :: Track()
: GenericTag(),
_album(NULL), _artist(NULL), _library(NULL), genre(NULL),
_album(NULL), _artist(NULL), _genre(NULL), _library(NULL),
track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0)
{}
Track :: Track(Album *album, Artist *artist, Library *library)
: _album(album), _artist(artist), _library(library)
Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library)
: _album(album), _artist(artist), _genre(genre), _library(library)
{
_library->inc_size();
}
Album *Track :: album() { return _album; }
Artist *Track :: artist() { return _artist; }
Genre *Track :: genre() { return _genre; }
Library *Track :: library() { return _library; }

View File

@ -41,14 +41,12 @@ class Track : public GenericTag {
private:
Album *_album; /**< Pointer to the Album containing this track. */
Artist *_artist; /**< Pointer to the Artist performing this track. */
Genre *_genre; /**< Pointer to the Genre describing this track. */
Library *_library; /**< Pointer to the Library containing this track. */
void set_length_str();
public:
/** Pointer to this track's genre information */
Genre *genre;
/** Track number of this track */
unsigned int track;
/** Length of this track (in seconds) */
@ -79,9 +77,10 @@ public:
*
* @param album The album containing this track.
* @param artist The artist performing this track.
* @param genre The genre describing this track.
* @param library The library containing this track.
*/
Track(Album *, Artist *, Library *);
Track(Album *, Artist *, Genre *, Library *);
/**
* Track constructor
@ -96,6 +95,7 @@ public:
Album *album(); /**< @return Track::_album. */
Artist *artist(); /**< @return Track::_artist. */
Genre *genre(); /**< @return Track::_genre. */
Library *library(); /**< @return Track::_library. */

View File

@ -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)

View File

@ -11,8 +11,8 @@ static void test_track_tag_default()
test_equal(track.album(), (Album *)NULL);
test_equal(track.artist(), (Artist *)NULL);
test_equal(track.genre(), (Genre *)NULL);
test_equal(track.library(), (Library *)NULL);
test_equal(track.genre, (Genre *)NULL);
test_equal(track.name(), (std::string)"");
test_equal(track.lowercase(), (std::string)"");
@ -34,11 +34,13 @@ static void test_track_tag_constructor()
{
Album *album = tags :: get_album("Hyrule Symphony", 1998);
Artist *artist = tags :: get_artist("Koji Kondo");
Genre *genre = tags :: get_genre("Video Game Music");
Library *library = tags :: get_library("/home/Zelda/Music");
Track track(album, artist, library);
Track track(album, artist, genre, library);
test_equal(track.album(), album);
test_equal(track.artist(), artist);
test_equal(track.genre(), genre);
test_equal(track.library(), library);
test_equal(track.library()->size(), (unsigned)1);
}