core/tags/track: Move track_last_play() out of the track struct

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-10-29 02:51:19 -04:00
parent 90cdfd4cbd
commit ee71786c09
4 changed files with 21 additions and 25 deletions

View File

@ -62,19 +62,6 @@ track :: ~track()
tr_library->li_size--;
}
const std::string track :: date() const
{
char *buf;
std::string res = "Never";
if (tr_count > 0) {
buf = date_string(&tr_date);
res = buf;
g_free(buf);
}
return res;
}
const std::string track :: primary_key() const
{
return make_key(tr_library, tr_path);
@ -185,3 +172,16 @@ void track_played(struct track *track)
date_today(&track->tr_date);
track_db_commit();
}
const std::string track_last_play(struct track *track)
{
std::string res = "Never";
char *buf;
if (track->tr_count > 0) {
buf = date_string(&track->tr_date);
res = buf;
g_free(buf);
}
return res;
}

View File

@ -127,7 +127,7 @@ void QueueModel::get_value_vfunc(const Gtk::TreeIter &iter, int column,
case 7:
return set_val(track->tr_count, value);
case 8:
return set_val(track->date(), value);
return set_val(track_last_play(track), value);
case 9:
return set_val(Glib::Markup::escape_text(track_path(track)), value);
}

View File

@ -58,13 +58,6 @@ struct track : public GenericTag {
~track(); /**< Track destructor. */
/**
* @return A locale-dependent string containing the day this
* track was last played, or "Never" if the track has
* never been played.
*/
const std::string date() const;
/**
* A track's primary key is the concatenation of the library index
* and the relative path.
@ -122,4 +115,7 @@ const std::string track_path(struct track *);
/* Called to mark a track tag as played. */
void track_played(struct track *);
/* Called to find the date that this track was last played. */
const std::string track_last_play(struct track *);
#endif /* OCARINA_CORE_TAGS_TRACK_H */

View File

@ -32,7 +32,7 @@ static void test_track_tag_default()
test_equal(track.name(), (std::string)"");
test_equal(track.lowercase(), (std::string)"");
test_equal(track.primary_key(), (std::string)"");
test_equal(track.date(), (std::string)"Never");
test_equal(track_last_play(&track), (std::string)"Never");
test_equal(track_path(&track), (std::string)"");
test_equal(track.tr_track, (unsigned)0);
@ -49,7 +49,7 @@ static void verify_track_tag(struct track *track, unsigned int size)
test_equal(track->name(), (std::string)"Legend of Zelda Medley");
test_equal(track->lowercase(), (std::string)"legend of zelda medley");
test_equal(track->date(), (std::string)"Never");
test_equal(track_last_play(track), (std::string)"Never");
test_equal(track_path(track), (std::string)MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3");
test_equal(track->primary_key(), (std::string)"0/Hyrule Symphony/13 - Legend of Zelda Medley.mp3");
@ -185,11 +185,11 @@ static void test_track_tag_locale()
date = string_tm2str(now);
test_equal(track->tr_count, (unsigned)0);
test_equal(track->date(), "Never");
test_equal(track_last_play(track), "Never");
track_played(track);
test_equal(track->tr_count, (unsigned)1);
test_equal(track->date(), date);
test_equal(track_last_play(track), date);
g_free(date);
}