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 bb85baeb authored by Laurent Montel's avatar Laurent Montel 😁

Allow to clear cache

parent fe7d2e32
......@@ -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)
......@@ -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();
}
......@@ -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;
};
}
......
......@@ -96,4 +96,8 @@ void GravatarCache::setMaximumSize(int maximumSize)
}
}
void GravatarCache::clear()
{
mCachePixmap.clear();
}
......@@ -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;
......
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