Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit fce4a885 authored by Laurent Montel's avatar Laurent Montel 😁

Use QCache .

Thanks David to show me this class
parent 4373cd1f
......@@ -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);
}
}
......@@ -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;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment