Clementine-audio-player-Mac.../src/song.h

155 lines
4.4 KiB
C
Raw Normal View History

2009-12-24 20:16:07 +01:00
#ifndef SONG_H
#define SONG_H
#include <QImage>
2009-12-24 20:16:07 +01:00
#include <QList>
2010-01-15 22:57:22 +01:00
#include <QSharedData>
#include <QSharedDataPointer>
#include <QSqlQuery>
#include <QString>
2009-12-24 20:16:07 +01:00
2010-02-03 23:20:31 +01:00
#include "engine_fwd.h"
2009-12-26 23:15:57 +01:00
namespace lastfm {
class Track;
}
2010-01-15 22:57:22 +01:00
struct SongData : public QSharedData {
SongData();
bool valid_;
int id_;
QString title_;
QString album_;
QString artist_;
QString albumartist_;
QString composer_;
int track_;
int disc_;
float bpm_;
int year_;
QString genre_;
QString comment_;
bool compilation_;
bool sampler_;
2010-01-15 22:57:22 +01:00
int length_;
int bitrate_;
int samplerate_;
int directory_id_;
QString filename_;
int mtime_;
int ctime_;
int filesize_;
// Filenames to album art for this song.
QString art_automatic_; // Guessed by LibraryWatcher
QString art_manual_; // Set by the user - should take priority
QImage image_;
2010-01-15 22:57:22 +01:00
};
2009-12-24 20:16:07 +01:00
class Song {
public:
Song();
2010-01-15 22:57:22 +01:00
Song(const Song& other);
2009-12-24 20:16:07 +01:00
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);
2009-12-26 23:15:57 +01:00
void InitFromLastFM(const lastfm::Track& track);
2010-02-03 23:20:31 +01:00
void InitFromSimpleMetaBundle(const Engine::SimpleMetaBundle& bundle);
2009-12-24 20:16:07 +01:00
// Save
void BindToQuery(QSqlQuery* query) const;
2009-12-29 20:22:02 +01:00
void ToLastFM(lastfm::Track* track) const;
2009-12-24 20:16:07 +01:00
// Simple accessors
2010-01-15 22:57:22 +01:00
bool is_valid() const { return d->valid_; }
int id() const { return d->id_; }
const QString& title() const { return d->title_; }
const QString& album() const { return d->album_; }
const QString& artist() const { return d->artist_; }
const QString& albumartist() const { return d->albumartist_; }
const QString& composer() const { return d->composer_; }
2010-01-15 22:57:22 +01:00
int track() const { return d->track_; }
int disc() const { return d->disc_; }
float bpm() const { return d->bpm_; }
int year() const { return d->year_; }
const QString& genre() const { return d->genre_; }
const QString& comment() const { return d->comment_; }
bool is_compilation() const { return d->compilation_ || d->sampler_; }
2010-01-15 22:57:22 +01:00
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_; }
const QString& filename() const { return d->filename_; }
2010-01-15 22:57:22 +01:00
uint mtime() const { return d->mtime_; }
uint ctime() const { return d->ctime_; }
int filesize() const { return d->filesize_; }
2009-12-24 20:16:07 +01:00
const QString& art_automatic() const { return d->art_automatic_; }
const QString& art_manual() const { return d->art_manual_; }
const QImage& image() const { return d->image_; }
2009-12-24 20:16:07 +01:00
// Pretty accessors
QString PrettyTitle() const;
QString PrettyTitleWithArtist() const;
QString PrettyLength() const;
// Loads and returns some album art for the song. Tries, in this order:
// 1) An image set explicitly with set_image (eg. last.fm radio)
// 2) An image set by the user with set_art_manual
// 3) An image found by the library scanner
QImage GetBestImage() const;
2009-12-24 20:16:07 +01:00
// Setters
2010-01-16 17:12:47 +01:00
bool IsEditable() const { return d->valid_ && !d->filename_.isNull(); }
bool Save() const;
2010-01-15 22:57:22 +01:00
void set_id(int id) { d->id_ = id; }
2010-01-16 17:12:47 +01:00
void set_title(const QString& v) { d->title_ = v; }
void set_album(const QString& v) { d->album_ = v; }
void set_artist(const QString& v) { d->artist_ = v; }
void set_albumartist(const QString& v) { d->albumartist_ = v; }
void set_composer(const QString& v) { d->composer_ = v; }
void set_track(int v) { d->track_ = v; }
void set_disc(int v) { d->disc_ = v; }
void set_bpm(float v) { d->bpm_ = v; }
void set_year(int v) { d->year_ = v; }
void set_genre(const QString& v) { d->genre_ = v; }
void set_comment(const QString& v) { d->comment_ = v; }
void set_compilation(bool v) { d->compilation_ = v; }
void set_sampler(bool v) { d->sampler_ = v; }
2010-01-16 17:12:47 +01:00
void set_length(int v) { d->length_ = v; }
void set_bitrate(int v) { d->bitrate_ = v; }
void set_samplerate(int v) { d->samplerate_ = v; }
void set_mtime(int v) { d->mtime_ = v; }
void set_ctime(int v) { d->ctime_ = v; }
void set_filesize(int v) { d->filesize_ = v; }
void set_art_automatic(const QString& v) { d->art_automatic_ = v; }
void set_art_manual(const QString& v) { d->art_manual_ = v; }
void set_image(const QImage& i) { d->image_ = i; }
2009-12-24 20:16:07 +01:00
// Comparison functions
bool IsMetadataEqual(const Song& other) const;
private:
2010-01-15 22:57:22 +01:00
QSharedDataPointer<SongData> d;
2009-12-24 20:16:07 +01:00
};
typedef QList<Song> SongList;
#endif // SONG_H