Commit 7a8a6291 authored by Laurent Montel's avatar Laurent Montel 😁

We need to store akonadiCollection

parent 6a1a3294
......@@ -17,6 +17,7 @@
#include "filterimporterpathcachetest.h"
#include "../filterimporterpathcache.h"
#include <AkonadiCore/Collection>
#include <QTest>
QTEST_MAIN(FilterImporterPathCacheTest)
......@@ -36,44 +37,44 @@ void FilterImporterPathCacheTest::shouldReturnEmptyStringWhenListIsEmpty()
{
MailCommon::FilterImporterPathCache cache;
QCOMPARE(cache.count(), 0);
QVERIFY(cache.convertedFilterPath(QStringLiteral("dd")).isEmpty());
QVERIFY(!cache.convertedFilterPath(QStringLiteral("foo")).isValid());
QCOMPARE(cache.count(), 0);
}
void FilterImporterPathCacheTest::shouldNotStoreEmptyValue()
{
MailCommon::FilterImporterPathCache cache;
cache.insert(QString(), QStringLiteral("foo"));
cache.insert(QString(), Akonadi::Collection(3));
QCOMPARE(cache.count(), 0);
cache.insert(QStringLiteral("foo"), QString());
cache.insert(QStringLiteral("foo"), Akonadi::Collection(-1));
QCOMPARE(cache.count(), 0);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
QCOMPARE(cache.count(), 1);
}
void FilterImporterPathCacheTest::shouldNotDuplicateEntries()
{
MailCommon::FilterImporterPathCache cache;
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo"));
cache.insert(QStringLiteral("foo1"), Akonadi::Collection(3));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo2"));
cache.insert(QStringLiteral("foo1"), Akonadi::Collection(4));
QCOMPARE(cache.count(), 1);
cache.insert(QStringLiteral("foo1"), QStringLiteral("foo3"));
cache.insert(QStringLiteral("foo1"), Akonadi::Collection(4));
QCOMPARE(cache.count(), 1);
//Add new one
cache.insert(QStringLiteral("foo2"), QStringLiteral("foo3"));
cache.insert(QStringLiteral("foo2"), Akonadi::Collection(4));
QCOMPARE(cache.count(), 2);
}
......@@ -82,12 +83,12 @@ void FilterImporterPathCacheTest::shouldReturnValues()
{
MailCommon::FilterImporterPathCache cache;
QString key = QStringLiteral("foo1");
QString cached = QStringLiteral("foo");
Akonadi::Collection cached = Akonadi::Collection(3);
cache.insert(key, cached);
QCOMPARE(cache.convertedFilterPath(key), cached);
//Use value in same key
cached = QStringLiteral("foo5");
cached = Akonadi::Collection(5);
cache.insert(key, cached);
QCOMPARE(cache.convertedFilterPath(key), cached);
}
......@@ -40,16 +40,16 @@ int FilterImporterPathCache::count() const
return mFilterCache.count();
}
void FilterImporterPathCache::insert(const QString &original, const QString &newValue)
void FilterImporterPathCache::insert(const QString &original, const Akonadi::Collection &newValue)
{
if (original.isEmpty() || newValue.isEmpty()) {
if (original.isEmpty() || !newValue.isValid()) {
return;
}
mFilterCache.insert(original, newValue);
}
QString FilterImporterPathCache::convertedFilterPath(const QString &original)
Akonadi::Collection FilterImporterPathCache::convertedFilterPath(const QString &original)
{
return mFilterCache.value(original);
}
......
......@@ -20,6 +20,7 @@
#include <QObject>
#include <QHash>
#include <AkonadiCore/Collection>
namespace MailCommon
{
class FilterImporterPathCache : public QObject
......@@ -31,12 +32,12 @@ public:
explicit FilterImporterPathCache(QObject *parent = nullptr);
~FilterImporterPathCache();
void insert(const QString &original, const QString &newValue);
QString convertedFilterPath(const QString &original);
void insert(const QString &original, const Akonadi::Collection &newValue);
Akonadi::Collection convertedFilterPath(const QString &original);
void clear();
int count() const;
private:
QHash<QString, QString> mFilterCache;
QHash<QString, Akonadi::Collection> mFilterCache;
};
}
......
......@@ -24,6 +24,7 @@
#include "mailcommon_debug.h"
#include "kmfilterlistbox.h"
#include "filterimporterpathcache.h"
#include "filteractions/filteractiondict.h"
#include "filteractions/filteractionwidget.h"
#include "filterimporterexporter.h"
......@@ -714,6 +715,7 @@ void KMFilterDialog::slotImportFilter(QAction *act)
void KMFilterDialog::importFilters(MailCommon::FilterImporterExporter::FilterType type)
{
MailCommon::FilterImporterPathCache::self()->clear();
FilterImporterExporter importer(this);
bool canceled = false;
QList<MailFilter *> filters = importer.importFilters(canceled, type);
......
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