Track: Hide the play count from the public
I provide an accessor function to keep this value from getting changed outside of this class. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
468a4e79d5
commit
eb23127f6d
|
@ -23,7 +23,7 @@ Database<Track> track_db("track.db", false);
|
|||
|
||||
Track :: Track(const std::string &f, Library *library)
|
||||
: _album(NULL), _artist(NULL), _genre(NULL), _library(library),
|
||||
play_count(0), last_year(0), last_month(0), last_day(0),
|
||||
_count(0), last_year(0), last_month(0), last_day(0),
|
||||
filepath(f.substr(library->primary_key().size() + 1))
|
||||
{
|
||||
library->inc_size();
|
||||
|
@ -40,7 +40,7 @@ void Track :: read(File &f)
|
|||
|
||||
f >> library_id >> artist_id >> album_id >> genre_id;
|
||||
f >> _track >> last_year >> last_month >> last_day;
|
||||
f >> play_count >> length;
|
||||
f >> _count >> length;
|
||||
|
||||
title = f.getline();
|
||||
filepath = f.getline();
|
||||
|
@ -62,7 +62,7 @@ void Track :: write(File &f)
|
|||
f << _library->index() << " " << _artist->index() << " ";
|
||||
f << _album->index() << " " << _genre->index() << " " << _track << " ";
|
||||
f << last_year << " " << last_month << " " << last_day << " ";
|
||||
f << play_count << " " << length << " " << title << std::endl;
|
||||
f << _count << " " << length << " " << title << std::endl;
|
||||
f << filepath << std::endl;
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ void Track :: played()
|
|||
time_t the_time = time(NULL);
|
||||
struct tm *now = localtime(&the_time);
|
||||
|
||||
play_count++;
|
||||
_count++;
|
||||
last_day = now->tm_mday;
|
||||
last_month = now->tm_mon + 1;
|
||||
last_year = now->tm_year + 1900;
|
||||
|
@ -177,7 +177,7 @@ int Track :: less_than(Track *rhs, sort_t field)
|
|||
case SORT_ALBUM:
|
||||
return _album->compare(rhs->album());
|
||||
case SORT_COUNT:
|
||||
return compare_uint(play_count, rhs->play_count);
|
||||
return compare_uint(_count, rhs->_count);
|
||||
case SORT_GENRE:
|
||||
return _genre->compare(rhs->genre());
|
||||
case SORT_LENGTH:
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
Track :: Track()
|
||||
: GenericTag(),
|
||||
_album(NULL), _artist(NULL), _genre(NULL), _library(NULL),
|
||||
_track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0)
|
||||
_count(0), _track(0), length(0), last_year(0), last_month(0), last_day(0)
|
||||
{}
|
||||
|
||||
Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
|
||||
unsigned int track)
|
||||
: _album(album), _artist(artist), _genre(genre), _library(library),
|
||||
_track(track)
|
||||
_count(0), _track(track)
|
||||
{
|
||||
_library->inc_size();
|
||||
}
|
||||
|
@ -30,4 +30,5 @@ Artist *Track :: artist() { return _artist; }
|
|||
Genre *Track :: genre() { return _genre; }
|
||||
Library *Track :: library() { return _library; }
|
||||
|
||||
unsigned int Track :: count() { return _count; }
|
||||
unsigned int Track :: track() { return _track; }
|
||||
|
|
|
@ -44,15 +44,14 @@ private:
|
|||
Genre *_genre; /**< Pointer to the Genre describing this track. */
|
||||
Library *_library; /**< Pointer to the Library containing this track. */
|
||||
|
||||
unsigned int _track; /**< Track number of this track. */
|
||||
unsigned int _count; /**< Number of times this track has been played. */
|
||||
unsigned int _track; /**< Track number of this track. */
|
||||
|
||||
void set_length_str();
|
||||
|
||||
public:
|
||||
/** Length of this track (in seconds) */
|
||||
unsigned int length;
|
||||
/** The number of times this track has been played */
|
||||
unsigned int play_count;
|
||||
/** The year this track was last played */
|
||||
unsigned int last_year;
|
||||
/** The month this track was last played */
|
||||
|
@ -99,6 +98,7 @@ public:
|
|||
Genre *genre(); /**< @return Track::_genre. */
|
||||
Library *library(); /**< @return Track::_library. */
|
||||
|
||||
unsigned int count(); /**< @return Track::_count. */
|
||||
unsigned int track(); /**< @return Track::_track. */
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,7 +124,7 @@ void QueueModel::get_value_uint(Track *track, int column,
|
|||
specific.set(track->album()->year());
|
||||
break;
|
||||
case 7:
|
||||
specific.set(track->play_count);
|
||||
specific.set(track->count());
|
||||
}
|
||||
|
||||
value.init(Glib::Value<unsigned int>::value_type());
|
||||
|
@ -155,7 +155,7 @@ void QueueModel::get_value_str(Track *track, int column,
|
|||
specific.set(track->genre()->name());
|
||||
break;
|
||||
case 8:
|
||||
if (track->play_count == 0)
|
||||
if (track->count() == 0)
|
||||
specific.set("Never");
|
||||
else {
|
||||
ss << track->last_month << " / ";
|
||||
|
|
|
@ -24,7 +24,7 @@ static void test_track_tag_default()
|
|||
|
||||
test_equal(track.track(), (unsigned)0);
|
||||
test_equal(track.length, (unsigned)0);
|
||||
test_equal(track.play_count, (unsigned)0);
|
||||
test_equal(track.count(), (unsigned)0);
|
||||
test_equal(track.last_year, (unsigned)0);
|
||||
test_equal(track.last_month, (unsigned)0);
|
||||
test_equal(track.last_day, (unsigned)0);
|
||||
|
@ -45,6 +45,7 @@ static void test_track_tag_constructor()
|
|||
test_equal(library->size(), (unsigned)1);
|
||||
|
||||
test_equal(track.track(), (unsigned)13);
|
||||
test_equal(track.count(), (unsigned)0);
|
||||
}
|
||||
|
||||
static void test_track_tag_destructor()
|
||||
|
|
Loading…
Reference in New Issue