dde-dock/frame/util/themeappicon.cpp
Hualet Wang db3fe712d3 Revert "appitem: make fetch icon asynchronous"
This reverts commit a5b044e58532f7bb3106730cae53329258cec2dc.

because QIcon used with multithread are not safe

Change-Id: I1502a23358b7b2f90d164f36861870f6c9df280c
2017-06-27 09:25:37 +08:00

58 lines
1.2 KiB
C++

#include "themeappicon.h"
#include <QIcon>
#include <QFile>
#include <QDebug>
ThemeAppIcon::ThemeAppIcon(QObject *parent) : QObject(parent)
{
}
ThemeAppIcon::~ThemeAppIcon()
{
}
const QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
{
const int s = size & ~1;
QPixmap pixmap;
do {
if (iconName.startsWith("data:image/"))
{
const QStringList strs = iconName.split("base64,");
if (strs.size() == 2)
pixmap.loadFromData(QByteArray::fromBase64(strs.at(1).toLatin1()));
if (!pixmap.isNull())
break;
}
if (QFile::exists(iconName))
{
pixmap = QPixmap(iconName);
if (!pixmap.isNull())
break;
}
const QIcon icon = QIcon::fromTheme(iconName, QIcon::fromTheme("application-x-desktop"));
pixmap = icon.pixmap(QSize(s, s));
if (!pixmap.isNull())
break;
pixmap = QPixmap(":/icons/resources/application-x-desktop.svg");
if (!pixmap.isNull())
break;
Q_UNREACHABLE();
} while (false);
return pixmap.scaled(s, s, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}