Refactoring

This commit is contained in:
Jonas Kvinge
2024-10-22 18:12:33 +02:00
parent dfcf715291
commit 8da2b9cd94
623 changed files with 9071 additions and 5126 deletions

View File

@@ -54,20 +54,21 @@
#include <QSettings>
#include <QtEvents>
#include "utilities/filenameconstants.h"
#include "constants/filenameconstants.h"
#include "constants/filefilterconstants.h"
#include "constants/coverssettings.h"
#include "utilities/strutils.h"
#include "utilities/mimeutils.h"
#include "utilities/coveroptions.h"
#include "utilities/coverutils.h"
#include "utilities/screenutils.h"
#include "core/application.h"
#include "core/logging.h"
#include "core/song.h"
#include "core/iconloader.h"
#include "core/settings.h"
#include "tagreader/tagreaderclient.h"
#include "collection/collectionfilteroptions.h"
#include "collection/collectionbackend.h"
#include "settings/coverssettingspage.h"
#include "streaming/streamingservices.h"
#include "streaming/streamingservice.h"
#include "albumcoverchoicecontroller.h"
@@ -80,15 +81,10 @@
using namespace Qt::Literals::StringLiterals;
const char *AlbumCoverChoiceController::kLoadImageFileFilter = QT_TR_NOOP("Images (*.png *.jpg *.jpeg *.bmp *.gif *.xpm *.pbm *.pgm *.ppm *.xbm)");
const char *AlbumCoverChoiceController::kSaveImageFileFilter = QT_TR_NOOP("Images (*.png *.jpg *.jpeg *.bmp *.xpm *.pbm *.ppm *.xbm)");
const char *AlbumCoverChoiceController::kAllFilesFilter = QT_TR_NOOP("All files (*)");
QSet<QString> *AlbumCoverChoiceController::sImageExtensions = nullptr;
AlbumCoverChoiceController::AlbumCoverChoiceController(QWidget *parent)
: QWidget(parent),
app_(nullptr),
cover_searcher_(nullptr),
cover_fetcher_(nullptr),
save_file_dialog_(nullptr),
@@ -130,12 +126,22 @@ AlbumCoverChoiceController::AlbumCoverChoiceController(QWidget *parent)
AlbumCoverChoiceController::~AlbumCoverChoiceController() = default;
void AlbumCoverChoiceController::Init(Application *app) {
void AlbumCoverChoiceController::Init(const SharedPtr<NetworkAccessManager> network,
const SharedPtr<TagReaderClient> tagreader_client,
const SharedPtr<CollectionBackend> collection_backend,
const SharedPtr<AlbumCoverLoader> albumcover_loader,
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
const SharedPtr<CoverProviders> cover_providers,
const SharedPtr<StreamingServices> streaming_services) {
app_ = app;
network_ = network;
tagreader_client_ = tagreader_client;
collection_backend_ = collection_backend;
current_albumcover_loader_ = current_albumcover_loader;
streaming_services_ = streaming_services;
cover_fetcher_ = new AlbumCoverFetcher(app_->cover_providers(), app->network(), this);
cover_searcher_ = new AlbumCoverSearcher(QIcon(u":/pictures/cdcase.png"_s), app, this);
cover_fetcher_ = new AlbumCoverFetcher(cover_providers, network, this);
cover_searcher_ = new AlbumCoverSearcher(QIcon(u":/pictures/cdcase.png"_s), albumcover_loader, this);
cover_searcher_->Init(cover_fetcher_);
QObject::connect(cover_fetcher_, &AlbumCoverFetcher::AlbumCoverFetched, this, &AlbumCoverChoiceController::AlbumCoverFetched);
@@ -145,13 +151,13 @@ void AlbumCoverChoiceController::Init(Application *app) {
void AlbumCoverChoiceController::ReloadSettings() {
Settings s;
s.beginGroup(CoversSettingsPage::kSettingsGroup);
cover_options_.cover_type = static_cast<CoverOptions::CoverType>(s.value(CoversSettingsPage::kSaveType, static_cast<int>(CoverOptions::CoverType::Cache)).toInt());
cover_options_.cover_filename = static_cast<CoverOptions::CoverFilename>(s.value(CoversSettingsPage::kSaveFilename, static_cast<int>(CoverOptions::CoverFilename::Pattern)).toInt());
cover_options_.cover_pattern = s.value(CoversSettingsPage::kSavePattern, u"%albumartist-%album"_s).toString();
cover_options_.cover_overwrite = s.value(CoversSettingsPage::kSaveOverwrite, false).toBool();
cover_options_.cover_lowercase = s.value(CoversSettingsPage::kSaveLowercase, false).toBool();
cover_options_.cover_replace_spaces = s.value(CoversSettingsPage::kSaveReplaceSpaces, false).toBool();
s.beginGroup(CoversSettings::kSettingsGroup);
cover_options_.cover_type = static_cast<CoverOptions::CoverType>(s.value(CoversSettings::kSaveType, static_cast<int>(CoverOptions::CoverType::Cache)).toInt());
cover_options_.cover_filename = static_cast<CoverOptions::CoverFilename>(s.value(CoversSettings::kSaveFilename, static_cast<int>(CoverOptions::CoverFilename::Pattern)).toInt());
cover_options_.cover_pattern = s.value(CoversSettings::kSavePattern, u"%albumartist-%album"_s).toString();
cover_options_.cover_overwrite = s.value(CoversSettings::kSaveOverwrite, false).toBool();
cover_options_.cover_lowercase = s.value(CoversSettings::kSaveLowercase, false).toBool();
cover_options_.cover_replace_spaces = s.value(CoversSettings::kSaveReplaceSpaces, false).toBool();
s.endGroup();
cover_types_ = AlbumCoverLoaderOptions::LoadTypes();
@@ -179,7 +185,7 @@ AlbumCoverImageResult AlbumCoverChoiceController::LoadImageFromFile(Song *song)
return AlbumCoverImageResult();
}
QString cover_file = QFileDialog::getOpenFileName(this, tr("Load cover from disk"), GetInitialPathForFileDialog(*song, QString()), tr(kLoadImageFileFilter) + u";;"_s + tr(kAllFilesFilter));
QString cover_file = QFileDialog::getOpenFileName(this, tr("Load cover from disk"), GetInitialPathForFileDialog(*song, QString()), tr(kLoadImageFileFilter) + u";;"_s + tr(kAllFilesFilterSpec));
if (cover_file.isEmpty()) return AlbumCoverImageResult();
QFile file(cover_file);
@@ -210,7 +216,7 @@ QUrl AlbumCoverChoiceController::LoadCoverFromFile(Song *song) {
if (!song->url().isValid() || !song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl();
QString cover_file = QFileDialog::getOpenFileName(this, tr("Load cover from disk"), GetInitialPathForFileDialog(*song, QString()), tr(kLoadImageFileFilter) + u";;"_s + tr(kAllFilesFilter));
QString cover_file = QFileDialog::getOpenFileName(this, tr("Load cover from disk"), GetInitialPathForFileDialog(*song, QString()), tr(kLoadImageFileFilter) + u";;"_s + tr(kAllFilesFilterSpec));
if (cover_file.isEmpty() || QImage(cover_file).isNull()) return QUrl();
switch (get_save_album_cover_type()) {
@@ -246,7 +252,7 @@ void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, const A
static const QRegularExpression regex_invalid_fat_characters(QLatin1String(kInvalidFatCharactersRegex), QRegularExpression::CaseInsensitiveOption);
initial_file_name.remove(regex_invalid_fat_characters);
QString save_filename = QFileDialog::getSaveFileName(this, tr("Save album cover"), GetInitialPathForFileDialog(song, initial_file_name), tr(kSaveImageFileFilter) + u";;"_s + tr(kAllFilesFilter));
QString save_filename = QFileDialog::getSaveFileName(this, tr("Save album cover"), GetInitialPathForFileDialog(song, initial_file_name), tr(kSaveImageFileFilter) + u";;"_s + tr(kAllFilesFilterSpec));
if (save_filename.isEmpty()) return;
@@ -316,7 +322,7 @@ void AlbumCoverChoiceController::LoadCoverFromURL(Song *song) {
AlbumCoverImageResult AlbumCoverChoiceController::LoadImageFromURL() {
if (!cover_from_url_dialog_) { cover_from_url_dialog_ = new CoverFromURLDialog(app_->network(), this); }
if (!cover_from_url_dialog_) { cover_from_url_dialog_ = new CoverFromURLDialog(network_, this); }
return cover_from_url_dialog_->Exec();
@@ -446,7 +452,7 @@ void AlbumCoverChoiceController::ShowCover(const Song &song, const QImage &image
case AlbumCoverLoaderOptions::Type::Embedded:{
if (song.art_embedded() && !song.url().isEmpty() && song.url().isValid() && song.url().isLocalFile()) {
QImage image_embedded_cover;
const TagReaderResult result = TagReaderClient::Instance()->LoadCoverImageBlocking(song.url().toLocalFile(), image_embedded_cover);
const TagReaderResult result = tagreader_client_->LoadCoverImageBlocking(song.url().toLocalFile(), image_embedded_cover);
if (result.success() && !image_embedded_cover.isNull()) {
QPixmap pixmap = QPixmap::fromImage(image_embedded_cover);
if (!pixmap.isNull()) {
@@ -548,11 +554,11 @@ void AlbumCoverChoiceController::SaveArtEmbeddedToSong(Song *song, const bool ar
song->set_art_unset(false);
if (song->source() == Song::Source::Collection) {
app_->collection_backend()->UpdateEmbeddedAlbumArtAsync(song->effective_albumartist(), song->album(), art_embedded);
collection_backend_->UpdateEmbeddedAlbumArtAsync(song->effective_albumartist(), song->album(), art_embedded);
}
if (*song == app_->current_albumcover_loader()->last_song()) {
app_->current_albumcover_loader()->LoadAlbumCover(*song);
if (*song == current_albumcover_loader_->last_song()) {
current_albumcover_loader_->LoadAlbumCover(*song);
}
}
@@ -567,7 +573,7 @@ void AlbumCoverChoiceController::SaveArtManualToSong(Song *song, const QUrl &art
// Update the backends.
switch (song->source()) {
case Song::Source::Collection:
app_->collection_backend()->UpdateManualAlbumArtAsync(song->effective_albumartist(), song->album(), art_manual);
collection_backend_->UpdateManualAlbumArtAsync(song->effective_albumartist(), song->album(), art_manual);
break;
case Song::Source::LocalFile:
case Song::Source::CDDA:
@@ -581,7 +587,7 @@ void AlbumCoverChoiceController::SaveArtManualToSong(Song *song, const QUrl &art
case Song::Source::Tidal:
case Song::Source::Spotify:
case Song::Source::Qobuz:
StreamingServicePtr service = app_->streaming_services()->ServiceBySource(song->source());
StreamingServicePtr service = streaming_services_->ServiceBySource(song->source());
if (!service) break;
if (service->artists_collection_backend()) {
service->artists_collection_backend()->UpdateManualAlbumArtAsync(song->effective_albumartist(), song->album(), art_manual);
@@ -595,8 +601,8 @@ void AlbumCoverChoiceController::SaveArtManualToSong(Song *song, const QUrl &art
break;
}
if (*song == app_->current_albumcover_loader()->last_song()) {
app_->current_albumcover_loader()->LoadAlbumCover(*song);
if (*song == current_albumcover_loader_->last_song()) {
current_albumcover_loader_->LoadAlbumCover(*song);
}
}
@@ -611,11 +617,11 @@ void AlbumCoverChoiceController::ClearAlbumCoverForSong(Song *song) {
song->clear_art_manual();
if (song->source() == Song::Source::Collection) {
app_->collection_backend()->ClearAlbumArtAsync(song->effective_albumartist(), song->album(), false);
collection_backend_->ClearAlbumArtAsync(song->effective_albumartist(), song->album(), false);
}
if (*song == app_->current_albumcover_loader()->last_song()) {
app_->current_albumcover_loader()->LoadAlbumCover(*song);
if (*song == current_albumcover_loader_->last_song()) {
current_albumcover_loader_->LoadAlbumCover(*song);
}
}
@@ -630,11 +636,11 @@ void AlbumCoverChoiceController::UnsetAlbumCoverForSong(Song *song) {
song->clear_art_automatic();
if (song->source() == Song::Source::Collection) {
app_->collection_backend()->UnsetAlbumArtAsync(song->effective_albumartist(), song->album());
collection_backend_->UnsetAlbumArtAsync(song->effective_albumartist(), song->album());
}
if (*song == app_->current_albumcover_loader()->last_song()) {
app_->current_albumcover_loader()->LoadAlbumCover(*song);
if (*song == current_albumcover_loader_->last_song()) {
current_albumcover_loader_->LoadAlbumCover(*song);
}
}
@@ -718,7 +724,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedToCollectionSongs(const Song &
void AlbumCoverChoiceController::SaveCoverEmbeddedToCollectionSongs(const QString &effective_albumartist, const QString &effective_album, const QString &cover_filename, const QByteArray &image_data, const QString &mime_type) {
QFuture<SongList> future = QtConcurrent::run(&CollectionBackend::GetAlbumSongs, app_->collection_backend(), effective_albumartist, effective_album, CollectionFilterOptions());
QFuture<SongList> future = QtConcurrent::run(&CollectionBackend::GetAlbumSongs, collection_backend_, effective_albumartist, effective_album, CollectionFilterOptions());
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
QObject::connect(watcher, &QFutureWatcher<SongList>::finished, this, [this, watcher, cover_filename, image_data, mime_type]() {
const SongList collection_songs = watcher->result();
@@ -736,7 +742,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedToSong(const Song &song, const
QMutexLocker l(&mutex_cover_save_tasks_);
cover_save_tasks_.append(song);
const bool art_embedded = !image_data.isNull();
TagReaderReplyPtr reply = app_->tag_reader_client()->SaveCoverAsync(song.url().toLocalFile(), SaveTagCoverData(cover_filename, image_data, mime_type));
TagReaderReplyPtr reply = tagreader_client_->SaveCoverAsync(song.url().toLocalFile(), SaveTagCoverData(cover_filename, image_data, mime_type));
QObject::connect(&*reply, &TagReaderReply::Finished, this, [this, reply, song, art_embedded]() { SaveEmbeddedCoverFinished(reply, song, art_embedded); });
}

View File

@@ -50,25 +50,33 @@ class QMenu;
class QDragEnterEvent;
class QDropEvent;
class Application;
class NetworkAccessManager;
class CollectionBackend;
class AlbumCoverLoader;
class CurrentAlbumCoverLoader;
class CoverProviders;
class AlbumCoverFetcher;
class AlbumCoverSearcher;
class CoverFromURLDialog;
struct CoverSearchStatistics;
class StreamingServices;
// Controller for the common album cover related menu options.
class AlbumCoverChoiceController : public QWidget {
Q_OBJECT
public:
static const char *kLoadImageFileFilter;
static const char *kSaveImageFileFilter;
static const char *kAllFilesFilter;
explicit AlbumCoverChoiceController(QWidget *parent = nullptr);
~AlbumCoverChoiceController() override;
void Init(Application *app);
void Init(const SharedPtr<NetworkAccessManager> network,
const SharedPtr<TagReaderClient> tagreader_client,
const SharedPtr<CollectionBackend> collection_backend,
const SharedPtr<AlbumCoverLoader> albumcover_loader,
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
const SharedPtr<CoverProviders> cover_providers,
const SharedPtr<StreamingServices> streaming_services);
void ReloadSettings();
CoverOptions::CoverType get_save_album_cover_type() const { return (save_embedded_cover_override_ ? CoverOptions::CoverType::Embedded : cover_options_.cover_type); }
@@ -172,7 +180,12 @@ class AlbumCoverChoiceController : public QWidget {
static bool IsKnownImageExtension(const QString &suffix);
static QSet<QString> *sImageExtensions;
Application *app_;
SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader_;
SharedPtr<NetworkAccessManager> network_;
SharedPtr<TagReaderClient> tagreader_client_;
SharedPtr<CollectionBackend> collection_backend_;
SharedPtr<StreamingServices> streaming_services_;
AlbumCoverSearcher *cover_searcher_;
AlbumCoverFetcher *cover_fetcher_;

View File

@@ -37,7 +37,9 @@
using namespace Qt::Literals::StringLiterals;
const char *AlbumCoverExport::kSettingsGroup = "AlbumCoverExport";
namespace {
constexpr char kSettingsGroup[] = "AlbumCoverExport";
}
AlbumCoverExport::AlbumCoverExport(QWidget *parent) : QDialog(parent), ui_(new Ui_AlbumCoverExport) {

View File

@@ -78,8 +78,6 @@ class AlbumCoverExport : public QDialog {
private:
Ui_AlbumCoverExport *ui_;
static const char *kSettingsGroup;
};
#endif // ALBUMCOVEREXPORT_H

View File

@@ -33,8 +33,9 @@ namespace {
constexpr int kMaxConcurrentRequests = 3;
}
AlbumCoverExporter::AlbumCoverExporter(QObject *parent)
AlbumCoverExporter::AlbumCoverExporter(const SharedPtr<TagReaderClient> tagreader_client, QObject *parent)
: QObject(parent),
tagreader_client_(tagreader_client),
thread_pool_(new QThreadPool(this)),
exported_(0),
skipped_(0),
@@ -52,7 +53,7 @@ void AlbumCoverExporter::SetCoverTypes(const AlbumCoverLoaderOptions::Types &cov
void AlbumCoverExporter::AddExportRequest(const Song &song) {
requests_.append(new CoverExportRunnable(dialog_result_, cover_types_, song));
requests_.append(new CoverExportRunnable(tagreader_client_, dialog_result_, cover_types_, song));
all_ = static_cast<int>(requests_.count());
}

View File

@@ -27,18 +27,21 @@
#include <QQueue>
#include <QString>
#include "includes/shared_ptr.h"
#include "albumcoverloaderoptions.h"
#include "albumcoverexport.h"
class QThreadPool;
class Song;
class CoverExportRunnable;
class TagReaderClient;
class AlbumCoverExporter : public QObject {
Q_OBJECT
public:
explicit AlbumCoverExporter(QObject *parent = nullptr);
explicit AlbumCoverExporter(const SharedPtr<TagReaderClient> tagreader_client, QObject *parent = nullptr);
void SetDialogResult(const AlbumCoverExport::DialogResult &dialog_result);
void SetCoverTypes(const AlbumCoverLoaderOptions::Types &cover_types);
@@ -58,6 +61,8 @@ class AlbumCoverExporter : public QObject {
private:
void AddJobsToPool();
const SharedPtr<TagReaderClient> tagreader_client_;
AlbumCoverLoaderOptions::Types cover_types_;
AlbumCoverExport::DialogResult dialog_result_;

View File

@@ -28,7 +28,7 @@
#include <QTimer>
#include <QString>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/song.h"
#include "albumcoverfetcher.h"

View File

@@ -36,7 +36,7 @@
#include <QUrl>
#include <QImage>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "coversearchstatistics.h"
#include "albumcoverimageresult.h"

View File

@@ -36,8 +36,8 @@
#include <QNetworkRequest>
#include <QNetworkReply>
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/networktimeouts.h"
#include "utilities/imageutils.h"

View File

@@ -35,7 +35,7 @@
#include <QUrl>
#include <QImage>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "albumcoverfetcher.h"
#include "coversearchstatistics.h"
#include "albumcoverimageresult.h"

View File

@@ -36,6 +36,7 @@
#include <QNetworkReply>
#include <QNetworkRequest>
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/networkaccessmanager.h"
#include "core/song.h"
@@ -54,8 +55,9 @@ namespace {
constexpr int kMaxRedirects = 3;
}
AlbumCoverLoader::AlbumCoverLoader(QObject *parent)
AlbumCoverLoader::AlbumCoverLoader(const SharedPtr<TagReaderClient> tagreader_client, QObject *parent)
: QObject(parent),
tagreader_client_(tagreader_client),
network_(new NetworkAccessManager(this)),
timer_process_tasks_(new QTimer(this)),
stop_requested_(false),
@@ -318,7 +320,7 @@ AlbumCoverLoader::LoadImageResult AlbumCoverLoader::LoadImage(TaskPtr task, cons
AlbumCoverLoader::LoadImageResult AlbumCoverLoader::LoadEmbeddedImage(TaskPtr task) {
if (task->art_embedded && task->song_url.isValid() && task->song_url.isLocalFile()) {
const TagReaderResult result = TagReaderClient::Instance()->LoadCoverDataBlocking(task->song_url.toLocalFile(), task->album_cover.image_data);
const TagReaderResult result = tagreader_client_->LoadCoverDataBlocking(task->song_url.toLocalFile(), task->album_cover.image_data);
if (result.success() && !task->album_cover.image_data.isEmpty() && task->album_cover.image.loadFromData(task->album_cover.image_data)) {
return LoadImageResult(AlbumCoverLoaderResult::Type::Embedded, LoadImageResult::Status::Success);
}

View File

@@ -32,7 +32,7 @@
#include <QString>
#include <QImage>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/song.h"
#include "albumcoverloaderoptions.h"
#include "albumcoverloaderresult.h"
@@ -42,12 +42,13 @@ class QThread;
class QTimer;
class QNetworkReply;
class NetworkAccessManager;
class TagReaderClient;
class AlbumCoverLoader : public QObject {
Q_OBJECT
public:
explicit AlbumCoverLoader(QObject *parent = nullptr);
explicit AlbumCoverLoader(const SharedPtr<TagReaderClient> tagreader_client, QObject *parent = nullptr);
void ExitAsync();
void Stop() { stop_requested_ = true; }
@@ -125,7 +126,8 @@ class AlbumCoverLoader : public QObject {
void LoadRemoteImageFinished(QNetworkReply *reply, AlbumCoverLoader::TaskPtr task, const AlbumCoverLoaderResult::Type result_type, const QUrl &cover_url);
private:
SharedPtr<NetworkAccessManager> network_;
const SharedPtr<TagReaderClient> tagreader_client_;
const SharedPtr<NetworkAccessManager> network_;
QTimer *timer_process_tasks_;
bool stop_requested_;
QMutex mutex_load_image_async_;

View File

@@ -22,7 +22,7 @@
#include <QSettings>
#include "core/settings.h"
#include "settings/coverssettingspage.h"
#include "constants/coverssettings.h"
using namespace Qt::Literals::StringLiterals;
@@ -37,9 +37,9 @@ AlbumCoverLoaderOptions::Types AlbumCoverLoaderOptions::LoadTypes() {
Types cover_types;
Settings s;
s.beginGroup(CoversSettingsPage::kSettingsGroup);
s.beginGroup(CoversSettings::kSettingsGroup);
const QStringList all_cover_types = QStringList() << u"art_unset"_s << u"art_embedded"_s << u"art_manual"_s << u"art_automatic"_s;
const QStringList cover_types_strlist = s.value(CoversSettingsPage::kTypes, all_cover_types).toStringList();
const QStringList cover_types_strlist = s.value(CoversSettings::kTypes, all_cover_types).toStringList();
for (const QString &cover_type_str : cover_types_strlist) {
if (cover_type_str == "art_unset"_L1) {
cover_types << AlbumCoverLoaderOptions::Type::Unset;

View File

@@ -61,13 +61,14 @@
#include <QSize>
#include <QtEvents>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "includes/scoped_ptr.h"
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "core/database.h"
#include "core/settings.h"
#include "core/database.h"
#include "core/networkaccessmanager.h"
#include "core/songmimedata.h"
#include "utilities/strutils.h"
#include "utilities/fileutils.h"
#include "utilities/imageutils.h"
@@ -78,8 +79,6 @@
#include "tagreader/tagreaderclient.h"
#include "collection/collectionbackend.h"
#include "collection/collectionquery.h"
#include "playlist/songmimedata.h"
#include "coverproviders.h"
#include "albumcovermanager.h"
#include "albumcoversearcher.h"
#include "albumcoverchoicecontroller.h"
@@ -88,6 +87,7 @@
#include "albumcoverfetcher.h"
#include "albumcoverloader.h"
#include "albumcoverloaderresult.h"
#include "coverproviders.h"
#include "coversearchstatistics.h"
#include "coversearchstatisticsdialog.h"
#include "albumcoverimageresult.h"
@@ -102,21 +102,31 @@ constexpr char kSettingsGroup[] = "CoverManager";
constexpr int kThumbnailSize = 120;
}
AlbumCoverManager::AlbumCoverManager(Application *app, SharedPtr<CollectionBackend> collection_backend, QMainWindow *mainwindow, QWidget *parent)
AlbumCoverManager::AlbumCoverManager(const SharedPtr<NetworkAccessManager> network,
const SharedPtr<CollectionBackend> collection_backend,
const SharedPtr<TagReaderClient> tagreader_client,
const SharedPtr<AlbumCoverLoader> albumcover_loader,
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
const SharedPtr<CoverProviders> cover_providers,
const SharedPtr<StreamingServices> streaming_services,
QMainWindow *mainwindow, QWidget *parent)
: QMainWindow(parent),
ui_(new Ui_CoverManager),
mainwindow_(mainwindow),
app_(app),
network_(network),
collection_backend_(collection_backend),
tagreader_client_(tagreader_client),
albumcover_loader_(albumcover_loader),
cover_providers_(cover_providers),
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
timer_album_cover_load_(new QTimer(this)),
filter_all_(nullptr),
filter_with_covers_(nullptr),
filter_without_covers_(nullptr),
cover_fetcher_(new AlbumCoverFetcher(app_->cover_providers(), app_->network(), this)),
cover_fetcher_(new AlbumCoverFetcher(cover_providers, network, this)),
cover_searcher_(nullptr),
cover_export_(nullptr),
cover_exporter_(new AlbumCoverExporter(this)),
cover_exporter_(new AlbumCoverExporter(tagreader_client_, this)),
artist_icon_(IconLoader::Load(u"folder-sound"_s)),
all_artists_icon_(IconLoader::Load(u"library-music"_s)),
image_nocover_thumbnail_(ImageUtils::GenerateNoCoverImage(QSize(120, 120), devicePixelRatio())),
@@ -142,9 +152,9 @@ AlbumCoverManager::AlbumCoverManager(Application *app, SharedPtr<CollectionBacke
ui_->action_add_to_playlist->setIcon(IconLoader::Load(u"media-playback-start"_s));
ui_->action_load->setIcon(IconLoader::Load(u"media-playback-start"_s));
album_cover_choice_controller_->Init(app_);
album_cover_choice_controller_->Init(network, tagreader_client, collection_backend, albumcover_loader, current_albumcover_loader, cover_providers, streaming_services);
cover_searcher_ = new AlbumCoverSearcher(icon_nocover_item_, app_, this);
cover_searcher_ = new AlbumCoverSearcher(icon_nocover_item_, albumcover_loader_, this);
cover_export_ = new AlbumCoverExport(this);
// Set up the status bar
@@ -241,7 +251,7 @@ void AlbumCoverManager::Init() {
s.endGroup();
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &AlbumCoverManager::AlbumCoverLoaded);
QObject::connect(&*albumcover_loader_, &AlbumCoverLoader::AlbumCoverLoaded, this, &AlbumCoverManager::AlbumCoverLoaded);
cover_searcher_->Init(cover_fetcher_);
@@ -320,7 +330,7 @@ void AlbumCoverManager::SaveSettings() {
void AlbumCoverManager::CancelRequests() {
app_->album_cover_loader()->CancelTasks(QSet<quint64>(cover_loading_tasks_.keyBegin(), cover_loading_tasks_.keyEnd()));
albumcover_loader_->CancelTasks(QSet<quint64>(cover_loading_tasks_.keyBegin(), cover_loading_tasks_.keyEnd()));
cover_loading_pending_.clear();
cover_loading_tasks_.clear();
cover_save_tasks_.clear();
@@ -363,7 +373,7 @@ void AlbumCoverManager::Reset() {
}
void AlbumCoverManager::EnableCoversButtons() {
ui_->button_fetch->setEnabled(app_->cover_providers()->HasAnyProviders());
ui_->button_fetch->setEnabled(cover_providers_->HasAnyProviders());
ui_->export_covers->setEnabled(true);
}
@@ -466,7 +476,7 @@ void AlbumCoverManager::LoadAlbumCoverAsync(AlbumItem *album_item) {
cover_options.types = cover_types_;
cover_options.desired_scaled_size = QSize(kThumbnailSize, kThumbnailSize);
cover_options.device_pixel_ratio = devicePixelRatioF();
quint64 cover_load_id = app_->album_cover_loader()->LoadImageAsync(cover_options, album_item->data(Role_ArtEmbedded).toBool(), album_item->data(Role_ArtAutomatic).toUrl(), album_item->data(Role_ArtManual).toUrl(), album_item->data(Role_ArtUnset).toBool(), album_item->urls.constFirst());
quint64 cover_load_id = albumcover_loader_->LoadImageAsync(cover_options, album_item->data(Role_ArtEmbedded).toBool(), album_item->data(Role_ArtAutomatic).toUrl(), album_item->data(Role_ArtManual).toUrl(), album_item->data(Role_ArtUnset).toBool(), album_item->urls.constFirst());
cover_loading_tasks_.insert(cover_load_id, album_item);
}
@@ -643,7 +653,7 @@ bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *e) {
album_cover_choice_controller_->cover_to_file_action()->setEnabled(some_with_covers);
album_cover_choice_controller_->cover_from_file_action()->setEnabled(context_menu_items_.size() == 1);
album_cover_choice_controller_->cover_from_url_action()->setEnabled(context_menu_items_.size() == 1);
album_cover_choice_controller_->search_for_cover_action()->setEnabled(app_->cover_providers()->HasAnyProviders());
album_cover_choice_controller_->search_for_cover_action()->setEnabled(cover_providers_->HasAnyProviders());
album_cover_choice_controller_->unset_cover_action()->setEnabled(some_with_covers || some_clear);
album_cover_choice_controller_->clear_cover_action()->setEnabled(some_with_covers || some_unset);
album_cover_choice_controller_->delete_cover_action()->setEnabled(some_with_covers);
@@ -757,7 +767,7 @@ void AlbumCoverManager::SaveCoverToFile() {
return;
case AlbumCoverLoaderOptions::Type::Embedded:
if (song.art_embedded()) {
const TagReaderResult tagreaderclient_result = TagReaderClient::Instance()->LoadCoverDataBlocking(song.url().toLocalFile(), result.image_data);
const TagReaderResult tagreaderclient_result = tagreader_client_->LoadCoverDataBlocking(song.url().toLocalFile(), result.image_data);
if (!tagreaderclient_result.success()) {
qLog(Error) << "Could not load embedded art from" << song.url() << tagreaderclient_result.error_string();
}
@@ -844,7 +854,7 @@ void AlbumCoverManager::SaveImageToAlbums(Song *song, const AlbumCoverImageResul
case CoverOptions::CoverType::Embedded:{
for (const QUrl &url : std::as_const(album_item->urls)) {
const bool art_embedded = !result.image_data.isEmpty();
TagReaderReplyPtr reply = app_->tag_reader_client()->SaveCoverAsync(url.toLocalFile(), SaveTagCoverData(result.image_data, result.mime_type));
TagReaderReplyPtr reply = tagreader_client_->SaveCoverAsync(url.toLocalFile(), SaveTagCoverData(result.image_data, result.mime_type));
QObject::connect(&*reply, &TagReaderReply::Finished, this, [this, reply, album_item, url, art_embedded]() {
SaveEmbeddedCoverFinished(reply, album_item, url, art_embedded);
});
@@ -994,7 +1004,7 @@ void AlbumCoverManager::SaveAndSetCover(AlbumItem *album_item, const AlbumCoverI
if (album_cover_choice_controller_->get_save_album_cover_type() == CoverOptions::CoverType::Embedded && Song::save_embedded_cover_supported(filetype) && !has_cue) {
for (const QUrl &url : urls) {
const bool art_embedded = !result.image_data.isEmpty();
TagReaderReplyPtr reply = app_->tag_reader_client()->SaveCoverAsync(url.toLocalFile(), SaveTagCoverData(result.cover_url.isValid() ? result.cover_url.toLocalFile() : QString(), result.image_data, result.mime_type));
TagReaderReplyPtr reply = tagreader_client_->SaveCoverAsync(url.toLocalFile(), SaveTagCoverData(result.cover_url.isValid() ? result.cover_url.toLocalFile() : QString(), result.image_data, result.mime_type));
QObject::connect(&*reply, &TagReaderReply::Finished, this, [this, reply, album_item, url, art_embedded]() {
SaveEmbeddedCoverFinished(reply, album_item, url, art_embedded);
});

View File

@@ -37,7 +37,7 @@
#include <QImage>
#include <QIcon>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/song.h"
#include "tagreader/tagreaderclient.h"
#include "albumcoverloaderoptions.h"
@@ -55,8 +55,11 @@ class QEvent;
class QCloseEvent;
class QShowEvent;
class Application;
class NetworkAccessManager;
class CollectionBackend;
class AlbumCoverLoader;
class CurrentAlbumCoverLoader;
class CoverProviders;
class SongMimeData;
class AlbumCoverExport;
class AlbumCoverExporter;
@@ -78,7 +81,15 @@ class AlbumCoverManager : public QMainWindow {
Q_OBJECT
public:
explicit AlbumCoverManager(Application *app, SharedPtr<CollectionBackend> collection_backend, QMainWindow *mainwindow, QWidget *parent = nullptr);
explicit AlbumCoverManager(const SharedPtr<NetworkAccessManager> network,
const SharedPtr<CollectionBackend> collection_backend,
const SharedPtr<TagReaderClient> tagreader_client,
const SharedPtr<AlbumCoverLoader> albumcover_loader,
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
const SharedPtr<CoverProviders> cover_providers,
const SharedPtr<StreamingServices> streaming_services,
QMainWindow *mainwindow,
QWidget *parent = nullptr);
~AlbumCoverManager() override;
void Reset();
@@ -190,8 +201,13 @@ class AlbumCoverManager : public QMainWindow {
private:
Ui_CoverManager *ui_;
QMainWindow *mainwindow_;
Application *app_;
SharedPtr<CollectionBackend> collection_backend_;
const SharedPtr<NetworkAccessManager> network_;
const SharedPtr<CollectionBackend> collection_backend_;
const SharedPtr<TagReaderClient> tagreader_client_;
const SharedPtr<AlbumCoverLoader> albumcover_loader_;
const SharedPtr<CoverProviders> cover_providers_;
AlbumCoverChoiceController *album_cover_choice_controller_;
QTimer *timer_album_cover_load_;

View File

@@ -33,10 +33,10 @@
#include <QMimeData>
#include <QDropEvent>
#include "core/scoped_ptr.h"
#include "includes/scoped_ptr.h"
#include "core/song.h"
#include "core/songmimedata.h"
#include "collection/collectionbackend.h"
#include "playlist/songmimedata.h"
#include "albumcovermanager.h"
#include "albumcovermanagerlist.h"

View File

@@ -47,9 +47,7 @@
#include <QKeySequence>
#include <QtEvents>
#include "core/application.h"
#include "utilities/strutils.h"
#include "utilities/timeutils.h"
#include "utilities/mimeutils.h"
#include "widgets/busyindicator.h"
#include "widgets/forcescrollperpixel.h"
@@ -114,10 +112,10 @@ void SizeOverlayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
}
AlbumCoverSearcher::AlbumCoverSearcher(const QIcon &no_cover_icon, Application *app, QWidget *parent)
AlbumCoverSearcher::AlbumCoverSearcher(const QIcon &no_cover_icon, const SharedPtr<AlbumCoverLoader> albumcover_loader, QWidget *parent)
: QDialog(parent),
ui_(new Ui_AlbumCoverSearcher),
app_(app),
albumcover_loader_(albumcover_loader),
model_(new QStandardItemModel(this)),
no_cover_icon_(no_cover_icon),
fetcher_(nullptr),
@@ -132,7 +130,7 @@ AlbumCoverSearcher::AlbumCoverSearcher(const QIcon &no_cover_icon, Application *
ui_->covers->setItemDelegate(new SizeOverlayDelegate(this));
ui_->covers->setModel(model_);
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &AlbumCoverSearcher::AlbumCoverLoaded);
QObject::connect(&*albumcover_loader_, &AlbumCoverLoader::AlbumCoverLoaded, this, &AlbumCoverSearcher::AlbumCoverLoaded);
QObject::connect(ui_->search, &QPushButton::clicked, this, &AlbumCoverSearcher::Search);
QObject::connect(ui_->covers, &GroupedIconView::doubleClicked, this, &AlbumCoverSearcher::CoverDoubleClicked);
@@ -220,7 +218,7 @@ void AlbumCoverSearcher::SearchFinished(const quint64 id, const CoverProviderSea
AlbumCoverLoaderOptions cover_options(AlbumCoverLoaderOptions::Option::RawImageData | AlbumCoverLoaderOptions::Option::OriginalImage | AlbumCoverLoaderOptions::Option::ScaledImage | AlbumCoverLoaderOptions::Option::PadScaledImage);
cover_options.desired_scaled_size = ui_->covers->iconSize(), ui_->covers->iconSize();
quint64 new_id = app_->album_cover_loader()->LoadImageAsync(cover_options, false, result.image_url, QUrl(), false);
quint64 new_id = albumcover_loader_->LoadImageAsync(cover_options, false, result.image_url, QUrl(), false);
QStandardItem *item = new QStandardItem;
item->setIcon(no_cover_icon_);

View File

@@ -48,7 +48,7 @@ class QPainter;
class QModelIndex;
class QKeyEvent;
class Application;
class AlbumCoverLoader;
class Ui_AlbumCoverSearcher;
class SizeOverlayDelegate : public QStyledItemDelegate {
@@ -65,7 +65,7 @@ class AlbumCoverSearcher : public QDialog {
Q_OBJECT
public:
explicit AlbumCoverSearcher(const QIcon &no_cover_icon, Application *app, QWidget *parent);
explicit AlbumCoverSearcher(const QIcon &no_cover_icon, const SharedPtr<AlbumCoverLoader> albumcover_loader, QWidget *parent);
~AlbumCoverSearcher() override;
enum Role {
@@ -95,7 +95,7 @@ class AlbumCoverSearcher : public QDialog {
private:
Ui_AlbumCoverSearcher *ui_;
Application *app_;
const SharedPtr<AlbumCoverLoader> albumcover_loader_;
QStandardItemModel *model_;
QIcon no_cover_icon_;

View File

@@ -36,8 +36,9 @@
using namespace Qt::Literals::StringLiterals;
CoverExportRunnable::CoverExportRunnable(const AlbumCoverExport::DialogResult &dialog_result, const AlbumCoverLoaderOptions::Types &cover_types, const Song &song, QObject *parent)
CoverExportRunnable::CoverExportRunnable(const SharedPtr<TagReaderClient> tagreader_client, const AlbumCoverExport::DialogResult &dialog_result, const AlbumCoverLoaderOptions::Types &cover_types, const Song &song, QObject *parent)
: QObject(parent),
tagreader_client_(tagreader_client),
dialog_result_(dialog_result),
cover_types_(cover_types),
song_(song) {}
@@ -78,7 +79,7 @@ void CoverExportRunnable::ProcessAndExportCover() {
break;
case AlbumCoverLoaderOptions::Type::Embedded:
if (song_.art_embedded() && dialog_result_.export_embedded_) {
const TagReaderResult result = TagReaderClient::Instance()->LoadCoverImageBlocking(song_.url().toLocalFile(), image);
const TagReaderResult result = tagreader_client_->LoadCoverImageBlocking(song_.url().toLocalFile(), image);
if (result.success() && !image.isNull()) {
extension = "jpg"_L1;
}
@@ -170,7 +171,7 @@ void CoverExportRunnable::ExportCover() {
break;
case AlbumCoverLoaderOptions::Type::Embedded:
if (song_.art_embedded() && dialog_result_.export_embedded_) {
const TagReaderResult result = TagReaderClient::Instance()->LoadCoverImageBlocking(song_.url().toLocalFile(), image);
const TagReaderResult result = tagreader_client_->LoadCoverImageBlocking(song_.url().toLocalFile(), image);
if (result.success() && !image.isNull()) {
embedded_cover = true;
extension = "jpg"_L1;

View File

@@ -28,15 +28,22 @@
#include <QRunnable>
#include <QString>
#include "includes/shared_ptr.h"
#include "core/song.h"
#include "albumcoverloaderoptions.h"
#include "albumcoverexport.h"
class TagReaderClient;
class CoverExportRunnable : public QObject, public QRunnable {
Q_OBJECT
public:
explicit CoverExportRunnable(const AlbumCoverExport::DialogResult &dialog_result, const AlbumCoverLoaderOptions::Types &cover_types, const Song &song, QObject *parent = nullptr);
explicit CoverExportRunnable(const SharedPtr<TagReaderClient> tagreader_client,
const AlbumCoverExport::DialogResult &dialog_result,
const AlbumCoverLoaderOptions::Types &cover_types,
const Song &song,
QObject *parent = nullptr);
void run() override;
@@ -51,6 +58,7 @@ class CoverExportRunnable : public QObject, public QRunnable {
void ProcessAndExportCover();
void ExportCover();
SharedPtr<TagReaderClient> tagreader_client_;
AlbumCoverExport::DialogResult dialog_result_;
AlbumCoverLoaderOptions::Types cover_types_;
Song song_;

View File

@@ -31,7 +31,7 @@
#include <QNetworkRequest>
#include <QUrl>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "utilities/mimeutils.h"
#include "widgets/busyindicator.h"

View File

@@ -28,7 +28,7 @@
#include <QDialog>
#include <QString>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "albumcoverimageresult.h"
class QWidget;

View File

@@ -24,8 +24,7 @@
#include <QObject>
#include <QString>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "coverprovider.h"
CoverProvider::CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent) : QObject(parent), app_(app), network_(network), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required), quality_(quality), batch_(batch), allow_missing_album_(allow_missing_album) {}
CoverProvider::CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, const SharedPtr<NetworkAccessManager> network, QObject *parent) : QObject(parent), network_(network), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required), quality_(quality), batch_(batch), allow_missing_album_(allow_missing_album) {}

View File

@@ -30,10 +30,9 @@
#include <QString>
#include <QStringList>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "albumcoverfetcher.h"
class Application;
class NetworkAccessManager;
// Each implementation of this interface downloads covers from one online service.
@@ -42,7 +41,7 @@ class CoverProvider : public QObject {
Q_OBJECT
public:
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent);
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, const SharedPtr<NetworkAccessManager> network, QObject *parent);
// A name (very short description) of this provider, like "last.fm".
QString name() const { return name_; }
@@ -79,15 +78,14 @@ class CoverProvider : public QObject {
using Param = QPair<QString, QString>;
using ParamList = QList<Param>;
Application *app_;
SharedPtr<NetworkAccessManager> network_;
QString name_;
const SharedPtr<NetworkAccessManager> network_;
const QString name_;
bool enabled_;
int order_;
bool authentication_required_;
float quality_;
bool batch_;
bool allow_missing_album_;
const bool authentication_required_;
const float quality_;
const bool batch_;
const bool allow_missing_album_;
};
#endif // COVERPROVIDER_H

View File

@@ -36,7 +36,7 @@
#include "coverprovider.h"
#include "coverproviders.h"
#include "settings/coverssettingspage.h"
#include "constants/coverssettings.h"
int CoverProviders::NextOrderId = 0;
@@ -60,8 +60,8 @@ void CoverProviders::ReloadSettings() {
}
Settings s;
s.beginGroup(CoversSettingsPage::kSettingsGroup);
const QStringList providers_enabled = s.value(CoversSettingsPage::kProviders, QStringList() << all_providers.values()).toStringList();
s.beginGroup(CoversSettings::kSettingsGroup);
const QStringList providers_enabled = s.value(CoversSettings::kProviders, QStringList() << all_providers.values()).toStringList();
s.endGroup();
int i = 0;

View File

@@ -29,10 +29,9 @@
#include <QImage>
#include <QStandardPaths>
#include "core/application.h"
#include "core/logging.h"
#include "core/song.h"
#include "core/temporaryfile.h"
#include "playlist/playlistmanager.h"
#include "albumcoverloader.h"
#include "albumcoverloaderresult.h"
#include "currentalbumcoverloader.h"
@@ -40,9 +39,9 @@
using std::make_unique;
using namespace Qt::Literals::StringLiterals;
CurrentAlbumCoverLoader::CurrentAlbumCoverLoader(Application *app, QObject *parent)
CurrentAlbumCoverLoader::CurrentAlbumCoverLoader(const SharedPtr<AlbumCoverLoader> albumcover_loader, QObject *parent)
: QObject(parent),
app_(app),
albumcover_loader_(albumcover_loader),
temp_file_pattern_(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + u"/strawberry-cover-XXXXXX.jpg"_s),
id_(0) {
@@ -52,8 +51,7 @@ CurrentAlbumCoverLoader::CurrentAlbumCoverLoader(Application *app, QObject *pare
options_.desired_scaled_size = QSize(120, 120);
options_.default_cover = u":/pictures/cdcase.png"_s;
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &CurrentAlbumCoverLoader::LoadAlbumCover);
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &CurrentAlbumCoverLoader::AlbumCoverReady);
QObject::connect(&*albumcover_loader, &AlbumCoverLoader::AlbumCoverLoaded, this, &CurrentAlbumCoverLoader::AlbumCoverReady);
ReloadSettingsAsync();
@@ -76,7 +74,7 @@ void CurrentAlbumCoverLoader::ReloadSettings() {
void CurrentAlbumCoverLoader::LoadAlbumCover(const Song &song) {
last_song_ = song;
id_ = app_->album_cover_loader()->LoadImageAsync(options_, last_song_);
id_ = albumcover_loader_->LoadImageAsync(options_, last_song_);
}

View File

@@ -29,19 +29,20 @@
#include <QString>
#include <QImage>
#include "core/scoped_ptr.h"
#include "includes/scoped_ptr.h"
#include "includes/shared_ptr.h"
#include "core/temporaryfile.h"
#include "core/song.h"
#include "albumcoverloaderoptions.h"
#include "albumcoverloaderresult.h"
class Application;
class AlbumCoverLoader;
class CurrentAlbumCoverLoader : public QObject {
Q_OBJECT
public:
explicit CurrentAlbumCoverLoader(Application *app, QObject *parent = nullptr);
explicit CurrentAlbumCoverLoader(const SharedPtr<AlbumCoverLoader> albumcover_loader, QObject *parent = nullptr);
~CurrentAlbumCoverLoader() override;
const AlbumCoverLoaderOptions &options() const { return options_; }
@@ -61,10 +62,10 @@ class CurrentAlbumCoverLoader : public QObject {
void AlbumCoverReady(const quint64 id, AlbumCoverLoaderResult result);
private:
Application *app_;
const SharedPtr<AlbumCoverLoader> albumcover_loader_;
AlbumCoverLoaderOptions options_;
QString temp_file_pattern_;
const QString temp_file_pattern_;
ScopedPtr<TemporaryFile> temp_cover_;
ScopedPtr<TemporaryFile> temp_cover_thumbnail_;

View File

@@ -39,7 +39,6 @@
#include <QJsonObject>
#include <QJsonArray>
#include "core/application.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
#include "core/song.h"
@@ -55,8 +54,8 @@ constexpr char kApiUrl[] = "https://api.deezer.com";
constexpr int kLimit = 10;
}
DeezerCoverProvider::DeezerCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Deezer"_s, true, false, 2.0, true, true, app, network, parent) {}
DeezerCoverProvider::DeezerCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Deezer"_s, true, false, 2.0, true, true, network, parent) {}
DeezerCoverProvider::~DeezerCoverProvider() {

View File

@@ -34,13 +34,12 @@
class NetworkAccessManager;
class QNetworkReply;
class Application;
class DeezerCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit DeezerCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit DeezerCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~DeezerCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -41,8 +41,7 @@
#include <QJsonValue>
#include <QJsonArray>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/networkaccessmanager.h"
#include "utilities/cryptutils.h"
@@ -58,8 +57,8 @@ const char *DiscogsCoverProvider::kAccessKeyB64 = "dGh6ZnljUGJlZ1NEeXBuSFFxSVk="
const char *DiscogsCoverProvider::kSecretKeyB64 = "ZkFIcmlaSER4aHhRSlF2U3d0bm5ZVmdxeXFLWUl0UXI=";
const int DiscogsCoverProvider::kRequestsDelay = 1000;
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Discogs"_s, false, false, 0.0, false, false, app, network, parent),
DiscogsCoverProvider::DiscogsCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Discogs"_s, false, false, 0.0, false, false, network, parent),
timer_flush_requests_(new QTimer(this)) {
timer_flush_requests_->setInterval(kRequestsDelay);

View File

@@ -35,20 +35,19 @@
#include <QString>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
#include "albumcoverfetcher.h"
class NetworkAccessManager;
class QNetworkReply;
class QTimer;
class Application;
class DiscogsCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit DiscogsCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit DiscogsCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~DiscogsCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -25,16 +25,15 @@
#include <QJsonDocument>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "coverprovider.h"
#include "jsoncoverprovider.h"
using namespace Qt::Literals::StringLiterals;
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: CoverProvider(name, enabled, authentication_required, quality, batch, allow_missing_album, app, network, parent) {}
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, const SharedPtr<NetworkAccessManager> network, QObject *parent)
: CoverProvider(name, enabled, authentication_required, quality, batch, allow_missing_album, network, parent) {}
QJsonObject JsonCoverProvider::ExtractJsonObj(const QByteArray &data) {

View File

@@ -27,17 +27,16 @@
#include <QString>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "coverprovider.h"
class Application;
class NetworkAccessManager;
class JsonCoverProvider : public CoverProvider {
Q_OBJECT
public:
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent);
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, const SharedPtr<NetworkAccessManager> network, QObject *parent);
protected:
QJsonObject ExtractJsonObj(const QByteArray &data);

View File

@@ -38,8 +38,7 @@
#include <QJsonObject>
#include <QJsonArray>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
@@ -55,8 +54,8 @@ constexpr char kApiKey[] = "211990b4c96782c05d1536e7219eb56e";
constexpr char kSecret[] = "80fd738f49596e9709b1bf9319c444a8";
} // namespace
LastFmCoverProvider::LastFmCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Last.fm"_s, true, false, 1.0, true, false, app, network, parent) {}
LastFmCoverProvider::LastFmCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Last.fm"_s, true, false, 1.0, true, false, network, parent) {}
LastFmCoverProvider::~LastFmCoverProvider() {

View File

@@ -29,18 +29,17 @@
#include <QString>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
class NetworkAccessManager;
class QNetworkReply;
class Application;
class LastFmCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit LastFmCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit LastFmCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~LastFmCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -36,8 +36,7 @@
#include <QJsonObject>
#include <QJsonArray>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
#include "albumcoverfetcher.h"
@@ -53,8 +52,8 @@ constexpr int kLimit = 8;
constexpr int kRequestsDelay = 1000;
} // namespace
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"MusicBrainz"_s, true, false, 1.5, true, false, app, network, parent),
MusicbrainzCoverProvider::MusicbrainzCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"MusicBrainz"_s, true, false, 1.5, true, false, network, parent),
timer_flush_requests_(new QTimer(this)) {
timer_flush_requests_->setInterval(kRequestsDelay);

View File

@@ -30,19 +30,18 @@
#include <QString>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
class QNetworkReply;
class QTimer;
class Application;
class NetworkAccessManager;
class MusicbrainzCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit MusicbrainzCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit MusicbrainzCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~MusicbrainzCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -32,18 +32,17 @@
#include <QJsonParseError>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/networkaccessmanager.h"
#include "providers/musixmatchprovider.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
#include "musixmatchcoverprovider.h"
using namespace Qt::Literals::StringLiterals;
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Musixmatch"_s, true, false, 1.0, true, false, app, network, parent) {}
MusixmatchCoverProvider::MusixmatchCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Musixmatch"_s, true, false, 1.0, true, false, network, parent) {}
MusixmatchCoverProvider::~MusixmatchCoverProvider() {

View File

@@ -28,7 +28,7 @@
#include <QVariant>
#include <QString>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
#include "providers/musixmatchprovider.h"
@@ -39,7 +39,7 @@ class MusixmatchCoverProvider : public JsonCoverProvider, MusixmatchProvider {
Q_OBJECT
public:
explicit MusixmatchCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit MusixmatchCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~MusixmatchCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -37,12 +37,12 @@
#include <QJsonArray>
#include <QTimer>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
#include "core/settings.h"
#include "utilities/timeconstants.h"
#include "core/song.h"
#include "constants/timeconstants.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
#include "opentidalcoverprovider.h"
@@ -61,8 +61,8 @@ constexpr const int kRequestsDelay = 1000;
using std::make_shared;
OpenTidalCoverProvider::OpenTidalCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"OpenTidal"_s, true, false, 2.5, true, false, app, network, parent),
OpenTidalCoverProvider::OpenTidalCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"OpenTidal"_s, true, false, 2.5, true, false, network, parent),
login_timer_(new QTimer(this)),
timer_flush_requests_(new QTimer(this)),
login_in_progress_(false),

View File

@@ -32,11 +32,10 @@
#include <QSslError>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
class QNetworkReply;
class Application;
class NetworkAccessManager;
class QTimer;
@@ -44,7 +43,7 @@ class OpenTidalCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit OpenTidalCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit OpenTidalCoverProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~OpenTidalCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -36,12 +36,10 @@
#include <QJsonObject>
#include <QJsonArray>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
#include "core/song.h"
#include "streaming/streamingservices.h"
#include "qobuz/qobuzservice.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
@@ -53,9 +51,9 @@ namespace {
constexpr int kLimit = 10;
}
QobuzCoverProvider::QobuzCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Qobuz"_s, true, true, 2.0, true, true, app, network, parent),
service_(app->streaming_services()->Service<QobuzService>()) {}
QobuzCoverProvider::QobuzCoverProvider(const QobuzServicePtr service, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Qobuz"_s, true, true, 2.0, true, true, network, parent),
service_(service) {}
QobuzCoverProvider::~QobuzCoverProvider() {

View File

@@ -30,19 +30,18 @@
#include <QJsonObject>
#include <QSslError>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
#include "qobuz/qobuzservice.h"
class QNetworkReply;
class Application;
class NetworkAccessManager;
class QobuzCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit QobuzCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit QobuzCoverProvider(const QobuzServicePtr service, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~QobuzCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;

View File

@@ -38,11 +38,9 @@
#include <QDesktopServices>
#include <QMessageBox>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
#include "streaming/streamingservices.h"
#include "spotify/spotifyservice.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
@@ -55,9 +53,9 @@ constexpr char kApiUrl[] = "https://api.spotify.com/v1";
constexpr int kLimit = 10;
} // namespace
SpotifyCoverProvider::SpotifyCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Spotify"_s, true, true, 2.5, true, true, app, network, parent),
service_(app->streaming_services()->Service<SpotifyService>()) {}
SpotifyCoverProvider::SpotifyCoverProvider(const SpotifyServicePtr service, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Spotify"_s, true, true, 2.5, true, true, network, parent),
service_(service) {}
SpotifyCoverProvider::~SpotifyCoverProvider() {

View File

@@ -34,19 +34,18 @@
#include <QJsonObject>
#include <QTimer>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
#include "spotify/spotifyservice.h"
class QNetworkReply;
class Application;
class NetworkAccessManager;
class SpotifyCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit SpotifyCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit SpotifyCoverProvider(const SpotifyServicePtr service, const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~SpotifyCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@@ -65,7 +64,7 @@ class SpotifyCoverProvider : public JsonCoverProvider {
void Error(const QString &error, const QVariant &debug = QVariant()) override;
private:
SharedPtr<SpotifyService> service_;
const SharedPtr<SpotifyService> service_;
QList<QNetworkReply*> replies_;
};

View File

@@ -34,12 +34,10 @@
#include <QJsonObject>
#include <QJsonArray>
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "core/logging.h"
#include "core/song.h"
#include "streaming/streamingservices.h"
#include "tidal/tidalservice.h"
#include "albumcoverfetcher.h"
#include "jsoncoverprovider.h"
@@ -51,9 +49,9 @@ namespace {
constexpr int kLimit = 10;
}
TidalCoverProvider::TidalCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Tidal"_s, true, true, 2.5, true, true, app, network, parent),
service_(app->streaming_services()->Service<TidalService>()) {}
TidalCoverProvider::TidalCoverProvider(const TidalServicePtr service, const SharedPtr<NetworkAccessManager> network, QObject *parent)
: JsonCoverProvider(u"Tidal"_s, true, true, 2.5, true, true, network, parent),
service_(service) {}
TidalCoverProvider::~TidalCoverProvider() {

View File

@@ -32,19 +32,18 @@
#include <QJsonValue>
#include <QJsonObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "jsoncoverprovider.h"
#include "tidal/tidalservice.h"
class QNetworkReply;
class Application;
class NetworkAccessManager;
class TidalCoverProvider : public JsonCoverProvider {
Q_OBJECT
public:
explicit TidalCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
explicit TidalCoverProvider(const TidalServicePtr service, const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
~TidalCoverProvider() override;
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
@@ -63,7 +62,7 @@ class TidalCoverProvider : public JsonCoverProvider {
void Error(const QString &error, const QVariant &debug = QVariant()) override;
private:
TidalServicePtr service_;
const TidalServicePtr service_;
QList<QNetworkReply*> replies_;
};