2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2019-11-26 22:30:14 +01:00
|
|
|
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COLLECTIONBACKEND_H
|
|
|
|
#define COLLECTIONBACKEND_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QObject>
|
2019-03-25 00:53:12 +01:00
|
|
|
#include <QFileInfo>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QUrl>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#include "core/song.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "collectionquery.h"
|
|
|
|
#include "directory.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-24 19:16:51 +02:00
|
|
|
class QThread;
|
2018-02-27 18:06:05 +01:00
|
|
|
class Database;
|
|
|
|
|
|
|
|
class CollectionBackendInterface : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit CollectionBackendInterface(QObject *parent = nullptr) : QObject(parent) {}
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual ~CollectionBackendInterface() {}
|
|
|
|
|
|
|
|
struct Album {
|
|
|
|
Album() {}
|
2019-07-07 21:14:24 +02:00
|
|
|
Album(const QString &_artist, const QString &_album_artist, const QString &_album_name, const QUrl &_art_automatic, const QUrl &_art_manual, const QUrl &_first_url) :
|
2018-02-27 18:06:05 +01:00
|
|
|
artist(_artist),
|
|
|
|
album_artist(_album_artist),
|
|
|
|
album_name(_album_name),
|
|
|
|
art_automatic(_art_automatic),
|
|
|
|
art_manual(_art_manual),
|
|
|
|
first_url(_first_url) {}
|
|
|
|
|
|
|
|
const QString &effective_albumartist() const {
|
|
|
|
return album_artist.isEmpty() ? artist : album_artist;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString artist;
|
|
|
|
QString album_artist;
|
|
|
|
QString album_name;
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
QUrl art_automatic;
|
|
|
|
QUrl art_manual;
|
2018-02-27 18:06:05 +01:00
|
|
|
QUrl first_url;
|
|
|
|
};
|
|
|
|
typedef QList<Album> AlbumList;
|
|
|
|
|
|
|
|
virtual QString songs_table() const = 0;
|
|
|
|
|
|
|
|
// Get a list of directories in the collection. Emits DirectoriesDiscovered.
|
|
|
|
virtual void LoadDirectoriesAsync() = 0;
|
|
|
|
|
|
|
|
virtual void UpdateTotalSongCountAsync() = 0;
|
|
|
|
virtual void UpdateTotalArtistCountAsync() = 0;
|
|
|
|
virtual void UpdateTotalAlbumCountAsync() = 0;
|
|
|
|
|
|
|
|
virtual SongList FindSongsInDirectory(int id) = 0;
|
|
|
|
virtual SubdirectoryList SubdirsInDirectory(int id) = 0;
|
|
|
|
virtual DirectoryList GetAllDirectories() = 0;
|
|
|
|
virtual void ChangeDirPath(int id, const QString &old_path, const QString &new_path) = 0;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
virtual SongList GetCompilationSongs(const QString &album, const QueryOptions &opt = QueryOptions()) = 0;
|
|
|
|
|
|
|
|
virtual AlbumList GetAllAlbums(const QueryOptions &opt = QueryOptions()) = 0;
|
|
|
|
virtual AlbumList GetAlbumsByArtist(const QString &artist, const QueryOptions &opt = QueryOptions()) = 0;
|
|
|
|
virtual AlbumList GetCompilationAlbums(const QueryOptions &opt = QueryOptions()) = 0;
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
virtual void UpdateManualAlbumArtAsync(const QString &artist, const QString &albumartist, const QString &album, const QUrl &cover_url) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual Album GetAlbumArt(const QString &artist, const QString &albumartist, const QString &album) = 0;
|
|
|
|
|
|
|
|
virtual Song GetSongById(int id) = 0;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Returns all sections of a song with the given filename. If there's just one section the resulting list will have it's size equal to 1.
|
2018-02-27 18:06:05 +01:00
|
|
|
virtual SongList GetSongsByUrl(const QUrl &url) = 0;
|
2018-05-01 00:41:33 +02:00
|
|
|
// Returns a section of a song with the given filename and beginning. If the section is not present in collection, returns invalid song.
|
2018-02-27 18:06:05 +01:00
|
|
|
// Using default beginning value is suitable when searching for single-section songs.
|
2019-11-25 00:28:49 +01:00
|
|
|
virtual Song GetSongByUrl(const QUrl &url, const qint64 beginning = 0) = 0;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
virtual void AddDirectory(const QString &path) = 0;
|
|
|
|
virtual void RemoveDirectory(const Directory &dir) = 0;
|
|
|
|
|
|
|
|
virtual bool ExecQuery(CollectionQuery *q) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CollectionBackend : public CollectionBackendInterface {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const char *kSettingsGroup;
|
|
|
|
|
|
|
|
Q_INVOKABLE CollectionBackend(QObject *parent = nullptr);
|
2019-07-24 19:16:51 +02:00
|
|
|
~CollectionBackend();
|
|
|
|
|
2019-07-02 00:48:40 +02:00
|
|
|
void Init(Database *db, const Song::Source source, const QString &songs_table, const QString &dirs_table, const QString &subdirs_table, const QString &fts_table);
|
2019-07-24 19:16:51 +02:00
|
|
|
void Close();
|
|
|
|
|
|
|
|
void ExitAsync();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Database *db() const { return db_; }
|
|
|
|
|
|
|
|
QString songs_table() const { return songs_table_; }
|
|
|
|
QString dirs_table() const { return dirs_table_; }
|
|
|
|
QString subdirs_table() const { return subdirs_table_; }
|
|
|
|
|
|
|
|
// Get a list of directories in the collection. Emits DirectoriesDiscovered.
|
|
|
|
void LoadDirectoriesAsync();
|
|
|
|
|
|
|
|
void UpdateTotalSongCountAsync();
|
|
|
|
void UpdateTotalArtistCountAsync();
|
|
|
|
void UpdateTotalAlbumCountAsync();
|
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
SongList FindSongsInDirectory(const int id);
|
|
|
|
SubdirectoryList SubdirsInDirectory(const int id);
|
2018-02-27 18:06:05 +01:00
|
|
|
DirectoryList GetAllDirectories();
|
2020-04-23 21:08:28 +02:00
|
|
|
void ChangeDirPath(const int id, const QString &old_path, const QString &new_path);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QStringList GetAll(const QString &column, const QueryOptions &opt = QueryOptions());
|
|
|
|
QStringList GetAllArtists(const QueryOptions &opt = QueryOptions());
|
|
|
|
QStringList GetAllArtistsWithAlbums(const QueryOptions &opt = QueryOptions());
|
|
|
|
SongList GetSongsByAlbum(const QString &album, const QueryOptions &opt = QueryOptions());
|
|
|
|
SongList GetSongs(const QString &artist, const QString &album, const QueryOptions &opt = QueryOptions());
|
|
|
|
|
|
|
|
SongList GetCompilationSongs(const QString &album, const QueryOptions &opt = QueryOptions());
|
|
|
|
|
|
|
|
AlbumList GetAllAlbums(const QueryOptions &opt = QueryOptions());
|
|
|
|
AlbumList GetCompilationAlbums(const QueryOptions &opt = QueryOptions());
|
2019-04-18 00:45:32 +02:00
|
|
|
AlbumList GetAlbumsByArtist(const QString &artist, const QueryOptions &opt = QueryOptions());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
void UpdateManualAlbumArtAsync(const QString &artist, const QString &albumartist, const QString &album, const QUrl &cover_url);
|
2018-02-27 18:06:05 +01:00
|
|
|
Album GetAlbumArt(const QString &artist, const QString &albumartist, const QString &album);
|
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
Song GetSongById(const int id);
|
2018-02-27 18:06:05 +01:00
|
|
|
SongList GetSongsById(const QList<int> &ids);
|
|
|
|
SongList GetSongsById(const QStringList &ids);
|
|
|
|
SongList GetSongsByForeignId(const QStringList &ids, const QString &table, const QString &column);
|
|
|
|
|
|
|
|
SongList GetSongsByUrl(const QUrl &url);
|
|
|
|
Song GetSongByUrl(const QUrl &url, qint64 beginning = 0);
|
|
|
|
|
|
|
|
void AddDirectory(const QString &path);
|
|
|
|
void RemoveDirectory(const Directory &dir);
|
|
|
|
|
|
|
|
bool ExecQuery(CollectionQuery *q);
|
|
|
|
SongList ExecCollectionQuery(CollectionQuery *query);
|
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
void IncrementPlayCountAsync(const int id);
|
|
|
|
void IncrementSkipCountAsync(const int id, const float progress);
|
|
|
|
void ResetStatisticsAsync(const int id);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void DeleteAll();
|
|
|
|
|
2020-04-13 03:39:51 +02:00
|
|
|
Song GetSongBySongId(const QString &song_id);
|
2019-06-07 23:02:43 +02:00
|
|
|
SongList GetSongsBySongId(const QStringList &song_ids);
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
Song::Source Source() const;
|
|
|
|
|
2020-05-12 18:45:24 +02:00
|
|
|
void AddOrUpdateSongsAsync(const SongList &songs);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
public slots:
|
2019-07-24 19:16:51 +02:00
|
|
|
void Exit();
|
2018-02-27 18:06:05 +01:00
|
|
|
void LoadDirectories();
|
|
|
|
void UpdateTotalSongCount();
|
|
|
|
void UpdateTotalArtistCount();
|
|
|
|
void UpdateTotalAlbumCount();
|
|
|
|
void AddOrUpdateSongs(const SongList &songs);
|
|
|
|
void UpdateMTimesOnly(const SongList &songs);
|
|
|
|
void DeleteSongs(const SongList &songs);
|
|
|
|
void MarkSongsUnavailable(const SongList &songs, bool unavailable = true);
|
|
|
|
void AddOrUpdateSubdirs(const SubdirectoryList &subdirs);
|
|
|
|
void UpdateCompilations();
|
2019-07-07 21:14:24 +02:00
|
|
|
void UpdateManualAlbumArt(const QString &artist, const QString &albumartist, const QString &album, const QUrl &cover_url);
|
2020-04-23 21:08:28 +02:00
|
|
|
void ForceCompilation(const QString &album, const QList<QString> &artists, const bool on);
|
|
|
|
void IncrementPlayCount(const int id);
|
|
|
|
void IncrementSkipCount(const int id, const float progress);
|
|
|
|
void ResetStatistics(const int id);
|
2019-03-25 00:53:12 +01:00
|
|
|
void SongPathChanged(const Song &song, const QFileInfo &new_file);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-24 19:16:51 +02:00
|
|
|
signals:
|
2018-02-27 18:06:05 +01:00
|
|
|
void DirectoryDiscovered(const Directory &dir, const SubdirectoryList &subdirs);
|
|
|
|
void DirectoryDeleted(const Directory &dir);
|
|
|
|
|
|
|
|
void SongsDiscovered(const SongList &songs);
|
|
|
|
void SongsDeleted(const SongList &songs);
|
2019-04-19 14:02:28 +02:00
|
|
|
void SongsStatisticsChanged(const SongList& songs);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void DatabaseReset();
|
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
void TotalSongCountUpdated(const int total);
|
|
|
|
void TotalArtistCountUpdated(const int total);
|
|
|
|
void TotalAlbumCountUpdated(const int total);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-24 19:16:51 +02:00
|
|
|
void ExitFinished();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private:
|
|
|
|
struct CompilationInfo {
|
2019-11-03 23:23:04 +01:00
|
|
|
CompilationInfo() : has_compilation_detected(0), has_not_compilation_detected(0) {}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-11-03 23:23:04 +01:00
|
|
|
QList<QUrl> urls;
|
2019-11-13 21:27:04 +01:00
|
|
|
QStringList artists;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-11-03 23:23:04 +01:00
|
|
|
int has_compilation_detected;
|
|
|
|
int has_not_compilation_detected;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
2019-11-13 21:27:04 +01:00
|
|
|
void UpdateCompilations(QSqlQuery &find_song, QSqlQuery &update_song, SongList &deleted_songs, SongList &added_songs, const QUrl &url, const bool compilation_detected);
|
2020-04-23 21:08:28 +02:00
|
|
|
AlbumList GetAlbums(const QString &artist, const QString &album_artist, const bool compilation_required = false, const QueryOptions &opt = QueryOptions());
|
|
|
|
AlbumList GetAlbums(const QString &artist, const bool compilation_required, const QueryOptions &opt = QueryOptions());
|
|
|
|
SubdirectoryList SubdirsInDirectory(const int id, QSqlDatabase &db);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
Song GetSongById(const int id, QSqlDatabase &db);
|
2018-02-27 18:06:05 +01:00
|
|
|
SongList GetSongsById(const QStringList &ids, QSqlDatabase &db);
|
|
|
|
|
2020-04-13 03:39:51 +02:00
|
|
|
Song GetSongBySongId(const QString &song_id, QSqlDatabase &db);
|
2019-06-08 12:03:48 +02:00
|
|
|
SongList GetSongsBySongId(const QStringList &song_ids, QSqlDatabase &db);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private:
|
|
|
|
Database *db_;
|
2019-07-02 00:48:40 +02:00
|
|
|
Song::Source source_;
|
2018-02-27 18:06:05 +01:00
|
|
|
QString songs_table_;
|
|
|
|
QString dirs_table_;
|
|
|
|
QString subdirs_table_;
|
|
|
|
QString fts_table_;
|
2019-07-24 19:16:51 +02:00
|
|
|
QThread *original_thread_;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COLLECTIONBACKEND_H
|
|
|
|
|