mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-07 15:48:51 +01:00
Use shared data for song
This commit is contained in:
parent
07ef49f380
commit
e0bb24af07
231
src/song.cpp
231
src/song.cpp
@ -17,6 +17,8 @@
|
|||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "trackslider.h"
|
||||||
|
|
||||||
const char* Song::kColumnSpec =
|
const char* Song::kColumnSpec =
|
||||||
"title, album, artist, albumartist, composer, "
|
"title, album, artist, albumartist, composer, "
|
||||||
"track, disc, bpm, year, genre, comment, compilation, "
|
"track, disc, bpm, year, genre, comment, compilation, "
|
||||||
@ -38,7 +40,7 @@ const char* Song::kUpdateSpec =
|
|||||||
"directory = :directory_id, filename = :filename, mtime = :mtime, "
|
"directory = :directory_id, filename = :filename, mtime = :mtime, "
|
||||||
"ctime = :ctime, filesize = :filesize";
|
"ctime = :ctime, filesize = :filesize";
|
||||||
|
|
||||||
Song::Song()
|
SongData::SongData()
|
||||||
: valid_(false),
|
: valid_(false),
|
||||||
id_(-1),
|
id_(-1),
|
||||||
track_(-1),
|
track_(-1),
|
||||||
@ -56,9 +58,19 @@ Song::Song()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Song::Song()
|
||||||
|
: d(new SongData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Song::Song(const Song &other)
|
||||||
|
: d(other.d)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Song::InitFromFile(const QString& filename, int directory_id) {
|
void Song::InitFromFile(const QString& filename, int directory_id) {
|
||||||
filename_ = filename;
|
d->filename_ = filename;
|
||||||
directory_id_ = directory_id;
|
d->directory_id_ = directory_id;
|
||||||
|
|
||||||
TagLib::FileRef fileref = TagLib::FileRef(QFile::encodeName(filename).constData());
|
TagLib::FileRef fileref = TagLib::FileRef(QFile::encodeName(filename).constData());
|
||||||
|
|
||||||
@ -66,23 +78,23 @@ void Song::InitFromFile(const QString& filename, int directory_id) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QFileInfo info(filename);
|
QFileInfo info(filename);
|
||||||
filesize_ = info.size();
|
d->filesize_ = info.size();
|
||||||
mtime_ = info.lastModified().toTime_t();
|
d->mtime_ = info.lastModified().toTime_t();
|
||||||
ctime_ = info.created().toTime_t();
|
d->ctime_ = info.created().toTime_t();
|
||||||
|
|
||||||
TagLib::Tag* tag = fileref.tag();
|
TagLib::Tag* tag = fileref.tag();
|
||||||
if (tag) {
|
if (tag) {
|
||||||
#define strip(x) TStringToQString( x ).trimmed()
|
#define strip(x) TStringToQString( x ).trimmed()
|
||||||
title_ = strip(tag->title());
|
d->title_ = strip(tag->title());
|
||||||
artist_ = strip(tag->artist());
|
d->artist_ = strip(tag->artist());
|
||||||
album_ = strip(tag->album());
|
d->album_ = strip(tag->album());
|
||||||
comment_ = strip(tag->comment());
|
d->comment_ = strip(tag->comment());
|
||||||
genre_ = strip(tag->genre());
|
d->genre_ = strip(tag->genre());
|
||||||
year_ = tag->year();
|
d->year_ = tag->year();
|
||||||
track_ = tag->track();
|
d->track_ = tag->track();
|
||||||
#undef strip
|
#undef strip
|
||||||
|
|
||||||
valid_ = true;
|
d->valid_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString disc;
|
QString disc;
|
||||||
@ -93,13 +105,13 @@ void Song::InitFromFile(const QString& filename, int directory_id) {
|
|||||||
disc = TStringToQString(file->ID3v2Tag()->frameListMap()["TPOS"].front()->toString()).trimmed();
|
disc = TStringToQString(file->ID3v2Tag()->frameListMap()["TPOS"].front()->toString()).trimmed();
|
||||||
|
|
||||||
if (!file->ID3v2Tag()->frameListMap()["TBPM"].isEmpty())
|
if (!file->ID3v2Tag()->frameListMap()["TBPM"].isEmpty())
|
||||||
bpm_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TBPM"].front()->toString()).trimmed().toFloat();
|
d->bpm_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TBPM"].front()->toString()).trimmed().toFloat();
|
||||||
|
|
||||||
if (!file->ID3v2Tag()->frameListMap()["TCOM"].isEmpty())
|
if (!file->ID3v2Tag()->frameListMap()["TCOM"].isEmpty())
|
||||||
composer_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TCOM"].front()->toString()).trimmed();
|
d->composer_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TCOM"].front()->toString()).trimmed();
|
||||||
|
|
||||||
if (!file->ID3v2Tag()->frameListMap()["TPE2"].isEmpty()) // non-standard: Apple, Microsoft
|
if (!file->ID3v2Tag()->frameListMap()["TPE2"].isEmpty()) // non-standard: Apple, Microsoft
|
||||||
albumartist_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TPE2"].front()->toString()).trimmed();
|
d->albumartist_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TPE2"].front()->toString()).trimmed();
|
||||||
|
|
||||||
if (!file->ID3v2Tag()->frameListMap()["TCMP"].isEmpty())
|
if (!file->ID3v2Tag()->frameListMap()["TCMP"].isEmpty())
|
||||||
compilation = TStringToQString(file->ID3v2Tag()->frameListMap()["TCMP"].front()->toString()).trimmed();
|
compilation = TStringToQString(file->ID3v2Tag()->frameListMap()["TCMP"].front()->toString()).trimmed();
|
||||||
@ -108,10 +120,10 @@ void Song::InitFromFile(const QString& filename, int directory_id) {
|
|||||||
else if (TagLib::Ogg::Vorbis::File* file = dynamic_cast<TagLib::Ogg::Vorbis::File*>(fileref.file())) {
|
else if (TagLib::Ogg::Vorbis::File* file = dynamic_cast<TagLib::Ogg::Vorbis::File*>(fileref.file())) {
|
||||||
if (file->tag()) {
|
if (file->tag()) {
|
||||||
if ( !file->tag()->fieldListMap()["COMPOSER"].isEmpty() )
|
if ( !file->tag()->fieldListMap()["COMPOSER"].isEmpty() )
|
||||||
composer_ = TStringToQString(file->tag()->fieldListMap()["COMPOSER"].front()).trimmed();
|
d->composer_ = TStringToQString(file->tag()->fieldListMap()["COMPOSER"].front()).trimmed();
|
||||||
|
|
||||||
if ( !file->tag()->fieldListMap()["BPM"].isEmpty() )
|
if ( !file->tag()->fieldListMap()["BPM"].isEmpty() )
|
||||||
bpm_ = TStringToQString(file->tag()->fieldListMap()["BPM"].front()).trimmed().toFloat();
|
d->bpm_ = TStringToQString(file->tag()->fieldListMap()["BPM"].front()).trimmed().toFloat();
|
||||||
|
|
||||||
if ( !file->tag()->fieldListMap()["DISCNUMBER"].isEmpty() )
|
if ( !file->tag()->fieldListMap()["DISCNUMBER"].isEmpty() )
|
||||||
disc = TStringToQString(file->tag()->fieldListMap()["DISCNUMBER"].front()).trimmed();
|
disc = TStringToQString(file->tag()->fieldListMap()["DISCNUMBER"].front()).trimmed();
|
||||||
@ -123,10 +135,10 @@ void Song::InitFromFile(const QString& filename, int directory_id) {
|
|||||||
else if (TagLib::FLAC::File* file = dynamic_cast<TagLib::FLAC::File*>(fileref.file())) {
|
else if (TagLib::FLAC::File* file = dynamic_cast<TagLib::FLAC::File*>(fileref.file())) {
|
||||||
if ( file->xiphComment() ) {
|
if ( file->xiphComment() ) {
|
||||||
if (!file->xiphComment()->fieldListMap()["COMPOSER"].isEmpty())
|
if (!file->xiphComment()->fieldListMap()["COMPOSER"].isEmpty())
|
||||||
composer_ = TStringToQString( file->xiphComment()->fieldListMap()["COMPOSER"].front() ).trimmed();
|
d->composer_ = TStringToQString( file->xiphComment()->fieldListMap()["COMPOSER"].front() ).trimmed();
|
||||||
|
|
||||||
if (!file->xiphComment()->fieldListMap()["BPM"].isEmpty() )
|
if (!file->xiphComment()->fieldListMap()["BPM"].isEmpty() )
|
||||||
bpm_ = TStringToQString( file->xiphComment()->fieldListMap()["BPM"].front() ).trimmed().toFloat();
|
d->bpm_ = TStringToQString( file->xiphComment()->fieldListMap()["BPM"].front() ).trimmed().toFloat();
|
||||||
|
|
||||||
if (!file->xiphComment()->fieldListMap()["DISCNUMBER"].isEmpty() )
|
if (!file->xiphComment()->fieldListMap()["DISCNUMBER"].isEmpty() )
|
||||||
disc = TStringToQString( file->xiphComment()->fieldListMap()["DISCNUMBER"].front() ).trimmed();
|
disc = TStringToQString( file->xiphComment()->fieldListMap()["DISCNUMBER"].front() ).trimmed();
|
||||||
@ -140,55 +152,55 @@ void Song::InitFromFile(const QString& filename, int directory_id) {
|
|||||||
int i = disc.indexOf('/');
|
int i = disc.indexOf('/');
|
||||||
if ( i != -1 )
|
if ( i != -1 )
|
||||||
// disc.right( i ).toInt() is total number of discs, we don't use this at the moment
|
// disc.right( i ).toInt() is total number of discs, we don't use this at the moment
|
||||||
disc_ = disc.left( i ).toInt();
|
d->disc_ = disc.left( i ).toInt();
|
||||||
else
|
else
|
||||||
disc_ = disc.toInt();
|
d->disc_ = disc.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( compilation.isEmpty() ) {
|
if ( compilation.isEmpty() ) {
|
||||||
// well, it wasn't set, but if the artist is VA assume it's a compilation
|
// well, it wasn't set, but if the artist is VA assume it's a compilation
|
||||||
if ( artist_.toLower() == "various artists" )
|
if ( d->artist_.toLower() == "various artists" )
|
||||||
compilation_ = true;
|
d->compilation_ = true;
|
||||||
} else {
|
} else {
|
||||||
int i = compilation.toInt();
|
int i = compilation.toInt();
|
||||||
compilation_ = (i == 1);
|
d->compilation_ = (i == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bitrate_ = fileref.audioProperties()->bitrate();
|
d->bitrate_ = fileref.audioProperties()->bitrate();
|
||||||
length_ = fileref.audioProperties()->length();
|
d->length_ = fileref.audioProperties()->length();
|
||||||
samplerate_ = fileref.audioProperties()->sampleRate();
|
d->samplerate_ = fileref.audioProperties()->sampleRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Song::InitFromQuery(const QSqlQuery& q) {
|
void Song::InitFromQuery(const QSqlQuery& q) {
|
||||||
valid_ = true;
|
d->valid_ = true;
|
||||||
|
|
||||||
#define tostr(n) (q.value(n).isNull() ? QString::null : q.value(n).toString())
|
#define tostr(n) (q.value(n).isNull() ? QString::null : q.value(n).toString())
|
||||||
#define toint(n) (q.value(n).isNull() ? -1 : q.value(n).toInt())
|
#define toint(n) (q.value(n).isNull() ? -1 : q.value(n).toInt())
|
||||||
#define tofloat(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
|
#define tofloat(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
|
||||||
|
|
||||||
id_ = toint(0);
|
d->id_ = toint(0);
|
||||||
title_ = tostr(1);
|
d->title_ = tostr(1);
|
||||||
album_ = tostr(2);
|
d->album_ = tostr(2);
|
||||||
artist_ = tostr(3);
|
d->artist_ = tostr(3);
|
||||||
albumartist_ = tostr(4);
|
d->albumartist_ = tostr(4);
|
||||||
composer_ = tostr(5);
|
d->composer_ = tostr(5);
|
||||||
track_ = toint(6);
|
d->track_ = toint(6);
|
||||||
disc_ = toint(7);
|
d->disc_ = toint(7);
|
||||||
bpm_ = tofloat(8);
|
d->bpm_ = tofloat(8);
|
||||||
year_ = toint(9);
|
d->year_ = toint(9);
|
||||||
genre_ = tostr(10);
|
d->genre_ = tostr(10);
|
||||||
comment_ = tostr(11);
|
d->comment_ = tostr(11);
|
||||||
compilation_ = q.value(12).toBool();
|
d->compilation_ = q.value(12).toBool();
|
||||||
|
|
||||||
length_ = toint(13);
|
d->length_ = toint(13);
|
||||||
bitrate_ = toint(14);
|
d->bitrate_ = toint(14);
|
||||||
samplerate_ = toint(15);
|
d->samplerate_ = toint(15);
|
||||||
|
|
||||||
directory_id_ = toint(16);
|
d->directory_id_ = toint(16);
|
||||||
filename_ = tostr(17);
|
d->filename_ = tostr(17);
|
||||||
mtime_ = toint(18);
|
d->mtime_ = toint(18);
|
||||||
ctime_ = toint(19);
|
d->ctime_ = toint(19);
|
||||||
filesize_ = toint(20);
|
d->filesize_ = toint(20);
|
||||||
|
|
||||||
#undef tostr
|
#undef tostr
|
||||||
#undef toint
|
#undef toint
|
||||||
@ -196,40 +208,40 @@ void Song::InitFromQuery(const QSqlQuery& q) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Song::InitFromLastFM(const lastfm::Track& track) {
|
void Song::InitFromLastFM(const lastfm::Track& track) {
|
||||||
valid_ = true;
|
d->valid_ = true;
|
||||||
|
|
||||||
title_ = track.title();
|
d->title_ = track.title();
|
||||||
album_ = track.album();
|
d->album_ = track.album();
|
||||||
artist_ = track.artist();
|
d->artist_ = track.artist();
|
||||||
track_ = track.trackNumber();
|
d->track_ = track.trackNumber();
|
||||||
length_ = track.duration();
|
d->length_ = track.duration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Song::BindToQuery(QSqlQuery *query) const {
|
void Song::BindToQuery(QSqlQuery *query) const {
|
||||||
#define intval(x) (x == -1 ? QVariant() : x)
|
#define intval(x) (x == -1 ? QVariant() : x)
|
||||||
|
|
||||||
query->bindValue(":title", title_);
|
query->bindValue(":title", d->title_);
|
||||||
query->bindValue(":album", album_);
|
query->bindValue(":album", d->album_);
|
||||||
query->bindValue(":artist", artist_);
|
query->bindValue(":artist", d->artist_);
|
||||||
query->bindValue(":albumartist", albumartist_);
|
query->bindValue(":albumartist", d->albumartist_);
|
||||||
query->bindValue(":composer", composer_);
|
query->bindValue(":composer", d->composer_);
|
||||||
query->bindValue(":track", intval(track_));
|
query->bindValue(":track", intval(d->track_));
|
||||||
query->bindValue(":disc", intval(disc_));
|
query->bindValue(":disc", intval(d->disc_));
|
||||||
query->bindValue(":bpm", intval(bpm_));
|
query->bindValue(":bpm", intval(d->bpm_));
|
||||||
query->bindValue(":year", intval(year_));
|
query->bindValue(":year", intval(d->year_));
|
||||||
query->bindValue(":genre", genre_);
|
query->bindValue(":genre", d->genre_);
|
||||||
query->bindValue(":comment", comment_);
|
query->bindValue(":comment", d->comment_);
|
||||||
query->bindValue(":compilation", compilation_ ? 1 : 0);
|
query->bindValue(":compilation", d->compilation_ ? 1 : 0);
|
||||||
|
|
||||||
query->bindValue(":length", intval(length_));
|
query->bindValue(":length", intval(d->length_));
|
||||||
query->bindValue(":bitrate", intval(bitrate_));
|
query->bindValue(":bitrate", intval(d->bitrate_));
|
||||||
query->bindValue(":samplerate", intval(samplerate_));
|
query->bindValue(":samplerate", intval(d->samplerate_));
|
||||||
|
|
||||||
query->bindValue(":directory_id", intval(directory_id_));
|
query->bindValue(":directory_id", intval(d->directory_id_));
|
||||||
query->bindValue(":filename", filename_);
|
query->bindValue(":filename", d->filename_);
|
||||||
query->bindValue(":mtime", intval(mtime_));
|
query->bindValue(":mtime", intval(d->mtime_));
|
||||||
query->bindValue(":ctime", intval(ctime_));
|
query->bindValue(":ctime", intval(d->ctime_));
|
||||||
query->bindValue(":filesize", intval(filesize_));
|
query->bindValue(":filesize", intval(d->filesize_));
|
||||||
|
|
||||||
#undef intval
|
#undef intval
|
||||||
}
|
}
|
||||||
@ -237,64 +249,55 @@ void Song::BindToQuery(QSqlQuery *query) const {
|
|||||||
void Song::ToLastFM(lastfm::Track* track) const {
|
void Song::ToLastFM(lastfm::Track* track) const {
|
||||||
lastfm::MutableTrack mtrack(*track);
|
lastfm::MutableTrack mtrack(*track);
|
||||||
|
|
||||||
mtrack.setArtist(artist_);
|
mtrack.setArtist(d->artist_);
|
||||||
mtrack.setAlbum(album_);
|
mtrack.setAlbum(d->album_);
|
||||||
mtrack.setTitle(title_);
|
mtrack.setTitle(d->title_);
|
||||||
mtrack.setDuration(length_);
|
mtrack.setDuration(d->length_);
|
||||||
mtrack.setTrackNumber(track_);
|
mtrack.setTrackNumber(d->track_);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Song::PrettyTitleWithArtist() const {
|
QString Song::PrettyTitleWithArtist() const {
|
||||||
QString title(title_);
|
QString title(d->title_);
|
||||||
|
|
||||||
if (title.isEmpty())
|
if (title.isEmpty())
|
||||||
title = QFileInfo(filename_).baseName();
|
title = QFileInfo(d->filename_).baseName();
|
||||||
|
|
||||||
if (compilation_ && !artist_.isEmpty())
|
if (d->compilation_ && !d->artist_.isEmpty())
|
||||||
title = artist_ + " - " + title;
|
title = d->artist_ + " - " + title;
|
||||||
|
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Song::PrettyTitle() const {
|
QString Song::PrettyTitle() const {
|
||||||
QString title(title_);
|
QString title(d->title_);
|
||||||
|
|
||||||
if (title.isEmpty())
|
if (title.isEmpty())
|
||||||
title = QFileInfo(filename_).baseName();
|
title = QFileInfo(d->filename_).baseName();
|
||||||
|
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Song::PrettyLength() const {
|
QString Song::PrettyLength() const {
|
||||||
if (length_ == -1)
|
if (d->length_ == -1)
|
||||||
return QString::null;
|
return QString::null;
|
||||||
|
|
||||||
int hours = length_ / (60*60);
|
return TrackSlider::PrettyTime(d->length_);
|
||||||
int minutes = (length_ / 60) % 60;
|
|
||||||
int seconds = length_ % 60;
|
|
||||||
|
|
||||||
QString text;
|
|
||||||
if (hours)
|
|
||||||
text.sprintf("%d:%02d:%02d", hours, minutes, seconds);
|
|
||||||
else
|
|
||||||
text.sprintf("%d:%02d", minutes, seconds);
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::IsMetadataEqual(const Song& other) const {
|
bool Song::IsMetadataEqual(const Song& other) const {
|
||||||
return title_ == other.title_ &&
|
return d->title_ == other.d->title_ &&
|
||||||
album_ == other.album_ &&
|
d->album_ == other.d->album_ &&
|
||||||
artist_ == other.artist_ &&
|
d->artist_ == other.d->artist_ &&
|
||||||
albumartist_ == other.albumartist_ &&
|
d->albumartist_ == other.d->albumartist_ &&
|
||||||
composer_ == other.composer_ &&
|
d->composer_ == other.d->composer_ &&
|
||||||
track_ == other.track_ &&
|
d->track_ == other.d->track_ &&
|
||||||
disc_ == other.disc_ &&
|
d->disc_ == other.d->disc_ &&
|
||||||
qFuzzyCompare(bpm_, other.bpm_) &&
|
qFuzzyCompare(d->bpm_, other.d->bpm_) &&
|
||||||
year_ == other.year_ &&
|
d->year_ == other.d->year_ &&
|
||||||
genre_ == other.genre_ &&
|
d->genre_ == other.d->genre_ &&
|
||||||
comment_ == other.comment_ &&
|
d->comment_ == other.d->comment_ &&
|
||||||
compilation_ == other.compilation_ &&
|
d->compilation_ == other.d->compilation_ &&
|
||||||
length_ == other.length_ &&
|
d->length_ == other.d->length_ &&
|
||||||
bitrate_ == other.bitrate_ &&
|
d->bitrate_ == other.d->bitrate_ &&
|
||||||
samplerate_ == other.samplerate_;
|
d->samplerate_ == other.d->samplerate_;
|
||||||
}
|
}
|
||||||
|
122
src/song.h
122
src/song.h
@ -4,69 +4,16 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
|
#include <QSharedData>
|
||||||
|
#include <QSharedDataPointer>
|
||||||
|
|
||||||
namespace lastfm {
|
namespace lastfm {
|
||||||
class Track;
|
class Track;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: QSharedData
|
struct SongData : public QSharedData {
|
||||||
class Song {
|
SongData();
|
||||||
public:
|
|
||||||
Song();
|
|
||||||
|
|
||||||
static const char* kColumnSpec;
|
|
||||||
static const char* kBindSpec;
|
|
||||||
static const char* kUpdateSpec;
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
void InitFromFile(const QString& filename, int directory_id);
|
|
||||||
void InitFromQuery(const QSqlQuery& query);
|
|
||||||
void InitFromLastFM(const lastfm::Track& track);
|
|
||||||
|
|
||||||
// Save
|
|
||||||
void BindToQuery(QSqlQuery* query) const;
|
|
||||||
void ToLastFM(lastfm::Track* track) const;
|
|
||||||
|
|
||||||
// Simple accessors
|
|
||||||
bool is_valid() const { return valid_; }
|
|
||||||
int id() const { return id_; }
|
|
||||||
|
|
||||||
QString title() const { return title_; }
|
|
||||||
QString album() const { return album_; }
|
|
||||||
QString artist() const { return artist_; }
|
|
||||||
QString albumartist() const { return albumartist_; }
|
|
||||||
QString composer() const { return composer_; }
|
|
||||||
int track() const { return track_; }
|
|
||||||
int disc() const { return disc_; }
|
|
||||||
float bpm() const { return bpm_; }
|
|
||||||
int year() const { return year_; }
|
|
||||||
QString genre() const { return genre_; }
|
|
||||||
QString comment() const { return comment_; }
|
|
||||||
bool is_compilation() const { return compilation_; }
|
|
||||||
|
|
||||||
int length() const { return length_; }
|
|
||||||
int bitrate() const { return bitrate_; }
|
|
||||||
int samplerate() const { return samplerate_; }
|
|
||||||
|
|
||||||
int directory_id() const { return directory_id_; }
|
|
||||||
QString filename() const { return filename_; }
|
|
||||||
uint mtime() const { return mtime_; }
|
|
||||||
uint ctime() const { return ctime_; }
|
|
||||||
int filesize() const { return filesize_; }
|
|
||||||
|
|
||||||
// Pretty accessors
|
|
||||||
QString PrettyTitle() const;
|
|
||||||
QString PrettyTitleWithArtist() const;
|
|
||||||
QString PrettyLength() const;
|
|
||||||
|
|
||||||
// Setters
|
|
||||||
void set_id(int id) { id_ = id; }
|
|
||||||
void set_title(const QString& title) { title_ = title; }
|
|
||||||
|
|
||||||
// Comparison functions
|
|
||||||
bool IsMetadataEqual(const Song& other) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool valid_;
|
bool valid_;
|
||||||
int id_;
|
int id_;
|
||||||
|
|
||||||
@ -94,6 +41,67 @@ class Song {
|
|||||||
int filesize_;
|
int filesize_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Song {
|
||||||
|
public:
|
||||||
|
Song();
|
||||||
|
Song(const Song& other);
|
||||||
|
|
||||||
|
static const char* kColumnSpec;
|
||||||
|
static const char* kBindSpec;
|
||||||
|
static const char* kUpdateSpec;
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
void InitFromFile(const QString& filename, int directory_id);
|
||||||
|
void InitFromQuery(const QSqlQuery& query);
|
||||||
|
void InitFromLastFM(const lastfm::Track& track);
|
||||||
|
|
||||||
|
// Save
|
||||||
|
void BindToQuery(QSqlQuery* query) const;
|
||||||
|
void ToLastFM(lastfm::Track* track) const;
|
||||||
|
|
||||||
|
// Simple accessors
|
||||||
|
bool is_valid() const { return d->valid_; }
|
||||||
|
int id() const { return d->id_; }
|
||||||
|
|
||||||
|
QString title() const { return d->title_; }
|
||||||
|
QString album() const { return d->album_; }
|
||||||
|
QString artist() const { return d->artist_; }
|
||||||
|
QString albumartist() const { return d->albumartist_; }
|
||||||
|
QString composer() const { return d->composer_; }
|
||||||
|
int track() const { return d->track_; }
|
||||||
|
int disc() const { return d->disc_; }
|
||||||
|
float bpm() const { return d->bpm_; }
|
||||||
|
int year() const { return d->year_; }
|
||||||
|
QString genre() const { return d->genre_; }
|
||||||
|
QString comment() const { return d->comment_; }
|
||||||
|
bool is_compilation() const { return d->compilation_; }
|
||||||
|
|
||||||
|
int length() const { return d->length_; }
|
||||||
|
int bitrate() const { return d->bitrate_; }
|
||||||
|
int samplerate() const { return d->samplerate_; }
|
||||||
|
|
||||||
|
int directory_id() const { return d->directory_id_; }
|
||||||
|
QString filename() const { return d->filename_; }
|
||||||
|
uint mtime() const { return d->mtime_; }
|
||||||
|
uint ctime() const { return d->ctime_; }
|
||||||
|
int filesize() const { return d->filesize_; }
|
||||||
|
|
||||||
|
// Pretty accessors
|
||||||
|
QString PrettyTitle() const;
|
||||||
|
QString PrettyTitleWithArtist() const;
|
||||||
|
QString PrettyLength() const;
|
||||||
|
|
||||||
|
// Setters
|
||||||
|
void set_id(int id) { d->id_ = id; }
|
||||||
|
void set_title(const QString& title) { d->title_ = title; }
|
||||||
|
|
||||||
|
// Comparison functions
|
||||||
|
bool IsMetadataEqual(const Song& other) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<SongData> d;
|
||||||
|
};
|
||||||
|
|
||||||
typedef QList<Song> SongList;
|
typedef QList<Song> SongList;
|
||||||
|
|
||||||
#endif // SONG_H
|
#endif // SONG_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user