Commit c0bd8890 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

When we import rules, we mustn't clear existing rules + add messagebox

when we imported 0 rules
parent 518bd9ec
......@@ -27,7 +27,7 @@ using namespace MessageViewer;
DKIMManagerRules::DKIMManagerRules(QObject *parent)
: QObject(parent)
{
loadRules();
(void)loadRules();
}
DKIMManagerRules::~DKIMManagerRules()
......@@ -64,12 +64,15 @@ QStringList DKIMManagerRules::ruleGroups(const KSharedConfig::Ptr &config) const
return config->groupList().filter(QRegularExpression(QStringLiteral("DKIM Rule #\\d+")));
}
void DKIMManagerRules::loadRules(const QString &fileName)
int DKIMManagerRules::loadRules(const QString &fileName)
{
const KSharedConfig::Ptr &config = KSharedConfig::openConfig(fileName.isEmpty() ? MessageViewer::DKIMUtil::defaultConfigFileName() : fileName, KConfig::NoGlobals);
const QStringList rulesGroups = ruleGroups(config);
mRules.clear();
if (fileName.isEmpty()) {
mRules.clear();
}
int numberOfRulesAdded = 0;
for (const QString &groupName : rulesGroups) {
KConfigGroup group = config->group(groupName);
const QStringList signedDomainIdentifier = group.readEntry(QLatin1String("SignedDomainIdentifier"), QStringList());
......@@ -85,8 +88,12 @@ void DKIMManagerRules::loadRules(const QString &fileName)
rule.setListId(listId);
rule.setSignedDomainIdentifier(signedDomainIdentifier);
rule.setRuleType(static_cast<DKIMRule::RuleType>(ruleType));
mRules.append(rule);
if (rule.isValid()) {
numberOfRulesAdded++;
mRules.append(rule);
}
}
return numberOfRulesAdded;
}
void DKIMManagerRules::saveRules(const QVector<DKIMRule> &lst)
......@@ -101,9 +108,9 @@ void DKIMManagerRules::clear()
save();
}
void DKIMManagerRules::importRules(const QString &fileName)
int DKIMManagerRules::importRules(const QString &fileName)
{
loadRules(fileName);
return loadRules(fileName);
}
void DKIMManagerRules::exportRules(const QString &fileName)
......
......@@ -46,12 +46,12 @@ public:
void clear();
void importRules(const QString &fileName);
Q_REQUIRED_RESULT int importRules(const QString &fileName);
void exportRules(const QString &fileName);
Q_REQUIRED_RESULT bool isEmpty() const;
private:
void loadRules(const QString &fileName = QString());
Q_REQUIRED_RESULT int loadRules(const QString &fileName = QString());
void save(const QString &fileName = QString());
Q_REQUIRED_RESULT QStringList ruleGroups(const KSharedConfig::Ptr &config) const;
QVector<DKIMRule> mRules;
......
......@@ -96,7 +96,9 @@ void DKIMManageRulesDialog::slotImport()
{
const QString fileName = QFileDialog::getOpenFileName(this, i18n("Import Rules"));
if (!fileName.isEmpty()) {
MessageViewer::DKIMManagerRules::self()->importRules(fileName);
if (MessageViewer::DKIMManagerRules::self()->importRules(fileName) == 0) {
KMessageBox::error(this, i18n("No rules imported."), i18n("Import Rules"));
}
}
}
......
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