From dd72ced367dbbdd5b7c775262ff2555debe69145 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 24 Jul 2013 11:53:17 +0100 Subject: Cleanup QFileIconProviderPrivate::getWinIcon(). No functionality is changed, just made the code more readable and removed some duplication. Needed to backport qtbase/46685f755b01288fd53c4483cb97a22c426a57f0. Code in Qt5 is already clean, no commit necessary there. Change-Id: I29fe871eeb0b45b619434e7941cc673033366f63 Reviewed-by: Friedemann Kleint --- src/gui/itemviews/qfileiconprovider.cpp | 41 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index 2808226..f1ad7e0 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -213,22 +213,19 @@ static bool isCacheable(const QFileInfo &fi) QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const { QIcon retIcon; - const QString fileExtension = QLatin1Char('.') + fileInfo.suffix().toUpper(); - QString key; - if (isCacheable(fileInfo)) - key = QLatin1String("qt_") + fileExtension; - QPixmap pixmap; - if (!key.isEmpty()) { + // If it's a file, non-{exe,lnk,ico} then we might have it cached already + if (isCacheable(fileInfo)) { + const QString fileExtension = QLatin1Char('.') + fileInfo.suffix().toUpper(); + key = QLatin1String("qt_") + fileExtension; QPixmapCache::find(key, pixmap); - } - - if (!pixmap.isNull()) { - retIcon.addPixmap(pixmap); - if (QPixmapCache::find(key + QLatin1Char('l'), pixmap)) + if (!pixmap.isNull()) { retIcon.addPixmap(pixmap); - return retIcon; + if (QPixmapCache::find(key + QLatin1Char('l'), pixmap)) + retIcon.addPixmap(pixmap); + return retIcon; + } } /* We don't use the variable, but by storing it statically, we @@ -240,14 +237,16 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const unsigned long val = 0; //Get the small icon + const unsigned int flags = #ifndef Q_OS_WINCE - val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), 0, &info, - sizeof(SHFILEINFO), SHGFI_ICON|SHGFI_SMALLICON|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX); + SHGFI_ICON|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX; #else - val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), 0, &info, - sizeof(SHFILEINFO), SHGFI_SMALLICON|SHGFI_SYSICONINDEX); + SHGFI_SYSICONINDEX; #endif + val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), + 0, &info, sizeof(SHFILEINFO), flags | SHGFI_SMALLICON); + // Even if GetFileInfo returns a valid result, hIcon can be empty in some cases if (val && info.hIcon) { if (fileInfo.isDir() && !fileInfo.isRoot()) { @@ -281,13 +280,9 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const } //Get the big icon -#ifndef Q_OS_WINCE - val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), 0, &info, - sizeof(SHFILEINFO), SHGFI_ICON|SHGFI_LARGEICON|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX); -#else - val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), 0, &info, - sizeof(SHFILEINFO), SHGFI_LARGEICON|SHGFI_SYSICONINDEX); -#endif + val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), + 0, &info, sizeof(SHFILEINFO), flags | SHGFI_LARGEICON); + if (val && info.hIcon) { if (fileInfo.isDir() && !fileInfo.isRoot()) { //using the unique icon index provided by windows save us from duplicate keys -- cgit v0.12