Commit 09ba0534 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add load/save rule

parent 3bd070fd
Pipeline #68248 canceled with stage
......@@ -6,6 +6,10 @@
#include "confirmbeforedeletingmanager.h"
#include "confirmbeforedeletingrule.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <QRegularExpression>
ConfirmBeforeDeletingManager::ConfirmBeforeDeletingManager(QObject *parent)
: QObject(parent)
{
......@@ -21,13 +25,44 @@ ConfirmBeforeDeletingManager *ConfirmBeforeDeletingManager::self()
return &s_self;
}
QString ConfirmBeforeDeletingManager::defaultConfigFileName() const
{
return QStringLiteral("confirmbeforedeletingrc");
}
void ConfirmBeforeDeletingManager::loadRules()
{
// TODO
const KSharedConfig::Ptr &config = KSharedConfig::openConfig(defaultConfigFileName(), KConfig::NoGlobals);
const QStringList rulesGroups = ruleGroups(config);
mRules.clear();
for (const QString &groupName : rulesGroups) {
ConfirmBeforeDeletingRule r;
KConfigGroup group = config->group(groupName);
r.load(group);
mRules.append(r);
}
}
QStringList ConfirmBeforeDeletingManager::ruleGroups(const KSharedConfig::Ptr &config) const
{
return config->groupList().filter(QRegularExpression(QStringLiteral("Confirm Deleting Rule #\\d+")));
}
void ConfirmBeforeDeletingManager::saveRules()
{
const KSharedConfig::Ptr &config = KSharedConfig::openConfig(defaultConfigFileName(), KConfig::NoGlobals);
const QStringList rulesGroups = ruleGroups(config);
for (const QString &group : rulesGroups) {
config->deleteGroup(group);
}
for (int i = 0, total = mRules.count(); i < total; ++i) {
const QString groupName = QStringLiteral("DKIM Rule #%1").arg(i);
KConfigGroup group = config->group(groupName);
const ConfirmBeforeDeletingRule &rule = mRules.at(i);
rule.save(); // TODO
}
for (const auto &r : qAsConst(mRules)) {
// TODO
// r.save();
......
......@@ -9,6 +9,7 @@
#include "confirmbeforedeletingrule.h"
#include "kmailconfirmbeforedeleting_export.h"
#include <AkonadiCore/Item>
#include <KSharedConfig>
#include <QObject>
#include <QVector>
......@@ -27,5 +28,7 @@ public:
Q_REQUIRED_RESULT bool deletingNeedToConfirm(const Akonadi::Item &list) const;
private:
Q_REQUIRED_RESULT QString defaultConfigFileName() const;
Q_REQUIRED_RESULT QStringList ruleGroups(const KSharedConfig::Ptr &config) const;
QVector<ConfirmBeforeDeletingRule> mRules;
};
......@@ -35,6 +35,19 @@ void ConfirmBeforeDeletingRule::setRuleType(RuleType newRuleType)
mRuleType = newRuleType;
}
void ConfirmBeforeDeletingRule::load(const KConfigGroup &group)
{
const QString pattern = group.readEntry(QStringLiteral("Pattern"), QString());
const QString checkType = group.readEntry(QStringLiteral("Type"), QString());
setPattern(pattern);
// TODO setRuleType();
}
void ConfirmBeforeDeletingRule::save() const
{
// TODO
}
bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item) const
{
bool needToConfirm = false;
......
......@@ -7,6 +7,7 @@
#pragma once
#include "kmailconfirmbeforedeleting_export.h"
#include <AkonadiCore/Item>
#include <KConfigGroup>
#include <QDebug>
#include <QString>
class KMAILCONFIRMBEFOREDELETING_EXPORT ConfirmBeforeDeletingRule
......@@ -28,15 +29,14 @@ public:
Q_REQUIRED_RESULT const QString &pattern() const;
void setPattern(const QString &newPattern);
void save();
void load();
// TODO save/Load
Q_REQUIRED_RESULT RuleType ruleType() const;
void setRuleType(RuleType newRuleType);
Q_REQUIRED_RESULT bool deletingNeedToConfirm(const Akonadi::Item &item) const;
void save() const;
void load(const KConfigGroup &group);
private:
QString mPattern;
RuleType mRuleType = RuleType::Unknown;
......
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