summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-05-15 15:01:52 +0200
committerMontel Laurent <[email protected]>2015-05-15 15:02:11 +0200
commitbb85baeb1816ca245a594990dffa1f9a2113e51c (patch)
treeee17b33d182051bd08418ee61b2d19afb0f31edd
parentfe7d2e32277627f639383ad389e9ce009e59236d (diff)
Allow to clear cache
-rw-r--r--messageviewer/tests/gravatarconfigwidgettest.cpp3
-rw-r--r--messageviewer/widgets/gravatarconfigwidget.cpp31
-rw-r--r--messageviewer/widgets/gravatarconfigwidget.h5
-rw-r--r--pimcommon/gravatar/gravatarcache.cpp4
-rw-r--r--pimcommon/gravatar/gravatarcache.h6
5 files changed, 47 insertions, 2 deletions
diff --git a/messageviewer/tests/gravatarconfigwidgettest.cpp b/messageviewer/tests/gravatarconfigwidgettest.cpp
index 7045934..6a920f0 100644
--- a/messageviewer/tests/gravatarconfigwidgettest.cpp
+++ b/messageviewer/tests/gravatarconfigwidgettest.cpp
@@ -18,6 +18,7 @@
#include "gravatarconfigwidgettest.h"
#include "../widgets/gravatarconfigwidget.h"
#include <QCheckBox>
+#include <QPushButton>
#include <qtest_kde.h>
GravatarConfigWidgetTest::GravatarConfigWidgetTest(QObject *parent)
@@ -40,6 +41,8 @@ void GravatarConfigWidgetTest::shouldHaveDefaultValue()
QCheckBox *useDefaultImage = qFindChild<QCheckBox *>(&w, QLatin1String("usedefaultimage"));
QVERIFY(useDefaultImage);
+ QPushButton *clearGravatarCache = qFindChild<QPushButton *>(&w, QLatin1String("cleargravatarcachebutton"));
+ QVERIFY(clearGravatarCache);
}
QTEST_KDEMAIN(GravatarConfigWidgetTest, GUI)
diff --git a/messageviewer/widgets/gravatarconfigwidget.cpp b/messageviewer/widgets/gravatarconfigwidget.cpp
index 1fd3a5e..977c918 100644
--- a/messageviewer/widgets/gravatarconfigwidget.cpp
+++ b/messageviewer/widgets/gravatarconfigwidget.cpp
@@ -16,10 +16,15 @@
*/
#include "gravatarconfigwidget.h"
-
+#include "pimcommon/gravatar/gravatarcache.h"
+#include <QDebug>
+#include <KStandardDirs>
#include <QVBoxLayout>
#include <KLocalizedString>
#include <QCheckBox>
+#include <QPushButton>
+#include <KGlobal>
+#include <QDir>
#include "settings/globalsettings.h"
#include "pimcommon/widgets/configureimmutablewidgetutils.h"
@@ -43,6 +48,15 @@ GravatarConfigWidget::GravatarConfigWidget(QWidget *parent)
mUseDefaultPixmap->setObjectName(QLatin1String("usedefaultimage"));
mainLayout->addWidget(mUseDefaultPixmap);
+ //KF5 add i18n
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ mainLayout->addLayout(buttonLayout);
+ mClearGravatarCache = new QPushButton(QLatin1String("Clear Gravatar Cache"));
+ mClearGravatarCache->setObjectName(QLatin1String("cleargravatarcachebutton"));
+ buttonLayout->addWidget(mClearGravatarCache);
+ buttonLayout->addStretch();
+
+ connect(mClearGravatarCache, SIGNAL(clicked(bool)), this, SLOT(slotClearGravatarCache()));
connect(mUseDefaultPixmap, SIGNAL(clicked(bool)), SIGNAL(configChanged(bool)));
connect(mEnableGravatarSupport, SIGNAL(clicked(bool)), SIGNAL(configChanged(bool)));
}
@@ -71,3 +85,18 @@ void GravatarConfigWidget::doResetToDefaultsOther()
GlobalSettings::self()->useDefaults( bUseDefaults );
}
+void GravatarConfigWidget::slotClearGravatarCache()
+{
+ const QString path = KGlobal::dirs()->locateLocal("data", QLatin1String("gravatar/"));
+ if (!path.isEmpty()) {
+ QDir dir(path);
+ if (dir.exists()) {
+ QFileInfoList list = dir.entryInfoList(); // get list of matching files and delete all
+ QFileInfo it;
+ Q_FOREACH( it, list ) {
+ dir.remove(it.fileName());
+ }
+ }
+ }
+ PimCommon::GravatarCache::self()->clear();
+}
diff --git a/messageviewer/widgets/gravatarconfigwidget.h b/messageviewer/widgets/gravatarconfigwidget.h
index edf813c..12c5cb3 100644
--- a/messageviewer/widgets/gravatarconfigwidget.h
+++ b/messageviewer/widgets/gravatarconfigwidget.h
@@ -21,6 +21,7 @@
#include <QWidget>
#include "messageviewer_export.h"
class QCheckBox;
+class QPushButton;
namespace MessageViewer {
class MESSAGEVIEWER_EXPORT GravatarConfigWidget : public QWidget
{
@@ -36,9 +37,13 @@ public:
Q_SIGNALS:
void configChanged(bool);
+private Q_SLOTS:
+ void slotClearGravatarCache();
+
private:
QCheckBox *mEnableGravatarSupport;
QCheckBox *mUseDefaultPixmap;
+ QPushButton *mClearGravatarCache;
};
}
diff --git a/pimcommon/gravatar/gravatarcache.cpp b/pimcommon/gravatar/gravatarcache.cpp
index 1ed233f..ecb9a9a 100644
--- a/pimcommon/gravatar/gravatarcache.cpp
+++ b/pimcommon/gravatar/gravatarcache.cpp
@@ -96,4 +96,8 @@ void GravatarCache::setMaximumSize(int maximumSize)
}
}
+void GravatarCache::clear()
+{
+ mCachePixmap.clear();
+}
diff --git a/pimcommon/gravatar/gravatarcache.h b/pimcommon/gravatar/gravatarcache.h
index 37ca8d0..60b8c80 100644
--- a/pimcommon/gravatar/gravatarcache.h
+++ b/pimcommon/gravatar/gravatarcache.h
@@ -18,10 +18,13 @@
#ifndef GRAVATARCACHE_H
#define GRAVATARCACHE_H
+#include "pimcommon_export.h"
+
#include <QPixmap>
#include <QCache>
+
namespace PimCommon {
-class GravatarCache
+class PIMCOMMON_EXPORT GravatarCache
{
public:
static GravatarCache *self();
@@ -37,6 +40,7 @@ public:
int maximumSize() const;
void setMaximumSize(int maximumSize);
+ void clear();
private:
QCache<QString, QPixmap> mCachePixmap;
int mMaximumSize;