libsaria: Track play count

I've had a library field for this for a while, but I haven't been using
it.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-15 10:29:26 -04:00
parent 36bd2c2b66
commit 34cd70fa39
7 changed files with 22 additions and 2 deletions

View File

@ -41,6 +41,7 @@ namespace libsaria
gint64 position();
string posstr();
string durstr();
bool played();
/* Volume functions */
/*float get_volume();

View File

@ -38,6 +38,7 @@ namespace libsaria
void add_path(string);
void delete_path(Path *);
void update_path(Path *);
void save_path(Path *);
Track *lookup(unsigned int, unsigned int);
Playlist *get_playlist();

View File

@ -35,6 +35,7 @@ namespace libsaria
string *artist_lc;
string *album_lc;
void read_tags();
void mark_played();
public:
Track();

View File

@ -99,4 +99,9 @@ namespace libsaria
return to_string(position());
}
bool audio::played()
{
return position() > ((duration() * 3) / 4);
}
};

View File

@ -37,7 +37,7 @@ static void do_save_path(ofstream &stream, void *data)
(*it).save(stream);
}
void save_path(libsaria::library::Path *path)
void libsaria::library::save_path(libsaria::library::Path *path)
{
string filepath = libdir + "/" + id_to_filename(path->id);
libsaria::app::save(filepath, do_save_path, &path->data_state, path);

View File

@ -8,7 +8,6 @@ extern libsaria::Set lib_playlist;
void do_update_path(struct libsaria::library::Path *);
void notify_path_updated(struct libsaria::library::Path *);
void save_path(struct libsaria::library::Path *);
libsaria::library::Path *push_path(libsaria::library::Path &);
unsigned int schedule_load();
void remove_file(libsaria::library::Path *);

View File

@ -143,9 +143,22 @@ namespace libsaria
{
}
void Track::mark_played()
{
if (audio::played()) {
count++;
path->data_state = DIRTY;
libsaria::library::save_path(path);
}
}
void Track::load(bool play)
{
if (cur)
cur->mark_played();
println("Loading: " + title + " by " + artist);
if (path) {
prefs::set("libsaria.current.library", path->id);
prefs::set("libsaria.current.track", id);