Add QImageReader::imageFormatsForMimeType replacement function
This commit is contained in:
@@ -989,6 +989,16 @@ bool IsColorDark(const QColor &color) {
|
|||||||
return ((30 * color.red() + 59 * color.green() + 11 * color.blue()) / 100) <= 130;
|
return ((30 * color.red() + 59 * color.green() + 11 * color.blue()) / 100) <= 130;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QByteArray> ImageFormatsForMimeType(const QByteArray &mimetype) {
|
||||||
|
|
||||||
|
if (mimetype == "image/bmp") return QList<QByteArray>() << "BMP";
|
||||||
|
else if (mimetype == "image/gif") return QList<QByteArray>() << "GIF";
|
||||||
|
else if (mimetype == "image/jpeg") return QList<QByteArray>() << "JPG";
|
||||||
|
else if (mimetype == "image/png") return QList<QByteArray>() << "PNG";
|
||||||
|
else return QList<QByteArray>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utilities
|
} // namespace Utilities
|
||||||
|
|
||||||
ScopedWCharArray::ScopedWCharArray(const QString &str)
|
ScopedWCharArray::ScopedWCharArray(const QString &str)
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ QString ReplaceVariable(const QString &variable, const Song &song, const QString
|
|||||||
|
|
||||||
bool IsColorDark(const QColor &color);
|
bool IsColorDark(const QColor &color);
|
||||||
|
|
||||||
|
QList<QByteArray> ImageFormatsForMimeType(const QByteArray &mimetype);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class ScopedWCharArray {
|
class ScopedWCharArray {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
#include "core/timeconstants.h"
|
#include "core/timeconstants.h"
|
||||||
|
#include "core/utilities.h"
|
||||||
#include "covermanager/albumcoverloader.h"
|
#include "covermanager/albumcoverloader.h"
|
||||||
#include "subsonicservice.h"
|
#include "subsonicservice.h"
|
||||||
#include "subsonicurlhandler.h"
|
#include "subsonicurlhandler.h"
|
||||||
@@ -769,15 +770,21 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const QString alb
|
|||||||
AlbumCoverFinishCheck();
|
AlbumCoverFinishCheck();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QByteArray format = QImageReader::imageFormatsForMimeType(mimetype.toUtf8()).first();
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||||
|
QList<QByteArray> format_list = QImageReader::imageFormatsForMimeType(mimetype.toUtf8());
|
||||||
|
#else
|
||||||
|
QList<QByteArray> format_list = Utilities::ImageFormatsForMimeType(mimetype.toUtf8());
|
||||||
|
#endif
|
||||||
|
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
if (data.isEmpty()) {
|
if (format_list.isEmpty() || data.isEmpty()) {
|
||||||
Error(QString("Received empty image data for %1").arg(url.toString()));
|
Error(QString("Received empty image data for %1").arg(url.toString()));
|
||||||
if (album_covers_requests_sent_.contains(album_id)) album_covers_requests_sent_.remove(album_id);
|
if (album_covers_requests_sent_.contains(album_id)) album_covers_requests_sent_.remove(album_id);
|
||||||
AlbumCoverFinishCheck();
|
AlbumCoverFinishCheck();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
QByteArray format = format_list.first();
|
||||||
QString fullfilename = filename + "." + format.toLower();
|
QString fullfilename = filename + "." + format.toLower();
|
||||||
|
|
||||||
QImage image;
|
QImage image;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
#include "core/timeconstants.h"
|
#include "core/timeconstants.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "core/utilities.h"
|
||||||
#include "covermanager/albumcoverloader.h"
|
#include "covermanager/albumcoverloader.h"
|
||||||
#include "tidalservice.h"
|
#include "tidalservice.h"
|
||||||
#include "tidalurlhandler.h"
|
#include "tidalurlhandler.h"
|
||||||
@@ -1166,15 +1167,21 @@ void TidalRequest::AlbumCoverReceived(QNetworkReply *reply, const QString &album
|
|||||||
AlbumCoverFinishCheck();
|
AlbumCoverFinishCheck();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QByteArray format = QImageReader::imageFormatsForMimeType(mimetype.toUtf8()).first();
|
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||||
|
QList<QByteArray> format_list = QImageReader::imageFormatsForMimeType(mimetype.toUtf8());
|
||||||
|
#else
|
||||||
|
QList<QByteArray> format_list = Utilities::ImageFormatsForMimeType(mimetype.toUtf8());
|
||||||
|
#endif
|
||||||
|
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
if (data.isEmpty()) {
|
if (format_list.isEmpty() || data.isEmpty()) {
|
||||||
Error(QString("Received empty image data for %1").arg(url.toString()));
|
Error(QString("Received empty image data for %1").arg(url.toString()));
|
||||||
if (album_covers_requests_sent_.contains(album_id)) album_covers_requests_sent_.remove(album_id);
|
if (album_covers_requests_sent_.contains(album_id)) album_covers_requests_sent_.remove(album_id);
|
||||||
AlbumCoverFinishCheck();
|
AlbumCoverFinishCheck();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
QByteArray format = format_list.first();
|
||||||
|
|
||||||
QImage image;
|
QImage image;
|
||||||
if (image.loadFromData(data, format)) {
|
if (image.loadFromData(data, format)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user