summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-05-15 07:12:01 +0200
committerMontel Laurent <[email protected]>2015-05-15 07:12:01 +0200
commitfce4a88557e1f8cc0d32f4a549a6658f298f4ba2 (patch)
tree5ba4bb63c8eee6d0192f2dbc96bb143b7ef78a28
parent4373cd1f4d324c0908f6dc925ef7d48ae3c34fd4 (diff)
Use QCache .
Thanks David to show me this class
-rw-r--r--pimcommon/gravatar/gravatarcache.cpp15
-rw-r--r--pimcommon/gravatar/gravatarcache.h4
2 files changed, 11 insertions, 8 deletions
diff --git a/pimcommon/gravatar/gravatarcache.cpp b/pimcommon/gravatar/gravatarcache.cpp
index 8553ede..1ed233f 100644
--- a/pimcommon/gravatar/gravatarcache.cpp
+++ b/pimcommon/gravatar/gravatarcache.cpp
@@ -26,9 +26,9 @@ using namespace PimCommon;
K_GLOBAL_STATIC( GravatarCache, s_gravatarCache )
GravatarCache::GravatarCache()
- : mMaximumSize(0)
+ : mMaximumSize(30)
{
-
+ mCachePixmap.setMaxCost(mMaximumSize);
}
GravatarCache::~GravatarCache()
@@ -49,7 +49,7 @@ void GravatarCache::saveGravatarPixmap(const QString &hashStr, const QPixmap &pi
//qDebug() << " path " << path;
if (pixmap.save(path)) {
//qDebug() <<" saved in cache "<< hashStr << path;
- mCachePixmap.insert(hashStr, pixmap);
+ mCachePixmap.insert(hashStr, new QPixmap(pixmap));
}
}
}
@@ -63,7 +63,7 @@ QPixmap GravatarCache::loadGravatarPixmap(const QString &hashStr, bool &gravatar
if (mCachePixmap.contains(hashStr)) {
//qDebug()<<" contains in cache "<< hashStr;
gravatarStored = true;
- return mCachePixmap.value(hashStr);
+ return *(mCachePixmap.object(hashStr));
} else {
const QString path = KGlobal::dirs()->locateLocal("data", QLatin1String("gravatar/") + hashStr + QLatin1String(".png"));
QFileInfo fi(path);
@@ -71,7 +71,7 @@ QPixmap GravatarCache::loadGravatarPixmap(const QString &hashStr, bool &gravatar
QPixmap pix;
if (pix.load(path)) {
//qDebug() << " add to cache "<<hashStr << path;
- mCachePixmap.insert(hashStr, pix);
+ mCachePixmap.insert(hashStr, new QPixmap(pix));
gravatarStored = true;
return pix;
}
@@ -90,7 +90,10 @@ int GravatarCache::maximumSize() const
void GravatarCache::setMaximumSize(int maximumSize)
{
- mMaximumSize = maximumSize;
+ if (mMaximumSize != maximumSize) {
+ mMaximumSize = maximumSize;
+ mCachePixmap.setMaxCost(mMaximumSize);
+ }
}
diff --git a/pimcommon/gravatar/gravatarcache.h b/pimcommon/gravatar/gravatarcache.h
index 259a095..37ca8d0 100644
--- a/pimcommon/gravatar/gravatarcache.h
+++ b/pimcommon/gravatar/gravatarcache.h
@@ -19,7 +19,7 @@
#define GRAVATARCACHE_H
#include <QPixmap>
-#include <QHash>
+#include <QCache>
namespace PimCommon {
class GravatarCache
{
@@ -38,7 +38,7 @@ public:
void setMaximumSize(int maximumSize);
private:
- QHash<QString, QPixmap> mCachePixmap;
+ QCache<QString, QPixmap> mCachePixmap;
int mMaximumSize;
};
}