diff options
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r-- | src/gui/itemviews/qfileiconprovider.cpp | 37 | ||||
-rw-r--r-- | src/gui/itemviews/qfileiconprovider.h | 1 | ||||
-rw-r--r-- | src/gui/itemviews/qfileiconprovider_p.h | 2 |
3 files changed, 36 insertions, 4 deletions
diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index f1ad7e0fc6..9fd9e9987d 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -89,10 +89,15 @@ QT_BEGIN_NAMESPACE */ QFileIconProviderPrivate::QFileIconProviderPrivate() : - homePath(QDir::home().absolutePath()) + homePath(QDir::home().absolutePath()), useCustomDirectoryIcons(true) { } +void QFileIconProviderPrivate::setUseCustomDirectoryIcons(bool enable) +{ + useCustomDirectoryIcons = enable; +} + QIcon QFileIconProviderPrivate::getIcon(QStyle::StandardPixmap name) const { switch (name) { @@ -213,6 +218,8 @@ static bool isCacheable(const QFileInfo &fi) QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const { QIcon retIcon; + static int defaultFolderIIcon = -1; + QString key; QPixmap pixmap; // If it's a file, non-{exe,lnk,ico} then we might have it cached already @@ -228,6 +235,19 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const } } + const bool cacheableDirIcon = fileInfo.isDir() && !fileInfo.isRoot(); + if (!useCustomDirectoryIcons && defaultFolderIIcon >= 0 && cacheableDirIcon) { + // We already have the default folder icon, just return it + key = QString::fromLatin1("qt_dir_%1").arg(defaultFolderIIcon); + QPixmapCache::find(key, pixmap); + if (!pixmap.isNull()) { + retIcon.addPixmap(pixmap); + if (QPixmapCache::find(key + QLatin1Char('l'), pixmap)) + retIcon.addPixmap(pixmap); + return retIcon; + } + } + /* We don't use the variable, but by storing it statically, we * ensure CoInitialize is only called once. */ static HRESULT comInit = CoInitialize(NULL); @@ -237,19 +257,28 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const unsigned long val = 0; //Get the small icon - const unsigned int flags = + unsigned int flags = #ifndef Q_OS_WINCE SHGFI_ICON|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX; #else SHGFI_SYSICONINDEX; #endif - val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(), - 0, &info, sizeof(SHFILEINFO), flags | SHGFI_SMALLICON); + if (cacheableDirIcon && !useCustomDirectoryIcons) { + flags |= SHGFI_USEFILEATTRIBUTES; + val = SHGetFileInfo(L"dummy", + FILE_ATTRIBUTE_DIRECTORY, &info, + sizeof(SHFILEINFO), flags | SHGFI_SMALLICON); + } else { + 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()) { + if (!useCustomDirectoryIcons && defaultFolderIIcon < 0) + defaultFolderIIcon = info.iIcon; //using the unique icon index provided by windows save us from duplicate keys key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon); QPixmapCache::find(key, pixmap); diff --git a/src/gui/itemviews/qfileiconprovider.h b/src/gui/itemviews/qfileiconprovider.h index 2ae4e81e86..3c98562313 100644 --- a/src/gui/itemviews/qfileiconprovider.h +++ b/src/gui/itemviews/qfileiconprovider.h @@ -70,6 +70,7 @@ private: Q_DECLARE_PRIVATE(QFileIconProvider) QScopedPointer<QFileIconProviderPrivate> d_ptr; Q_DISABLE_COPY(QFileIconProvider) + friend class QFileDialog; }; #endif // QT_NO_FILEICONPROVIDER diff --git a/src/gui/itemviews/qfileiconprovider_p.h b/src/gui/itemviews/qfileiconprovider_p.h index 704418b589..a44ae51180 100644 --- a/src/gui/itemviews/qfileiconprovider_p.h +++ b/src/gui/itemviews/qfileiconprovider_p.h @@ -57,6 +57,7 @@ class QFileIconProviderPrivate public: QFileIconProviderPrivate(); + void setUseCustomDirectoryIcons(bool enable); QIcon getIcon(QStyle::StandardPixmap name) const; #ifdef Q_WS_WIN QIcon getWinIcon(const QFileInfo &fi) const; @@ -67,6 +68,7 @@ public: const QString homePath; private: + bool useCustomDirectoryIcons; mutable QIcon file; mutable QIcon fileLink; mutable QIcon directory; |