|
|
@ -91,7 +91,8 @@ namespace |
|
|
|
if (!ext.isEmpty()) |
|
|
|
if (!ext.isEmpty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPixmap cached; |
|
|
|
QPixmap cached; |
|
|
|
if (QPixmapCache::find(ext, &cached)) return {cached}; |
|
|
|
if (QPixmapCache::find(ext, &cached)) |
|
|
|
|
|
|
|
return {cached}; |
|
|
|
|
|
|
|
|
|
|
|
const QPixmap pixmap = pixmapForExtension(ext); |
|
|
|
const QPixmap pixmap = pixmapForExtension(ext); |
|
|
|
if (!pixmap.isNull()) |
|
|
|
if (!pixmap.isNull()) |
|
|
@ -115,16 +116,17 @@ namespace |
|
|
|
QPixmap pixmapForExtension(const QString &ext) const override |
|
|
|
QPixmap pixmapForExtension(const QString &ext) const override |
|
|
|
{ |
|
|
|
{ |
|
|
|
const std::wstring extWStr = QString(u'.' + ext).toStdWString(); |
|
|
|
const std::wstring extWStr = QString(u'.' + ext).toStdWString(); |
|
|
|
SHFILEINFO sfi {}; |
|
|
|
|
|
|
|
HRESULT hr = ::SHGetFileInfoW(extWStr.c_str(), |
|
|
|
SHFILEINFOW sfi {}; |
|
|
|
FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES); |
|
|
|
const HRESULT hr = ::SHGetFileInfoW(extWStr.c_str(), |
|
|
|
|
|
|
|
FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), (SHGFI_ICON | SHGFI_USEFILEATTRIBUTES)); |
|
|
|
if (FAILED(hr)) |
|
|
|
if (FAILED(hr)) |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
|
|
|
|
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) |
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) |
|
|
|
auto iconPixmap = QPixmap::fromImage(QImage::fromHICON(sfi.hIcon)); |
|
|
|
const auto iconPixmap = QPixmap::fromImage(QImage::fromHICON(sfi.hIcon)); |
|
|
|
#else |
|
|
|
#else |
|
|
|
QPixmap iconPixmap = QtWin::fromHICON(sfi.hIcon); |
|
|
|
const QPixmap iconPixmap = QtWin::fromHICON(sfi.hIcon); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
::DestroyIcon(sfi.hIcon); |
|
|
|
::DestroyIcon(sfi.hIcon); |
|
|
|
return iconPixmap; |
|
|
|
return iconPixmap; |
|
|
@ -158,30 +160,24 @@ namespace |
|
|
|
return (!testIcon1.isNull() || !testIcon2.isNull()); |
|
|
|
return (!testIcon1.isNull() || !testIcon2.isNull()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MimeFileIconProvider : public UnifiedFileIconProvider |
|
|
|
class MimeFileIconProvider final : public UnifiedFileIconProvider |
|
|
|
{ |
|
|
|
{ |
|
|
|
using QFileIconProvider::icon; |
|
|
|
using QFileIconProvider::icon; |
|
|
|
|
|
|
|
|
|
|
|
QIcon icon(const QFileInfo &info) const override |
|
|
|
QIcon icon(const QFileInfo &info) const override |
|
|
|
{ |
|
|
|
{ |
|
|
|
const QMimeType mimeType = m_db.mimeTypeForFile(info, QMimeDatabase::MatchExtension); |
|
|
|
const QMimeType mimeType = QMimeDatabase().mimeTypeForFile(info, QMimeDatabase::MatchExtension); |
|
|
|
QIcon res = QIcon::fromTheme(mimeType.iconName()); |
|
|
|
|
|
|
|
if (!res.isNull()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = QIcon::fromTheme(mimeType.genericIconName()); |
|
|
|
const auto mimeIcon = QIcon::fromTheme(mimeType.iconName()); |
|
|
|
if (!res.isNull()) |
|
|
|
if (!mimeIcon.isNull()) |
|
|
|
{ |
|
|
|
return mimeIcon; |
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
const auto genericIcon = QIcon::fromTheme(mimeType.genericIconName()); |
|
|
|
|
|
|
|
if (!genericIcon.isNull()) |
|
|
|
|
|
|
|
return genericIcon; |
|
|
|
|
|
|
|
|
|
|
|
return UnifiedFileIconProvider::icon(info); |
|
|
|
return UnifiedFileIconProvider::icon(info); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
QMimeDatabase m_db; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
#endif // Q_OS_WIN
|
|
|
|
#endif // Q_OS_WIN
|
|
|
|
} |
|
|
|
} |
|
|
|