summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
authorSergio Martins <sergio.martins@kdab.com>2013-07-24 11:53:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-25 23:19:35 +0200
commitdd72ced367dbbdd5b7c775262ff2555debe69145 (patch)
tree2f37e7c098691949d887bbaafdd61b7c31870223 /src/gui/itemviews
parented4ef3d23142bd23d62f44babee074d0a102c72f (diff)
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 <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qfileiconprovider.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp
index 2808226fe2..f1ad7e0fc6 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