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

Reduce duplicate code

parent fc686c0c
Pipeline #22346 passed with stage
in 42 minutes and 51 seconds
...@@ -80,11 +80,18 @@ QVector<KeyInfo> DKIMManagerKey::keys() const ...@@ -80,11 +80,18 @@ QVector<KeyInfo> DKIMManagerKey::keys() const
return mKeys; return mKeys;
} }
void DKIMManagerKey::loadKeys() QStringList DKIMManagerKey::keyRecorderList(KSharedConfig::Ptr &config) const
{ {
const KSharedConfig::Ptr &config = KSharedConfig::openConfig(MessageViewer::DKIMUtil::defaultConfigFileName(), KConfig::NoGlobals); config = KSharedConfig::openConfig(MessageViewer::DKIMUtil::defaultConfigFileName(), KConfig::NoGlobals);
const QStringList keyGroups const QStringList keyGroups
= config->groupList().filter(QRegularExpression(QStringLiteral("DKIM Key Record #\\d+"))); = config->groupList().filter(QRegularExpression(QStringLiteral("DKIM Key Record #\\d+")));
return keyGroups;
}
void DKIMManagerKey::loadKeys()
{
KSharedConfig::Ptr config;
const QStringList keyGroups = keyRecorderList(config);
mKeys.clear(); mKeys.clear();
for (const QString &groupName : keyGroups) { for (const QString &groupName : keyGroups) {
...@@ -98,9 +105,8 @@ void DKIMManagerKey::loadKeys() ...@@ -98,9 +105,8 @@ void DKIMManagerKey::loadKeys()
void DKIMManagerKey::saveKeys() void DKIMManagerKey::saveKeys()
{ {
const KSharedConfig::Ptr &config = KSharedConfig::openConfig(MessageViewer::DKIMUtil::defaultConfigFileName(), KConfig::NoGlobals); KSharedConfig::Ptr config;
const QStringList filterGroups const QStringList filterGroups = keyRecorderList(config);
= config->groupList().filter(QRegularExpression(QStringLiteral("DKIM Key Record #\\d+")));
for (const QString &group : filterGroups) { for (const QString &group : filterGroups) {
config->deleteGroup(group); config->deleteGroup(group);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "messageviewer_export.h" #include "messageviewer_export.h"
#include "config-messageviewer.h" #include "config-messageviewer.h"
#include <QVector> #include <QVector>
#include <KSharedConfig>
namespace QCA { namespace QCA {
class Initializer; class Initializer;
} }
...@@ -75,6 +76,7 @@ public: ...@@ -75,6 +76,7 @@ public:
void saveKeys(); void saveKeys();
Q_REQUIRED_RESULT QString keyValue(const QString &selector, const QString &domain); Q_REQUIRED_RESULT QString keyValue(const QString &selector, const QString &domain);
private: private:
Q_REQUIRED_RESULT QStringList keyRecorderList(KSharedConfig::Ptr &config) const;
QVector<KeyInfo> mKeys; QVector<KeyInfo> mKeys;
QCA::Initializer *mQcaInitializer = nullptr; QCA::Initializer *mQcaInitializer = nullptr;
}; };
......
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