GH-2584, GH-1663 Limit icon size to 512x512

This commit is contained in:
janrupf 2019-06-18 14:13:53 +02:00 committed by Petr Mrázek
parent ce12f1a734
commit 8369dbdcc0

View File

@ -254,17 +254,7 @@ void IconList::installIcons(const QStringList &iconFiles)
{ {
for (QString file : iconFiles) for (QString file : iconFiles)
{ {
QFileInfo fileinfo(file); installIcon(file, QFileInfo(file).fileName());
if (!fileinfo.isReadable() || !fileinfo.isFile())
continue;
QString target = FS::PathCombine(m_dir.dirName(), fileinfo.fileName());
QString suffix = fileinfo.suffix();
if (suffix != "jpeg" && suffix != "png" && suffix != "jpg" && suffix != "ico" && suffix != "svg" && suffix != "gif")
continue;
if (!QFile::copy(file, target))
continue;
} }
} }
@ -272,11 +262,24 @@ void IconList::installIcon(const QString &file, const QString &name)
{ {
QFileInfo fileinfo(file); QFileInfo fileinfo(file);
if(!fileinfo.isReadable() || !fileinfo.isFile()) if(!fileinfo.isReadable() || !fileinfo.isFile())
{
qWarning() << "Failed to install icon" << fileinfo.absoluteFilePath();
return; return;
}
QString target = FS::PathCombine(m_dir.dirName(), name); QString target = FS::PathCombine(m_dir.dirName(), name);
QFile::copy(file, target); QPixmap icon(fileinfo.absoluteFilePath());
if(icon.isNull())
{
qWarning() << "Icon " << fileinfo.absoluteFilePath() << "is null";
return;
}
auto currentSize = icon.size();
auto targetedWidth = qMin(currentSize.width(), 512);
auto targetedHeight = qMin(currentSize.height(), 512);
icon.scaled(targetedWidth, targetedHeight).save(target);
} }
bool IconList::iconFileExists(const QString &key) const bool IconList::iconFileExists(const QString &key) const