summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-07-16 07:37:39 (GMT)
committerNorwegian Rock Cat <qt-info@nokia.com>2009-07-16 07:43:44 (GMT)
commit8734464e27b7a3fadb1adeefc3971d8a1e5103bd (patch)
treebadca715a7a2330ad08ac0c5aa4f2a76713f4b99
parenta4b88269aae0e546580a7ad6a20866cc582afd41 (diff)
downloadQt-8734464e27b7a3fadb1adeefc3971d8a1e5103bd.zip
Qt-8734464e27b7a3fadb1adeefc3971d8a1e5103bd.tar.gz
Qt-8734464e27b7a3fadb1adeefc3971d8a1e5103bd.tar.bz2
Better caching of file system icon providers.
It turns out that we weren't doing any caching of icons provided by the file system. We now use the similar trick that's used on Windows which does some caching on the file extension. We do fill up the cache needlessly with extra information (16, 32, 64, and 128) icons. We probably could be better with a iconRef engine that generates these sizes on demand. Still performance is 100% better with this which means using it in itemviews works. Reviewed-by: Jens Bache-Wiig
-rw-r--r--src/gui/itemviews/qfileiconprovider.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp
index ed663b3..6338e49 100644
--- a/src/gui/itemviews/qfileiconprovider.cpp
+++ b/src/gui/itemviews/qfileiconprovider.cpp
@@ -45,11 +45,11 @@
#include <qstyle.h>
#include <qapplication.h>
#include <qdir.h>
+#include <qpixmapcache.h>
#if defined(Q_WS_WIN)
#define _WIN32_IE 0x0500
#include <objbase.h>
#include <private/qpixmapdata_p.h>
-#include <qpixmapcache.h>
#elif defined(Q_WS_MAC)
#include <private/qt_mac_p.h>
#endif
@@ -316,6 +316,31 @@ QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const
QIcon QFileIconProviderPrivate::getMacIcon(const QFileInfo &fi) const
{
QIcon retIcon;
+ QString fileExtension = fi.suffix().toUpper();
+ fileExtension.prepend(QLatin1String("."));
+
+ const QString keyBase = QLatin1String("qt_") + fileExtension;
+
+ QPixmap pixmap;
+ if (fi.isFile() && !fi.isExecutable() && !fi.isSymLink()) {
+ QPixmapCache::find(keyBase + QLatin1String("16"), pixmap);
+ }
+
+ if (!pixmap.isNull()) {
+ retIcon.addPixmap(pixmap);
+ if (QPixmapCache::find(keyBase + QLatin1String("32"), pixmap)) {
+ retIcon.addPixmap(pixmap);
+ if (QPixmapCache::find(keyBase + QLatin1String("64"), pixmap)) {
+ retIcon.addPixmap(pixmap);
+ if (QPixmapCache::find(keyBase + QLatin1String("128"), pixmap)) {
+ retIcon.addPixmap(pixmap);
+ return retIcon;
+ }
+ }
+ }
+ }
+
+
FSRef macRef;
OSStatus status = FSPathMakeRef(reinterpret_cast<const UInt8*>(fi.canonicalFilePath().toUtf8().constData()),
&macRef, 0);
@@ -334,6 +359,16 @@ QIcon QFileIconProviderPrivate::getMacIcon(const QFileInfo &fi) const
extern void qt_mac_constructQIconFromIconRef(const IconRef, const IconRef, QIcon*, QStyle::StandardPixmap = QStyle::SP_CustomBase); // qmacstyle_mac.cpp
qt_mac_constructQIconFromIconRef(iconRef, 0, &retIcon);
ReleaseIconRef(iconRef);
+
+ pixmap = retIcon.pixmap(16);
+ QPixmapCache::insert(keyBase + QLatin1String("16"), pixmap);
+ pixmap = retIcon.pixmap(32);
+ QPixmapCache::insert(keyBase + QLatin1String("32"), pixmap);
+ pixmap = retIcon.pixmap(64);
+ QPixmapCache::insert(keyBase + QLatin1String("64"), pixmap);
+ pixmap = retIcon.pixmap(128);
+ QPixmapCache::insert(keyBase + QLatin1String("128"), pixmap);
+
return retIcon;
}
#endif