2009-12-24 20:16:07 +01:00
|
|
|
#ifndef LIBRARYBACKEND_H
|
|
|
|
#define LIBRARYBACKEND_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSqlError>
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QMutex>
|
2010-02-27 21:12:22 +01:00
|
|
|
#include <QSet>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include "directory.h"
|
|
|
|
#include "song.h"
|
2010-02-28 19:04:50 +01:00
|
|
|
#include "libraryquery.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
class LibraryBackend : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-03-03 00:37:12 +01:00
|
|
|
LibraryBackend(QObject* parent = 0, const QString& database_name = QString());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-28 23:07:59 +01:00
|
|
|
struct Album {
|
2010-02-28 20:25:52 +01:00
|
|
|
QString artist;
|
2010-02-28 19:04:50 +01:00
|
|
|
QString album_name;
|
2010-02-28 23:07:59 +01:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
QString art_automatic;
|
|
|
|
QString art_manual;
|
|
|
|
};
|
2010-02-28 23:07:59 +01:00
|
|
|
typedef QList<Album> AlbumList;
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-03-08 19:07:18 +01:00
|
|
|
static const int kSchemaVersion;
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// This actually refers to the location of the sqlite database
|
2010-03-03 00:37:12 +01:00
|
|
|
static QString DefaultDatabaseDirectory();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Get a list of directories in the library. Emits DirectoriesDiscovered.
|
|
|
|
void LoadDirectoriesAsync();
|
|
|
|
|
|
|
|
// Counts the songs in the library. Emits TotalSongCountUpdated
|
|
|
|
void UpdateTotalSongCountAsync();
|
|
|
|
|
|
|
|
SongList FindSongsInDirectory(int id);
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
QStringList GetAllArtists(const QueryOptions& opt = QueryOptions());
|
|
|
|
SongList GetSongs(const QString& artist, const QString& album, const QueryOptions& opt = QueryOptions());
|
|
|
|
|
|
|
|
bool HasCompilations(const QueryOptions& opt = QueryOptions());
|
|
|
|
SongList GetCompilationSongs(const QString& album, const QueryOptions& opt = QueryOptions());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-28 23:07:59 +01:00
|
|
|
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
|
|
|
AlbumList GetAlbumsByArtist(const QString& artist, const QueryOptions& opt = QueryOptions());
|
|
|
|
AlbumList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
|
|
|
|
|
2010-02-28 20:25:52 +01:00
|
|
|
void UpdateManualAlbumArtAsync(const QString& artist, const QString& album, const QString& art);
|
2010-02-28 23:07:59 +01:00
|
|
|
Album GetAlbumArt(const QString& artist, const QString& album);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
Song GetSongById(int id);
|
|
|
|
|
|
|
|
void AddDirectory(const QString& path);
|
|
|
|
void RemoveDirectory(const Directory& dir);
|
|
|
|
|
2010-02-27 21:12:22 +01:00
|
|
|
void UpdateCompilationsAsync();
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
public slots:
|
|
|
|
void LoadDirectories();
|
|
|
|
void UpdateTotalSongCount();
|
|
|
|
void AddOrUpdateSongs(const SongList& songs);
|
|
|
|
void UpdateMTimesOnly(const SongList& songs);
|
|
|
|
void DeleteSongs(const SongList& songs);
|
2010-02-27 21:12:22 +01:00
|
|
|
void UpdateCompilations();
|
2010-03-03 19:38:20 +01:00
|
|
|
void UpdateManualAlbumArt(const QString& artist, const QString& album, const QString& art);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void Error(const QString& message);
|
|
|
|
|
|
|
|
void DirectoriesDiscovered(const DirectoryList& directories);
|
|
|
|
void DirectoriesDeleted(const DirectoryList& directories);
|
|
|
|
|
|
|
|
void SongsDiscovered(const SongList& songs);
|
|
|
|
void SongsDeleted(const SongList& songs);
|
|
|
|
|
|
|
|
void TotalSongCountUpdated(int total);
|
|
|
|
|
|
|
|
private:
|
2010-02-27 21:12:22 +01:00
|
|
|
struct CompilationInfo {
|
|
|
|
CompilationInfo() : has_samplers(false), has_not_samplers(false) {}
|
|
|
|
|
|
|
|
QSet<QString> artists;
|
|
|
|
QSet<QString> directories;
|
|
|
|
|
|
|
|
bool has_samplers;
|
|
|
|
bool has_not_samplers;
|
|
|
|
};
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
QSqlDatabase Connect();
|
2010-02-27 21:12:22 +01:00
|
|
|
void UpdateDatabaseSchema(int version, QSqlDatabase& db);
|
2009-12-24 20:16:07 +01:00
|
|
|
bool CheckErrors(const QSqlError& error);
|
|
|
|
|
2010-02-27 21:12:22 +01:00
|
|
|
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
|
|
|
SongList& updated_songs,
|
|
|
|
const QString& album, int sampler);
|
2010-02-28 23:07:59 +01:00
|
|
|
AlbumList GetAlbums(const QString& artist, bool compilation = false,
|
|
|
|
const QueryOptions& opt = QueryOptions());
|
2010-02-27 21:12:22 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private:
|
|
|
|
static const char* kDatabaseName;
|
2010-02-27 21:12:22 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
QString directory_;
|
|
|
|
QMutex connect_mutex_;
|
2010-03-01 23:00:15 +01:00
|
|
|
|
2010-03-03 00:37:12 +01:00
|
|
|
// Used by tests
|
|
|
|
QString injected_database_name_;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LIBRARYBACKEND_H
|