2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#ifndef LIBRARYBACKEND_H
|
|
|
|
#define LIBRARYBACKEND_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2010-02-27 21:12:22 +01:00
|
|
|
#include <QSet>
|
2011-11-28 14:51:35 +01:00
|
|
|
#include <QUrl>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include "directory.h"
|
2010-02-28 19:04:50 +01:00
|
|
|
#include "libraryquery.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-05-09 02:10:26 +02:00
|
|
|
class Database;
|
2010-11-18 21:19:33 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
namespace smart_playlists {
|
|
|
|
class Search;
|
|
|
|
}
|
2010-03-21 14:29:06 +01:00
|
|
|
|
2010-08-31 23:24:57 +02:00
|
|
|
class LibraryBackendInterface : public QObject {
|
2011-05-20 01:02:15 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
LibraryBackendInterface(QObject* parent = nullptr) : QObject(parent) {}
|
2010-08-31 23:24:57 +02:00
|
|
|
virtual ~LibraryBackendInterface() {}
|
2010-06-02 18:22:20 +02:00
|
|
|
|
2010-02-28 23:07:59 +01:00
|
|
|
struct Album {
|
2010-03-23 22:52:42 +01:00
|
|
|
Album() {}
|
|
|
|
Album(const QString& _artist, const QString& _album_name,
|
2010-07-19 20:08:25 +02:00
|
|
|
const QString& _art_automatic, const QString& _art_manual,
|
2011-04-28 14:27:53 +02:00
|
|
|
const QUrl& _first_url)
|
2014-02-07 16:34:20 +01:00
|
|
|
: artist(_artist),
|
|
|
|
album_name(_album_name),
|
|
|
|
art_automatic(_art_automatic),
|
|
|
|
art_manual(_art_manual),
|
|
|
|
first_url(_first_url) {}
|
2010-03-23 22:52:42 +01:00
|
|
|
|
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;
|
2011-04-28 14:27:53 +02:00
|
|
|
QUrl first_url;
|
2010-02-28 19:04:50 +01:00
|
|
|
};
|
2010-02-28 23:07:59 +01:00
|
|
|
typedef QList<Album> AlbumList;
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2011-08-29 03:37:55 +02:00
|
|
|
virtual QString songs_table() const = 0;
|
|
|
|
|
2010-08-31 23:24:57 +02:00
|
|
|
// Get a list of directories in the library. Emits DirectoriesDiscovered.
|
|
|
|
virtual void LoadDirectoriesAsync() = 0;
|
|
|
|
|
|
|
|
// Counts the songs in the library. Emits TotalSongCountUpdated
|
|
|
|
virtual void UpdateTotalSongCountAsync() = 0;
|
|
|
|
|
|
|
|
virtual SongList FindSongsInDirectory(int id) = 0;
|
|
|
|
virtual SubdirectoryList SubdirsInDirectory(int id) = 0;
|
|
|
|
virtual DirectoryList GetAllDirectories() = 0;
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual void ChangeDirPath(int id, const QString& old_path,
|
|
|
|
const QString& new_path) = 0;
|
2010-08-31 23:24:57 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual QStringList GetAllArtists(
|
|
|
|
const QueryOptions& opt = QueryOptions()) = 0;
|
|
|
|
virtual QStringList GetAllArtistsWithAlbums(
|
|
|
|
const QueryOptions& opt = QueryOptions()) = 0;
|
|
|
|
virtual SongList GetSongsByAlbum(
|
|
|
|
const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
|
|
|
|
virtual SongList GetSongs(const QString& artist, const QString& album,
|
|
|
|
const QueryOptions& opt = QueryOptions()) = 0;
|
2010-08-31 23:24:57 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual SongList GetCompilationSongs(
|
|
|
|
const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
|
2010-08-31 23:24:57 +02:00
|
|
|
|
|
|
|
virtual AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions()) = 0;
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual AlbumList GetAlbumsByArtist(
|
|
|
|
const QString& artist, const QueryOptions& opt = QueryOptions()) = 0;
|
|
|
|
virtual AlbumList GetCompilationAlbums(
|
|
|
|
const QueryOptions& opt = QueryOptions()) = 0;
|
|
|
|
|
|
|
|
virtual void UpdateManualAlbumArtAsync(const QString& artist,
|
|
|
|
const QString& album,
|
|
|
|
const QString& art) = 0;
|
2010-08-31 23:24:57 +02:00
|
|
|
virtual Album GetAlbumArt(const QString& artist, const QString& album) = 0;
|
|
|
|
|
|
|
|
virtual Song GetSongById(int id) = 0;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Returns all sections of a song with the given filename. If there's just one
|
|
|
|
// section
|
2011-01-15 19:46:23 +01:00
|
|
|
// the resulting list will have it's size equal to 1.
|
2011-04-28 14:27:53 +02:00
|
|
|
virtual SongList GetSongsByUrl(const QUrl& url) = 0;
|
2014-02-07 16:34:20 +01:00
|
|
|
// Returns a section of a song with the given filename and beginning. If the
|
|
|
|
// section
|
2011-01-12 00:09:59 +01:00
|
|
|
// is not present in library, returns invalid song.
|
2014-02-07 16:34:20 +01:00
|
|
|
// Using default beginning value is suitable when searching for single-section
|
|
|
|
// songs.
|
2011-04-28 14:27:53 +02:00
|
|
|
virtual Song GetSongByUrl(const QUrl& url, qint64 beginning = 0) = 0;
|
2011-01-12 00:09:59 +01:00
|
|
|
|
2010-08-31 23:24:57 +02:00
|
|
|
virtual void AddDirectory(const QString& path) = 0;
|
|
|
|
virtual void RemoveDirectory(const Directory& dir) = 0;
|
|
|
|
|
|
|
|
virtual bool ExecQuery(LibraryQuery* q) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LibraryBackend : public LibraryBackendInterface {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-02-24 18:36:37 +01:00
|
|
|
static const char* kSettingsGroup;
|
|
|
|
|
2014-02-10 16:03:54 +01:00
|
|
|
Q_INVOKABLE LibraryBackend(QObject* parent = nullptr);
|
2014-02-07 16:34:20 +01:00
|
|
|
void Init(Database* db, const QString& songs_table, const QString& dirs_table,
|
|
|
|
const QString& subdirs_table, const QString& fts_table);
|
2010-08-31 23:24:57 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Database* db() const { return db_; }
|
2010-08-31 23:24:57 +02:00
|
|
|
|
2010-05-09 19:32:07 +02:00
|
|
|
QString songs_table() const { return songs_table_; }
|
|
|
|
QString dirs_table() const { return dirs_table_; }
|
|
|
|
QString subdirs_table() const { return subdirs_table_; }
|
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-04-04 16:59:55 +02:00
|
|
|
SubdirectoryList SubdirsInDirectory(int id);
|
2010-07-04 14:10:44 +02:00
|
|
|
DirectoryList GetAllDirectories();
|
2011-04-28 14:27:53 +02:00
|
|
|
void ChangeDirPath(int id, const QString& old_path, const QString& new_path);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QStringList GetAll(const QString& column,
|
|
|
|
const QueryOptions& opt = QueryOptions());
|
2010-02-28 19:04:50 +01:00
|
|
|
QStringList GetAllArtists(const QueryOptions& opt = QueryOptions());
|
2010-06-12 00:35:41 +02:00
|
|
|
QStringList GetAllArtistsWithAlbums(const QueryOptions& opt = QueryOptions());
|
2014-02-07 16:34:20 +01:00
|
|
|
SongList GetSongsByAlbum(const QString& album,
|
|
|
|
const QueryOptions& opt = QueryOptions());
|
|
|
|
SongList GetSongs(const QString& artist, const QString& album,
|
|
|
|
const QueryOptions& opt = QueryOptions());
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
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());
|
2014-02-07 16:34:20 +01:00
|
|
|
AlbumList GetAlbumsByArtist(const QString& artist,
|
|
|
|
const QueryOptions& opt = QueryOptions());
|
2010-02-28 23:07:59 +01:00
|
|
|
AlbumList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
|
|
|
|
|
2014-02-07 16:34:20 +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);
|
2010-11-27 17:14:09 +01:00
|
|
|
SongList GetSongsById(const QList<int>& ids);
|
|
|
|
SongList GetSongsById(const QStringList& ids);
|
|
|
|
SongList GetSongsByForeignId(const QStringList& ids, const QString& table,
|
|
|
|
const QString& column);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2011-04-28 14:27:53 +02:00
|
|
|
SongList GetSongsByUrl(const QUrl& url);
|
|
|
|
Song GetSongByUrl(const QUrl& url, qint64 beginning = 0);
|
2011-01-12 00:09:59 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void AddDirectory(const QString& path);
|
|
|
|
void RemoveDirectory(const Directory& dir);
|
|
|
|
|
2010-03-31 02:30:57 +02:00
|
|
|
bool ExecQuery(LibraryQuery* q);
|
2012-02-19 14:38:24 +01:00
|
|
|
SongList ExecLibraryQuery(LibraryQuery* query);
|
2010-11-18 21:19:33 +01:00
|
|
|
SongList FindSongs(const smart_playlists::Search& search);
|
2013-03-26 23:56:46 +01:00
|
|
|
SongList GetAllSongs();
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2010-10-17 21:27:31 +02:00
|
|
|
void IncrementPlayCountAsync(int id);
|
2010-11-01 22:15:52 +01:00
|
|
|
void IncrementSkipCountAsync(int id, float progress);
|
2010-12-25 12:54:21 +01:00
|
|
|
void ResetStatisticsAsync(int id);
|
2010-10-17 22:53:48 +02:00
|
|
|
void UpdateSongRatingAsync(int id, float rating);
|
2014-04-20 03:07:44 +02:00
|
|
|
void UpdateSongsRatingAsync(const QList<int>& ids, float rating);
|
2010-10-17 21:27:31 +02:00
|
|
|
|
2010-11-26 00:05:37 +01:00
|
|
|
void DeleteAll();
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
public slots:
|
|
|
|
void LoadDirectories();
|
|
|
|
void UpdateTotalSongCount();
|
2010-11-27 17:14:09 +01:00
|
|
|
void AddOrUpdateSongs(const SongList& songs);
|
2009-12-24 20:16:07 +01:00
|
|
|
void UpdateMTimesOnly(const SongList& songs);
|
|
|
|
void DeleteSongs(const SongList& songs);
|
2014-02-01 20:21:28 +01:00
|
|
|
void MarkSongsUnavailable(const SongList& songs, bool unavailable = true);
|
2010-04-04 16:59:55 +02:00
|
|
|
void AddOrUpdateSubdirs(const SubdirectoryList& subdirs);
|
2010-02-27 21:12:22 +01:00
|
|
|
void UpdateCompilations();
|
2014-02-07 16:34:20 +01:00
|
|
|
void UpdateManualAlbumArt(const QString& artist, const QString& album,
|
|
|
|
const QString& art);
|
|
|
|
void ForceCompilation(const QString& album, const QList<QString>& artists,
|
|
|
|
bool on);
|
2010-10-17 21:27:31 +02:00
|
|
|
void IncrementPlayCount(int id);
|
2010-11-01 22:15:52 +01:00
|
|
|
void IncrementSkipCount(int id, float progress);
|
2010-12-25 12:54:21 +01:00
|
|
|
void ResetStatistics(int id);
|
2010-10-17 22:53:48 +02:00
|
|
|
void UpdateSongRating(int id, float rating);
|
2014-04-20 03:07:44 +02:00
|
|
|
void UpdateSongsRating(const QList<int>& id_list, float rating);
|
2010-05-09 02:10:26 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
signals:
|
|
|
|
void DirectoryDiscovered(const Directory& dir,
|
|
|
|
const SubdirectoryList& subdirs);
|
2010-05-09 02:10:26 +02:00
|
|
|
void DirectoryDeleted(const Directory& dir);
|
|
|
|
|
|
|
|
void SongsDiscovered(const SongList& songs);
|
|
|
|
void SongsDeleted(const SongList& songs);
|
2010-10-17 21:34:45 +02:00
|
|
|
void SongsStatisticsChanged(const SongList& songs);
|
2013-03-30 23:42:29 +01:00
|
|
|
void SongsRatingChanged(const SongList& songs);
|
2010-11-26 00:05:37 +01:00
|
|
|
void DatabaseReset();
|
2010-05-09 02:10:26 +02:00
|
|
|
|
|
|
|
void TotalSongCountUpdated(int total);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-11-01 22:15:52 +01:00
|
|
|
static const char* kNewScoreSql;
|
|
|
|
|
2010-02-27 21:12:22 +01:00
|
|
|
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
2010-03-21 23:14:07 +01:00
|
|
|
SongList& deleted_songs, SongList& added_songs,
|
2010-02-27 21:12:22 +01:00
|
|
|
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-04-01 18:59:32 +02:00
|
|
|
SubdirectoryList SubdirsInDirectory(int id, QSqlDatabase& db);
|
2010-11-27 17:14:09 +01:00
|
|
|
|
2010-10-17 21:27:31 +02:00
|
|
|
Song GetSongById(int id, QSqlDatabase& db);
|
2010-11-27 17:14:09 +01:00
|
|
|
SongList GetSongsById(const QStringList& ids, QSqlDatabase& db);
|
2010-02-27 21:12:22 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private:
|
2012-02-12 14:41:50 +01:00
|
|
|
Database* db_;
|
2010-05-09 02:10:26 +02:00
|
|
|
QString songs_table_;
|
|
|
|
QString dirs_table_;
|
|
|
|
QString subdirs_table_;
|
2010-06-20 18:30:10 +02:00
|
|
|
QString fts_table_;
|
2013-02-24 18:36:37 +01:00
|
|
|
bool save_statistics_in_file_;
|
2013-03-30 23:42:29 +01:00
|
|
|
bool save_ratings_in_file_;
|
2010-04-04 18:28:34 +02:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // LIBRARYBACKEND_H
|