dkimpolicywidget.cpp 5.57 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2019-2020 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "dkimpolicywidget.h"
21 22
#include <KLocalizedString>
#include <QCheckBox>
Laurent Montel's avatar
Laurent Montel committed
23
#include <QVBoxLayout>
Laurent Montel's avatar
Laurent Montel committed
24
#include <MessageViewer/DKIMManageRulesDialog>
25 26
#include "messageviewer/messageviewersettings.h"
#include <PimCommon/ConfigureImmutableWidgetUtils>
Laurent Montel's avatar
Laurent Montel committed
27 28
#include <QPointer>
#include <QPushButton>
29 30 31

using namespace PimCommon::ConfigureImmutableWidgetUtils;

Laurent Montel's avatar
Laurent Montel committed
32 33 34 35 36 37
DKIMPolicyWidget::DKIMPolicyWidget(QWidget *parent)
    : QWidget(parent)
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->setObjectName(QStringLiteral("mainLayout"));
    mainLayout->setContentsMargins(0, 0, 0, 0);
38 39 40 41

    mVerifyIfEmailMustBeSigned = new QCheckBox(i18n("Check if e-mail should be signed"), this);
    mVerifyIfEmailMustBeSigned->setObjectName(QStringLiteral("mVerifyIfEmailMustBeSigned"));
    mainLayout->addWidget(mVerifyIfEmailMustBeSigned);
Laurent Montel's avatar
Laurent Montel committed
42
    connect(mVerifyIfEmailMustBeSigned, &QCheckBox::toggled, this, [this](bool state) {
43
        mUseDMARC->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
44
        mUseDefaultRules->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
45
        mRulesButton->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
46
        mAutoGenerateOnlyIfSenderInSDID->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
47
        mAutoGenerateRule->setEnabled(state);
48
        mReadAuthResultHeader->setEnabled(state);
49 50 51 52 53 54 55
    });

    mUseDMARC = new QCheckBox(i18n("Use DMARC to heuristically determine if an e-mail should be signed"), this);
    mUseDMARC->setObjectName(QStringLiteral("mUseDMARC"));
    mUseDMARC->setEnabled(false);
    mainLayout->addWidget(mUseDMARC);

56 57 58 59 60 61 62 63 64 65
    mReadAuthResultHeader = new QCheckBox(i18n("Read Authentication-Results header"), this);
    mReadAuthResultHeader->setObjectName(QStringLiteral("mReadAuthResultHeader"));
    mReadAuthResultHeader->setEnabled(false);
    mainLayout->addWidget(mReadAuthResultHeader);

    mUseDefaultRules = new QCheckBox(i18n("Use default rule"), this);
    mUseDefaultRules->setObjectName(QStringLiteral("mUseDefaultRules"));
    mUseDefaultRules->setEnabled(false);
    mainLayout->addWidget(mUseDefaultRules);

Laurent Montel's avatar
Laurent Montel committed
66 67 68 69 70
    mAutoGenerateRule = new QCheckBox(i18n("Autogenerate rule"), this);
    mAutoGenerateRule->setObjectName(QStringLiteral("mAutoGenerateRule"));
    mAutoGenerateRule->setEnabled(false);
    mainLayout->addWidget(mAutoGenerateRule);

Laurent Montel's avatar
Laurent Montel committed
71 72
    //TODO Add spacer
    mAutoGenerateOnlyIfSenderInSDID = new QCheckBox(QStringLiteral("    ") + i18n("Autogenerate when Sender in SDID"), this);
Laurent Montel's avatar
Laurent Montel committed
73 74 75 76
    mAutoGenerateOnlyIfSenderInSDID->setObjectName(QStringLiteral("mAutoGenerateOnlyIfSenderInSDID"));
    mAutoGenerateOnlyIfSenderInSDID->setEnabled(false);
    mainLayout->addWidget(mAutoGenerateOnlyIfSenderInSDID);

Laurent Montel's avatar
Laurent Montel committed
77 78 79 80 81 82 83
    QHBoxLayout *ruleLayout = new QHBoxLayout;
    mainLayout->addLayout(ruleLayout);
    mRulesButton = new QPushButton(i18n("Show Rules"), this);
    mRulesButton->setObjectName(QStringLiteral("rules"));
    mRulesButton->setEnabled(false);
    ruleLayout->addWidget(mRulesButton);
    connect(mRulesButton, &QPushButton::clicked, this, [this]() {
Laurent Montel's avatar
Laurent Montel committed
84
        QPointer<MessageViewer::DKIMManageRulesDialog> dlg = new MessageViewer::DKIMManageRulesDialog(this);
Laurent Montel's avatar
Laurent Montel committed
85 86 87 88 89
        dlg->exec();
        delete dlg;
    });
    ruleLayout->addStretch(1);

90
    mainLayout->addStretch(1);
Laurent Montel's avatar
Laurent Montel committed
91 92 93 94 95
}

DKIMPolicyWidget::~DKIMPolicyWidget()
{
}
96 97 98 99 100

void DKIMPolicyWidget::loadSettings()
{
    loadWidget(mVerifyIfEmailMustBeSigned, MessageViewer::MessageViewerSettings::self()->checkIfEmailShouldBeSignedItem());
    loadWidget(mUseDMARC, MessageViewer::MessageViewerSettings::self()->useDMarcItem());
Laurent Montel's avatar
Laurent Montel committed
101
    loadWidget(mUseDefaultRules, MessageViewer::MessageViewerSettings::self()->useDefaultRulesItem());
Laurent Montel's avatar
Laurent Montel committed
102
    loadWidget(mAutoGenerateRule, MessageViewer::MessageViewerSettings::self()->autogenerateRuleItem());
103
    loadWidget(mReadAuthResultHeader, MessageViewer::MessageViewerSettings::self()->useAuthenticationResultsItem());
Laurent Montel's avatar
Laurent Montel committed
104
    loadWidget(mAutoGenerateOnlyIfSenderInSDID, MessageViewer::MessageViewerSettings::self()->autogenerateRuleOnlyIfSenderOnSDIDItem());
105 106 107 108 109 110
}

void DKIMPolicyWidget::saveSettings()
{
    saveCheckBox(mVerifyIfEmailMustBeSigned, MessageViewer::MessageViewerSettings::self()->checkIfEmailShouldBeSignedItem());
    saveCheckBox(mUseDMARC, MessageViewer::MessageViewerSettings::self()->useDMarcItem());
Laurent Montel's avatar
Laurent Montel committed
111
    saveCheckBox(mUseDefaultRules, MessageViewer::MessageViewerSettings::self()->useDefaultRulesItem());
Laurent Montel's avatar
Laurent Montel committed
112
    saveCheckBox(mAutoGenerateRule, MessageViewer::MessageViewerSettings::self()->autogenerateRuleItem());
113
    saveCheckBox(mReadAuthResultHeader, MessageViewer::MessageViewerSettings::self()->useAuthenticationResultsItem());
Laurent Montel's avatar
Laurent Montel committed
114
    saveCheckBox(mAutoGenerateOnlyIfSenderInSDID, MessageViewer::MessageViewerSettings::self()->autogenerateRuleOnlyIfSenderOnSDIDItem());
115 116 117 118 119 120 121 122
}

void DKIMPolicyWidget::resetSettings()
{
    const bool bUseDefaults = MessageViewer::MessageViewerSettings::self()->useDefaults(true);
    loadSettings();
    MessageViewer::MessageViewerSettings::self()->useDefaults(bUseDefaults);
}