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

Load/save info from identity

parent 34773046
......@@ -11,11 +11,11 @@ macro(add_kmail_confirmaddress_unittest _source _additional)
target_link_libraries( ${_name} Qt5::Test KF5::IconThemes KF5::MessageComposer KF5::I18n KF5::PimCommon)
endmacro ()
add_kmail_confirmaddress_unittest(confirmaddressplugintest.cpp "../confirmaddressplugin.cpp;../confirmaddressinterface.cpp;../confirmaddressconfigurewidget.cpp;../confirmaddressdialog.cpp;../confirmaddresswidget.cpp;../confirmaddressconfiguretab.cpp")
add_kmail_confirmaddress_unittest(confirmaddressplugintest.cpp "../confirmaddressplugin.cpp;../confirmaddressinterface.cpp;../confirmaddressconfigurewidget.cpp;../confirmaddressdialog.cpp;../confirmaddresswidget.cpp;../confirmaddressconfiguretab.cpp;../confirmaddressconfiguretabwidget.cpp")
add_kmail_confirmaddress_unittest(confirmaddressinterfacetest.cpp "../confirmaddressinterface.cpp;../confirmaddressconfigurewidget.cpp;../confirmaddressdialog.cpp;../confirmaddresswidget.cpp;../confirmaddressconfiguretab.cpp")
add_kmail_confirmaddress_unittest(confirmaddressinterfacetest.cpp "../confirmaddressinterface.cpp;../confirmaddressconfigurewidget.cpp;../confirmaddressdialog.cpp;../confirmaddresswidget.cpp;../confirmaddressconfiguretab.cpp;../confirmaddressconfiguretabwidget.cpp")
add_kmail_confirmaddress_unittest(confirmaddressconfigurewidgettest.cpp "../confirmaddressconfigurewidget.cpp;../confirmaddressconfiguretab.cpp")
add_kmail_confirmaddress_unittest(confirmaddressconfigurewidgettest.cpp "../confirmaddressconfigurewidget.cpp;../confirmaddressconfiguretab.cpp;../confirmaddressconfiguretabwidget.cpp")
add_kmail_confirmaddress_unittest(confirmaddressdialogtest.cpp "../confirmaddressdialog.cpp;../confirmaddresswidget.cpp")
......@@ -23,4 +23,4 @@ add_kmail_confirmaddress_unittest(confirmaddresswidgettest.cpp "../confirmaddres
add_kmail_confirmaddress_unittest(confirmaddressconfiguretabwidgettest.cpp "../confirmaddressconfiguretabwidget.cpp")
add_kmail_confirmaddress_unittest(confirmaddressconfiguretabtest.cpp "../confirmaddressconfiguretab.cpp")
add_kmail_confirmaddress_unittest(confirmaddressconfiguretabtest.cpp "../confirmaddressconfiguretab.cpp;../confirmaddressconfiguretabwidget.cpp")
......@@ -19,9 +19,11 @@
#include "confirmaddressconfiguretab.h"
#include "confirmaddressconfiguretabwidget.h"
#include <QVBoxLayout>
#include <QTabWidget>
#include <KIdentityManagement/IdentityManager>
#include <KIdentityManagement/Identity>
ConfirmAddressConfigureTab::ConfirmAddressConfigureTab(QWidget *parent)
: QWidget(parent)
......@@ -42,24 +44,36 @@ ConfirmAddressConfigureTab::~ConfirmAddressConfigureTab()
}
void ConfirmAddressConfigureTab::loadSettings()
void ConfirmAddressConfigureTab::loadSettings(const KConfigGroup &grp)
{
Q_FOREACH (ConfirmAddressConfigureTabWidget *w, mListTabWidget) {
w->loadSettings(grp);
}
}
void ConfirmAddressConfigureTab::saveSettings()
void ConfirmAddressConfigureTab::saveSettings(KConfigGroup &grp)
{
Q_FOREACH (ConfirmAddressConfigureTabWidget *w, mListTabWidget) {
w->saveSettings(grp);
}
}
void ConfirmAddressConfigureTab::resetSettings()
{
Q_FOREACH (ConfirmAddressConfigureTabWidget *w, mListTabWidget) {
w->resetSettings();
}
}
void ConfirmAddressConfigureTab::initTab()
{
//KIdentityManagement::IdentityManager manager(true);
//TODO
KIdentityManagement::IdentityManager manager(true);
KIdentityManagement::IdentityManager::ConstIterator end = manager.end();
for (KIdentityManagement::IdentityManager::ConstIterator it = manager.begin(); it != end; ++it) {
ConfirmAddressConfigureTabWidget *w = new ConfirmAddressConfigureTabWidget(this);
connect(w, &ConfirmAddressConfigureTabWidget::configureChanged, this, &ConfirmAddressConfigureTab::configureChanged);
mTabWidget->addTab(w, (*it).identityName());
w->setIdentity((*it).uoid());
mListTabWidget.append(w);
}
}
......@@ -23,7 +23,8 @@
#include <QWidget>
class QTabWidget;
class KConfigGroup;
class ConfirmAddressConfigureTabWidget;
class ConfirmAddressConfigureTab : public QWidget
{
Q_OBJECT
......@@ -31,8 +32,8 @@ public:
explicit ConfirmAddressConfigureTab(QWidget *parent = Q_NULLPTR);
~ConfirmAddressConfigureTab();
void loadSettings();
void saveSettings();
void loadSettings(const KConfigGroup &grp);
void saveSettings(KConfigGroup &grp);
void resetSettings();
Q_SIGNALS:
......@@ -41,6 +42,7 @@ Q_SIGNALS:
private:
void initTab();
QTabWidget *mTabWidget;
QList<ConfirmAddressConfigureTabWidget *> mListTabWidget;
};
#endif // CONFIRMADDRESSCONFIGURETAB_H
......@@ -18,6 +18,7 @@
*/
#include "confirmaddressconfiguretabwidget.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <QGroupBox>
#include <QVBoxLayout>
......@@ -79,3 +80,22 @@ void ConfirmAddressConfigureTabWidget::resetSettings()
mDomainNameListEditor->setStringList({});
mWhiteListEditor->setStringList({});
}
void ConfirmAddressConfigureTabWidget::loadSettings(const KConfigGroup &grp)
{
KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(mIdentity));
mDomainNameListEditor->setStringList(identityGroup.readEntry("Domains", QStringList()));
mWhiteListEditor->setStringList(identityGroup.readEntry("Emails", QStringList()));
}
void ConfirmAddressConfigureTabWidget::saveSettings(KConfigGroup &grp)
{
KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(mIdentity));
identityGroup.writeEntry("Domains", mDomainNameListEditor->stringList());
identityGroup.writeEntry("Emails", mWhiteListEditor->stringList());
}
void ConfirmAddressConfigureTabWidget::setIdentity(const uint &identity)
{
mIdentity = identity;
}
......@@ -26,6 +26,7 @@ namespace PimCommon
class SimpleStringListEditor;
}
class QTabWidget;
class KConfigGroup;
class ConfirmAddressConfigureTabWidget : public QWidget
{
Q_OBJECT
......@@ -34,6 +35,11 @@ public:
~ConfirmAddressConfigureTabWidget();
void resetSettings();
void loadSettings(const KConfigGroup &grp);
void saveSettings(KConfigGroup &grp);
void setIdentity(const uint &identity);
Q_SIGNALS:
void configureChanged();
......
......@@ -24,6 +24,7 @@
#include <QVBoxLayout>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QRegularExpression>
ConfirmAddressConfigureWidget::ConfirmAddressConfigureWidget(QWidget *parent)
: MessageComposer::PluginEditorCheckBeforeSendConfigureWidget(parent)
......@@ -38,6 +39,7 @@ ConfirmAddressConfigureWidget::ConfirmAddressConfigureWidget(QWidget *parent)
mConfirmAddressConfigureTab = new ConfirmAddressConfigureTab(this);
mConfirmAddressConfigureTab->setObjectName(QStringLiteral("confirmaddresstab"));
connect(mConfirmAddressConfigureTab, &ConfirmAddressConfigureTab::configureChanged, this, &ConfirmAddressConfigureWidget::configureChanged);
vboxlayout->addWidget(mConfirmAddressConfigureTab);
}
......@@ -48,27 +50,27 @@ ConfirmAddressConfigureWidget::~ConfirmAddressConfigureWidget()
void ConfirmAddressConfigureWidget::loadSettings()
{
#if 0
KConfigGroup grp(KSharedConfig::openConfig(), "Confirm Address");
mEnable->setChecked(grp.readEntry("Enabled", false));
mDomainNameListEditor->setStringList(grp.readEntry("Domains", QStringList()));
mWhiteListEditor->setStringList(grp.readEntry("Emails", QStringList()));
#endif
mConfirmAddressConfigureTab->loadSettings(grp);
}
void ConfirmAddressConfigureWidget::saveSettings()
{
#if 0
KConfigGroup grp(KSharedConfig::openConfig(), "Confirm Address");
KSharedConfig::Ptr config = KSharedConfig::openConfig();
// first, delete all filter groups:
const QStringList filterGroups = config->groupList().filter(QRegularExpression(QLatin1String("Confirm Address \\d+")));
Q_FOREACH (const QString &group, filterGroups) {
config->deleteGroup(group);
}
KConfigGroup grp(config, "Confirm Address");
grp.writeEntry("Enabled", mEnable->isChecked());
grp.writeEntry("Domains", mDomainNameListEditor->stringList());
grp.writeEntry("Emails", mWhiteListEditor->stringList());
#endif
mConfirmAddressConfigureTab->saveSettings(grp);
}
void ConfirmAddressConfigureWidget::resetSettings()
{
//TODO
mConfirmAddressConfigureTab->resetSettings();
}
void ConfirmAddressConfigureWidget::slotEnableChanged(bool state)
......
......@@ -25,6 +25,9 @@
#include <KConfigGroup>
#include <KSharedConfig>
#include <KIdentityManagement/IdentityManager>
#include <KIdentityManagement/Identity>
ConfirmAddressInterface::ConfirmAddressInterface(QObject *parent)
: MessageComposer::PluginEditorCheckBeforeSendInterface(parent),
mEnabled(false)
......@@ -41,7 +44,11 @@ bool ConfirmAddressInterface::exec(const MessageComposer::PluginEditorCheckBefor
{
if (mEnabled) {
// not configurated => validate it.
if (mDomains.isEmpty() && mWhiteLists.isEmpty()) {
if (!mHashSettings.contains(params.identity())) {
return true;
}
const ConfirmAddressSettings settings = mHashSettings.value(params.identity());
if (settings.mDomains.isEmpty() && settings.mWhiteLists.isEmpty()) {
return true;
}
#ifdef USE_PLUGIN
......@@ -62,9 +69,18 @@ bool ConfirmAddressInterface::exec(const MessageComposer::PluginEditorCheckBefor
void ConfirmAddressInterface::reloadConfig()
{
//TODO use identity ?
KConfigGroup grp(KSharedConfig::openConfig(), "Confirm Address");
mEnabled = grp.readEntry("Enabled", false);
mDomains = grp.readEntry("Domains", QStringList());
mWhiteLists = grp.readEntry("Emails", QStringList());
mHashSettings.clear();
KIdentityManagement::IdentityManager manager(true);
KIdentityManagement::IdentityManager::ConstIterator end = manager.end();
for (KIdentityManagement::IdentityManager::ConstIterator it = manager.begin(); it != end; ++it) {
const uint identity = (*it).uoid();
KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(identity));
ConfirmAddressSettings settings;
settings.mDomains = identityGroup.readEntry("Domains", QStringList());
settings.mWhiteLists = identityGroup.readEntry("Emails", QStringList());
mHashSettings.insert(identity, settings);
}
}
......@@ -21,7 +21,7 @@
#define CONFIRMADDRESSINTERFACE_H
#include <MessageComposer/PluginEditorCheckBeforeSendInterface>
#include <QHash>
class ConfirmAddressInterface : public MessageComposer::PluginEditorCheckBeforeSendInterface
{
Q_OBJECT
......@@ -35,8 +35,15 @@ public Q_SLOTS:
private:
bool mEnabled;
QStringList mDomains;
QStringList mWhiteLists;
struct ConfirmAddressSettings
{
QStringList mDomains;
QStringList mWhiteLists;
};
QHash<uint, ConfirmAddressSettings> mHashSettings;
};
#endif // CONFIRMADDRESSINTERFACE_H
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