/** * @file * Copyright 2014 (c) Anna Schumaker. */ #include #include #include Track :: Track() : GenericTag(), _album(NULL), _artist(NULL), _genre(NULL), _library(NULL), _count(0), _length(0), _track(0) {} Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library, const std::string &filepath, const std::string &name, unsigned int length, unsigned int track) : GenericTag(name), _album(album), _artist(artist), _genre(genre), _library(library), _count(0), _length(length), _track(track), _path(filepath.substr(library->primary_key().size() + 1)) { //filter :: add(name(), index()); //filter :: add(_artist->name(), index()); //filter :: add(_album->name(), index()); _library->inc_size(); } Track :: ~Track() { if (_library) _library->dec_size(); } Album *Track :: album() { return _album; } Artist *Track :: artist() { return _artist; } Genre *Track :: genre() { return _genre; } Library *Track :: library() { return _library; } unsigned int Track :: count() { return _count; } unsigned int Track :: length() { return _length; } unsigned int Track :: track() { return _track; } const std::string Track :: date() const { struct tm tm; char buffer[20]; std::string res = "Never"; if (_count > 0) { tm.tm_mday = _date.day; tm.tm_mon = _date.month - 1; tm.tm_year = _date.year - 1900; strftime(buffer, 20, "%Ex", &tm); res = buffer; } return res; } const std::string Track :: path() const { if (_library) return _library->primary_key() + "/" + _path; return ""; } const std::string Track :: length_str() const { std::stringstream ss; unsigned int minutes = _length / 60; unsigned int seconds = _length % 60; ss << minutes << ":"; if (seconds < 10) ss << 0; ss << seconds; return ss.str(); } const std::string Track :: primary_key() const { std::stringstream ss; if (_library) ss << _library->index() << "/" << _path; return ss.str(); } void Track :: played() { time_t rawtime = time(NULL); struct tm *now = localtime(&rawtime); _count++; _date.day = now->tm_mday; _date.month = now->tm_mon + 1; _date.year = now->tm_year + 1900; //tagdb :: commit(); } int Track :: compare_date(const Track *rhs) { int ret = _date.year - rhs->_date.year; if (ret == 0) { ret = _date.month - rhs->_date.month; if (ret == 0) ret = _date.day - rhs->_date.day; } return ret; }