From 2300629df599938d67c13ed134e788db0fe8b21a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 3 May 2017 10:46:38 +0200 Subject: QWindowsFileIconEngine::filePixmap(): Handle non-existent files Pass SHGFI_USEFILEATTRIBUTES/FILE_ATTRIBUTE_NORMAL to ShGetFileInfo() in case a file does not exist to obtain an icon. SHGFI_USEFILEATTRIBUTES cannot be used unconditionally as it breaks custom directory icons. The functionality is then on par with XCB which obtains icons via QMimeDatabase look-up. Task-number: QTBUG-25319 Change-Id: Icd894d97fd8d1a2c4d5d39e86afe89843e6720c4 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/windows/qwindowstheme.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 3e2cb5e9e9..7916211219 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -864,12 +864,18 @@ QPixmap QWindowsFileIconEngine::filePixmap(const QSize &size, QIcon::Mode, QIcon } SHFILEINFO info; - const unsigned int flags = - SHGFI_ICON|iconSize|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX; - - const bool val = cacheableDirIcon && useDefaultFolderIcon - ? shGetFileInfoBackground(QString::fromWCharArray(L"dummy"), FILE_ATTRIBUTE_DIRECTORY, &info, flags | SHGFI_USEFILEATTRIBUTES) - : shGetFileInfoBackground(filePath, 0, &info, flags); + unsigned int flags = SHGFI_ICON | iconSize | SHGFI_SYSICONINDEX | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX; + DWORD attributes = 0; + QString path = filePath; + if (cacheableDirIcon && useDefaultFolderIcon) { + flags |= SHGFI_USEFILEATTRIBUTES; + attributes |= FILE_ATTRIBUTE_DIRECTORY; + path = QStringLiteral("dummy"); + } else if (!fileInfo().exists()) { + flags |= SHGFI_USEFILEATTRIBUTES; + attributes |= FILE_ATTRIBUTE_NORMAL; + } + const bool val = shGetFileInfoBackground(path, attributes, &info, flags); // Even if GetFileInfo returns a valid result, hIcon can be empty in some cases if (val && info.hIcon) { -- cgit v1.2.3