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;
@ -673,21 +673,19 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultP
pending_cache_keys_.remove(cache_key);
if (!result) return;
// 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.
QPixmapCache::insert(cache_key, no_cover_icon_);
}
else {
QPixmap image_pixmap;
image_pixmap = QPixmap::fromImage(result->image_scaled);
image_pixmap = QPixmap::fromImage(result.image_scaled);
QPixmapCache::insert(cache_key, image_pixmap);
}
// 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);
std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(disk_cache_key));
if (!disk_cache_img) {
@ -696,7 +694,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultP
disk_cache_metadata.setUrl(disk_cache_key);
QIODevice *device_iconcache = sIconCache->prepare(disk_cache_metadata);
if (device_iconcache) {
result->image_scaled.save(device_iconcache, "XPM");
result.image_scaled.save(device_iconcache, "XPM");
sIconCache->insert(device_iconcache);
}
}

View File

@ -231,7 +231,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
// Called after ResetAsync
void ResetAsyncQueryFinished();
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result);
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
private:
// 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_ = Song();
album_cover_.reset();
album_cover_ = AlbumCoverImageResult();
app_->scrobbler()->ClearPlaying();
@ -3038,11 +3038,7 @@ void MainWindow::SearchForCover() {
}
void MainWindow::SaveCoverToFile() {
if (album_cover_) {
album_cover_choice_controller_->SaveCoverToFileManual(song_, album_cover_);
}
album_cover_choice_controller_->SaveCoverToFileManual(song_, album_cover_);
}
void MainWindow::UnsetCover() {
@ -3058,11 +3054,7 @@ void MainWindow::DeleteCover() {
}
void MainWindow::ShowCover() {
if (album_cover_) {
album_cover_choice_controller_->ShowCover(song_, album_cover_->image);
}
album_cover_choice_controller_->ShowCover(song_, album_cover_.image);
}
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;
song_ = song;
if (result) {
album_cover_ = result->album_cover;
emit AlbumCoverReady(song, result->album_cover->image);
}
else {
album_cover_.reset();
emit AlbumCoverReady(song, QImage());
}
album_cover_ = result.album_cover;
emit AlbumCoverReady(song, result.album_cover.image);
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_->cover_to_file_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.success && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset);
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_->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_->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();

View File

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

View File

@ -122,7 +122,6 @@ void RegisterMetaTypes() {
qRegisterMetaType<PlaylistSequence::RepeatMode>("PlaylistSequence::RepeatMode");
qRegisterMetaType<PlaylistSequence::ShuffleMode>("PlaylistSequence::ShuffleMode");
qRegisterMetaType<AlbumCoverLoaderResult>("AlbumCoverLoaderResult");
qRegisterMetaType<AlbumCoverLoaderResultPtr>("AlbumCoverLoaderResultPtr");
qRegisterMetaType<AlbumCoverLoaderResult::Type>("AlbumCoverLoaderResult::Type");
qRegisterMetaType<CoverProviderSearchResult>("CoverProviderSearchResult");
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.
void Mpris2::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result) {
if (!result) return;
void Mpris2::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
last_metadata_ = QVariantMap();
song.ToXesam(&last_metadata_);
@ -397,11 +395,11 @@ void Mpris2::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result
AddMetadata("mpris:trackid", current_track_id(), &last_metadata_);
QUrl cover_url;
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;
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;
}
else if (result->temp_cover_url.isValid() && result->temp_cover_url.isLocalFile()) {
cover_url = result->temp_cover_url;
else if (result.temp_cover_url.isValid() && result.temp_cover_url.isLocalFile()) {
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) {
cover_url = song.art_manual();

View File

@ -202,7 +202,7 @@ class Mpris2 : public QObject {
void PlaylistChanged(const MprisPlaylist &playlist);
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 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;
QStandardItem *item = pending_covers_.take(id);
if (!item) return;
if (result && result->success && !result->image_scaled.isNull() && result->type != AlbumCoverLoaderResult::Type::ManuallyUnset) {
item->setIcon(QIcon(QPixmap::fromImage(result->image_scaled)));
if (result.success && !result.image_scaled.isNull() && result.type != AlbumCoverLoaderResult::Type::ManuallyUnset) {
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);
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 ModelReset();

View File

@ -21,8 +21,6 @@
#include "config.h"
#include <memory>
#include <QtGlobal>
#include <QGuiApplication>
#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));
if (cover_file.isEmpty()) return AlbumCoverImageResultPtr();
if (cover_file.isEmpty()) return AlbumCoverImageResult();
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>();
AlbumCoverImageResult result;
QFile file(cover_file);
if (file.open(QIODevice::ReadOnly)) {
result->image_data = file.readAll();
result.image_data = file.readAll();
file.close();
if (result->image_data.isEmpty()) {
if (result.image_data.isEmpty()) {
qLog(Error) << "Cover file" << cover_file << "is empty.";
emit Error(tr("Cover file %1 is empty.").arg(cover_file));
}
else {
result->mime_type = Utilities::MimeTypeFromData(result->image_data);
result->image.loadFromData(result->image_data);
result->cover_url = QUrl::fromLocalFile(cover_file);
result.mime_type = Utilities::MimeTypeFromData(result.image_data);
result.image.loadFromData(result.image_data);
result.cover_url = QUrl::fromLocalFile(cover_file);
}
}
else {
@ -231,9 +229,7 @@ QUrl AlbumCoverChoiceController::LoadCoverFromFile(Song *song) {
}
void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, AlbumCoverImageResultPtr result) {
if (!result) return;
void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, const AlbumCoverImageResult &result) {
QString initial_file_name = "/";
@ -260,10 +256,10 @@ void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, AlbumCo
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);
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();
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 {
if (!result->image.save(save_filename)) {
if (!result.image.save(save_filename)) {
qLog(Error) << "Failed writing cover to file" << 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();
AlbumCoverImageResultPtr result = LoadImageFromURL();
const AlbumCoverImageResult result = LoadImageFromURL();
if (!result || result->image.isNull()) {
if (result.image.isNull()) {
return QUrl();
}
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); }
@ -333,8 +329,8 @@ QUrl AlbumCoverChoiceController::SearchForCover(Song *song) {
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl();
// Get something sensible to stick in the search box
AlbumCoverImageResultPtr result = SearchForImage(song);
if (result && result->is_valid()) {
AlbumCoverImageResult result = SearchForImage(song);
if (result.is_valid()) {
return SaveCoverAutomatic(song, result);
}
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();
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->has_embedded_cover() && song->save_embedded_cover_supported()) {
SaveCoverEmbeddedAutomatic(*song, std::make_shared<AlbumCoverImageResult>());
SaveCoverEmbeddedAutomatic(*song, AlbumCoverImageResult());
}
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);
@ -526,7 +522,7 @@ void AlbumCoverChoiceController::AlbumCoverFetched(const quint64 id, AlbumCoverI
song = cover_fetching_tasks_.take(id);
}
if (result && result->is_valid()) {
if (result.is_valid()) {
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(),
song->effective_albumartist(),
@ -613,12 +609,10 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
const QString &album,
const QString &album_id,
const QString &album_dir,
AlbumCoverImageResultPtr result,
const AlbumCoverImageResult &result,
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();
QFile file(filepath);
@ -632,9 +626,9 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
}
QUrl cover_url;
if (result->is_jpeg()) {
if (result.is_jpeg()) {
if (file.open(QIODevice::WriteOnly)) {
if (file.write(result->image_data) > 0) {
if (file.write(result.image_data) > 0) {
cover_url = QUrl::fromLocalFile(filepath);
}
else {
@ -649,16 +643,14 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
}
}
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;
}
void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, AlbumCoverImageResultPtr result) {
if (!result) return;
void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, const AlbumCoverImageResult &result) {
if (song.source() == Song::Source::Collection) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@ -673,13 +665,13 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, Al
QList<QUrl> urls;
urls.reserve(songs.count());
for (const Song &s : songs) urls << s.url();
if (result->is_jpeg()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image_data);
if (result.is_jpeg()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
QMutexLocker l(&mutex_cover_save_tasks_);
cover_save_tasks_.insert(id, song);
}
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_);
cover_save_tasks_.insert(id, song);
}
@ -687,11 +679,11 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, Al
watcher->setFuture(future);
}
else {
if (result->is_jpeg()) {
app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), result->image_data);
if (result.is_jpeg()) {
app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), result.image_data);
}
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()) {
QImage image = qvariant_cast<QImage>(e->mimeData()->imageData());
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;
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.
// Otherwise, the path to the chosen cover will be returned.
AlbumCoverImageResultPtr LoadImageFromFile(Song *song);
AlbumCoverImageResult LoadImageFromFile(Song *song);
QUrl LoadCoverFromFile(Song *song);
// 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.
void SaveCoverToFileManual(const Song &song, AlbumCoverImageResultPtr result);
void SaveCoverToFileManual(const Song &song, const AlbumCoverImageResult &result);
// 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.
QUrl LoadCoverFromURL(Song *song);
AlbumCoverImageResultPtr LoadImageFromURL();
AlbumCoverImageResult LoadImageFromURL();
// 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.
QUrl SearchForCover(Song *song);
AlbumCoverImageResultPtr SearchForImage(Song *song);
AlbumCoverImageResult SearchForImage(Song *song);
// Returns a path which indicates that the cover has been unset manually.
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);
// 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 SaveCoverToFileAutomatic(const Song *song, 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, AlbumCoverImageResultPtr result, const bool force_overwrite = false);
void SaveCoverEmbeddedAutomatic(const Song &song, AlbumCoverImageResultPtr result);
QUrl SaveCoverAutomatic(Song *song, const AlbumCoverImageResult &result);
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, const AlbumCoverImageResult &result, const bool force_overwrite = false);
void SaveCoverEmbeddedAutomatic(const Song &song, const AlbumCoverImageResult &result);
void SaveCoverEmbeddedAutomatic(const Song &song, const QUrl &cover_url);
void SaveCoverEmbeddedAutomatic(const Song &song, const QString &cover_filename);
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; }
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);
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;
AlbumCoverFetcherSearch *search = active_requests_.take(request_id);

View File

@ -118,12 +118,12 @@ class AlbumCoverFetcher : public QObject {
void Clear();
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);
private slots:
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();
private:

View File

@ -23,7 +23,6 @@
#include <algorithm>
#include <cmath>
#include <memory>
#include <QObject>
#include <QCoreApplication>
@ -257,7 +256,7 @@ void AlbumCoverFetcherSearch::AllProvidersFinished() {
// No results?
if (results_.isEmpty()) {
statistics_.missing_images_++;
emit AlbumCoverFetched(request_.id, AlbumCoverImageResultPtr());
emit AlbumCoverFetched(request_.id, AlbumCoverImageResult());
return;
}
@ -333,7 +332,7 @@ void AlbumCoverFetcherSearch::ProviderCoverFetchFinished(QNetworkReply *reply) {
}
result.image_size = 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();
}
else {
@ -381,7 +380,7 @@ float AlbumCoverFetcherSearch::ScoreImage(const QSize size) {
void AlbumCoverFetcherSearch::SendBestImage() {
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>();
AlbumCoverImageResult result;
if (!candidate_images_.isEmpty()) {
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_++;
statistics_.chosen_width_ += result->image.width();
statistics_.chosen_height_ += result->image.height();
statistics_.chosen_width_ += result.image.width();
statistics_.chosen_height_ += result.image.height();
}
else {
statistics_.missing_images_++;

View File

@ -69,7 +69,7 @@ class AlbumCoverFetcherSearch : public QObject {
void SearchFinished(quint64, const CoverProviderSearchResults &results);
// 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:
void ProviderSearchResults(const int id, const CoverProviderSearchResults &results);
@ -108,9 +108,9 @@ class AlbumCoverFetcherSearch : public QObject {
// QMap is sorted by key (score).
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;
AlbumCoverImageResultPtr album_cover;
AlbumCoverImageResult album_cover;
};
QMultiMap<float, CandidateImage> candidate_images_;

View File

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

View File

@ -114,7 +114,6 @@ quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options,
task->options = options;
task->song = song;
task->state = State::Manual;
task->album_cover = std::make_shared<AlbumCoverImageResult>();
return EnqueueTask(task);
@ -131,13 +130,12 @@ quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options,
task->options = options;
task->song = song;
task->state = State::Manual;
task->album_cover = std::make_shared<AlbumCoverImageResult>();
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>();
task->options = options;
@ -151,8 +149,7 @@ quint64 AlbumCoverLoader::LoadImageAsync(const AlbumCoverLoaderOptions &options,
TaskPtr task = std::make_shared<Task>();
task->options = options;
task->album_cover = std::make_shared<AlbumCoverImageResult>();
task->album_cover->image = image;
task->album_cover.image = image;
return EnqueueTask(task);
@ -197,16 +194,16 @@ void AlbumCoverLoader::ProcessTask(TaskPtr task) {
}
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_thumbnail;
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_) {
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;
}
@ -223,7 +220,7 @@ void AlbumCoverLoader::NextState(TaskPtr task) {
}
else {
// 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) {
// 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);
}
@ -270,17 +267,17 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
if (!cover_url.isEmpty() && !cover_url.path().isEmpty()) {
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()) {
QByteArray image_data = TagReaderClient::Instance()->LoadEmbeddedArtBlocking(task->song.url().toLocalFile());
if (!image_data.isEmpty()) {
QImage image;
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 {
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();
QImage image;
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 {
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 {
@ -315,10 +312,10 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
file.close();
QImage image;
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 {
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 {
@ -337,11 +334,11 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(TaskPtr task) {
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, cover_url]() { RemoteFetchFinished(reply, cover_url); });
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;
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_);
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;
}
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 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);
void CancelTask(const quint64 id);
@ -79,7 +79,7 @@ class AlbumCoverLoader : public QObject {
signals:
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);
protected slots:
@ -105,7 +105,7 @@ class AlbumCoverLoader : public QObject {
quint64 id;
Song song;
AlbumCoverImageResultPtr album_cover;
AlbumCoverImageResult album_cover;
State state;
AlbumCoverLoaderResult::Type type;
bool art_updated;
@ -117,7 +117,7 @@ class AlbumCoverLoader : public QObject {
explicit TryLoadResult(const bool _started_async = false,
const bool _loaded_success = false,
const AlbumCoverLoaderResult::Type _type = AlbumCoverLoaderResult::Type::None,
AlbumCoverImageResultPtr _album_cover = AlbumCoverImageResultPtr()) :
const AlbumCoverImageResult &_album_cover = AlbumCoverImageResult()) :
started_async(_started_async),
loaded_success(_loaded_success),
type(_type),
@ -127,7 +127,7 @@ class AlbumCoverLoader : public QObject {
bool loaded_success;
AlbumCoverLoaderResult::Type type;
AlbumCoverImageResultPtr album_cover;
AlbumCoverImageResult album_cover;
};
quint64 EnqueueTask(TaskPtr task);

View File

@ -22,8 +22,6 @@
#include "config.h"
#include <memory>
#include <QImage>
#include <QUrl>
@ -43,7 +41,7 @@ class AlbumCoverLoaderResult {
explicit AlbumCoverLoaderResult(const bool _success = false,
const Type _type = Type::None,
AlbumCoverImageResultPtr _album_cover = AlbumCoverImageResultPtr(),
AlbumCoverImageResult _album_cover = AlbumCoverImageResult(),
const QImage &_image_scaled = QImage(),
const QImage &_image_thumbnail = QImage(),
const bool _updated = false) :
@ -52,17 +50,11 @@ class AlbumCoverLoaderResult {
album_cover(_album_cover),
image_scaled(_image_scaled),
image_thumbnail(_image_thumbnail),
updated(_updated) {
if (!_album_cover) {
_album_cover = std::make_shared<AlbumCoverImageResult>();
}
}
updated(_updated) {}
bool success;
Type type;
AlbumCoverImageResultPtr album_cover;
AlbumCoverImageResult album_cover;
QImage image_scaled;
QImage image_thumbnail;
bool updated;
@ -71,9 +63,6 @@ class AlbumCoverLoaderResult {
};
using AlbumCoverLoaderResultPtr = std::shared_ptr<AlbumCoverLoaderResult>;
Q_DECLARE_METATYPE(AlbumCoverLoaderResult)
Q_DECLARE_METATYPE(AlbumCoverLoaderResultPtr)
#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;
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_);
}
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_ImageData, result->image_data);
//item->setData(Role_Image, result.image_original);
//item->setData(Role_ImageData, result.image_data);
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;
AlbumItem *item = cover_fetching_tasks_.take(id);
if (result && !result->image.isNull()) {
if (!result.image.isNull()) {
SaveAndSetCover(item, result);
}
@ -699,8 +699,8 @@ void AlbumCoverManager::LoadCoverFromFile() {
Song song = GetSingleSelectionAsSong();
if (!song.is_valid()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->LoadImageFromFile(&song);
if (result || !result->image.isNull()) {
const AlbumCoverImageResult result = album_cover_choice_controller_->LoadImageFromFile(&song);
if (!result.image.isNull()) {
SaveImageToAlbums(&song, result);
}
@ -711,32 +711,32 @@ void AlbumCoverManager::SaveCoverToFile() {
Song song = GetSingleSelectionAsSong();
if (!song.is_valid() || song.has_manually_unset_cover()) return;
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>();
AlbumCoverImageResult result;
// 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())) {
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())) {
result->image_data = Utilities::ReadDataFromFile(song.art_manual().path());
result.image_data = Utilities::ReadDataFromFile(song.art_manual().path());
}
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())) {
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())) {
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()) {
result->image.loadFromData(result->image_data);
if (!result.image_data.isEmpty()) {
result.image.loadFromData(result.image_data);
}
album_cover_choice_controller_->SaveCoverToFileManual(song, result);
@ -748,8 +748,8 @@ void AlbumCoverManager::LoadCoverFromURL() {
Song song = GetSingleSelectionAsSong();
if (!song.is_valid()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->LoadImageFromURL();
if (result && result->is_valid()) {
const AlbumCoverImageResult &result = album_cover_choice_controller_->LoadImageFromURL();
if (result.is_valid()) {
SaveImageToAlbums(&song, result);
}
@ -760,18 +760,16 @@ void AlbumCoverManager::SearchForCover() {
Song song = GetFirstSelectedAsSong();
if (!song.is_valid()) return;
AlbumCoverImageResultPtr result = album_cover_choice_controller_->SearchForImage(&song);
if (result && result->is_valid()) {
const AlbumCoverImageResult result = album_cover_choice_controller_->SearchForImage(&song);
if (result.is_valid()) {
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()) {
case CoverOptions::CoverType::Cache:
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()) {
quint64 id = -1;
if (result->is_jpeg()) {
id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image_data);
if (result.is_jpeg()) {
id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
}
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) {
cover_save_tasks_.insert(id, album_item);
@ -955,9 +953,7 @@ void AlbumCoverManager::LoadSelectedToPlaylist() {
}
void AlbumCoverManager::SaveAndSetCover(AlbumItem *item, AlbumCoverImageResultPtr result) {
if (!result) return;
void AlbumCoverManager::SaveAndSetCover(AlbumItem *item, const AlbumCoverImageResult &result) {
const QString albumartist = item->data(Role_AlbumArtist).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();
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()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image_data);
if (result.is_jpeg()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
cover_save_tasks_.insert(id, item);
}
else if (!result->image.isNull()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->image);
else if (!result.image.isNull()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image);
cover_save_tasks_.insert(id, item);
}
else if (!result->cover_url.isEmpty() && result->cover_url.isLocalFile()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result->cover_url.toLocalFile());
else if (!result.cover_url.isEmpty() && result.cover_url.isLocalFile()) {
quint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.cover_url.toLocalFile());
cover_save_tasks_.insert(id, item);
}
}
else {
QUrl cover_url;
if (!result->cover_url.isEmpty() && result->cover_url.isValid() && result->cover_url.isLocalFile()) {
cover_url = result->cover_url;
if (!result.cover_url.isEmpty() && result.cover_url.isValid() && result.cover_url.isLocalFile()) {
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);
}

View File

@ -137,9 +137,9 @@ class AlbumCoverManager : public QMainWindow {
void UpdateStatusText();
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;
SongMimeData *GetMimeDataForAlbums(const QModelIndexList &indexes) const;
@ -152,11 +152,11 @@ class AlbumCoverManager : public QMainWindow {
private slots:
void ArtistChanged(QListWidgetItem *current);
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result);
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
void UpdateFilter();
void FetchAlbumCovers();
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();
// On the context menu

View File

@ -21,8 +21,6 @@
#include "config.h"
#include <memory>
#include <QWidget>
#include <QDialog>
#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_->album->setText(album);
@ -169,16 +167,16 @@ AlbumCoverImageResultPtr AlbumCoverSearcher::Exec(const QString &artist, const Q
Search();
}
if (exec() == QDialog::Rejected) return AlbumCoverImageResultPtr();
if (exec() == QDialog::Rejected) return AlbumCoverImageResult();
QModelIndex selected = ui_->covers->currentIndex();
if (!selected.isValid() || !selected.data(Role_ImageFetchFinished).toBool())
return AlbumCoverImageResultPtr();
return AlbumCoverImageResult();
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>();
result->image_data = selected.data(Role_ImageData).toByteArray();
result->image = selected.data(Role_Image).value<QImage>();
result->mime_type = Utilities::MimeTypeFromData(result->image_data);
AlbumCoverImageResult result;
result.image_data = selected.data(Role_ImageData).toByteArray();
result.image = selected.data(Role_Image).value<QImage>();
result.mime_type = Utilities::MimeTypeFromData(result.image_data);
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;
QStandardItem *item = cover_loading_tasks_.take(id);
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());
return;
}
const QPixmap pixmap = QPixmap::fromImage(result->image_thumbnail);
const QPixmap pixmap = QPixmap::fromImage(result.image_thumbnail);
if (pixmap.isNull()) {
model_->removeRow(item->row());
return;
@ -265,10 +263,10 @@ void AlbumCoverSearcher::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoad
const QIcon icon(pixmap);
item->setData(true, Role_ImageFetchFinished);
item->setData(result->album_cover->image_data, Role_ImageData);
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.size(), Role_ImageSize);
item->setData(result.album_cover.image_data, Role_ImageData);
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.size(), Role_ImageSize);
if (!icon.isNull()) item->setIcon(icon);
}

View File

@ -88,7 +88,7 @@ class AlbumCoverSearcher : public QDialog {
void Init(AlbumCoverFetcher *fetcher);
AlbumCoverImageResultPtr Exec(const QString &artist, const QString &album);
AlbumCoverImageResult Exec(const QString &artist, const QString &album);
protected:
void keyPressEvent(QKeyEvent*) override;
@ -96,7 +96,7 @@ class AlbumCoverSearcher : public QDialog {
private slots:
void Search();
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);

View File

@ -21,8 +21,6 @@
#include "config.h"
#include <memory>
#include <QWidget>
#include <QDialog>
#include <QApplication>
@ -54,11 +52,11 @@ CoverFromURLDialog::~CoverFromURLDialog() {
delete ui_;
}
AlbumCoverImageResultPtr CoverFromURLDialog::Exec() {
AlbumCoverImageResult CoverFromURLDialog::Exec() {
// reset state
ui_->url->setText("");
last_album_cover_.reset();
last_album_cover_ = AlbumCoverImageResult();
QClipboard *clipboard = QApplication::clipboard();
ui_->url->setText(clipboard->text());
@ -92,17 +90,17 @@ void CoverFromURLDialog::LoadCoverFromURLFinished() {
return;
}
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>();
result->image_data = reply->readAll();
result->image.loadFromData(result->image_data);
result->mime_type = Utilities::MimeTypeFromData(result->image_data);
AlbumCoverImageResult result;
result.image_data = reply->readAll();
result.image.loadFromData(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;
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;
// 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:
void accept() override;
@ -53,7 +53,7 @@ class CoverFromURLDialog : public QDialog {
private:
NetworkAccessManager *network_;
Ui_CoverFromURLDialog *ui_;
AlbumCoverImageResultPtr last_album_cover_;
AlbumCoverImageResult last_album_cover_;
};
#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;
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_->setAutoRemove(true);
if (temp_cover_->open()) {
if (result->album_cover->image.save(temp_cover_->fileName(), "JPEG")) {
result->temp_cover_url = QUrl::fromLocalFile(temp_cover_->fileName());
if (result.album_cover.image.save(temp_cover_->fileName(), "JPEG")) {
result.temp_cover_url = QUrl::fromLocalFile(temp_cover_->fileName());
}
else {
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;
if (result && !result->image_thumbnail.isNull()) {
if (!result.image_thumbnail.isNull()) {
temp_cover_thumbnail_ = std::make_unique<QTemporaryFile>(temp_file_pattern_);
temp_cover_thumbnail_->setAutoRemove(true);
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());
}
else {
@ -108,11 +108,11 @@ void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverL
}
}
if (result && result->updated) {
last_song_.set_art_manual(result->album_cover->cover_url);
if (result.updated) {
last_song_.set_art_manual(result.album_cover.cover_url);
}
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);
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);
private slots:
void TempAlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr result);
void TempAlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResult result);
private:
Application *app_;

View File

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

View File

@ -93,7 +93,7 @@ class EditTagDialog : public QDialog {
New
};
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);
QVariant original_value(const QString &id) const { return value(original_, id); }
@ -104,7 +104,7 @@ class EditTagDialog : public QDialog {
Song original_;
Song current_;
UpdateCoverAction cover_action_;
AlbumCoverImageResultPtr cover_result_;
AlbumCoverImageResult cover_result_;
};
private slots:
@ -120,7 +120,7 @@ class EditTagDialog : public QDialog {
void FetchTag();
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 SaveCoverToFile();
@ -147,7 +147,7 @@ class EditTagDialog : public QDialog {
};
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 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;
@ -865,15 +865,15 @@ void InternetSearchView::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResu
QModelIndex idx = cover_loader_task.first;
QString key = cover_loader_task.second;
if (albumcover_result && albumcover_result->success && !albumcover_result->image_scaled.isNull()) {
QPixmap pixmap = QPixmap::fromImage(albumcover_result->image_scaled);
if (albumcover_result.success && !albumcover_result.image_scaled.isNull()) {
QPixmap pixmap = QPixmap::fromImage(albumcover_result.image_scaled);
if (!pixmap.isNull()) {
QPixmapCache::insert(key, pixmap);
}
if (idx.isValid()) {
QStandardItem *item = front_model_->itemFromIndex(idx);
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 SetGroupBy(const CollectionModel::Grouping g);
void AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr albumcover_result);
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &albumcover_result);
public slots:
void ReloadSettings();

View File

@ -2316,16 +2316,14 @@ void Playlist::UpdateScrobblePoint(const qint64 seek_point_nanosec) {
}
void Playlist::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result) {
if (!result) return;
void Playlist::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
// 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();
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.";
item->SetArtManual(result->album_cover->cover_url);
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.";
item->SetArtManual(result.album_cover.cover_url);
ScheduleSaveAsync();
}
}

View File

@ -320,7 +320,7 @@ class Playlist : public QAbstractListModel {
void RepopulateDynamicPlaylist();
void TurnOffDynamicPlaylist();
void AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResultPtr result);
void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result);
signals:
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 (result) {
album_cover = result->album_cover;
}
if ((song != Song() && song_playing_ == Song()) || result.album_cover.image == current_song_cover_art_) return;
if ((song != Song() && song_playing_ == Song()) || (!album_cover && current_song_cover_art_.isNull()) || (album_cover && album_cover->image == current_song_cover_art_)) return;
if (album_cover) {
current_song_cover_art_ = album_cover->image;
}
else {
current_song_cover_art_ = QImage();
}
current_song_cover_art_ = result.album_cover.image;
if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType::Album) {
if (song.art_automatic().isEmpty() && song.art_manual().isEmpty()) {

View File

@ -183,7 +183,7 @@ class PlaylistView : public QTreeView {
void Playing();
void Stopped();
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 SetRatingLockStatus(const bool state);
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;
@ -319,11 +319,11 @@ void RadioModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultPtr re
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));
}
else {
QPixmapCache::insert(cache_key, QPixmap::fromImage(result->image_scaled));
QPixmapCache::insert(cache_key, QPixmap::fromImage(result.image_scaled));
}
const QModelIndex idx = ItemToIndex(item);

View File

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