Use const reference for AlbumCoverLoaderResult

This commit is contained in:
Jonas Kvinge
2023-04-09 22:26:17 +02:00
parent f8d2c7eba3
commit 2f17647cd3
37 changed files with 242 additions and 309 deletions

View File

@@ -661,7 +661,7 @@ QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
} }
void CollectionModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result) { void CollectionModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
if (!pending_art_.contains(id)) return; if (!pending_art_.contains(id)) return;
@@ -673,21 +673,19 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultP
pending_cache_keys_.remove(cache_key); pending_cache_keys_.remove(cache_key);
if (!result) return;
// Insert this image in the cache. // Insert this image in the cache.
if (!result->success || result->image_scaled.isNull() || result->type == AlbumCoverLoaderResult::Type::ManuallyUnset) { if (!result.success || result.image_scaled.isNull() || result.type == AlbumCoverLoaderResult::Type::ManuallyUnset) {
// Set the no_cover image so we don't continually try to load art. // Set the no_cover image so we don't continually try to load art.
QPixmapCache::insert(cache_key, no_cover_icon_); QPixmapCache::insert(cache_key, no_cover_icon_);
} }
else { else {
QPixmap image_pixmap; QPixmap image_pixmap;
image_pixmap = QPixmap::fromImage(result->image_scaled); image_pixmap = QPixmap::fromImage(result.image_scaled);
QPixmapCache::insert(cache_key, image_pixmap); QPixmapCache::insert(cache_key, image_pixmap);
} }
// If we have a valid cover not already in the disk cache // If we have a valid cover not already in the disk cache
if (use_disk_cache_ && sIconCache && result->success && !result->image_scaled.isNull()) { if (use_disk_cache_ && sIconCache && result.success && !result.image_scaled.isNull()) {
const QUrl disk_cache_key = AlbumIconPixmapDiskCacheKey(cache_key); const QUrl disk_cache_key = AlbumIconPixmapDiskCacheKey(cache_key);
std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(disk_cache_key)); std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(disk_cache_key));
if (!disk_cache_img) { if (!disk_cache_img) {
@@ -696,7 +694,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultP
disk_cache_metadata.setUrl(disk_cache_key); disk_cache_metadata.setUrl(disk_cache_key);
QIODevice *device_iconcache = sIconCache->prepare(disk_cache_metadata); QIODevice *device_iconcache = sIconCache->prepare(disk_cache_metadata);
if (device_iconcache) { if (device_iconcache) {
result->image_scaled.save(device_iconcache, "XPM"); result.image_scaled.save(device_iconcache, "XPM");
sIconCache->insert(device_iconcache); sIconCache->insert(device_iconcache);
} }
} }

View File

@@ -231,7 +231,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
// Called after ResetAsync // Called after ResetAsync
void ResetAsyncQueryFinished(); void ResetAsyncQueryFinished();
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
private: private:
// Provides some optimizations for loading the list of items in the root. // Provides some optimizations for loading the list of items in the root.

View File

@@ -1304,7 +1304,7 @@ void MainWindow::MediaStopped() {
song_playing_ = Song(); song_playing_ = Song();
song_ = Song(); song_ = Song();
album_cover_.reset(); album_cover_ = AlbumCoverImageResult();
app_->scrobbler()->ClearPlaying(); app_->scrobbler()->ClearPlaying();
@@ -3038,11 +3038,7 @@ void MainWindow::SearchForCover() {
} }
void MainWindow::SaveCoverToFile() { void MainWindow::SaveCoverToFile() {
album_cover_choice_controller_->SaveCoverToFileManual(song_, album_cover_);
if (album_cover_) {
album_cover_choice_controller_->SaveCoverToFileManual(song_, album_cover_);
}
} }
void MainWindow::UnsetCover() { void MainWindow::UnsetCover() {
@@ -3058,11 +3054,7 @@ void MainWindow::DeleteCover() {
} }
void MainWindow::ShowCover() { void MainWindow::ShowCover() {
album_cover_choice_controller_->ShowCover(song_, album_cover_.image);
if (album_cover_) {
album_cover_choice_controller_->ShowCover(song_, album_cover_->image);
}
} }
void MainWindow::SearchCoverAutomatically() { void MainWindow::SearchCoverAutomatically() {
@@ -3071,29 +3063,24 @@ void MainWindow::SearchCoverAutomatically() {
} }
void MainWindow::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result) { void MainWindow::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
if (song != song_playing_) return; if (song != song_playing_) return;
song_ = song; song_ = song;
if (result) { album_cover_ = result.album_cover;
album_cover_ = result->album_cover;
emit AlbumCoverReady(song, result->album_cover->image); emit AlbumCoverReady(song, result.album_cover.image);
}
else {
album_cover_.reset();
emit AlbumCoverReady(song, QImage());
}
const bool enable_change_art = song.is_collection_song() && !song.effective_albumartist().isEmpty() && !song.album().isEmpty(); const bool enable_change_art = song.is_collection_song() && !song.effective_albumartist().isEmpty() && !song.album().isEmpty();
album_cover_choice_controller_->show_cover_action()->setEnabled(result && result->success && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset); album_cover_choice_controller_->show_cover_action()->setEnabled(result.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
album_cover_choice_controller_->cover_to_file_action()->setEnabled(result && result->success && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset); album_cover_choice_controller_->cover_to_file_action()->setEnabled(result.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
album_cover_choice_controller_->cover_from_file_action()->setEnabled(enable_change_art); album_cover_choice_controller_->cover_from_file_action()->setEnabled(enable_change_art);
album_cover_choice_controller_->cover_from_url_action()->setEnabled(enable_change_art); album_cover_choice_controller_->cover_from_url_action()->setEnabled(enable_change_art);
album_cover_choice_controller_->search_for_cover_action()->setEnabled(app_->cover_providers()->HasAnyProviders() && enable_change_art); album_cover_choice_controller_->search_for_cover_action()->setEnabled(app_->cover_providers()->HasAnyProviders() && enable_change_art);
album_cover_choice_controller_->unset_cover_action()->setEnabled(enable_change_art && !song.has_manually_unset_cover()); album_cover_choice_controller_->unset_cover_action()->setEnabled(enable_change_art && !song.has_manually_unset_cover());
album_cover_choice_controller_->clear_cover_action()->setEnabled(enable_change_art && !song.art_manual().isEmpty()); album_cover_choice_controller_->clear_cover_action()->setEnabled(enable_change_art && !song.art_manual().isEmpty());
album_cover_choice_controller_->delete_cover_action()->setEnabled(enable_change_art && result && result->success && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset); album_cover_choice_controller_->delete_cover_action()->setEnabled(enable_change_art && result.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
GetCoverAutomatically(); GetCoverAutomatically();

View File

@@ -257,7 +257,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void DeleteCover(); void DeleteCover();
void ShowCover(); void ShowCover();
void SearchCoverAutomatically(); void SearchCoverAutomatically();
void AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result);
void ScrobblingEnabledChanged(const bool value); void ScrobblingEnabledChanged(const bool value);
void ScrobbleButtonVisibilityChanged(const bool value); void ScrobbleButtonVisibilityChanged(const bool value);
@@ -390,7 +390,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
Song song_; Song song_;
Song song_playing_; Song song_playing_;
AlbumCoverImageResultPtr album_cover_; AlbumCoverImageResult album_cover_;
bool exit_; bool exit_;
int exit_count_; int exit_count_;
bool delete_files_; bool delete_files_;

View File

@@ -122,7 +122,6 @@ void RegisterMetaTypes() {
qRegisterMetaType<PlaylistSequence::RepeatMode>("PlaylistSequence::RepeatMode"); qRegisterMetaType<PlaylistSequence::RepeatMode>("PlaylistSequence::RepeatMode");
qRegisterMetaType<PlaylistSequence::ShuffleMode>("PlaylistSequence::ShuffleMode"); qRegisterMetaType<PlaylistSequence::ShuffleMode>("PlaylistSequence::ShuffleMode");
qRegisterMetaType<AlbumCoverLoaderResult>("AlbumCoverLoaderResult"); qRegisterMetaType<AlbumCoverLoaderResult>("AlbumCoverLoaderResult");
qRegisterMetaType<AlbumCoverLoaderResultPtr>("AlbumCoverLoaderResultPtr");
qRegisterMetaType<AlbumCoverLoaderResult::Type>("AlbumCoverLoaderResult::Type"); qRegisterMetaType<AlbumCoverLoaderResult::Type>("AlbumCoverLoaderResult::Type");
qRegisterMetaType<CoverProviderSearchResult>("CoverProviderSearchResult"); qRegisterMetaType<CoverProviderSearchResult>("CoverProviderSearchResult");
qRegisterMetaType<CoverProviderSearchResults>("CoverProviderSearchResults"); qRegisterMetaType<CoverProviderSearchResults>("CoverProviderSearchResults");

View File

@@ -386,9 +386,7 @@ void Mpris2::CurrentSongChanged(const Song &song) {
} }
// ... and we add the cover information later, when it's available. // ... and we add the cover information later, when it's available.
void Mpris2::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result) { void Mpris2::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
if (!result) return;
last_metadata_ = QVariantMap(); last_metadata_ = QVariantMap();
song.ToXesam(&last_metadata_); song.ToXesam(&last_metadata_);
@@ -397,11 +395,11 @@ void Mpris2::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result
AddMetadata("mpris:trackid", current_track_id(), &last_metadata_); AddMetadata("mpris:trackid", current_track_id(), &last_metadata_);
QUrl cover_url; QUrl cover_url;
if (result->album_cover->cover_url.isValid() && result->album_cover->cover_url.isLocalFile() && QFile(result->album_cover->cover_url.toLocalFile()).exists()) { if (result.album_cover.cover_url.isValid() && result.album_cover.cover_url.isLocalFile() && QFile(result.album_cover.cover_url.toLocalFile()).exists()) {
cover_url = result->album_cover->cover_url; cover_url = result.album_cover.cover_url;
} }
else if (result->temp_cover_url.isValid() && result->temp_cover_url.isLocalFile()) { else if (result.temp_cover_url.isValid() && result.temp_cover_url.isLocalFile()) {
cover_url = result->temp_cover_url; cover_url = result.temp_cover_url;
} }
else if (song.art_manual().isValid() && song.art_manual().isLocalFile() && song.art_manual().path() != Song::kManuallyUnsetCover && song.art_manual().path() != Song::kEmbeddedCover) { else if (song.art_manual().isValid() && song.art_manual().isLocalFile() && song.art_manual().path() != Song::kManuallyUnsetCover && song.art_manual().path() != Song::kEmbeddedCover) {
cover_url = song.art_manual(); cover_url = song.art_manual();

View File

@@ -202,7 +202,7 @@ class Mpris2 : public QObject {
void PlaylistChanged(const MprisPlaylist &playlist); void PlaylistChanged(const MprisPlaylist &playlist);
private slots: private slots:
void AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result = AlbumCoverLoaderResultPtr()); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result = AlbumCoverLoaderResult());
void EngineStateChanged(EngineBase::State newState); void EngineStateChanged(EngineBase::State newState);
void VolumeChanged(); void VolumeChanged();

View File

@@ -96,15 +96,15 @@ void StandardItemIconLoader::ModelReset() {
} }
void StandardItemIconLoader::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result) { void StandardItemIconLoader::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
if (!pending_covers_.contains(id)) return; if (!pending_covers_.contains(id)) return;
QStandardItem *item = pending_covers_.take(id); QStandardItem *item = pending_covers_.take(id);
if (!item) return; if (!item) return;
if (result && result->success && !result->image_scaled.isNull() && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset) { if (result.success && !result.image_scaled.isNull() && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset) {
item->setIcon(QIcon(QPixmap::fromImage(result->image_scaled))); item->setIcon(QIcon(QPixmap::fromImage(result.image_scaled)));
} }
} }

View File

@@ -55,7 +55,7 @@ class StandardItemIconLoader : public QObject {
void LoadIcon(const Song &song, QStandardItem *for_item); void LoadIcon(const Song &song, QStandardItem *for_item);
private slots: private slots:
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
void RowsAboutToBeRemoved(const QModelIndex &parent, int begin, int end); void RowsAboutToBeRemoved(const QModelIndex &parent, int begin, int end);
void ModelReset(); void ModelReset();

View File

@@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <memory>
#include <QtGlobal> #include <QtGlobal>
#include <QGuiApplication> #include <QGuiApplication>
#include <QtConcurrentRun> #include <QtConcurrentRun>
@@ -170,27 +168,27 @@ QList<QAction*> AlbumCoverChoiceController::GetAllActions() {
} }
AlbumCoverImageResultPtr AlbumCoverChoiceController::LoadImageFromFile(Song *song) { AlbumCoverImageResult AlbumCoverChoiceController::LoadImageFromFile(Song *song) {
if (!song->url().isLocalFile()) return AlbumCoverImageResultPtr(); if (!song->url().isLocalFile()) return AlbumCoverImageResult();
QString cover_file = QFileDialog::getOpenFileName(this, tr("Load cover from disk"), GetInitialPathForFileDialog(*song, QString()), tr(kLoadImageFileFilter) + ";;" + tr(kAllFilesFilter)); QString cover_file = QFileDialog::getOpenFileName(this, tr("Load cover from disk"), GetInitialPathForFileDialog(*song, QString()), tr(kLoadImageFileFilter) + ";;" + tr(kAllFilesFilter));
if (cover_file.isEmpty()) return AlbumCoverImageResultPtr(); if (cover_file.isEmpty()) return AlbumCoverImageResult();
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>(); AlbumCoverImageResult result;
QFile file(cover_file); QFile file(cover_file);
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
result->image_data = file.readAll(); result.image_data = file.readAll();
file.close(); file.close();
if (result->image_data.isEmpty()) { if (result.image_data.isEmpty()) {
qLog(Error) << "Cover file" << cover_file << "is empty."; qLog(Error) << "Cover file" << cover_file << "is empty.";
emit Error(tr("Cover file %1 is empty.").arg(cover_file)); emit Error(tr("Cover file %1 is empty.").arg(cover_file));
} }
else { else {
result->mime_type = Utilities::MimeTypeFromData(result->image_data); result.mime_type = Utilities::MimeTypeFromData(result.image_data);
result->image.loadFromData(result->image_data); result.image.loadFromData(result.image_data);
result->cover_url = QUrl::fromLocalFile(cover_file); result.cover_url = QUrl::fromLocalFile(cover_file);
} }
} }
else { else {
@@ -231,9 +229,7 @@ QUrl AlbumCoverChoiceController::LoadCoverFromFile(Song *song) {
} }
void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, AlbumCoverImageResultPtr result) { void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, const AlbumCoverImageResult &result) {
if (!result) return;
QString initial_file_name = "/"; QString initial_file_name = "/";
@@ -260,10 +256,10 @@ void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, AlbumCo
fileinfo.setFile(save_filename); fileinfo.setFile(save_filename);
} }
if (result->is_jpeg() && fileinfo.completeSuffix().compare("jpg", Qt::CaseInsensitive) == 0) { if (result.is_jpeg() && fileinfo.completeSuffix().compare("jpg", Qt::CaseInsensitive) == 0) {
QFile file(save_filename); QFile file(save_filename);
if (file.open(QIODevice::WriteOnly)) { if (file.open(QIODevice::WriteOnly)) {
if (file.write(result->image_data) <= 0) { if (file.write(result.image_data) <= 0) {
qLog(Error) << "Failed writing cover to file" << save_filename << file.errorString(); qLog(Error) << "Failed writing cover to file" << save_filename << file.errorString();
emit Error(tr("Failed writing cover to file %1: %2").arg(save_filename, file.errorString())); emit Error(tr("Failed writing cover to file %1: %2").arg(save_filename, file.errorString()));
} }
@@ -275,7 +271,7 @@ void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, AlbumCo
} }
} }
else { else {
if (!result->image.save(save_filename)) { if (!result.image.save(save_filename)) {
qLog(Error) << "Failed writing cover to file" << save_filename; qLog(Error) << "Failed writing cover to file" << save_filename;
emit Error(tr("Failed writing cover to file %1.").arg(save_filename)); emit Error(tr("Failed writing cover to file %1.").arg(save_filename));
} }
@@ -309,9 +305,9 @@ QUrl AlbumCoverChoiceController::LoadCoverFromURL(Song *song) {
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl(); if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl();
AlbumCoverImageResultPtr result = LoadImageFromURL(); const AlbumCoverImageResult result = LoadImageFromURL();
if (!result || result->image.isNull()) { if (result.image.isNull()) {
return QUrl(); return QUrl();
} }
else { else {
@@ -320,7 +316,7 @@ QUrl AlbumCoverChoiceController::LoadCoverFromURL(Song *song) {
} }
AlbumCoverImageResultPtr AlbumCoverChoiceController::LoadImageFromURL() { 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(app_->network(), this); }
@@ -333,8 +329,8 @@ QUrl AlbumCoverChoiceController::SearchForCover(Song *song) {
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl(); if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl();
// Get something sensible to stick in the search box // Get something sensible to stick in the search box
AlbumCoverImageResultPtr result = SearchForImage(song); AlbumCoverImageResult result = SearchForImage(song);
if (result && result->is_valid()) { if (result.is_valid()) {
return SaveCoverAutomatic(song, result); return SaveCoverAutomatic(song, result);
} }
else { else {
@@ -343,9 +339,9 @@ QUrl AlbumCoverChoiceController::SearchForCover(Song *song) {
} }
AlbumCoverImageResultPtr AlbumCoverChoiceController::SearchForImage(Song *song) { AlbumCoverImageResult AlbumCoverChoiceController::SearchForImage(Song *song) {
if (!song->url().isLocalFile()) return AlbumCoverImageResultPtr(); if (!song->url().isLocalFile()) return AlbumCoverImageResult();
QString album = song->effective_album(); QString album = song->effective_album();
album = album.remove(Song::kAlbumRemoveDisc).remove(Song::kAlbumRemoveMisc); album = album.remove(Song::kAlbumRemoveDisc).remove(Song::kAlbumRemoveMisc);
@@ -381,7 +377,7 @@ bool AlbumCoverChoiceController::DeleteCover(Song *song, const bool manually_uns
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return false; if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return false;
if (song->has_embedded_cover() && song->save_embedded_cover_supported()) { if (song->has_embedded_cover() && song->save_embedded_cover_supported()) {
SaveCoverEmbeddedAutomatic(*song, std::make_shared<AlbumCoverImageResult>()); SaveCoverEmbeddedAutomatic(*song, AlbumCoverImageResult());
} }
QString art_automatic; QString art_automatic;
@@ -517,7 +513,7 @@ quint64 AlbumCoverChoiceController::SearchCoverAutomatically(const Song &song) {
} }
void AlbumCoverChoiceController::AlbumCoverFetched(const quint64 id, AlbumCoverImageResultPtr result, const CoverSearchStatistics &statistics) { void AlbumCoverChoiceController::AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics) {
Q_UNUSED(statistics); Q_UNUSED(statistics);
@@ -526,7 +522,7 @@ void AlbumCoverChoiceController::AlbumCoverFetched(const quint64 id, AlbumCoverI
song = cover_fetching_tasks_.take(id); song = cover_fetching_tasks_.take(id);
} }
if (result && result->is_valid()) { if (result.is_valid()) {
SaveCoverAutomatic(&song, result); SaveCoverAutomatic(&song, result);
} }
@@ -596,7 +592,7 @@ void AlbumCoverChoiceController::SaveArtManualToSong(Song *song, const QUrl &art
} }
QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song *song, AlbumCoverImageResultPtr result, const bool force_overwrite) { QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song *song, const AlbumCoverImageResult &result, const bool force_overwrite) {
return SaveCoverToFileAutomatic(song->source(), return SaveCoverToFileAutomatic(song->source(),
song->effective_albumartist(), song->effective_albumartist(),
@@ -613,12 +609,10 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
const QString &album, const QString &album,
const QString &album_id, const QString &album_id,
const QString &album_dir, const QString &album_dir,
AlbumCoverImageResultPtr result, const AlbumCoverImageResult &result,
const bool force_overwrite) { const bool force_overwrite) {
if (!result) return QUrl(); QString filepath = CoverUtils::CoverFilePath(cover_options_, source, artist, album, album_id, album_dir, result.cover_url, "jpg");
QString filepath = CoverUtils::CoverFilePath(cover_options_, source, artist, album, album_id, album_dir, result->cover_url, "jpg");
if (filepath.isEmpty()) return QUrl(); if (filepath.isEmpty()) return QUrl();
QFile file(filepath); QFile file(filepath);
@@ -632,9 +626,9 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
} }
QUrl cover_url; QUrl cover_url;
if (result->is_jpeg()) { if (result.is_jpeg()) {
if (file.open(QIODevice::WriteOnly)) { if (file.open(QIODevice::WriteOnly)) {
if (file.write(result->image_data) > 0) { if (file.write(result.image_data) > 0) {
cover_url = QUrl::fromLocalFile(filepath); cover_url = QUrl::fromLocalFile(filepath);
} }
else { else {
@@ -649,16 +643,14 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
} }
} }
else { else {
if (result->image.save(filepath, "JPG")) cover_url = QUrl::fromLocalFile(filepath); if (result.image.save(filepath, "JPG")) cover_url = QUrl::fromLocalFile(filepath);
} }
return cover_url; return cover_url;
} }
void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, AlbumCoverImageResultPtr result) { void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, const AlbumCoverImageResult &result) {
if (!result) return;
if (song.source() == Song::Source::Collection) { if (song.source() == Song::Source::Collection) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@@ -673,13 +665,13 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, Al
QList<QUrl> urls; QList<QUrl> urls;
urls.reserve(songs.count()); urls.reserve(songs.count());
for (const Song &s : songs) urls << s.url(); for (const Song &s : songs) urls << s.url();
if (result->is_jpeg()) { if (result.is_jpeg()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image_data); quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
QMutexLocker l(&mutex_cover_save_tasks_); QMutexLocker l(&mutex_cover_save_tasks_);
cover_save_tasks_.insert(id, song); cover_save_tasks_.insert(id, song);
} }
else { else {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image); quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image);
QMutexLocker l(&mutex_cover_save_tasks_); QMutexLocker l(&mutex_cover_save_tasks_);
cover_save_tasks_.insert(id, song); cover_save_tasks_.insert(id, song);
} }
@@ -687,11 +679,11 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, Al
watcher->setFuture(future); watcher->setFuture(future);
} }
else { else {
if (result->is_jpeg()) { if (result.is_jpeg()) {
app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), result->image_data); app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), result.image_data);
} }
else { else {
app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), result->image); app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), result.image);
} }
} }
@@ -779,7 +771,7 @@ QUrl AlbumCoverChoiceController::SaveCover(Song *song, const QDropEvent *e) {
if (e->mimeData()->hasImage()) { if (e->mimeData()->hasImage()) {
QImage image = qvariant_cast<QImage>(e->mimeData()->imageData()); QImage image = qvariant_cast<QImage>(e->mimeData()->imageData());
if (!image.isNull()) { if (!image.isNull()) {
return SaveCoverAutomatic(song, std::make_shared<AlbumCoverImageResult>(image)); return SaveCoverAutomatic(song, AlbumCoverImageResult(image));
} }
} }
@@ -787,7 +779,7 @@ QUrl AlbumCoverChoiceController::SaveCover(Song *song, const QDropEvent *e) {
} }
QUrl AlbumCoverChoiceController::SaveCoverAutomatic(Song *song, AlbumCoverImageResultPtr result) { QUrl AlbumCoverChoiceController::SaveCoverAutomatic(Song *song, const AlbumCoverImageResult &result) {
QUrl cover_url; QUrl cover_url;
switch(get_save_album_cover_type()) { switch(get_save_album_cover_type()) {

View File

@@ -99,22 +99,22 @@ class AlbumCoverChoiceController : public QWidget {
// Lets the user choose a cover from disk. If no cover will be chosen or the chosen cover will not be a proper image, this returns an empty string. // Lets the user choose a cover from disk. If no cover will be chosen or the chosen cover will not be a proper image, this returns an empty string.
// Otherwise, the path to the chosen cover will be returned. // Otherwise, the path to the chosen cover will be returned.
AlbumCoverImageResultPtr LoadImageFromFile(Song *song); AlbumCoverImageResult LoadImageFromFile(Song *song);
QUrl LoadCoverFromFile(Song *song); QUrl LoadCoverFromFile(Song *song);
// Shows a dialog that allows user to save the given image on disk. // Shows a dialog that allows user to save the given image on disk.
// The image is supposed to be the cover of the given song's album. // The image is supposed to be the cover of the given song's album.
void SaveCoverToFileManual(const Song &song, AlbumCoverImageResultPtr result); void SaveCoverToFileManual(const Song &song, const AlbumCoverImageResult &result);
// Downloads the cover from an URL given by user. // Downloads the cover from an URL given by user.
// This returns the downloaded image or null image if something went wrong for example when user cancelled the dialog. // This returns the downloaded image or null image if something went wrong for example when user cancelled the dialog.
QUrl LoadCoverFromURL(Song *song); QUrl LoadCoverFromURL(Song *song);
AlbumCoverImageResultPtr LoadImageFromURL(); AlbumCoverImageResult LoadImageFromURL();
// Lets the user choose a cover among all that have been found on last.fm. // Lets the user choose a cover among all that have been found on last.fm.
// Returns the chosen cover or null cover if user didn't choose anything. // Returns the chosen cover or null cover if user didn't choose anything.
QUrl SearchForCover(Song *song); QUrl SearchForCover(Song *song);
AlbumCoverImageResultPtr SearchForImage(Song *song); AlbumCoverImageResult SearchForImage(Song *song);
// Returns a path which indicates that the cover has been unset manually. // Returns a path which indicates that the cover has been unset manually.
QUrl UnsetCover(Song *song, const bool clear_art_automatic = false); QUrl UnsetCover(Song *song, const bool clear_art_automatic = false);
@@ -140,10 +140,10 @@ class AlbumCoverChoiceController : public QWidget {
QUrl SaveCover(Song *song, const QDropEvent *e); QUrl SaveCover(Song *song, const QDropEvent *e);
// Saves the given image in album directory or cache as a cover for 'album artist' - 'album'. The method returns path of the image. // Saves the given image in album directory or cache as a cover for 'album artist' - 'album'. The method returns path of the image.
QUrl SaveCoverAutomatic(Song *song, AlbumCoverImageResultPtr result); QUrl SaveCoverAutomatic(Song *song, const AlbumCoverImageResult &result);
QUrl SaveCoverToFileAutomatic(const Song *song, AlbumCoverImageResultPtr result, const bool force_overwrite = false); QUrl SaveCoverToFileAutomatic(const Song *song, const AlbumCoverImageResult &result, const bool force_overwrite = false);
QUrl SaveCoverToFileAutomatic(const Song::Source source, const QString &artist, const QString &album, const QString &album_id, const QString &album_dir, AlbumCoverImageResultPtr result, const bool force_overwrite = false); QUrl SaveCoverToFileAutomatic(const Song::Source source, const QString &artist, const QString &album, const QString &album_id, const QString &album_dir, const AlbumCoverImageResult &result, const bool force_overwrite = false);
void SaveCoverEmbeddedAutomatic(const Song &song, AlbumCoverImageResultPtr result); void SaveCoverEmbeddedAutomatic(const Song &song, const AlbumCoverImageResult &result);
void SaveCoverEmbeddedAutomatic(const Song &song, const QUrl &cover_url); void SaveCoverEmbeddedAutomatic(const Song &song, const QUrl &cover_url);
void SaveCoverEmbeddedAutomatic(const Song &song, const QString &cover_filename); void SaveCoverEmbeddedAutomatic(const Song &song, const QString &cover_filename);
void SaveCoverEmbeddedAutomatic(const QList<QUrl> &urls, const QImage &image); void SaveCoverEmbeddedAutomatic(const QList<QUrl> &urls, const QImage &image);
@@ -154,7 +154,7 @@ class AlbumCoverChoiceController : public QWidget {
void set_save_embedded_cover_override(const bool value) { save_embedded_cover_override_ = value; } void set_save_embedded_cover_override(const bool value) { save_embedded_cover_override_ = value; }
private slots: private slots:
void AlbumCoverFetched(const quint64 id, AlbumCoverImageResultPtr result, const CoverSearchStatistics &statistics); void AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics);
void SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success, const bool cleared); void SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success, const bool cleared);
signals: signals:

View File

@@ -150,7 +150,7 @@ void AlbumCoverFetcher::SingleSearchFinished(const quint64 request_id, const Cov
} }
void AlbumCoverFetcher::SingleCoverFetched(const quint64 request_id, AlbumCoverImageResultPtr result) { void AlbumCoverFetcher::SingleCoverFetched(const quint64 request_id, const AlbumCoverImageResult &result) {
if (!active_requests_.contains(request_id)) return; if (!active_requests_.contains(request_id)) return;
AlbumCoverFetcherSearch *search = active_requests_.take(request_id); AlbumCoverFetcherSearch *search = active_requests_.take(request_id);

View File

@@ -118,12 +118,12 @@ class AlbumCoverFetcher : public QObject {
void Clear(); void Clear();
signals: signals:
void AlbumCoverFetched(const quint64 request_id, AlbumCoverImageResultPtr result, const CoverSearchStatistics &statistics); void AlbumCoverFetched(const quint64 request_id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics);
void SearchFinished(const quint64 request_id, const CoverProviderSearchResults &results, const CoverSearchStatistics &statistics); void SearchFinished(const quint64 request_id, const CoverProviderSearchResults &results, const CoverSearchStatistics &statistics);
private slots: private slots:
void SingleSearchFinished(const quint64 id, const CoverProviderSearchResults &results); void SingleSearchFinished(const quint64 id, const CoverProviderSearchResults &results);
void SingleCoverFetched(const quint64 id, AlbumCoverImageResultPtr result); void SingleCoverFetched(const quint64 id, const AlbumCoverImageResult &result);
void StartRequests(); void StartRequests();
private: private:

View File

@@ -23,7 +23,6 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <memory>
#include <QObject> #include <QObject>
#include <QCoreApplication> #include <QCoreApplication>
@@ -257,7 +256,7 @@ void AlbumCoverFetcherSearch::AllProvidersFinished() {
// No results? // No results?
if (results_.isEmpty()) { if (results_.isEmpty()) {
statistics_.missing_images_++; statistics_.missing_images_++;
emit AlbumCoverFetched(request_.id, AlbumCoverImageResultPtr()); emit AlbumCoverFetched(request_.id, AlbumCoverImageResult());
return; return;
} }
@@ -333,7 +332,7 @@ void AlbumCoverFetcherSearch::ProviderCoverFetchFinished(QNetworkReply *reply) {
} }
result.image_size = image.size(); result.image_size = image.size();
result.score_quality = ScoreImage(image.size()); result.score_quality = ScoreImage(image.size());
candidate_images_.insert(result.score(), CandidateImage(result, std::make_shared<AlbumCoverImageResult>(result.image_url, mime_type, image_data, image))); candidate_images_.insert(result.score(), CandidateImage(result, AlbumCoverImageResult(result.image_url, mime_type, image_data, image)));
qLog(Debug) << reply->url() << "from" << result.provider << "scored" << result.score(); qLog(Debug) << reply->url() << "from" << result.provider << "scored" << result.score();
} }
else { else {
@@ -381,7 +380,7 @@ float AlbumCoverFetcherSearch::ScoreImage(const QSize size) {
void AlbumCoverFetcherSearch::SendBestImage() { void AlbumCoverFetcherSearch::SendBestImage() {
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>(); AlbumCoverImageResult result;
if (!candidate_images_.isEmpty()) { if (!candidate_images_.isEmpty()) {
QList<CandidateImage> candidate_images = candidate_images_.values(); QList<CandidateImage> candidate_images = candidate_images_.values();
@@ -392,8 +391,8 @@ void AlbumCoverFetcherSearch::SendBestImage() {
statistics_.chosen_images_by_provider_[best_image.result.provider]++; statistics_.chosen_images_by_provider_[best_image.result.provider]++;
statistics_.chosen_images_++; statistics_.chosen_images_++;
statistics_.chosen_width_ += result->image.width(); statistics_.chosen_width_ += result.image.width();
statistics_.chosen_height_ += result->image.height(); statistics_.chosen_height_ += result.image.height();
} }
else { else {
statistics_.missing_images_++; statistics_.missing_images_++;

View File

@@ -69,7 +69,7 @@ class AlbumCoverFetcherSearch : public QObject {
void SearchFinished(quint64, const CoverProviderSearchResults &results); void SearchFinished(quint64, const CoverProviderSearchResults &results);
// It's the end of search and we've fetched a cover. // It's the end of search and we've fetched a cover.
void AlbumCoverFetched(const quint64 id, AlbumCoverImageResultPtr result); void AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result);
private slots: private slots:
void ProviderSearchResults(const int id, const CoverProviderSearchResults &results); void ProviderSearchResults(const int id, const CoverProviderSearchResults &results);
@@ -108,9 +108,9 @@ class AlbumCoverFetcherSearch : public QObject {
// QMap is sorted by key (score). // QMap is sorted by key (score).
struct CandidateImage { struct CandidateImage {
CandidateImage(const CoverProviderSearchResult &_result, AlbumCoverImageResultPtr _album_cover) : result(_result), album_cover(_album_cover) {} CandidateImage(const CoverProviderSearchResult &_result, const AlbumCoverImageResult &_album_cover) : result(_result), album_cover(_album_cover) {}
CoverProviderSearchResult result; CoverProviderSearchResult result;
AlbumCoverImageResultPtr album_cover; AlbumCoverImageResult album_cover;
}; };
QMultiMap<float, CandidateImage> candidate_images_; QMultiMap<float, CandidateImage> candidate_images_;

View File

@@ -22,8 +22,6 @@
#include "config.h" #include "config.h"
#include <memory>
#include <QMetaType> #include <QMetaType>
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
@@ -52,9 +50,6 @@ class AlbumCoverImageResult {
}; };
using AlbumCoverImageResultPtr = std::shared_ptr<AlbumCoverImageResult>;
Q_DECLARE_METATYPE(AlbumCoverImageResult) Q_DECLARE_METATYPE(AlbumCoverImageResult)
Q_DECLARE_METATYPE(AlbumCoverImageResultPtr)
#endif // ALBUMCOVERIMAGERESULT_H #endif // ALBUMCOVERIMAGERESULT_H

View File

@@ -114,7 +114,6 @@ quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options,
task->options = options; task->options = options;
task->song = song; task->song = song;
task->state = State::Manual; task->state = State::Manual;
task->album_cover = std::make_shared<AlbumCoverImageResult>();
return EnqueueTask(task); return EnqueueTask(task);
@@ -131,13 +130,12 @@ quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options,
task->options = options; task->options = options;
task->song = song; task->song = song;
task->state = State::Manual; task->state = State::Manual;
task->album_cover = std::make_shared<AlbumCoverImageResult>();
return EnqueueTask(task); return EnqueueTask(task);
} }
quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options, AlbumCoverImageResultPtr album_cover) { quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options, const AlbumCoverImageResult &album_cover) {
TaskPtr task = std::make_shared<Task>(); TaskPtr task = std::make_shared<Task>();
task->options = options; task->options = options;
@@ -151,8 +149,7 @@ quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options,
TaskPtr task = std::make_shared<Task>(); TaskPtr task = std::make_shared<Task>();
task->options = options; task->options = options;
task->album_cover = std::make_shared<AlbumCoverImageResult>(); task->album_cover.image = image;
task->album_cover->image = image;
return EnqueueTask(task); return EnqueueTask(task);
@@ -197,16 +194,16 @@ void AlbumCoverLoader::ProcessTask(TaskPtr task) {
} }
if (result.loaded_success) { if (result.loaded_success) {
result.album_cover->mime_type = Utilities::MimeTypeFromData(result.album_cover->image_data); result.album_cover.mime_type = Utilities::MimeTypeFromData(result.album_cover.image_data);
QImage image_scaled; QImage image_scaled;
QImage image_thumbnail; QImage image_thumbnail;
if (task->options.get_image_ && task->options.scale_output_image_) { if (task->options.get_image_ && task->options.scale_output_image_) {
image_scaled = ImageUtils::ScaleAndPad(result.album_cover->image, task->options.scale_output_image_, task->options.pad_output_image_, task->options.desired_height_); image_scaled = ImageUtils::ScaleAndPad(result.album_cover.image, task->options.scale_output_image_, task->options.pad_output_image_, task->options.desired_height_);
} }
if (task->options.get_image_ && task->options.create_thumbnail_) { if (task->options.get_image_ && task->options.create_thumbnail_) {
image_thumbnail = ImageUtils::CreateThumbnail(result.album_cover->image, task->options.pad_thumbnail_image_, task->options.thumbnail_size_); image_thumbnail = ImageUtils::CreateThumbnail(result.album_cover.image, task->options.pad_thumbnail_image_, task->options.thumbnail_size_);
} }
emit AlbumCoverLoaded(task->id, std::make_shared<AlbumCoverLoaderResult>(result.loaded_success, result.type, result.album_cover, image_scaled, image_thumbnail, task->art_updated)); emit AlbumCoverLoaded(task->id, AlbumCoverLoaderResult(result.loaded_success, result.type, result.album_cover, image_scaled, image_thumbnail, task->art_updated));
return; return;
} }
@@ -223,7 +220,7 @@ void AlbumCoverLoader::NextState(TaskPtr task) {
} }
else { else {
// Give up // Give up
emit AlbumCoverLoaded(task->id, std::make_shared<AlbumCoverLoaderResult>(false, AlbumCoverLoaderResult::Type::None, std::make_shared<AlbumCoverImageResult>(task->options.default_output_image_), task->options.default_scaled_image_, task->options.default_thumbnail_image_, task->art_updated)); emit AlbumCoverLoaded(task->id, AlbumCoverLoaderResult(false, AlbumCoverLoaderResult::Type::None, AlbumCoverImageResult(task->options.default_output_image_), task->options.default_scaled_image_, task->options.default_thumbnail_image_, task->art_updated));
} }
} }
@@ -231,7 +228,7 @@ void AlbumCoverLoader::NextState(TaskPtr task) {
AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) { AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
// Only scale and pad. // Only scale and pad.
if (task->album_cover->is_valid()) { if (task->album_cover.is_valid()) {
return TryLoadResult(false, true, AlbumCoverLoaderResult::Type::Embedded, task->album_cover); return TryLoadResult(false, true, AlbumCoverLoaderResult::Type::Embedded, task->album_cover);
} }
@@ -270,17 +267,17 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
if (!cover_url.isEmpty() && !cover_url.path().isEmpty()) { if (!cover_url.isEmpty() && !cover_url.path().isEmpty()) {
if (cover_url.path() == Song::kManuallyUnsetCover) { if (cover_url.path() == Song::kManuallyUnsetCover) {
return TryLoadResult(false, true, AlbumCoverLoaderResult::Type::ManuallyUnset, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), QByteArray(), task->options.default_output_image_)); return TryLoadResult(false, true, AlbumCoverLoaderResult::Type::ManuallyUnset, AlbumCoverImageResult(cover_url, QString(), QByteArray(), task->options.default_output_image_));
} }
else if (cover_url.path() == Song::kEmbeddedCover && task->song.url().isLocalFile()) { else if (cover_url.path() == Song::kEmbeddedCover && task->song.url().isLocalFile()) {
QByteArray image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(task->song.url().toLocalFile()); QByteArray image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(task->song.url().toLocalFile());
if (!image_data.isEmpty()) { if (!image_data.isEmpty()) {
QImage image; QImage image;
if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) { if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) {
return TryLoadResult(false, !image.isNull(), AlbumCoverLoaderResult::Type::Embedded, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), image_data, image)); return TryLoadResult(false, !image.isNull(), AlbumCoverLoaderResult::Type::Embedded, AlbumCoverImageResult(cover_url, QString(), image_data, image));
} }
else { else {
return TryLoadResult(false, !image_data.isEmpty(), AlbumCoverLoaderResult::Type::Embedded, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), image_data, image)); return TryLoadResult(false, !image_data.isEmpty(), AlbumCoverLoaderResult::Type::Embedded, AlbumCoverImageResult(cover_url, QString(), image_data, image));
} }
} }
} }
@@ -293,10 +290,10 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
file.close(); file.close();
QImage image; QImage image;
if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) { if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) {
return TryLoadResult(false, !image.isNull(), type, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image)); return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
} }
else { else {
return TryLoadResult(false, !image_data.isEmpty(), type, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image)); return TryLoadResult(false, !image_data.isEmpty(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
} }
} }
else { else {
@@ -315,10 +312,10 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
file.close(); file.close();
QImage image; QImage image;
if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) { if (!image_data.isEmpty() && task->options.get_image_ && image.loadFromData(image_data)) {
return TryLoadResult(false, !image.isNull(), type, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image)); return TryLoadResult(false, !image.isNull(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
} }
else { else {
return TryLoadResult(false, !image_data.isEmpty(), type, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image)); return TryLoadResult(false, !image_data.isEmpty(), type, AlbumCoverImageResult(cover_url, QString(), image_data, image.isNull() ? task->options.default_output_image_ : image));
} }
} }
else { else {
@@ -337,11 +334,11 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, cover_url]() { RemoteFetchFinished(reply, cover_url); }); QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, cover_url]() { RemoteFetchFinished(reply, cover_url); });
remote_tasks_.insert(reply, task); remote_tasks_.insert(reply, task);
return TryLoadResult(true, false, type, std::make_shared<AlbumCoverImageResult>(cover_url)); return TryLoadResult(true, false, type, AlbumCoverImageResult(cover_url));
} }
} }
return TryLoadResult(false, false, AlbumCoverLoaderResult::Type::None, std::make_shared<AlbumCoverImageResult>(cover_url, QString(), QByteArray(), task->options.default_output_image_)); return TryLoadResult(false, false, AlbumCoverLoaderResult::Type::None, AlbumCoverImageResult(cover_url, QString(), QByteArray(), task->options.default_output_image_));
} }
@@ -378,7 +375,7 @@ void AlbumCoverLoader::RemoteFetchFinished(QNetworkReply *reply, const QUrl &cov
QImage image_thumbnail; QImage image_thumbnail;
if (task->options.scale_output_image_) image_scaled = ImageUtils::ScaleAndPad(image, task->options.scale_output_image_, task->options.pad_output_image_, task->options.desired_height_); if (task->options.scale_output_image_) image_scaled = ImageUtils::ScaleAndPad(image, task->options.scale_output_image_, task->options.pad_output_image_, task->options.desired_height_);
if (task->options.create_thumbnail_) image_thumbnail = ImageUtils::CreateThumbnail(image, task->options.pad_thumbnail_image_, task->options.thumbnail_size_); if (task->options.create_thumbnail_) image_thumbnail = ImageUtils::CreateThumbnail(image, task->options.pad_thumbnail_image_, task->options.thumbnail_size_);
emit AlbumCoverLoaded(task->id, std::make_shared<AlbumCoverLoaderResult>(true, task->type, std::make_shared<AlbumCoverImageResult>(cover_url, mime_type, (task->options.get_image_data_ ? image_data : QByteArray()), image), image_scaled, image_thumbnail, task->art_updated)); emit AlbumCoverLoaded(task->id, AlbumCoverLoaderResult(true, task->type, AlbumCoverImageResult(cover_url, mime_type, (task->options.get_image_data_ ? image_data : QByteArray()), image), image_scaled, image_thumbnail, task->art_updated));
return; return;
} }
else { else {

View File

@@ -64,7 +64,7 @@ class AlbumCoverLoader : public QObject {
quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const Song &song); quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const Song &song);
quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const QUrl &art_automatic, const QUrl &art_manual, const QUrl &song_url = QUrl(), const Song::Source song_source = Song::Source::Unknown); quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const QUrl &art_automatic, const QUrl &art_manual, const QUrl &song_url = QUrl(), const Song::Source song_source = Song::Source::Unknown);
quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, AlbumCoverImageResultPtr album_cover); quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const AlbumCoverImageResult &album_cover);
quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const QImage &image); quint64 LoadImageAsync(const AlbumCoverLoaderOptions &options, const QImage &image);
void CancelTask(const quint64 id); void CancelTask(const quint64 id);
@@ -79,7 +79,7 @@ class AlbumCoverLoader : public QObject {
signals: signals:
void ExitFinished(); void ExitFinished();
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
void SaveEmbeddedCoverAsyncFinished(const quint64 id, const bool success, const bool cleared); void SaveEmbeddedCoverAsyncFinished(const quint64 id, const bool success, const bool cleared);
protected slots: protected slots:
@@ -105,7 +105,7 @@ class AlbumCoverLoader : public QObject {
quint64 id; quint64 id;
Song song; Song song;
AlbumCoverImageResultPtr album_cover; AlbumCoverImageResult album_cover;
State state; State state;
AlbumCoverLoaderResult::Type type; AlbumCoverLoaderResult::Type type;
bool art_updated; bool art_updated;
@@ -117,7 +117,7 @@ class AlbumCoverLoader : public QObject {
explicit TryLoadResult(const bool _started_async = false, explicit TryLoadResult(const bool _started_async = false,
const bool _loaded_success = false, const bool _loaded_success = false,
const AlbumCoverLoaderResult::Type _type = AlbumCoverLoaderResult::Type::None, const AlbumCoverLoaderResult::Type _type = AlbumCoverLoaderResult::Type::None,
AlbumCoverImageResultPtr _album_cover = AlbumCoverImageResultPtr()) : const AlbumCoverImageResult &_album_cover = AlbumCoverImageResult()) :
started_async(_started_async), started_async(_started_async),
loaded_success(_loaded_success), loaded_success(_loaded_success),
type(_type), type(_type),
@@ -127,7 +127,7 @@ class AlbumCoverLoader : public QObject {
bool loaded_success; bool loaded_success;
AlbumCoverLoaderResult::Type type; AlbumCoverLoaderResult::Type type;
AlbumCoverImageResultPtr album_cover; AlbumCoverImageResult album_cover;
}; };
quint64 EnqueueTask(TaskPtr task); quint64 EnqueueTask(TaskPtr task);

View File

@@ -22,8 +22,6 @@
#include "config.h" #include "config.h"
#include <memory>
#include <QImage> #include <QImage>
#include <QUrl> #include <QUrl>
@@ -43,7 +41,7 @@ class AlbumCoverLoaderResult {
explicit AlbumCoverLoaderResult(const bool _success = false, explicit AlbumCoverLoaderResult(const bool _success = false,
const Type _type = Type::None, const Type _type = Type::None,
AlbumCoverImageResultPtr _album_cover = AlbumCoverImageResultPtr(), AlbumCoverImageResult _album_cover = AlbumCoverImageResult(),
const QImage &_image_scaled = QImage(), const QImage &_image_scaled = QImage(),
const QImage &_image_thumbnail = QImage(), const QImage &_image_thumbnail = QImage(),
const bool _updated = false) : const bool _updated = false) :
@@ -52,17 +50,11 @@ class AlbumCoverLoaderResult {
album_cover(_album_cover), album_cover(_album_cover),
image_scaled(_image_scaled), image_scaled(_image_scaled),
image_thumbnail(_image_thumbnail), image_thumbnail(_image_thumbnail),
updated(_updated) { updated(_updated) {}
if (!_album_cover) {
_album_cover = std::make_shared<AlbumCoverImageResult>();
}
}
bool success; bool success;
Type type; Type type;
AlbumCoverImageResultPtr album_cover; AlbumCoverImageResult album_cover;
QImage image_scaled; QImage image_scaled;
QImage image_thumbnail; QImage image_thumbnail;
bool updated; bool updated;
@@ -71,9 +63,6 @@ class AlbumCoverLoaderResult {
}; };
using AlbumCoverLoaderResultPtr = std::shared_ptr<AlbumCoverLoaderResult>;
Q_DECLARE_METATYPE(AlbumCoverLoaderResult) Q_DECLARE_METATYPE(AlbumCoverLoaderResult)
Q_DECLARE_METATYPE(AlbumCoverLoaderResultPtr)
#endif // ALBUMCOVERLOADERRESULT_H #endif // ALBUMCOVERLOADERRESULT_H

View File

@@ -433,21 +433,21 @@ void AlbumCoverManager::ArtistChanged(QListWidgetItem *current) {
} }
void AlbumCoverManager::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result) { void AlbumCoverManager::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
if (!cover_loading_tasks_.contains(id)) return; if (!cover_loading_tasks_.contains(id)) return;
AlbumItem *item = cover_loading_tasks_.take(id); AlbumItem *item = cover_loading_tasks_.take(id);
if (!result || !result->success || result->image_scaled.isNull() || result->type == AlbumCoverLoaderResult::Type::ManuallyUnset) { if (!result.success || result.image_scaled.isNull() || result.type == AlbumCoverLoaderResult::Type::ManuallyUnset) {
item->setIcon(icon_nocover_item_); item->setIcon(icon_nocover_item_);
} }
else { else {
item->setIcon(QPixmap::fromImage(result->image_scaled)); item->setIcon(QPixmap::fromImage(result.image_scaled));
} }
//item->setData(Role_Image, result->image_original); //item->setData(Role_Image, result.image_original);
//item->setData(Role_ImageData, result->image_data); //item->setData(Role_ImageData, result.image_data);
UpdateFilter(); UpdateFilter();
@@ -537,12 +537,12 @@ void AlbumCoverManager::FetchAlbumCovers() {
} }
void AlbumCoverManager::AlbumCoverFetched(const quint64 id, AlbumCoverImageResultPtr result, const CoverSearchStatistics &statistics) { void AlbumCoverManager::AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics) {
if (!cover_fetching_tasks_.contains(id)) return; if (!cover_fetching_tasks_.contains(id)) return;
AlbumItem *item = cover_fetching_tasks_.take(id); AlbumItem *item = cover_fetching_tasks_.take(id);
if (result && !result->image.isNull()) { if (!result.image.isNull()) {
SaveAndSetCover(item, result); SaveAndSetCover(item, result);
} }
@@ -699,8 +699,8 @@ void AlbumCoverManager::LoadCoverFromFile() {
Song song = GetSingleSelectionAsSong(); Song song = GetSingleSelectionAsSong();
if (!song.is_valid()) return; if (!song.is_valid()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->LoadImageFromFile(&song); const AlbumCoverImageResult result = album_cover_choice_controller_->LoadImageFromFile(&song);
if (result || !result->image.isNull()) { if (!result.image.isNull()) {
SaveImageToAlbums(&song, result); SaveImageToAlbums(&song, result);
} }
@@ -711,32 +711,32 @@ void AlbumCoverManager::SaveCoverToFile() {
Song song = GetSingleSelectionAsSong(); Song song = GetSingleSelectionAsSong();
if (!song.is_valid() || song.has_manually_unset_cover()) return; if (!song.is_valid() || song.has_manually_unset_cover()) return;
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>(); AlbumCoverImageResult result;
// Load the image from disk // Load the image from disk
if (!song.art_manual().isEmpty() && !song.has_manually_unset_cover() && song.art_manual().isLocalFile() && QFile::exists(song.art_manual().toLocalFile())) { if (!song.art_manual().isEmpty() && !song.has_manually_unset_cover() && song.art_manual().isLocalFile() && QFile::exists(song.art_manual().toLocalFile())) {
result->image_data = Utilities::ReadDataFromFile(song.art_manual().toLocalFile()); result.image_data = Utilities::ReadDataFromFile(song.art_manual().toLocalFile());
} }
else if (!song.art_manual().isEmpty() && !song.art_manual().path().isEmpty() && song.art_manual().scheme().isEmpty() && QFile::exists(song.art_manual().path())) { else if (!song.art_manual().isEmpty() && !song.art_manual().path().isEmpty() && song.art_manual().scheme().isEmpty() && QFile::exists(song.art_manual().path())) {
result->image_data = Utilities::ReadDataFromFile(song.art_manual().path()); result.image_data = Utilities::ReadDataFromFile(song.art_manual().path());
} }
else if (song.has_embedded_cover()) { else if (song.has_embedded_cover()) {
result->image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(song.url().toLocalFile()); result.image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(song.url().toLocalFile());
} }
else if (!song.art_automatic().isEmpty() && song.art_automatic().isLocalFile() && QFile::exists(song.art_automatic().toLocalFile())) { else if (!song.art_automatic().isEmpty() && song.art_automatic().isLocalFile() && QFile::exists(song.art_automatic().toLocalFile())) {
result->image_data = Utilities::ReadDataFromFile(song.art_automatic().toLocalFile()); result.image_data = Utilities::ReadDataFromFile(song.art_automatic().toLocalFile());
} }
else if (!song.art_automatic().isEmpty() && !song.art_automatic().path().isEmpty() && song.art_automatic().scheme().isEmpty() && QFile::exists(song.art_automatic().path())) { else if (!song.art_automatic().isEmpty() && !song.art_automatic().path().isEmpty() && song.art_automatic().scheme().isEmpty() && QFile::exists(song.art_automatic().path())) {
result->image_data = Utilities::ReadDataFromFile(song.art_automatic().path()); result.image_data = Utilities::ReadDataFromFile(song.art_automatic().path());
} }
if (!result->is_valid()) return; if (!result.is_valid()) return;
result->mime_type = Utilities::MimeTypeFromData(result->image_data); result.mime_type = Utilities::MimeTypeFromData(result.image_data);
if (!result->image_data.isEmpty()) { if (!result.image_data.isEmpty()) {
result->image.loadFromData(result->image_data); result.image.loadFromData(result.image_data);
} }
album_cover_choice_controller_->SaveCoverToFileManual(song, result); album_cover_choice_controller_->SaveCoverToFileManual(song, result);
@@ -748,8 +748,8 @@ void AlbumCoverManager::LoadCoverFromURL() {
Song song = GetSingleSelectionAsSong(); Song song = GetSingleSelectionAsSong();
if (!song.is_valid()) return; if (!song.is_valid()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->LoadImageFromURL(); const AlbumCoverImageResult &result = album_cover_choice_controller_->LoadImageFromURL();
if (result && result->is_valid()) { if (result.is_valid()) {
SaveImageToAlbums(&song, result); SaveImageToAlbums(&song, result);
} }
@@ -760,18 +760,16 @@ void AlbumCoverManager::SearchForCover() {
Song song = GetFirstSelectedAsSong(); Song song = GetFirstSelectedAsSong();
if (!song.is_valid()) return; if (!song.is_valid()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->SearchForImage(&song); const AlbumCoverImageResult result = album_cover_choice_controller_->SearchForImage(&song);
if (result && result->is_valid()) { if (result.is_valid()) {
SaveImageToAlbums(&song, result); SaveImageToAlbums(&song, result);
} }
} }
void AlbumCoverManager::SaveImageToAlbums(Song *song, AlbumCoverImageResultPtr result) { void AlbumCoverManager::SaveImageToAlbums(Song *song, const AlbumCoverImageResult &result) {
if (!result) return; QUrl cover_url = result.cover_url;
QUrl cover_url = result->cover_url;
switch (album_cover_choice_controller_->get_save_album_cover_type()) { switch (album_cover_choice_controller_->get_save_album_cover_type()) {
case CoverOptions::CoverType::Cache: case CoverOptions::CoverType::Cache:
case CoverOptions::CoverType::Album: case CoverOptions::CoverType::Album:
@@ -807,11 +805,11 @@ void AlbumCoverManager::SaveImageToAlbums(Song *song, AlbumCoverImageResultPtr r
if (album_cover_choice_controller_->get_save_album_cover_type() == CoverOptions::CoverType::Embedded && !urls.isEmpty()) { if (album_cover_choice_controller_->get_save_album_cover_type() == CoverOptions::CoverType::Embedded && !urls.isEmpty()) {
quint64 id = -1; quint64 id = -1;
if (result->is_jpeg()) { if (result.is_jpeg()) {
id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image_data); id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
} }
else { else {
id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image); id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image);
} }
for (AlbumItem *album_item : album_items) { for (AlbumItem *album_item : album_items) {
cover_save_tasks_.insert(id, album_item); cover_save_tasks_.insert(id, album_item);
@@ -955,9 +953,7 @@ void AlbumCoverManager::LoadSelectedToPlaylist() {
} }
void AlbumCoverManager::SaveAndSetCover(AlbumItem *item, AlbumCoverImageResultPtr result) { void AlbumCoverManager::SaveAndSetCover(AlbumItem *item, const AlbumCoverImageResult &result) {
if (!result) return;
const QString albumartist = item->data(Role_AlbumArtist).toString(); const QString albumartist = item->data(Role_AlbumArtist).toString();
const QString album = item->data(Role_Album).toString(); const QString album = item->data(Role_Album).toString();
@@ -966,25 +962,25 @@ void AlbumCoverManager::SaveAndSetCover(AlbumItem *item, AlbumCoverImageResultPt
const bool has_cue = !item->data(Role_CuePath).toString().isEmpty(); const bool has_cue = !item->data(Role_CuePath).toString().isEmpty();
if (album_cover_choice_controller_->get_save_album_cover_type() == CoverOptions::CoverType::Embedded && Song::save_embedded_cover_supported(filetype) && !has_cue) { if (album_cover_choice_controller_->get_save_album_cover_type() == CoverOptions::CoverType::Embedded && Song::save_embedded_cover_supported(filetype) && !has_cue) {
if (result->is_jpeg()) { if (result.is_jpeg()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image_data); quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
cover_save_tasks_.insert(id, item); cover_save_tasks_.insert(id, item);
} }
else if (!result->image.isNull()) { else if (!result.image.isNull()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image); quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image);
cover_save_tasks_.insert(id, item); cover_save_tasks_.insert(id, item);
} }
else if (!result->cover_url.isEmpty() && result->cover_url.isLocalFile()) { else if (!result.cover_url.isEmpty() && result.cover_url.isLocalFile()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->cover_url.toLocalFile()); quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.cover_url.toLocalFile());
cover_save_tasks_.insert(id, item); cover_save_tasks_.insert(id, item);
} }
} }
else { else {
QUrl cover_url; QUrl cover_url;
if (!result->cover_url.isEmpty() && result->cover_url.isValid() && result->cover_url.isLocalFile()) { if (!result.cover_url.isEmpty() && result.cover_url.isValid() && result.cover_url.isLocalFile()) {
cover_url = result->cover_url; cover_url = result.cover_url;
} }
else if (!result->image_data.isEmpty() || !result->image.isNull()) { else if (!result.image_data.isEmpty() || !result.image.isNull()) {
cover_url = album_cover_choice_controller_->SaveCoverToFileAutomatic(Song::Source::Collection, albumartist, album, QString(), urls.first().adjusted(QUrl::RemoveFilename).path(), result, false); cover_url = album_cover_choice_controller_->SaveCoverToFileAutomatic(Song::Source::Collection, albumartist, album, QString(), urls.first().adjusted(QUrl::RemoveFilename).path(), result, false);
} }

View File

@@ -137,9 +137,9 @@ class AlbumCoverManager : public QMainWindow {
void UpdateStatusText(); void UpdateStatusText();
bool ShouldHide(const AlbumItem &item, const QString &filter, const HideCovers hide_covers) const; bool ShouldHide(const AlbumItem &item, const QString &filter, const HideCovers hide_covers) const;
void SaveAndSetCover(AlbumItem *item, AlbumCoverImageResultPtr result); void SaveAndSetCover(AlbumItem *item, const AlbumCoverImageResult &result);
void SaveImageToAlbums(Song *song, AlbumCoverImageResultPtr result); void SaveImageToAlbums(Song *song, const AlbumCoverImageResult &result);
SongList GetSongsInAlbums(const QModelIndexList &indexes) const; SongList GetSongsInAlbums(const QModelIndexList &indexes) const;
SongMimeData *GetMimeDataForAlbums(const QModelIndexList &indexes) const; SongMimeData *GetMimeDataForAlbums(const QModelIndexList &indexes) const;
@@ -152,11 +152,11 @@ class AlbumCoverManager : public QMainWindow {
private slots: private slots:
void ArtistChanged(QListWidgetItem *current); void ArtistChanged(QListWidgetItem *current);
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
void UpdateFilter(); void UpdateFilter();
void FetchAlbumCovers(); void FetchAlbumCovers();
void ExportCovers(); void ExportCovers();
void AlbumCoverFetched(const quint64 id, AlbumCoverImageResultPtr result, const CoverSearchStatistics &statistics); void AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics);
void CancelRequests(); void CancelRequests();
// On the context menu // On the context menu

View File

@@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <memory>
#include <QWidget> #include <QWidget>
#include <QDialog> #include <QDialog>
#include <QStandardItemModel> #include <QStandardItemModel>
@@ -159,7 +157,7 @@ void AlbumCoverSearcher::Init(AlbumCoverFetcher *fetcher) {
} }
AlbumCoverImageResultPtr AlbumCoverSearcher::Exec(const QString &artist, const QString &album) { AlbumCoverImageResult AlbumCoverSearcher::Exec(const QString &artist, const QString &album) {
ui_->artist->setText(artist); ui_->artist->setText(artist);
ui_->album->setText(album); ui_->album->setText(album);
@@ -169,16 +167,16 @@ AlbumCoverImageResultPtr AlbumCoverSearcher::Exec(const QString &artist, const Q
Search(); Search();
} }
if (exec() == QDialog::Rejected) return AlbumCoverImageResultPtr(); if (exec() == QDialog::Rejected) return AlbumCoverImageResult();
QModelIndex selected = ui_->covers->currentIndex(); QModelIndex selected = ui_->covers->currentIndex();
if (!selected.isValid() || !selected.data(Role_ImageFetchFinished).toBool()) if (!selected.isValid() || !selected.data(Role_ImageFetchFinished).toBool())
return AlbumCoverImageResultPtr(); return AlbumCoverImageResult();
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>(); AlbumCoverImageResult result;
result->image_data = selected.data(Role_ImageData).toByteArray(); result.image_data = selected.data(Role_ImageData).toByteArray();
result->image = selected.data(Role_Image).value<QImage>(); result.image = selected.data(Role_Image).value<QImage>();
result->mime_type = Utilities::MimeTypeFromData(result->image_data); result.mime_type = Utilities::MimeTypeFromData(result.image_data);
return result; return result;
@@ -244,19 +242,19 @@ void AlbumCoverSearcher::SearchFinished(const quint64 id, const CoverProviderSea
} }
void AlbumCoverSearcher::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResultPtr result) { void AlbumCoverSearcher::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
if (!cover_loading_tasks_.contains(id)) return; if (!cover_loading_tasks_.contains(id)) return;
QStandardItem *item = cover_loading_tasks_.take(id); QStandardItem *item = cover_loading_tasks_.take(id);
if (cover_loading_tasks_.isEmpty()) ui_->busy->hide(); if (cover_loading_tasks_.isEmpty()) ui_->busy->hide();
if (!result || !result->success || result->album_cover->image_data == nullptr || result->album_cover->image_data.isNull() || result->album_cover->image.isNull() || result->image_thumbnail.isNull()) { if (!result.success || result.album_cover.image_data.isNull() || result.album_cover.image.isNull() || result.image_thumbnail.isNull()) {
model_->removeRow(item->row()); model_->removeRow(item->row());
return; return;
} }
const QPixmap pixmap = QPixmap::fromImage(result->image_thumbnail); const QPixmap pixmap = QPixmap::fromImage(result.image_thumbnail);
if (pixmap.isNull()) { if (pixmap.isNull()) {
model_->removeRow(item->row()); model_->removeRow(item->row());
return; return;
@@ -265,10 +263,10 @@ void AlbumCoverSearcher::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoad
const QIcon icon(pixmap); const QIcon icon(pixmap);
item->setData(true, Role_ImageFetchFinished); item->setData(true, Role_ImageFetchFinished);
item->setData(result->album_cover->image_data, Role_ImageData); item->setData(result.album_cover.image_data, Role_ImageData);
item->setData(result->album_cover->image, Role_Image); item->setData(result.album_cover.image, Role_Image);
item->setData(result->album_cover->image.width() * result->album_cover->image.height(), Role_ImageDimensions); item->setData(result.album_cover.image.width() * result.album_cover.image.height(), Role_ImageDimensions);
item->setData(result->album_cover->image.size(), Role_ImageSize); item->setData(result.album_cover.image.size(), Role_ImageSize);
if (!icon.isNull()) item->setIcon(icon); if (!icon.isNull()) item->setIcon(icon);
} }

View File

@@ -88,7 +88,7 @@ class AlbumCoverSearcher : public QDialog {
void Init(AlbumCoverFetcher *fetcher); void Init(AlbumCoverFetcher *fetcher);
AlbumCoverImageResultPtr Exec(const QString &artist, const QString &album); AlbumCoverImageResult Exec(const QString &artist, const QString &album);
protected: protected:
void keyPressEvent(QKeyEvent*) override; void keyPressEvent(QKeyEvent*) override;
@@ -96,7 +96,7 @@ class AlbumCoverSearcher : public QDialog {
private slots: private slots:
void Search(); void Search();
void SearchFinished(const quint64 id, const CoverProviderSearchResults &results); void SearchFinished(const quint64 id, const CoverProviderSearchResults &results);
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
void CoverDoubleClicked(const QModelIndex &idx); void CoverDoubleClicked(const QModelIndex &idx);

View File

@@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <memory>
#include <QWidget> #include <QWidget>
#include <QDialog> #include <QDialog>
#include <QApplication> #include <QApplication>
@@ -54,11 +52,11 @@ CoverFromURLDialog::~CoverFromURLDialog() {
delete ui_; delete ui_;
} }
AlbumCoverImageResultPtr CoverFromURLDialog::Exec() { AlbumCoverImageResult CoverFromURLDialog::Exec() {
// reset state // reset state
ui_->url->setText(""); ui_->url->setText("");
last_album_cover_.reset(); last_album_cover_ = AlbumCoverImageResult();
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
ui_->url->setText(clipboard->text()); ui_->url->setText(clipboard->text());
@@ -92,17 +90,17 @@ void CoverFromURLDialog::LoadCoverFromURLFinished() {
return; return;
} }
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>(); AlbumCoverImageResult result;
result->image_data = reply->readAll(); result.image_data = reply->readAll();
result->image.loadFromData(result->image_data); result.image.loadFromData(result.image_data);
result->mime_type = Utilities::MimeTypeFromData(result->image_data); result.mime_type = Utilities::MimeTypeFromData(result.image_data);
if (!result->image.isNull()) { if (result.image.isNull()) {
QMessageBox::information(this, tr("Fetching cover error"), tr("The site you requested is not an image!"));
}
else {
last_album_cover_ = result; last_album_cover_ = result;
QDialog::accept(); QDialog::accept();
} }
else {
QMessageBox::information(this, tr("Fetching cover error"), tr("The site you requested is not an image!"));
}
} }

View File

@@ -44,7 +44,7 @@ class CoverFromURLDialog : public QDialog {
~CoverFromURLDialog() override; ~CoverFromURLDialog() override;
// Opens the dialog. This returns an image found at the URL chosen by user or null image if the dialog got rejected. // Opens the dialog. This returns an image found at the URL chosen by user or null image if the dialog got rejected.
AlbumCoverImageResultPtr Exec(); AlbumCoverImageResult Exec();
private slots: private slots:
void accept() override; void accept() override;
@@ -53,7 +53,7 @@ class CoverFromURLDialog : public QDialog {
private: private:
NetworkAccessManager *network_; NetworkAccessManager *network_;
Ui_CoverFromURLDialog *ui_; Ui_CoverFromURLDialog *ui_;
AlbumCoverImageResultPtr last_album_cover_; AlbumCoverImageResult last_album_cover_;
}; };
#endif // COVERFROMURLDIALOG_H #endif // COVERFROMURLDIALOG_H

View File

@@ -70,17 +70,17 @@ void CurrentAlbumCoverLoader::LoadAlbumCover(const Song &song) {
} }
void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result) { void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResult result) {
if (id != id_) return; if (id != id_) return;
id_ = 0; id_ = 0;
if (result && !result->album_cover->image.isNull()) { if (!result.album_cover.image.isNull()) {
temp_cover_ = std::make_unique<QTemporaryFile>(temp_file_pattern_); temp_cover_ = std::make_unique<QTemporaryFile>(temp_file_pattern_);
temp_cover_->setAutoRemove(true); temp_cover_->setAutoRemove(true);
if (temp_cover_->open()) { if (temp_cover_->open()) {
if (result->album_cover->image.save(temp_cover_->fileName(), "JPEG")) { if (result.album_cover.image.save(temp_cover_->fileName(), "JPEG")) {
result->temp_cover_url = QUrl::fromLocalFile(temp_cover_->fileName()); result.temp_cover_url = QUrl::fromLocalFile(temp_cover_->fileName());
} }
else { else {
qLog(Error) << "Failed to save cover image to" << temp_cover_->fileName() << temp_cover_->errorString(); qLog(Error) << "Failed to save cover image to" << temp_cover_->fileName() << temp_cover_->errorString();
@@ -92,11 +92,11 @@ void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverL
} }
QUrl thumbnail_url; QUrl thumbnail_url;
if (result && !result->image_thumbnail.isNull()) { if (!result.image_thumbnail.isNull()) {
temp_cover_thumbnail_ = std::make_unique<QTemporaryFile>(temp_file_pattern_); temp_cover_thumbnail_ = std::make_unique<QTemporaryFile>(temp_file_pattern_);
temp_cover_thumbnail_->setAutoRemove(true); temp_cover_thumbnail_->setAutoRemove(true);
if (temp_cover_thumbnail_->open()) { if (temp_cover_thumbnail_->open()) {
if (result->image_thumbnail.save(temp_cover_thumbnail_->fileName(), "JPEG")) { if (result.image_thumbnail.save(temp_cover_thumbnail_->fileName(), "JPEG")) {
thumbnail_url = QUrl::fromLocalFile(temp_cover_thumbnail_->fileName()); thumbnail_url = QUrl::fromLocalFile(temp_cover_thumbnail_->fileName());
} }
else { else {
@@ -108,11 +108,11 @@ void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverL
} }
} }
if (result && result->updated) { if (result.updated) {
last_song_.set_art_manual(result->album_cover->cover_url); last_song_.set_art_manual(result.album_cover.cover_url);
} }
emit AlbumCoverLoaded(last_song_, result); emit AlbumCoverLoaded(last_song_, result);
emit ThumbnailLoaded(last_song_, thumbnail_url, result->image_thumbnail); emit ThumbnailLoaded(last_song_, thumbnail_url, result.image_thumbnail);
} }

View File

@@ -52,11 +52,11 @@ class CurrentAlbumCoverLoader : public QObject {
void LoadAlbumCover(const Song &song); void LoadAlbumCover(const Song &song);
signals: signals:
void AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result);
void ThumbnailLoaded(const Song &song, const QUrl &thumbnail_uri, const QImage &image); void ThumbnailLoaded(const Song &song, const QUrl &thumbnail_uri, const QImage &image);
private slots: private slots:
void TempAlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void TempAlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResult result);
private: private:
Application *app_; Application *app_;

View File

@@ -25,7 +25,6 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <limits> #include <limits>
#include <memory>
#include <QtGlobal> #include <QtGlobal>
#include <QtConcurrent> #include <QtConcurrent>
@@ -342,7 +341,7 @@ bool EditTagDialog::eventFilter(QObject *o, QEvent *e) {
if (event->mimeData()->hasImage()) { if (event->mimeData()->hasImage()) {
QImage image = qvariant_cast<QImage>(event->mimeData()->imageData()); QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());
if (!image.isNull()) { if (!image.isNull()) {
UpdateCover(UpdateCoverAction::New, std::make_shared<AlbumCoverImageResult>(image)); UpdateCover(UpdateCoverAction::New, AlbumCoverImageResult(image));
} }
} }
break; break;
@@ -638,10 +637,10 @@ void EditTagDialog::SelectionChanged() {
bool lyrics_enabled = false; bool lyrics_enabled = false;
for (const QModelIndex &idx : indexes) { for (const QModelIndex &idx : indexes) {
if (data_[idx.row()].cover_action_ == UpdateCoverAction::None) { if (data_[idx.row()].cover_action_ == UpdateCoverAction::None) {
data_[idx.row()].cover_result_ = std::make_shared<AlbumCoverImageResult>(); data_[idx.row()].cover_result_ = AlbumCoverImageResult();
} }
const Song &song = data_[idx.row()].original_; const Song &song = data_[idx.row()].original_;
if (data_[idx.row()].cover_action_ != first_cover_action || (first_cover_action != UpdateCoverAction::None && data_[idx.row()].cover_result_->image_data != data_[indexes.first().row()].cover_result_->image_data)) { if (data_[idx.row()].cover_action_ != first_cover_action || (first_cover_action != UpdateCoverAction::None && data_[idx.row()].cover_result_.image_data != data_[indexes.first().row()].cover_result_.image_data)) {
action_different = true; action_different = true;
} }
if (data_[idx.row()].cover_action_ != first_cover_action || if (data_[idx.row()].cover_action_ != first_cover_action ||
@@ -889,34 +888,34 @@ void EditTagDialog::UpdateStatisticsTab(const Song &song) {
} }
void EditTagDialog::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result) { void EditTagDialog::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
if (id == tags_cover_art_id_) { if (id == tags_cover_art_id_) {
ui_->tags_art->clear(); ui_->tags_art->clear();
bool enable_change_art = false; bool enable_change_art = false;
if (result->success && !result->image_scaled.isNull() && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset) { if (result.success && !result.image_scaled.isNull() && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset) {
ui_->tags_art->setPixmap(QPixmap::fromImage(result->image_scaled)); ui_->tags_art->setPixmap(QPixmap::fromImage(result.image_scaled));
for (const QModelIndex &idx : ui_->song_list->selectionModel()->selectedIndexes()) { for (const QModelIndex &idx : ui_->song_list->selectionModel()->selectedIndexes()) {
data_[idx.row()].cover_result_ = result->album_cover; data_[idx.row()].cover_result_ = result.album_cover;
enable_change_art = data_[idx.row()].original_.is_collection_song(); enable_change_art = data_[idx.row()].original_.is_collection_song();
} }
} }
else { else {
ui_->tags_art->setPixmap(QPixmap::fromImage(image_no_cover_thumbnail_)); ui_->tags_art->setPixmap(QPixmap::fromImage(image_no_cover_thumbnail_));
for (const QModelIndex &idx : ui_->song_list->selectionModel()->selectedIndexes()) { for (const QModelIndex &idx : ui_->song_list->selectionModel()->selectedIndexes()) {
data_[idx.row()].cover_result_ = std::make_shared<AlbumCoverImageResult>(); data_[idx.row()].cover_result_ = AlbumCoverImageResult();
enable_change_art = data_[idx.row()].original_.is_collection_song(); enable_change_art = data_[idx.row()].original_.is_collection_song();
} }
} }
tags_cover_art_id_ = -1; tags_cover_art_id_ = -1;
album_cover_choice_controller_->show_cover_action()->setEnabled(result->success && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset); album_cover_choice_controller_->show_cover_action()->setEnabled(result.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
album_cover_choice_controller_->cover_to_file_action()->setEnabled(result->success && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset); album_cover_choice_controller_->cover_to_file_action()->setEnabled(result.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
album_cover_choice_controller_->delete_cover_action()->setEnabled(enable_change_art && result->success && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset); album_cover_choice_controller_->delete_cover_action()->setEnabled(enable_change_art && result.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
} }
else if (id == summary_cover_art_id_) { else if (id == summary_cover_art_id_) {
if (result->success && !result->image_scaled.isNull() && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset) { if (result.success && !result.image_scaled.isNull() && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset) {
ui_->summary_art->setPixmap(QPixmap::fromImage(result->image_scaled)); ui_->summary_art->setPixmap(QPixmap::fromImage(result.image_scaled));
} }
else { else {
ui_->summary_art->setPixmap(QPixmap::fromImage(image_no_cover_thumbnail_)); ui_->summary_art->setPixmap(QPixmap::fromImage(image_no_cover_thumbnail_));
@@ -981,8 +980,8 @@ void EditTagDialog::LoadCoverFromFile() {
Song *song = GetFirstSelected(); Song *song = GetFirstSelected();
if (!song) return; if (!song) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->LoadImageFromFile(song); const AlbumCoverImageResult result = album_cover_choice_controller_->LoadImageFromFile(song);
if (result && result->is_valid()) UpdateCover(UpdateCoverAction::New, result); if (result.is_valid()) UpdateCover(UpdateCoverAction::New, result);
} }
@@ -999,8 +998,8 @@ void EditTagDialog::LoadCoverFromURL() {
if (ui_->song_list->selectionModel()->selectedIndexes().isEmpty()) return; if (ui_->song_list->selectionModel()->selectedIndexes().isEmpty()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->LoadImageFromURL(); const AlbumCoverImageResult result = album_cover_choice_controller_->LoadImageFromURL();
if (result && result->is_valid()) UpdateCover(UpdateCoverAction::New, result); if (result.is_valid()) UpdateCover(UpdateCoverAction::New, result);
} }
@@ -1009,8 +1008,8 @@ void EditTagDialog::SearchForCover() {
Song *song = GetFirstSelected(); Song *song = GetFirstSelected();
if (!song) return; if (!song) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->SearchForImage(song); const AlbumCoverImageResult result = album_cover_choice_controller_->SearchForImage(song);
if (result && result->is_valid()) UpdateCover(UpdateCoverAction::New, result); if (result.is_valid()) UpdateCover(UpdateCoverAction::New, result);
} }
@@ -1047,11 +1046,11 @@ void EditTagDialog::ShowCover() {
if (ui_->song_list->selectionModel()->selectedIndexes().isEmpty()) return; if (ui_->song_list->selectionModel()->selectedIndexes().isEmpty()) return;
const Data &first_data = data_[ui_->song_list->selectionModel()->selectedIndexes().first().row()]; const Data &first_data = data_[ui_->song_list->selectionModel()->selectedIndexes().first().row()];
album_cover_choice_controller_->ShowCover(first_data.current_, first_data.cover_result_->image); album_cover_choice_controller_->ShowCover(first_data.current_, first_data.cover_result_.image);
} }
void EditTagDialog::UpdateCover(const UpdateCoverAction action, AlbumCoverImageResultPtr result) { void EditTagDialog::UpdateCover(const UpdateCoverAction action, const AlbumCoverImageResult &result) {
const QModelIndexList indexes = ui_->song_list->selectionModel()->selectedIndexes(); const QModelIndexList indexes = ui_->song_list->selectionModel()->selectedIndexes();
if (indexes.isEmpty()) return; if (indexes.isEmpty()) return;
@@ -1166,8 +1165,8 @@ void EditTagDialog::SaveData() {
if ((!ref.current_.effective_albumartist().isEmpty() && !ref.current_.album().isEmpty()) && if ((!ref.current_.effective_albumartist().isEmpty() && !ref.current_.album().isEmpty()) &&
(!ui_->checkbox_embedded_cover->isChecked() || !ref.original_.save_embedded_cover_supported())) { (!ui_->checkbox_embedded_cover->isChecked() || !ref.original_.save_embedded_cover_supported())) {
QUrl cover_url; QUrl cover_url;
if (!ref.cover_result_->cover_url.isEmpty() && ref.cover_result_->cover_url.isLocalFile() && QFile::exists(ref.cover_result_->cover_url.toLocalFile())) { if (!ref.cover_result_.cover_url.isEmpty() && ref.cover_result_.cover_url.isLocalFile() && QFile::exists(ref.cover_result_.cover_url.toLocalFile())) {
cover_url = ref.cover_result_->cover_url; cover_url = ref.cover_result_.cover_url;
} }
else { else {
QString cover_hash = CoverUtils::Sha1CoverHash(ref.current_.effective_albumartist(), ref.current_.album()).toHex(); QString cover_hash = CoverUtils::Sha1CoverHash(ref.current_.effective_albumartist(), ref.current_.album()).toHex();
@@ -1224,9 +1223,9 @@ void EditTagDialog::SaveData() {
TagReaderClient::SaveCoverOptions savecover_options; TagReaderClient::SaveCoverOptions savecover_options;
savecover_options.enabled = save_embedded_cover; savecover_options.enabled = save_embedded_cover;
if (save_embedded_cover && ref.cover_action_ == UpdateCoverAction::New) { if (save_embedded_cover && ref.cover_action_ == UpdateCoverAction::New) {
if (!ref.cover_result_->image.isNull()) { if (!ref.cover_result_.image.isNull()) {
savecover_options.is_jpeg = ref.cover_result_->is_jpeg(); savecover_options.is_jpeg = ref.cover_result_.is_jpeg();
savecover_options.cover_data = ref.cover_result_->image_data; savecover_options.cover_data = ref.cover_result_.image_data;
} }
else if (!embedded_cover_from_file.isEmpty()) { else if (!embedded_cover_from_file.isEmpty()) {
savecover_options.cover_filename = embedded_cover_from_file; savecover_options.cover_filename = embedded_cover_from_file;

View File

@@ -93,7 +93,7 @@ class EditTagDialog : public QDialog {
New New
}; };
struct Data { struct Data {
explicit Data(const Song &song = Song()) : original_(song), current_(song), cover_action_(UpdateCoverAction::None), cover_result_(std::make_shared<AlbumCoverImageResult>()) {} explicit Data(const Song &song = Song()) : original_(song), current_(song), cover_action_(UpdateCoverAction::None) {}
static QVariant value(const Song &song, const QString &id); static QVariant value(const Song &song, const QString &id);
QVariant original_value(const QString &id) const { return value(original_, id); } QVariant original_value(const QString &id) const { return value(original_, id); }
@@ -104,7 +104,7 @@ class EditTagDialog : public QDialog {
Song original_; Song original_;
Song current_; Song current_;
UpdateCoverAction cover_action_; UpdateCoverAction cover_action_;
AlbumCoverImageResultPtr cover_result_; AlbumCoverImageResult cover_result_;
}; };
private slots: private slots:
@@ -120,7 +120,7 @@ class EditTagDialog : public QDialog {
void FetchTag(); void FetchTag();
void FetchTagSongChosen(const Song &original_song, const Song &new_metadata); void FetchTagSongChosen(const Song &original_song, const Song &new_metadata);
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
void LoadCoverFromFile(); void LoadCoverFromFile();
void SaveCoverToFile(); void SaveCoverToFile();
@@ -147,7 +147,7 @@ class EditTagDialog : public QDialog {
}; };
Song *GetFirstSelected(); Song *GetFirstSelected();
void UpdateCover(const UpdateCoverAction action, AlbumCoverImageResultPtr result = AlbumCoverImageResultPtr()); void UpdateCover(const UpdateCoverAction action, const AlbumCoverImageResult &result = AlbumCoverImageResult());
bool DoesValueVary(const QModelIndexList &sel, const QString &id) const; bool DoesValueVary(const QModelIndexList &sel, const QString &id) const;
bool IsValueModified(const QModelIndexList &sel, const QString &id) const; bool IsValueModified(const QModelIndexList &sel, const QString &id) const;

View File

@@ -857,7 +857,7 @@ void InternetSearchView::LazyLoadAlbumCover(const QModelIndex &proxy_index) {
} }
void InternetSearchView::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr albumcover_result) { void InternetSearchView::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &albumcover_result) {
if (!cover_loader_tasks_.contains(id)) return; if (!cover_loader_tasks_.contains(id)) return;
@@ -865,15 +865,15 @@ void InternetSearchView::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResu
QModelIndex idx = cover_loader_task.first; QModelIndex idx = cover_loader_task.first;
QString key = cover_loader_task.second; QString key = cover_loader_task.second;
if (albumcover_result && albumcover_result->success && !albumcover_result->image_scaled.isNull()) { if (albumcover_result.success && !albumcover_result.image_scaled.isNull()) {
QPixmap pixmap = QPixmap::fromImage(albumcover_result->image_scaled); QPixmap pixmap = QPixmap::fromImage(albumcover_result.image_scaled);
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
QPixmapCache::insert(key, pixmap); QPixmapCache::insert(key, pixmap);
} }
if (idx.isValid()) { if (idx.isValid()) {
QStandardItem *item = front_model_->itemFromIndex(idx); QStandardItem *item = front_model_->itemFromIndex(idx);
if (item) { if (item) {
item->setData(albumcover_result->image_scaled, Qt::DecorationRole); item->setData(albumcover_result.image_scaled, Qt::DecorationRole);
} }
} }
} }

View File

@@ -173,7 +173,7 @@ class InternetSearchView : public QWidget {
void GroupByClicked(QAction *action); void GroupByClicked(QAction *action);
void SetGroupBy(const CollectionModel::Grouping g); void SetGroupBy(const CollectionModel::Grouping g);
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr albumcover_result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &albumcover_result);
public slots: public slots:
void ReloadSettings(); void ReloadSettings();

View File

@@ -2316,16 +2316,14 @@ void Playlist::UpdateScrobblePoint(const qint64 seek_point_nanosec) {
} }
void Playlist::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result) { void Playlist::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
if (!result) return;
// Update art_manual for local songs that are not in the collection. // Update art_manual for local songs that are not in the collection.
if (((result->type == AlbumCoverLoaderResult::Type::Manual && result->album_cover->cover_url.isLocalFile()) || result->type == AlbumCoverLoaderResult::Type::ManuallyUnset) && (song.source() == Song::Source::LocalFile || song.source() == Song::Source::CDDA || song.source() == Song::Source::Device)) { if (((result.type == AlbumCoverLoaderResult::Type::Manual && result.album_cover.cover_url.isLocalFile()) || result.type == AlbumCoverLoaderResult::Type::ManuallyUnset) && (song.source() == Song::Source::LocalFile || song.source() == Song::Source::CDDA || song.source() == Song::Source::Device)) {
PlaylistItemPtr item = current_item(); PlaylistItemPtr item = current_item();
if (item && item->Metadata() == song && (!item->Metadata().art_manual_is_valid() || (result->type == AlbumCoverLoaderResult::Type::ManuallyUnset && !item->Metadata().has_manually_unset_cover()))) { if (item && item->Metadata() == song && (!item->Metadata().art_manual_is_valid() || (result.type == AlbumCoverLoaderResult::Type::ManuallyUnset && !item->Metadata().has_manually_unset_cover()))) {
qLog(Debug) << "Updating art manual for local song" << song.title() << song.album() << song.title() << "to" << result->album_cover->cover_url << "in playlist."; qLog(Debug) << "Updating art manual for local song" << song.title() << song.album() << song.title() << "to" << result.album_cover.cover_url << "in playlist.";
item->SetArtManual(result->album_cover->cover_url); item->SetArtManual(result.album_cover.cover_url);
ScheduleSaveAsync(); ScheduleSaveAsync();
} }
} }

View File

@@ -320,7 +320,7 @@ class Playlist : public QAbstractListModel {
void RepopulateDynamicPlaylist(); void RepopulateDynamicPlaylist();
void TurnOffDynamicPlaylist(); void TurnOffDynamicPlaylist();
void AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result);
signals: signals:
void RestoreFinished(); void RestoreFinished();

View File

@@ -1461,21 +1461,11 @@ void PlaylistView::Stopped() {
} }
void PlaylistView::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result) { void PlaylistView::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
AlbumCoverImageResultPtr album_cover; if ((song != Song() && song_playing_ == Song()) || result.album_cover.image == current_song_cover_art_) return;
if (result) {
album_cover = result->album_cover;
}
if ((song != Song() && song_playing_ == Song()) || (!album_cover && current_song_cover_art_.isNull()) || (album_cover && album_cover->image == current_song_cover_art_)) return; current_song_cover_art_ = result.album_cover.image;
if (album_cover) {
current_song_cover_art_ = album_cover->image;
}
else {
current_song_cover_art_ = QImage();
}
if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType::Album) { if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType::Album) {
if (song.art_automatic().isEmpty() && song.art_manual().isEmpty()) { if (song.art_automatic().isEmpty() && song.art_manual().isEmpty()) {

View File

@@ -183,7 +183,7 @@ class PlaylistView : public QTreeView {
void Playing(); void Playing();
void Stopped(); void Stopped();
void SongChanged(const Song &song); void SongChanged(const Song &song);
void AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result = AlbumCoverLoaderResultPtr()); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result = AlbumCoverLoaderResult());
void DynamicModeChanged(const bool dynamic); void DynamicModeChanged(const bool dynamic);
void SetRatingLockStatus(const bool state); void SetRatingLockStatus(const bool state);
void RatingHoverIn(const QModelIndex &idx, const QPoint pos); void RatingHoverIn(const QModelIndex &idx, const QPoint pos);

View File

@@ -307,7 +307,7 @@ QPixmap RadioModel::ChannelIcon(const QModelIndex &idx) {
} }
void RadioModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result) { void RadioModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
if (!pending_art_.contains(id)) return; if (!pending_art_.contains(id)) return;
@@ -319,11 +319,11 @@ void RadioModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr re
pending_cache_keys_.remove(cache_key); pending_cache_keys_.remove(cache_key);
if (!result || !result->success || result->image_scaled.isNull() || result->type == AlbumCoverLoaderResult::Type::ManuallyUnset) { if (!result.success || result.image_scaled.isNull() || result.type == AlbumCoverLoaderResult::Type::ManuallyUnset) {
QPixmapCache::insert(cache_key, ServiceIcon(item)); QPixmapCache::insert(cache_key, ServiceIcon(item));
} }
else { else {
QPixmapCache::insert(cache_key, QPixmap::fromImage(result->image_scaled)); QPixmapCache::insert(cache_key, QPixmap::fromImage(result.image_scaled));
} }
const QModelIndex idx = ItemToIndex(item); const QModelIndex idx = ItemToIndex(item);

View File

@@ -84,7 +84,7 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
QString SortText(QString text); QString SortText(QString text);
private slots: private slots:
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
private: private:
static const int kTreeIconSize; static const int kTreeIconSize;