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 <gabriel.dedietrich@qt.io>
This commit is contained in:
Friedemann Kleint 2017-05-03 10:46:38 +02:00
parent fb78adf8df
commit 2300629df5

View File

@ -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) {