CurrentAlbumCoverLoader: Port away from QTemporaryFile
This commit is contained in:
@@ -27,11 +27,11 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QTemporaryFile>
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
|
#include "core/temporaryfile.h"
|
||||||
#include "playlist/playlistmanager.h"
|
#include "playlist/playlistmanager.h"
|
||||||
#include "albumcoverloader.h"
|
#include "albumcoverloader.h"
|
||||||
#include "albumcoverloaderresult.h"
|
#include "albumcoverloaderresult.h"
|
||||||
@@ -58,12 +58,7 @@ CurrentAlbumCoverLoader::CurrentAlbumCoverLoader(Application *app, QObject *pare
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentAlbumCoverLoader::~CurrentAlbumCoverLoader() {
|
CurrentAlbumCoverLoader::~CurrentAlbumCoverLoader() = default;
|
||||||
|
|
||||||
if (temp_cover_) temp_cover_->remove();
|
|
||||||
if (temp_cover_thumbnail_) temp_cover_thumbnail_->remove();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CurrentAlbumCoverLoader::ReloadSettingsAsync() {
|
void CurrentAlbumCoverLoader::ReloadSettingsAsync() {
|
||||||
|
|
||||||
@@ -90,35 +85,33 @@ void CurrentAlbumCoverLoader::AlbumCoverReady(const quint64 id, AlbumCoverLoader
|
|||||||
id_ = 0;
|
id_ = 0;
|
||||||
|
|
||||||
if (!result.album_cover.image.isNull()) {
|
if (!result.album_cover.image.isNull()) {
|
||||||
temp_cover_ = make_unique<QTemporaryFile>(temp_file_pattern_);
|
temp_cover_ = make_unique<TemporaryFile>(temp_file_pattern_);
|
||||||
temp_cover_->setAutoRemove(true);
|
if (!temp_cover_->filename().isEmpty()) {
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Failed to open" << temp_cover_->fileName() << temp_cover_->errorString();
|
qLog(Error) << "Failed to open" << temp_cover_->filename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl thumbnail_url;
|
QUrl thumbnail_url;
|
||||||
if (!result.image_scaled.isNull()) {
|
if (!result.image_scaled.isNull()) {
|
||||||
temp_cover_thumbnail_ = make_unique<QTemporaryFile>(temp_file_pattern_);
|
temp_cover_thumbnail_ = make_unique<TemporaryFile>(temp_file_pattern_);
|
||||||
temp_cover_thumbnail_->setAutoRemove(true);
|
if (temp_cover_thumbnail_->filename().isEmpty()) {
|
||||||
if (temp_cover_thumbnail_->open()) {
|
if (result.image_scaled.save(temp_cover_thumbnail_->filename(), "JPEG")) {
|
||||||
if (result.image_scaled.save(temp_cover_thumbnail_->fileName(), "JPEG")) {
|
thumbnail_url = QUrl::fromLocalFile(temp_cover_thumbnail_->filename());
|
||||||
thumbnail_url = QUrl::fromLocalFile(temp_cover_thumbnail_->fileName());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Unable to save cover thumbnail image to" << temp_cover_thumbnail_->fileName();
|
qLog(Error) << "Unable to save cover thumbnail image to" << temp_cover_thumbnail_->filename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Unable to open" << temp_cover_thumbnail_->fileName();
|
qLog(Error) << "Unable to open" << temp_cover_thumbnail_->filename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QTemporaryFile>
|
|
||||||
|
|
||||||
#include "core/scoped_ptr.h"
|
#include "core/scoped_ptr.h"
|
||||||
|
#include "core/temporaryfile.h"
|
||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
#include "albumcoverloaderoptions.h"
|
#include "albumcoverloaderoptions.h"
|
||||||
#include "albumcoverloaderresult.h"
|
#include "albumcoverloaderresult.h"
|
||||||
@@ -66,8 +66,8 @@ class CurrentAlbumCoverLoader : public QObject {
|
|||||||
|
|
||||||
QString temp_file_pattern_;
|
QString temp_file_pattern_;
|
||||||
|
|
||||||
ScopedPtr<QTemporaryFile> temp_cover_;
|
ScopedPtr<TemporaryFile> temp_cover_;
|
||||||
ScopedPtr<QTemporaryFile> temp_cover_thumbnail_;
|
ScopedPtr<TemporaryFile> temp_cover_thumbnail_;
|
||||||
quint64 id_;
|
quint64 id_;
|
||||||
|
|
||||||
Song last_song_;
|
Song last_song_;
|
||||||
|
|||||||
Reference in New Issue
Block a user