diff --git a/share/demo.kdbx b/share/demo.kdbx index 736fe7544a..5195cd19dd 100644 Binary files a/share/demo.kdbx and b/share/demo.kdbx differ diff --git a/src/core/IconDownloader.cpp b/src/core/IconDownloader.cpp index 1dccc554c0..1cb030c1e6 100644 --- a/src/core/IconDownloader.cpp +++ b/src/core/IconDownloader.cpp @@ -20,6 +20,7 @@ #include "core/NetworkManager.h" #include +#include #include #define MAX_REDIRECTS 5 @@ -188,7 +189,7 @@ void IconDownloader::fetchFinished() } } else { // No redirect, and we theoretically have some icon data now. - image.loadFromData(m_bytesReceived); + image = parseImage(m_bytesReceived); } } @@ -206,3 +207,33 @@ void IconDownloader::fetchFinished() emit finished(url, image); } } + +/** + * Parse fetched image bytes. + * + * Parses the given byte array into a QImage. Unlike QImage::loadFromData(), this method + * tries to extract the highest resolution image from .ICO files. + * + * @param imageBytes raw image bytes + * @return parsed image + */ +QImage IconDownloader::parseImage(QByteArray& imageBytes) const +{ + QBuffer buff(&imageBytes); + buff.open(QIODevice::ReadOnly); + QImageReader reader(&buff); + + if (reader.imageCount() <= 0) { + return reader.read(); + } + + QImage img; + for (int i = 0; i < reader.imageCount(); ++i) { + if (img.isNull() || reader.size().width() > img.size().width()) { + img = reader.read(); + } + reader.jumpToNextImage(); + } + + return img; +} diff --git a/src/core/IconDownloader.h b/src/core/IconDownloader.h index e2b8c4f2df..008e57aaba 100644 --- a/src/core/IconDownloader.h +++ b/src/core/IconDownloader.h @@ -50,6 +50,7 @@ private slots: private: void fetchFavicon(const QUrl& url); + QImage parseImage(QByteArray& imageBytes) const; QString m_url; QUrl m_fetchUrl;